订阅
纠错
加入自媒体

使用Python+OpenCV+Dlib实现人脸检测与人脸特征关键点识别

2020-08-12 10:12
磐创AI
关注

太棒了,但我们能做点更酷的事吗?步骤4:实时检测是的,你没看错!这可能就是你想要的效果!下一步是连接我们的网络摄像头,从你的视频流中进行实时地关键点识别。你可以通过使用相机遍历视频帧或使用视频文件来对面部进行实时面部关键点检测。如果要使用自己的摄像机,请参考以下代码,如果使用的是视频文件,请确保将数字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 ☆

<上一页  1  2  3  
声明: 本文由入驻维科号的作者撰写,观点仅代表作者本人,不代表OFweek立场。如有侵权或其他问题,请联系举报。

发表评论

0条评论,0人参与

请输入评论内容...

请输入评论/评论长度6~500个字

您提交的评论过于频繁,请输入验证码继续

暂无评论

暂无评论

人工智能 猎头职位 更多
扫码关注公众号
OFweek人工智能网
获取更多精彩内容
文章纠错
x
*文字标题:
*纠错内容:
联系邮箱:
*验 证 码:

粤公网安备 44030502002758号