我遇到以下错误:
File "rropcode.py", line 35, in <module>
imgHSV = cv2.cvtColor(entrada, cv2.COLOR_BGR2HSV)
cv2.error: /home/pi/opencv-3.3.0/modules/imgproc/src/color.cpp:10705: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cvtColor
我已经尝试了该主题的其他解决方案,但是没有一个起作用。
这是我的代码
import cv2
import time
import numpy as np
import RPi.GPIO as gpio
Hmin = 42
Hmax = 92
Smin = 62
Smax = 255
Vmin = 63
Vmax = 235
rangeMin = np.array([Hmin, Smin, Vmin], np.uint8)
rangeMax = np.array([Hmax, Smax, Vmax], np.uint8)
minArea = 50
cv2.namedWindow("Entrada")
cv2.namedWindow("HSV")
cv2.namedWindow("Thre")
cv2.namedWindow("Erosao")
width = 160
height = 120
capture = cv2.VideoCapture(0)
if capture.isOpened():
capture.set(cv2.CV_CAP_PROP_FRAME_WIDTH, width)
capture.set(cv2.CV_CAP_PROP_FRAME_HEIGHT, height)
while True:
ret, entrada = capture.read()
# I'M HAVING AN ISSUE IN THE NEXT LINE
**imgHSV = cv2.cvtColor(entrada, cv2.COLOR_BGR2HSV)**
imgThresh = cv2.inRange(imgHSV, rangeMin, rangeMax)
imgErode = cv2.erode(imgThresh, None, iterations = 3)
以粗体标出的行抛出上述错误。
答案 0 :(得分:0)
这在评论中要处理很久,因此我将在此处临时进行。您可以测试此代码并告诉您是否看到图像或看到哪些打印语句吗?
import cv2
import numpy as np
capture = cv2.VideoCapture(0)
if capture.isOpened():
print("Camera openend")
ret, img = capture.read()
if ret:
print("Image read")
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()