【发布时间】:2015-12-31 17:23:50
【问题描述】:
我在 Spyder Python 2.7 上安装了 Opencv 3.1.4,全部运行在 32 位 Windows Vista 上。
我的代码是
import cv2
import sys
cascPath = "C:\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
video_capture = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_DO_CANNY_PRUNING
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the resulting frame
cv2.imshow('Video', frame)
print faces
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
但是我有这个错误
runfile('C:/Anaconda2/Scripts/tracking-video-fonctionnel.py', wdir='C:/Anaconda2/Scripts')
Traceback (most recent call last):
File "<ipython-input-2-3b1671aa3a09>", line 1, in <module>
runfile('C:/Anaconda2/Scripts/tracking-video-fonctionnel.py', wdir='C:/Anaconda2/Scripts')
File "C:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "C:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Anaconda2/Scripts/tracking-video-fonctionnel.py", line 20, in <module>
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
error: C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\imgproc\src\color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor
但是,此代码在具有相同 spyder 和 opencv 但在 Windows 7 64 位的另一台计算机上运行
我认为问题出在 opencv 上,因为我无法导入 cv2.cv 但我可以导入 cv2
谢谢
【问题讨论】: