日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 人脸关键点检测_opencv+python+dlib人脸关键点检测、实时检测

發布時間:2023/12/20 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 人脸关键点检测_opencv+python+dlib人脸关键点检测、实时检测 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

安裝的是anaconde3、python3.7.3,3.7環境安裝dlib太麻煩,

在anaconde3中新建環境python3.6.8,

在3.6環境下安裝dlib-19.6.1-cp36-cp36m-win_amd64.whl,下載地址:https://pypi.org/project/dlib/19.6.1/#files

vscode更改配置

其中shape_predictor_68_face_landmarks.dat官方訓練數據下載地址:http://dlib.net/files/,里面還有5點模型。

效果圖如下:

# _*_ coding:utf-8 _*_

import numpy as np

import cv2

import dlib

detector = dlib.get_frontal_face_detector()

predictor = dlib.shape_predictor("data/shape_predictor_68_face_landmarks.dat")

# cv2讀取圖像

img = cv2.imread("img/test3.jpg")

# 取灰度

img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

# 人臉數rects

rects = detector(img_gray, 0)

for i in range(len(rects)):

landmarks = np.matrix([[p.x, p.y] for p in predictor(img, rects[i]).parts()])

for idx, point in enumerate(landmarks):

# 68點的坐標

pos = (point[0, 0], point[0, 1])

# 利用cv2.circle給每個特征點畫一個圈,共68個

cv2.circle(img, pos, 2, color=(0, 255, 0))

# 利用cv2.putText輸出1-68

font = cv2.FONT_HERSHEY_SIMPLEX

cv2.putText(img, str(idx + 1), None, font, 0.8, (0, 0, 255), 1, cv2.LINE_AA)

cv2.namedWindow("img", 2)

cv2.imshow("img", img)

cv2.waitKey(0)

攝像頭實時檢測:

#_*_ coding:utf-8 _*_

importnumpy as npimportcv2importdlib

cap=cv2.VideoCapture(0)

detector=dlib.get_frontal_face_detector()

predictor= dlib.shape_predictor("data/shape_predictor_68_face_landmarks.dat")while 1:

ret, img=cap.read()#取灰度

img_gray =cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)#人臉數rects

rects =detector(img_gray, 0)for i inrange(len(rects)):

landmarks= np.matrix([[p.x, p.y] for p inpredictor(img, rects[i]).parts()])for idx, point inenumerate(landmarks):#68點的坐標

pos = (point[0, 0], point[0, 1])#利用cv2.circle給每個特征點畫一個圈,共68個

cv2.circle(img, pos, 2, color=(0, 255, 0))#利用cv2.putText輸出1-68

font =cv2.FONT_HERSHEY_SIMPLEX

cv2.putText(img, str(idx+ 1), None, font, 0.8, (0, 0, 255), 1, cv2.LINE_AA)

cv2.namedWindow("img", 2)

cv2.imshow("img", img)if cv2.waitKey(1) & 0xFF == ord("q"):break

總結

以上是生活随笔為你收集整理的python 人脸关键点检测_opencv+python+dlib人脸关键点检测、实时检测的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。