0
我有一个代码来检测两种颜色绿色和蓝色。我要检查,如果检测 绿色打印的按摩,如果检测蓝色彩色打印,另一条消息也检查颜色Opencv Python
这里是代码:
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
# Take each frame
_, frame = cap.read()
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of blue color in HSV
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
lower_green = np.array([50, 50, 120])
upper_green = np.array([70, 255, 255])
green_mask = cv2.inRange(hsv, lower_green, upper_green) # I have the Green threshold image.
# Threshold the HSV image to get only blue colors
blue_mask = cv2.inRange(hsv, lower_blue, upper_blue)
mask = blue_mask + green_mask
############this is the Error ####################
if mask==green_mask:
print "DOne"
################################################
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
运行上面的代码给我下面的错误:
if mask==green_mask:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
任何想法如何解决这个问题?
你的意思是我需要写这个如果在一个函数中的条件,并调用它,即时通讯抱歉,我需要eny提示这个函数@MD。 Nazmul Kibria –
看到我的编辑....希望能解决您的问题 –
非常感谢它很有效 如果您介意给我发电子邮件更多Qustions plez @MD。 Nazmul Kibria –