免费建单页网站,做头像网站静态,html5wap网站模板,制作网站的免费软件本周暂时比较清闲#xff0c;可以保持每日一更的速度。国外身份证项目新增需求#xff0c;检测出身份证正面的人脸。最开始考虑mobilenet-ssd#xff0c;经同事提醒#xff0c;有现成的人脸库dlib#xff0c;那就用传统方法尝试一下。dlib安装dlib的安装小费一波周折…本周暂时比较清闲可以保持每日一更的速度。国外身份证项目新增需求检测出身份证正面的人脸。最开始考虑mobilenet-ssd经同事提醒有现成的人脸库dlib那就用传统方法尝试一下。dlib安装dlib的安装小费一波周折我的python版本是3.6直接pip install dlib安装失败。https://pypi.org/project/dlib/19.6.0/找到python3.6对应的whl文件下载安装或者直接pip install dlib19.6.0 提示Successfully installed dlib-19.6.0安装成功。事情没那么简单import dlib时报错 ImportError: DLL load failed: 找不到指定的模块。下载dlib-19.8.1-cp36-cp36m-win_amd64.whl然后cd到相应的目录下 pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl代码import dlibimport cv2import osdef resize(img, widthNone, heightNone, intercv2.INTER_AREA):initialize the dimensions of the input image and obtainthe image sizedim None(h, w) img.shape[:2]if width is None and height is None:return imgif width is None:r height / float(h)dim (int(w * r), height)else:r width / float(w)dim (width, int(h * r))# resize the imageresized cv2.resize(img, dim, interpolationinter)# return the resized imagereturn resized# 使用 Dlib 的正面人脸检测器 frontal_face_detectordetector 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, width512)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)随便网上找了张图测试效果如下以上就是本文的全部内容希望对大家的学习有所帮助您可能感兴趣的文章: