神剑山庄资源网 Design By www.hcban.com
本周暂时比较清闲,可以保持每日一更的速度。
国外身份证项目新增需求,检测出身份证正面的人脸。最开始考虑mobilenet-ssd,经同事提醒,有现成的人脸库dlib,那就用传统方法尝试一下。
dlib安装
dlib的安装小费一波周折,我的python版本是3.6,直接pip install dlib安装失败。https://pypi.org/project/dlib/19.6.0/找到python3.6对应的whl文件下载安装或者直接pip install dlib==19.6.0 提示Successfully installed dlib-19.6.0安装成功。事情没那么简单,import dlib时报错: ImportError: DLL load failed: 找不到指定的模块。
还是版本的问题,查找最新版本的whl :https://pypi.org/simple/dlib/
下载 dlib-19.8.1-cp36-cp36m-win_amd64.whl 然后cd到相应的目录下 pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl
代码
import dlib import cv2 import os def resize(img, width=None, height=None, inter=cv2.INTER_AREA): """ initialize the dimensions of the input image and obtain the image size """ dim = None (h, w) = img.shape[:2] if width is None and height is None: return img if width is None: r = height / float(h) dim = (int(w * r), height) else: r = width / float(w) dim = (width, int(h * r)) # resize the image resized = cv2.resize(img, dim, interpolation=inter) # return the resized image return resized # 使用 Dlib 的正面人脸检测器 frontal_face_detector detector = dlib.get_frontal_face_detector() # 图片所在路径 imgs_path = 'test/' filelist = os.listdir(imgs_path) # 使用 detector 检测器来检测图像中的人脸 for img_path in filelist: img = cv2.imread(imgs_path + img_path) img = resize(img, width=512) faces = detector(img, 1) print("人脸数 / Faces in all: ", len(faces)) for i, d in enumerate(faces): w = d.right() - d.left() h = d.bottom() - d.top() d_left = int(d.left() - w * 0.25) d_right = int(d.right() + w * 0.25) d_top = int(d.top() - w * 0.70) d_bottom = int(d.bottom() + w * 0.2) print("第", i + 1, "个人脸的矩形框坐标:", "left:", d_left, "right:", d_right, "top:", d_top, "bottom:", d_bottom) cv2.rectangle(img, tuple([d_left, d_top]), tuple([d_right, d_bottom]), (0, 255, 255), 2) cv2.imshow("img", img) cv2.waitKey(0) cv2.imwrite('./result.jpg',img)
随便网上找了张图测试,效果如下
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com
暂无python 基于dlib库的人脸检测的实现的评论...
更新日志
2024年09月30日
2024年09月30日
- 孙悦.1996-伙伴【正大国际】【WAV+CUE】
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】