訂閱
糾錯
加入自媒體

使用Python+OpenCV+Dlib實現(xiàn)人臉檢測與人臉特征關鍵點識別

太棒了,但我們能做點更酷的事嗎?步驟4:實時檢測是的,你沒看錯!這可能就是你想要的效果!下一步是連接我們的網絡攝像頭,從你的視頻流中進行實時地關鍵點識別。你可以通過使用相機遍歷視頻幀或使用視頻文件來對面部進行實時面部關鍵點檢測。如果要使用自己的攝像機,請參考以下代碼,如果使用的是視頻文件,請確保將數(shù)字0更改為視頻路徑。如果要結束窗口,請按鍵盤上的ESC鍵:import cv2import dlib
# Load the detectordetector = dlib.get_frontal_face_detector()
# Load the predictorpredictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
# read the imagecap = cv2.VideoCapture(0)
while True:    _, frame = cap.read()    # Convert image into grayscale    gray = cv2.cvtColor(src=frame, code=cv2.COLOR_BGR2GRAY)
   # Use detector to find landmarks    faces = detector(gray)
   for face in faces:        x1 = face.left()  # left point        y1 = face.top()  # top point        x2 = face.right()  # right point        y2 = face.bottom()  # bottom point
       # Create landmark object        landmarks = predictor(image=gray, box=face)
       # Loop through all the points        for n in range(0, 68):            x = landmarks.part(n).x            y = landmarks.part(n).y
           # Draw a circle            cv2.circle(img=frame, center=(x, y), radius=3, color=(0, 255, 0), thickness=-1)
   # show the image    cv2.imshow(winname="Face", mat=frame)
   # Exit when escape is pressed    if cv2.waitKey(delay=1) == 27:        break
# When everything done, release the video capture and video write objectscap.release()
# Close all windowscv2.destroyAllWindows()最后的結果是:

在弱光條件下,盡管上面的圖像中有一些錯誤,但其結果也相當準確,如果照明效果好的話結果會更加準確。結論OpenCV和DLib是兩個功能非常強大的庫,它們簡化了ML和計算機視覺的工作,今天我們只是觸及了最基本的東西,還有很多東西需要從中學習。非常感謝你的閱讀!


☆ END ☆

<上一頁  1  2  3  
聲明: 本文由入駐維科號的作者撰寫,觀點僅代表作者本人,不代表OFweek立場。如有侵權或其他問題,請聯(lián)系舉報。

發(fā)表評論

0條評論,0人參與

請輸入評論內容...

請輸入評論/評論長度6~500個字

您提交的評論過于頻繁,請輸入驗證碼繼續(xù)

暫無評論

暫無評論

    掃碼關注公眾號
    OFweek人工智能網
    獲取更多精彩內容
    文章糾錯
    x
    *文字標題:
    *糾錯內容:
    聯(lián)系郵箱:
    *驗 證 碼:

    粵公網安備 44030502002758號