-3
import cv2
import numpy as np

img = cv2.imread("Yash.jpeg")
blank = np.zeros(img.shape[:2])

cv2.imshow("YASH", img)
cv2.imshow("Blank", blank)

mask = cv2.circle(blank, (img.shape[1]//2, img.shape[0]//2), 150, 255, -1)
cv2.imshow("Mask", mask)

masked = cv2.bitwise_and(img, img, mask = mask)  # Error in this line
cv2.imshow("MASKED", masked)

cv2.waitKey(0)
cv2.destroyAllWindows()

** Traceback (most recent call last): File "D:/pythonProject1/masing.py", line 13, in masked = cv2.bitwise_or(img, img, mask = mask) cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-i1s8y2i1\opencv\modules\core\src\arithm.cpp:250: error: (-215:Assertion failed) (mtype == CV_8U || mtype == CV_8S) && _mask.sameSize(*psrc1) in function 'cv::binary_op' **

Yash
  • 11
  • 6

1 Answers1

1

Just correct to:

blank = np.zeros(img.shape[:2], dtype='uint8')

The error is a data type error

FrancecoMartino
  • 409
  • 2
  • 5