Я разрабатываю приложение в 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()