В моем коде есть какая-то ошибка при использовании маски в cv2 - PullRequest
0 голосов
/ 24 сентября 2019
  1. Это код

import numpy as np  
import argparse  
import cv2

ap= argparse.ArgumentParser()  
ap.add_argument("-i", "-image", required= True, help= "Enter path of image")  
args= vars(ap.parse_args())  

image= cv2.imread("2.coin.jpeg")  
cv2.imshow("origional image", image)  
cv2.waitKey(0)  

blurred= cv2.GaussianBlur(image, (5, 5), 0)  
cv2.imshow("Gaussian blur", blurred)  

(T, thresh)= cv2.threshold(blurred, 155, 255, cv2.THRESH_BINARY)  
cv2.imshow("Threshold binary", thresh)  

(T, threshInv)= cv2.threshold(blurred, 155, 255, cv2.THRESH_BINARY_INV) 
cv2.imshow("Threshold Inv binary", threshInv)  
cv2.waitKey(0)  

cv2.imshow("only cat", cv2.bitwise_and(image, image, mask= threshInv))  
cv2.waitKey(0)  
Это ошибка
 File "Threshold.py", line 25, in <module>
    cv2.imshow("only cat", cv2.bitwise_and(image, image, mask= thresh))
cv2.error: OpenCV(4.1.1) /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'

https://www.google.com/imgres?imgurl=https%3A%2F%2Fimage.shutterstock.com%2Fimage-photo%2Fsouth-african-rands-coins-collection-260nw-493233256.jpg&imgrefurl=https%3A%2F%2Fwww.shutterstock.com%2Fsearch%2Fsouth%2Bafrican%2Bcoins&docid=QblUHdnrK9fmmM&tbnid=i8wVEEFiCLTWCM%3A&vet=10ahUKEwjntcjTjurkAhVN7nMBHbSxAb0QMwiIAihSMFI..i&w=518&h=280&bih=754&biw=1536&q=coins&ved=0ahUKEwjntcjTjurkAhVN7nMBHbSxAb0QMwiIAihSMFI&iact=mrc&uact=8

...