cv2.error:OpenCV(4.5.2)error:(-215:Assertion failed)!_src.empty() in function 'cv::cvtColor'

Asked 2 years ago, Updated 2 years ago, 148 views

This error occurred while implementing Mask-RCNN.
I am sorry for the poor writing, but I look forward to hearing from you.

error messages:

 cv2.error: OpenCV(4.5.2) error:(-215: Assertion failed)!_src.empty() in function 'cv::cvtColor'

Where the error message points:

 image=cv2.imread("images/image.jpg")
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
image=imutils.resize (image, width=512)

running environment:

tensorflow:1.14.0
tensorflow-gpu:1.14.0
keras —2.1.5
opencv-python:4.5.2.52

python python3 opencv anaconda

2022-09-30 19:53

1 Answers

Could it be that simply imread() has failed to load the image and passed an empty matrix to the first argument src of cvtColor()?
OpenCV imread() returns an empty matrix if it fails (although it is hard to understand why it does not throw an exception).

These problems are usually encountered by others, and it is recommended that you search for them first, as you often find a solution as soon as you Google the full text or part of the error message.

However, without having to go out of your way to search for this assertion error, calmly reading the error message and comparing it to API references, or tracking variables through debugger and print() functions should be an easy problem.

assertion (assertion) describes a conditional expression that must be met (must be true) during execution of the program, such as preconditions and postconditions, and if it becomes false, it is assumed that there is a bug in the logic.

Depending on the programming language and development environment, error messages may be carefully localized into Japanese, but most of them are in English.If you can't read English, it's a pre-programming problem, so please learn English first.Most of the English used in technical documents is simple syntax, and at least high school level English skills are enough to manage.If you don't understand a word, you can search the web.There is also machine translation, but I do not recommend the translation from English to Japanese because it is still not accurate and I often make a curious translation.


2022-09-30 19:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.