why do i get this error

asked 2020-08-12 10:35:37 -0600

masked = cv2.bitwise_and(img,img,mask=mask[:,:,2])
cv2_imshow(masked)                   

cv2.waitKey(0)                            # Cleanup after any key is pressed
cv2.destroyAllWindows()

This is my code 👆🏽

error                                     Traceback (most recent call last)
<ipython-input-49-5e3cd31dccb0> in <module>()
      1 #layer 2 is the red layer. Rememeber (B,G,R)
----> 2 masked = cv2.bitwise_and(img,img,mask=mask[:,:,2])
      3 cv2_imshow(masked)
      4 
      5 cv2.waitKey(0)                            # Cleanup after any key is pressed

error: OpenCV(4.1.2) /io/opencv/modules/core/src/arithm.cpp:245: error: (-215:Assertion failed) (mtype == CV_8U || mtype == CV_8S) && _mask.sameSize(*psrc1) in function 'binary_op'

And the error 👆🏽 P.S. I am using Google Colaboratory

edit retag flag offensive close merge delete

Comments

sorry for the downvote, but before asking anywhere, you should try to debug it locally (and use your own head, mate !).

it's either the type or the size, so print that out for all your input arrays (and then probably facepalm ..)

berak gravatar imageberak ( 2020-08-12 10:51:24 -0600 )edit

besides that, you cannot use this code on colab:

cv2.waitKey(0)                            # Cleanup after any key is pressed
cv2.destroyAllWindows()

that's why they have the cv2_imshow() dropin in the 1st place ....

berak gravatar imageberak ( 2020-08-12 11:15:35 -0600 )edit