我只是将蒙版加在一起,并用它
np.where来蒙版原始图像。
img=cv2.imread("img.bmp")img_hsv=cv2.cvtColor(img, cv2.COLOR_BGR2HSV)# lower mask (0-10)lower_red = np.array([0,50,50])upper_red = np.array([10,255,255])mask0 = cv2.inRange(img_hsv, lower_red, upper_red)# upper mask (170-180)lower_red = np.array([170,50,50])upper_red = np.array([180,255,255])mask1 = cv2.inRange(img_hsv, lower_red, upper_red)# join my masksmask = mask0+mask1# set my output img to zero everywhere except my maskoutput_img = img.copy()output_img[np.where(mask==0)] = 0# or your HSV image, which I *believe* is what you wantoutput_hsv = img_hsv.copy()output_hsv[np.where(mask==0)] = 0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)