使用Python+OpenCV+Dlib實現(xiàn)人臉檢測與人臉特征關(guān)鍵點識別
太棒了,但我們能做點更酷的事嗎?步驟4:實時檢測是的,你沒看錯!這可能就是你想要的效果!下一步是連接我們的網(wǎng)絡(luò)攝像頭,從你的視頻流中進(jìn)行實時地關(guān)鍵點識別。你可以通過使用相機(jī)遍歷視頻幀或使用視頻文件來對面部進(jìn)行實時面部關(guān)鍵點檢測。如果要使用自己的攝像機(jī),請參考以下代碼,如果使用的是視頻文件,請確保將數(shù)字0更改為視頻路徑。如果要結(jié)束窗口,請按鍵盤上的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é)果是:
在弱光條件下,盡管上面的圖像中有一些錯誤,但其結(jié)果也相當(dāng)準(zhǔn)確,如果照明效果好的話結(jié)果會更加準(zhǔn)確。結(jié)論OpenCV和DLib是兩個功能非常強(qiáng)大的庫,它們簡化了ML和計算機(jī)視覺的工作,今天我們只是觸及了最基本的東西,還有很多東西需要從中學(xué)習(xí)。非常感謝你的閱讀!
☆ END ☆

請輸入評論內(nèi)容...
請輸入評論/評論長度6~500個字
最新活動更多
推薦專題
- 1 UALink規(guī)范發(fā)布:挑戰(zhàn)英偉達(dá)AI統(tǒng)治的開始
- 2 北電數(shù)智主辦酒仙橋論壇,探索AI產(chǎn)業(yè)發(fā)展新路徑
- 3 降薪、加班、裁員三重暴擊,“AI四小龍”已折戟兩家
- 4 “AI寒武紀(jì)”爆發(fā)至今,五類新物種登上歷史舞臺
- 5 國產(chǎn)智駕迎戰(zhàn)特斯拉FSD,AI含量差幾何?
- 6 光計算迎來商業(yè)化突破,但落地仍需時間
- 7 東陽光:2024年扭虧、一季度凈利大增,液冷疊加具身智能打開成長空間
- 8 地平線自動駕駛方案解讀
- 9 封殺AI“照騙”,“淘寶們”終于不忍了?
- 10 優(yōu)必選:營收大增主靠小件,虧損繼續(xù)又逢關(guān)稅,能否乘機(jī)器人東風(fēng)翻身?