python實現圖片,視頻人臉識別(dlib版)
圖片人臉檢測
#coding=utf-8import cv2import dlibpath = 'img/meinv.png'img = cv2.imread(path)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)#人臉分類器detector = dlib.get_frontal_face_detector()# 獲取人臉檢測器predictor = dlib.shape_predictor( 'C:Python36Libsite-packagesdlib-datashape_predictor_68_face_landmarks.dat')dets = detector(gray, 1)for face in dets: shape = predictor(img, face) # 尋找人臉的68個標定點 # 遍歷所有點,打印出其坐標,并圈出來 for pt in shape.parts(): pt_pos = (pt.x, pt.y) cv2.circle(img, pt_pos, 2, (0, 255, 0), 1) cv2.imshow('image', img)cv2.waitKey(0)cv2.destroyAllWindows()
視頻人臉檢測
# coding=utf-8import cv2import dlibdetector = dlib.get_frontal_face_detector() #使用默認的人類識別器模型def discern(img): gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) dets = detector(gray, 1) for face in dets: left = face.left() top = face.top() right = face.right() bottom = face.bottom() cv2.rectangle(img, (left, top), (right, bottom), (0, 255, 0), 2) cv2.imshow('image', img)cap = cv2.VideoCapture(0)while (1): ret, img = cap.read() discern(img) if cv2.waitKey(1) & 0xFF == ord(’q’): breakcap.release()cv2.destroyAllWindows()
那么,OpenCV和Dlib的視頻識別對比,有兩個地方是不同的:
1.Dlib模型識別的準確率和效果要好于OpenCV;
2.Dlib識別的性能要比OpenCV差,使用視頻測試的時候Dlib有明顯的卡頓,但是OpenCV就好很多,基本看不出來;
以上就是python實現圖片,視頻人臉識別(dlib版)的詳細內容,更多關于python 人臉識別的資料請關注好吧啦網其它相關文章!
相關文章:
