首页 > 编程知识 正文

python图像处理库,百度人脸识别离线sdk

时间:2023-05-03 11:27:07 阅读:174699 作者:3272

dlibdlib介绍

这里主要试着实现脸部检测。 dlib的面部检测主要基于HOG-SVM,与opencv的面部检测【之前写的博客】的面部检测不同。 相比之下,dlib的识别精度更高,即使是很少的遮挡也能识别。 (但是,必须具体分析情况。 部分面部反而可以用opencv检测到。 )但是,dlib的面部识别的图像大小大于80X80可以得到更好的识别效果。 dlib还可以对齐68个键。

如果想要更高的识别精度,因为我以前做实验识别的数据都是一个人的头像,所以我直接简单粗暴地把这两个结合了起来。 写if else,哈哈哈哈哈哈

但是,安装dlib库很麻烦。 需要另外下载很多其他库,并下载VS。 我记得安装后找了很多教程,花了点功夫安装。

实现:

importdlibimportcv2#dlib正面面部检测器frontal _ face _ detector detector=dlib.get _ frontal _ face _ detector (#图像所在路径img (64,64 ) ) #img_gray=cv2.cvtcolor ) img, cv2.COLOR_RGB2GRAY )用于生成Dlib的图像窗口# win=dlib.image _ window (# win.set _ image ) img ) )使用检测器在图像中Faces in all:),len ) Faces ) ) for i,dinenumerate ) faces ) : print ),第),第) )。 d.left (,(t ),) right: )、d.right )、(t )、(top: )、d.top )、) t )、) bottom: ) )。 d.top () )、tuple(d.right )、d.bottom ) )、0,255,255 )、2 ) else3360print ) ' noface ' ) cv2.non img )

正如前面的博客测试图所示,我们发现dlib无法识别所有内容。 所以,请具体看看自己识别的数据集。

我又换了一张像素大的,但都识别出来了。

关键点定位:

#实例化检测器=dlib.get _ frontal _ face _ detector (predictor=dlib.shape _ predictor (shape _ predictor ) img=cv2.im read (r ' c : (users (Lenovo ) desktop )2.jpg ) #面部数量rects=detector ) img, 1 )打印(len (rects ) (print )打印(rects ) forIinrange ) len ) rects ) ) : landmarks=NP.matrix ([ [ p [ p.x,p.y ] frex ] ) ) )。 1 ) print(idx,pos ) )利用cv2.circle圈定每个特征点,共68个cv2.circle ) img,pos,5,color=) 0,255, 0 ) #利用cv2.putText输出1-68 font=cv2.font _ Hershey _ simplex # cv2.put text (img,str(idx1),pos,font,0.8,cc

原图

结果

要键入的参数:

链接: https://pan.Baidu.com/s/1 kcdickj9VF S1 smka 87 ejrg

抽屉代码: ju3e

完整版见my github

其中有实现批量处理的代码。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。