1. 程式人生 > >opencv rtsp 人臉識別

opencv rtsp 人臉識別

import cv2
import dlib
import json
face_detector = dlib.get_frontal_face_detector()

cap = cv2.VideoCapture("rtsp://admin:[email protected]:554/h264/ch6/main/av_stream")

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

ret,frame = cap.read()
while ret:
ret,frame = cap.read()
#frame = cv2.imread('r.jpg')
cv2.imshow("frame",frame)

gray = frame#cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)


faces=face_detector(gray)
# print faces
for i in faces:
#print i.left(),i.right()
f=gray[i.top()-20: i.bottom()+20 , i.left()-20 : i.right()+20,:]
cv2.imshow('face',f)
#cv2.imwrite('2.jpg',f)

 

if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
cap.release()