OpenCV VideoCapture运行缓慢

时间:2018-09-04 10:21:18

标签: python-2.7 opencv3.0

我正在python(ver-2.7)中开发一个应用程序,用于使用opencv3进行实时人脸检测。目前,我可以使用VideoCapture(1)访问视频流,但是实时视频的加载速度非常慢。

    import cv2
    import time
    detector=cv2.CascadeClassifier('lbpcascade_frontalface.xml')
    cam=cv2.VideoCapture(1)
    cam.open("http://root:admin@192.168.1.201/mjpg/video.mjpg")
    Id=raw_input('enter your id')
    sampleNum=0
    while(True):
       ret, img = cam.read()
       gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
       faces = detector.detectMultiScale(gray, 1.2,3)
       for (x,y,w,h) in faces:
         cv2.rectangle(img,(x,y),(x+w,y+h),(255,255,0),2)
         #incrementing sample number 
         sampleNum=sampleNum+1
         #saving the captured face in the dataset folder        
         cv2.imwrite("dataset/User."+Id +'.'+ str(sampleNum) + ".jpg", 
         gray[y:y+h,x:x+w])
         cv2.imshow('frame',img)   
      if cv2.waitKey(100) & 0xFF == ord('q'):
         break

     elif sampleNum>19:
         break

    cam.release()
    cv2.destroyAllWindows()

0 个答案:

没有答案