. Advertisement .
. Advertisement .
When users try to run the software, they want to know more about this error: “error: (-215:Assertion failed)! src.empty() in function ‘cvtColor’“.
It is one popular problem shared by all developers. So, what exactly is this, and how can it be fixed? We’ll go over everything with you.
When Does The Error “error: (-215:Assertion failed) !_src.empty() in function ‘cvtColor’” Happen?
You are attempting to read an Image in Python using openCV, but you encounter the following error.
“cv2.error: OpenCV(3.4.3) /Users/ssc/build/skvark/opencv-python/ opencv/modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'”
And here is your code:
“frame = cv2.imread('path' % count)”
Cause of error?
Here are some possible causes of the error: 0
– Your camera is not connected.
– cap.read() has failed.
– Syntax error (mistaken “.”)
Some Basic Solutions
Here are some solutions for you.
It’s extremely easy to use. Let’s look at an example to learn more about this. In Windows Python, prefix file names with r”……,” as in
im = cv2.imread("D:\My_Image\CANON80D\dang\fvrt.jpg",1)
Check that Image is properly loaded. This error occurs whenever an image fails to load properly or when you check to see if the images exist in the path you specify and ensure that the count variable contains a valid number.
You can check to see if the image exists and try again.
import numpy as np import cv2 img = cv2.imread('your_image.png', 0) cv2.imshow('image', img)
If you are having the same issue when trying to read one frame from the webcam, check to see if the webcam would be used for another assignment and close it. This will resolve the issue.
We spent a lot of precious time dealing with this mistake after discovering the camera was available on the internet in a Google Hangouts collective. Additionally, ensure that the video camera drivers are updated.
Following these steps:
img = cv2.imread(img_path)
print(img) or print(img.shape)
For those who are still bothered by this issue, the method depicted in the figure above has proven to be the most useful: “error: (-215:Assertion failed) !_src.empty() in function ‘cvtColor’“.
If you still need help or have frequent questions, we have a lively group where everyone is always willing to help. Finally, we wish you a wonderful session full of inventive code solutions.
Leave a comment