Skip to content Skip to sidebar Skip to footer

Opencv(4.0.0) Python Error: (-215:assertion Failed) (mtype == Cv_8u || Mtype == Cv_8s) && _mask.samesize(*psrc1) In Function 'cv::binary_op'

I am trying to apply mask on an image using opencv bitwise-not. I am able to achieve this result if I read both original and mask image in Greyscale mode, but it doesn't work on 3

Solution 1:

As the error hints, the problem actually is the mask shape. From the docs:

mask – optional operation mask, 8-bit single channel array, that specifies elements of the output array to be changed.

Your label is a 3-channel image, which is incompatible; that's the reason why the greyscale was working, but since your Mask.png actually is a black and white image you should go for it without any worries:

label = cv2.imread("Mask.png", cv2.IMREAD_GREYSCALE)

Post a Comment for "Opencv(4.0.0) Python Error: (-215:assertion Failed) (mtype == Cv_8u || Mtype == Cv_8s) && _mask.samesize(*psrc1) In Function 'cv::binary_op'"