訂閱
糾錯(cuò)
加入自媒體

使用Python+OpenCV+Dlib實(shí)現(xiàn)人臉檢測(cè)與人臉特征關(guān)鍵點(diǎn)識(shí)別

太棒了,但我們能做點(diǎn)更酷的事嗎?步驟4:實(shí)時(shí)檢測(cè)是的,你沒看錯(cuò)!這可能就是你想要的效果!下一步是連接我們的網(wǎng)絡(luò)攝像頭,從你的視頻流中進(jìn)行實(shí)時(shí)地關(guān)鍵點(diǎn)識(shí)別。你可以通過(guò)使用相機(jī)遍歷視頻幀或使用視頻文件來(lái)對(duì)面部進(jìn)行實(shí)時(shí)面部關(guān)鍵點(diǎn)檢測(cè)。如果要使用自己的攝像機(jī),請(qǐng)參考以下代碼,如果使用的是視頻文件,請(qǐng)確保將數(shù)字0更改為視頻路徑。如果要結(jié)束窗口,請(qǐng)按鍵盤上的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()最后的結(jié)果是:

在弱光條件下,盡管上面的圖像中有一些錯(cuò)誤,但其結(jié)果也相當(dāng)準(zhǔn)確,如果照明效果好的話結(jié)果會(huì)更加準(zhǔn)確。結(jié)論OpenCV和DLib是兩個(gè)功能非常強(qiáng)大的庫(kù),它們簡(jiǎn)化了ML和計(jì)算機(jī)視覺的工作,今天我們只是觸及了最基本的東西,還有很多東西需要從中學(xué)習(xí)。非常感謝你的閱讀!


☆ END ☆

<上一頁(yè)  1  2  3  
聲明: 本文由入駐維科號(hào)的作者撰寫,觀點(diǎn)僅代表作者本人,不代表OFweek立場(chǎng)。如有侵權(quán)或其他問(wèn)題,請(qǐng)聯(lián)系舉報(bào)。

發(fā)表評(píng)論

0條評(píng)論,0人參與

請(qǐng)輸入評(píng)論內(nèi)容...

請(qǐng)輸入評(píng)論/評(píng)論長(zhǎng)度6~500個(gè)字

您提交的評(píng)論過(guò)于頻繁,請(qǐng)輸入驗(yàn)證碼繼續(xù)

  • 看不清,點(diǎn)擊換一張  刷新

暫無(wú)評(píng)論

暫無(wú)評(píng)論

人工智能 獵頭職位 更多
掃碼關(guān)注公眾號(hào)
OFweek人工智能網(wǎng)
獲取更多精彩內(nèi)容
文章糾錯(cuò)
x
*文字標(biāo)題:
*糾錯(cuò)內(nèi)容:
聯(lián)系郵箱:
*驗(yàn) 證 碼:

粵公網(wǎng)安備 44030502002758號(hào)