我正在尝试使用python opencv来寻找面孔

时间:2018-03-27 07:09:26

标签: python opencv

我已经安装了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吗? 我需要在从网络摄像头拍摄时找到面孔。

0 个答案:

没有答案