使用Python+OpenCV+Dlib實現(xiàn)人臉檢測與人臉特征關鍵點識別
太棒了,但我們能做點更酷的事嗎?步驟4:實時檢測是的,你沒看錯!這可能就是你想要的效果!下一步是連接我們的網(wǎng)絡攝像頭,從你的視頻流中進行實時地關鍵點識別。你可以通過使用相機遍歷視頻幀或使用視頻文件來對面部進行實時面部關鍵點檢測。如果要使用自己的攝像機,請參考以下代碼,如果使用的是視頻文件,請確保將數(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 ☆

請輸入評論內容...
請輸入評論/評論長度6~500個字
最新活動更多
-
7月22-29日立即報名>> 【線下論壇】第三屆安富利汽車生態(tài)圈峰會
-
7.30-8.1火熱報名中>> 全數(shù)會2025(第六屆)機器人及智能工廠展
-
7月31日免費預約>> OFweek 2025具身智能機器人產(chǎn)業(yè)技術創(chuàng)新應用論壇
-
免費參會立即報名>> 7月30日- 8月1日 2025全數(shù)會工業(yè)芯片與傳感儀表展
-
即日-2025.8.1立即下載>> 《2024智能制造產(chǎn)業(yè)高端化、智能化、綠色化發(fā)展藍皮書》
-
8月5日立即報名>> 【在線會議】CAE優(yōu)化設計:醫(yī)療器械設計的應用案例與方案解析
推薦專題