Python用dilb提取照片上人脸的示例

作者:凹凸曼大人 时间:2021-07-04 23:34:47 

上代码:


#coding=utf-8

import cv2
import dlib

path = "imagePath/9.jpg"
img = cv2.imread(path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#人脸分类器
detector = dlib.get_frontal_face_detector()
# 获取人脸检测器
predictor = dlib.shape_predictor(
 "shape_predictor_68_face_landmarks.dat"
)
color = (0, 255, 0) # 定义绘制颜色

dets = detector(gray, 1)
for face in dets:
 shape = predictor(img, face) # 寻找人脸的68个标定点
 chang=[]
 kuan= []
 # 遍历所有点,打印出其坐标,并圈出来
 for pt in shape.parts():
   pt_pos = (pt.x, pt.y)
   chang.append(pt.x)
   kuan.append(pt.y)
   #cv2.circle(img, pt_pos, 1, (0, 255, 0), 1)
 x1 = max(chang)
 x2 = min(chang)
 y1 = max(kuan)
 y2 = min(kuan)
 cv2.rectangle(img, (x2, y2), (x1, y1), color, 1)
 cropped = img[y2 + 1:y1, x2 + 1:x1] # 裁剪坐标为[y0:y1, x0:x1]
 cv2.imshow("image", cropped)
 k = cv2.waitKey(0)
 if k == ord("s"):
   cv2.imwrite("imagePath/9-7.png", cropped)
cv2.destroyAllWindows()

识别效果:

Python用dilb提取照片上人脸的示例

来源:https://www.cnblogs.com/aotumandaren/p/13848280.html

标签:Python,dilb,人脸识别
0
投稿

猜你喜欢

  • PHP实现数组根据某个字段进行水平合并,横向合并案例分析

    2023-10-04 04:55:53
  • 数据库基础:MySQL 添加用户的两种方法

    2009-05-07 14:26:00
  • 基于Python制作一个简单的文章搜索工具

    2021-07-08 02:16:28
  • 全兼容的纯CSS级联菜单要点浅析

    2009-06-10 14:42:00
  • 从8个方面优化ASP代码

    2007-09-16 18:01:00
  • 用CSS实现图片等比例缩放

    2008-01-18 21:10:00
  • MySQL (root@%) does not exist的问题

    2011-03-16 15:31:00
  • js+csss实现的一个带复选框的下拉框

    2023-08-18 03:11:19
  • JavaScript 实现 Konami Code

    2009-05-26 12:44:00
  • 自动定时备份sqlserver数据库的方法

    2011-11-03 17:28:17
  • SQL语句练习实例之一——找出最近的两次晋升日期与工资额

    2011-10-24 20:16:42
  • MySQL聚焦Web 2.0可扩展性

    2012-01-05 19:02:19
  • asp 静态页面的另一种思路

    2011-04-08 10:32:00
  • PHP脚本监控Nginx 502错误并自动重启php-fpm

    2023-09-26 00:11:45
  • PHP const定义常量及global定义全局常量实例解析

    2023-11-17 07:24:57
  • JS实现运动缓冲效果的封装函数示例

    2023-06-30 14:34:45
  • PHP curl get post 请求的封装函数示例【get、post、put、delete等请求类型】

    2023-05-25 01:24:18
  • SQL Server查询速度慢原因及优化方法

    2008-12-03 15:19:00
  • CSS浏览器兼容方案

    2008-06-10 12:21:00
  • 用PHP编写和读取XML的几种方式

    2023-11-18 22:30:27
  • asp之家 网络编程 m.aspxhome.com