Hello Guys, How are you all? Hope You all Are Fine. Today I am just trying to read image through cv2 in my code and I am facing following error cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’ in python. So Here I am Explain to you all the possible solutions here.
Without wasting your time, Let’s start This Article to Solve This Error.
- How cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' Error Occurs ?
- How To Solve cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' Error ?
- Solution 1: Check Image path
- Solution 2: wrong image location
- Solution 3: Give Full Path
- Summary
How cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’ Error Occurs ?
I am just trying to read image through cv2 in my code and I am facing following error.
cv2.error: OpenCV(4.5.2) C:\Users\ssc\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
How To Solve cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’ Error ?
- How To Solve cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’ Error ?
To Solve cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’ Error Please check image path. This error usually occurs when image is not loaded correctly in any way. Second solution is You might given wrong image location. Or esle try to assign diffrent path. Third Solution is I just give full path and that was worked for me.
- cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’
To Solve cv2.error: OpenCV(4.5.2) color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’ Error Please check image path. This error usually occurs when image is not loaded correctly in any way. Second solution is You might given wrong image location. Or esle try to assign diffrent path. Third Solution is I just give full path and that was worked for me.
Solution 1: Check Image path
Please check image path. This error usually occurs when image is not loaded correctly in any way.
Here is how this error occurs.
import cv2
im = cv2.imread("WRONG IMAGE ADDRESS.jpg", 1)
im = cv2.cvtColor(im, cv2.COLOR_RGB2GRAY)
// Now we will face this error.
cv2.error: OpenCV(4.5.2) C:\Users\ssc\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
Try to giving the image address directly; something like
im = cv2.imread("D:\\your_image.jpg", 1)
Solution 2: wrong image location
You might given wrong image location. Or esle try to assign diffrent path.
im = cv2.imread("../images/car.jpg",1)
Solution 3: Give Full Path
I just give full path and that was worked for me.
im = cv2.imread("D:\My_Image\CANON80D\dang\fvrt.jpg",1)
Summary
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read
this is the third time I am commenting on your site and whenever I am stuck with any problem this site’s solution worked for me. Thank you so much, guys.
Ohh, Thank You So Much adam For Your Valuable Words.