I am using a opencv to manipulate an image. The exact error is:
OpenCV(4.1.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
I have searched all over the internet but I cannot find a solution to this.
The same image is called multiple times in this process and most part of it works fine. I get an error in this function:
def percentage(image, box_points): #box point is touple here. ((x1,y1),(x2,y2))
x1=box_points[0][0]
x2=box_points[1][0]
y1=box_points[0][1]
y2=box_points[1][1]
rows,cols,c =image.shape
M = cv2.getRotationMatrix2D((cols/2,rows/2),90,1)
image = cv2.warpAffine(image,M,(cols,rows))
image=image[int(x1):int(x2),int(y1):int(y2)]
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# ret, bw_img = cv2.threshold(image,160,255,cv2.THRESH_BINARY)
# bw_img = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 5, 7)
bw_img = cv2.adaptiveThreshold(image,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY,11,2)
# image=image[int(x1):int(x2),int(y1):int(y2)]
# bw_img is our binary image here.
count = cv2.countNonZero(bw_img)
total = bw_img.shape[1] * bw_img.shape[0]
ratio = count/total
ratio =1-ratio
return ratio, bw_img
I get an error in the line where I call cv2.cvtColor. The function gives ratio of black pixels and total pixels. The same image is called several times in this whole project therefore the error should not be related to absence of image.
Also, while testing, I rotated image by 90 degrees counter-clockwise. And this works fine, but just for one specific image. Help me here.
I am attaching original image here. It works when I rotate it by 90 degrees.