0
我在下面的代碼中試圖做的是用python創建一個opencv程序來打開我的筆記本電腦攝像頭和篩選相機,以便它只會顯示我的衣服。但是我偶爾也運行該程序,因爲我遇到了似乎來自代碼第10行的錯誤。這絕對不是一個錯誤的錯誤,我再次檢查它。opencv與python篩選顏色給出錯誤
的代碼示例
#color filtering
import cv2
import numpy as np
#use camera
cap = cv2.VideoCapture(1)
while True:
_, frame = cap.read()
`this line seem to be the source-->` hsv=cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# hsv hue sat value
# try to get the value of the color that you want
lower_red = np.array([150,150,150])
upper_red = np.array([180,255,255])
mask = cv2.inRange(hsv, lower_red, upper_red)
res = cv2.bitwise_and(frame,frame, mask = mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('result',res)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
#release camera
cap.release()
錯誤
Traceback (most recent call last):
File "D:/Program_Files/Python/legit8.py", line 10, in <module>
hsv=cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:10705: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cv::cvtColor
非常感謝你的傢伙應該把這個答案,我會立即給你豎起大拇指:D – jakson
我做了,並刪除了評論,也許我應該保持這個大聲笑很高興有幫助! – magicleon