使用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 ☆
發(fā)表評(píng)論
請(qǐng)輸入評(píng)論內(nèi)容...
請(qǐng)輸入評(píng)論/評(píng)論長(zhǎng)度6~500個(gè)字
最新活動(dòng)更多
-
即日-10.29立即報(bào)名>> 2024德州儀器嵌入式技術(shù)創(chuàng)新發(fā)展研討會(huì)
-
10月31日立即下載>> 【限時(shí)免費(fèi)下載】TE暖通空調(diào)系統(tǒng)高效可靠的組件解決方案
-
即日-11.13立即報(bào)名>>> 【在線會(huì)議】多物理場(chǎng)仿真助跑新能源汽車
-
11月14日立即報(bào)名>> 2024工程師系列—工業(yè)電子技術(shù)在線會(huì)議
-
12月19日立即報(bào)名>> 【線下會(huì)議】OFweek 2024(第九屆)物聯(lián)網(wǎng)產(chǎn)業(yè)大會(huì)
-
即日-12.26火熱報(bào)名中>> OFweek2024中國(guó)智造CIO在線峰會(huì)
推薦專題
- 1 Intel宣布40年來(lái)最重大轉(zhuǎn)型:年底前裁員15000人、拋掉2/3房產(chǎn)
- 2 因美封殺TikTok,字節(jié)股價(jià)骨折!估值僅Meta1/5
- 3 宏山激光重磅發(fā)布行業(yè)解決方案,助力智能制造產(chǎn)業(yè)新飛躍
- 4 國(guó)產(chǎn)AI芯片公司破產(chǎn)!白菜價(jià)拍賣
- 5 具身智能火了,但規(guī)模落地還需時(shí)間
- 6 國(guó)產(chǎn)英偉達(dá)們,抓緊沖刺A股
- 7 三次錯(cuò)失風(fēng)口!OpenAI前員工殺回AI編程賽道,老東家捧金相助
- 8 英特爾賦能智慧醫(yī)療,共創(chuàng)數(shù)字化未來(lái)
- 9 英偉達(dá)的麻煩在后頭?
- 10 將“網(wǎng)紅”變成“商品”,AI“爆改”實(shí)力拉滿
- 高級(jí)軟件工程師 廣東省/深圳市
- 自動(dòng)化高級(jí)工程師 廣東省/深圳市
- 光器件研發(fā)工程師 福建省/福州市
- 銷售總監(jiān)(光器件) 北京市/海淀區(qū)
- 激光器高級(jí)銷售經(jīng)理 上海市/虹口區(qū)
- 光器件物理工程師 北京市/海淀區(qū)
- 激光研發(fā)工程師 北京市/昌平區(qū)
- 技術(shù)專家 廣東省/江門市
- 封裝工程師 北京市/海淀區(qū)
- 結(jié)構(gòu)工程師 廣東省/深圳市