我已经安装了python和opencv。
import cv2
工作正常,但
import cv
结果
ImportError: No module named 'cv2.cv'; 'cv2' is not a package
我读到python3不再支持cv,但我需要代码
import sys
import cv2
import cv
import numpy
cascPath = "C:\cv/haarcascade_frontalface_default.xml"
cascade = cv2.CascadeClassifier(cascPath)
def detect(image):
bitmap = cv.fromarray(image)
faces = cascade.detectMultiScale(bitmap, cascade, cv.CreateMemStorage(0))
if faces:
for (x,y,w,h),n in faces:
pass
cv2.rectangle(image,(x,y),(x+w,y+h),(255,255,255),2)
return image
if __name__ == "__main__":
cam = cv2.VideoCapture(0)
while 1:
_,frame =cam.read()
frame = numpy.asarray(detect(frame))
cv2.imshow("features", frame)
if cv2.waitKey(10) == 0x1b: # ESC
print ('ESC pressed. Exiting ...')
break
我应该在python2上试试还是有办法没有cv吗? 我需要在从网络摄像头拍摄时找到面孔。