人脸识别 , aardio调用FaceCoreEx.dll类库实现面部检测
By
admin
at 2023-09-11 • 0人收藏 • 1608人看过
我对人脸识别ViewFaceCore库进行了二次封装,
这样就可以在aardio中简单调用了.
注意: dll需要.netFrameWork4.6.1以上运行库,我编译用的4.7.2
import console; import dotNet; import System.Drawing; var viewFaceCoredll = dotNet.load("\FaceCoreEx.dll"); var fc = viewFaceCoredll.new("FaceCoreEx.Core"); //获取检测到的人脸数量 var ret = fc.FromFlie(io.fullpath("\images\Jay_4.jpg")); //显示位置和得分 for(i=0;ret-1;1){ var info = fc.GetInfo(i) console.log(info.X) console.log(info.Y) console.log(info.Width) console.log(info.Height) console.log(info.Score) } console.pause(true);
完整工程如下: 文件300多M是因为包含里所有的人脸数据匹配文件
链接:
https://pan.baidu.com/s/1FoXoMMqhy56NVaqR9Zo31g?pwd=uzd4
提取码:uzd4
下面是二次封装的FaceCoreEx类库源码:
将上面工程中的 ViewFaceCore.dll 和ViewFaceCore.Extension.SystemDrawing.dll 引用在类库工程中即可.
using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.Linq; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Text; using System.Threading; using System.Threading.Tasks; using ViewFaceCore.Core; using ViewFaceCore.Model; namespace FaceCoreEx { public class Core { private FaceInfo[] infos; public int FromFlie(string path) { var bitmap = Bitmap.FromFile(path); var faceImage = ViewFaceCore.ViewFaceSystemDrawingExtension.ToFaceImage(bitmap); FaceDetector faceDetector = new FaceDetector(); infos = faceDetector.Detect(faceImage); bitmap.Dispose(); faceImage.Dispose(); faceDetector.Dispose(); return infos.Length; } public InfoStruct GetInfo(int index) { InfoStruct info = new InfoStruct(){ X = 0, Y = 0, Width = 0, Height = 0, Score = 0 }; if (index>=0 && index< infos.Length) { info.X = infos[index].Location.X; info.Y = infos[index].Location.Y; info.Width = infos[index].Location.Width; info.Height = infos[index].Location.Height; info.Score = infos[index].Score; } return info; } public struct InfoStruct { public int X; public int Y; public int Width; public int Height; public double Score; }; } }
工程文件同在一个百度盘里.
10 个回复 | 最后更新于 2023-09-14
登录后方可回帖
感谢分享, 试了下, 效果很好
有个小问题, 我希望能够识别几个, 不知道该怎么修改呢?
我尝试了如下方法, 发现会有很大机会会出错,出错信息:
我的代码, 拖放图片到窗体测试
另外, 方法 FromFlie 是不是 FromFile 的误拼呢?