Open CV Error: Assertion failed (scn ==2 && depth == CV_8U) in cvtColor
Hi all,
I'm trying to read a 16-bit float exr image and convert it into grayscale for further image processing using openCV in python 2.7, however I encounter the above error "OpenCV Error: Assertion failed (scn == 2 && depth == CV_8U) in cvtColor"
Below is my code snippet
# load the image and convert it to grayscale
image = cv2.imread(args["image"],cv2.IMREAD_UNCHANGED)
gray = cv2.cvtColor(image, cv2.COLOR_BGR5552GRAY)
I have tried to use numpy to convert it to an unsigned 16-bit int using the below line but still am getting the same error
imageCopy = np.uint16(image)
I have tried to use cv2.COLOR_BGR5552GRAY
, cv2.COLOR_BGR5652GRAY
and cv2.COLOR_BGR2GRAY
but to no avail.
Any help would be highly appreciated.
Thanks!
are you sure, your input image was ever read properly ?
print out:
np.shape(image)
it's either empty, or not bgr555 (2 channels)
also, IF it is 16bit float exr, COLOR_BGR5552GRAY is the wrong flag (it expects 2 uint8 values per pixel)
Thanks for replying Berak. Initially I began by using the sinple method BGR2GRAY and could view the image using imshow(). I have an RGBA (4 channel) 16-bit depth float EXR inage that I'm using for my tests. So what would be the correct way to process this image or make it ready for further processing using openCV? Also which is the correct method to be used for the above 16-bit 4 channel RGBA EXR image to convert it from Color to grayscale?
BGR2GRAY is ok, for that.