我已經在Spyder Python 2.7上安裝了Opencv 3.1.4,它們都運行在Windows Vista 32位上。錯誤Spyder Python + opencv 3
我的代碼是
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
感謝的
版本3.1應該可以工作。在你的代碼中,我只能看到需要更改的flags屬性。 – ibininja