【发布时间】:2016-08-23 09:00:24
【问题描述】:
无论是在虚拟环境还是普通 Python shell 中尝试执行脚本时,我都会收到此消息。
File "/home/pi/facesample1.py", line 10, in <module>
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
error: /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp:8000: error: (-215) scn == 3 || scn == 4 in function cvtColor
这是我的代码:
import cv2
#Load an image from file
image = cv2.imread("fronthead.jpg", 1)
#Load a cascade file for detecting faces
face_cascade = cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml')
#Convert to grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#Look for faces in the image using the loaded cascade file
faces = face_cascade.detectMultiScale(gray, 1.1, 5)
print "Found "+str(len(faces))+" face(s)"
#Draw a rectangle around every found face
for (x,y,w,h) in faces:
cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,0),2)
#Save the result image
cv2.imwrite('camresult.jpg',image)
为什么会出现这个错误?
【问题讨论】:
标签: python c++ opencv raspberry-pi3