人脸识别 调用2.0的arcface

栏目: 编程工具 · 发布时间: 5年前

内容简介:记录下使用1.初始化[DllImport("libarcsoft_face_engine.dll", EntryPoint = "ASFInitEngine", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]

记录下使用 虹软技术 的过程中的问题

1.初始化

[DllImport("libarcsoft_face_engine.dll", EntryPoint = "ASFInitEngine", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]

private static extern int ASFInitEngine(uint detectMode, int orientPriority, int scale, int maxFaceNumber, uint combinedMask, out IntPtr pEngine);

开始时,写了个long detectMode,返回错误信息是:0x16004,(detectFaceScaleVal 不支持)正式鬼扯,害我各种调整scale。

改成uint就ok了。

话说就一个mode,您弄

const uint ASF_DETECT_MODE_VIDEO = 0x00000000; //Video模式,一般用于多帧连续检测

const uint ASF_DETECT_MODE_IMAGE = 0xFFFFFFFF; //Image模式,一般用于静态图的单次检测

这两宝贝,我也是醉了。0/1不行吗?

2.人脸检测

[DllImport("libarcsoft_face_engine.dll", EntryPoint = "ASFDetectFaces", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]

private static extern int ASFDetectFaces(IntPtr pEngine, int width, int height, int format, IntPtr pImageData, out ASF_MultiFaceInfo faceInfo);

开始时,弄了张身份证照片,102的宽度,不是4的倍数,返回0x1600F,手动编辑图片,拉伸成104的宽度便告成功。

最终写了个方法,自动设成4的倍数,如下:

private (int W, int H, IntPtr PImageData) GetImageData(Bitmap bitmap)
    {

        var bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
        int width = (bitmap.Width + 3) / 4 * 4;

        var bytesCount = bmpData.Height * width * 3;
        IntPtr pImageData = Marshal.AllocCoTaskMem(bytesCount);
        if (width == bitmap.Width)
            CopyMemory(pImageData, bmpData.Scan0, bytesCount);
        else
            for (int i = 0; i < bitmap.Height; i++)
                CopyMemory(IntPtr.Add(pImageData, i * width * 3), IntPtr.Add(bmpData.Scan0, i * bmpData.Stride), bmpData.Stride);
        bitmap.UnlockBits(bmpData);
        return new ValueTuple<int, int, IntPtr>(width, bitmap.Height, pImageData);
    }

踩了这两个坑后,便愉快的运行了。

话说2.0的优点也不少:

1.特征值缩小了,由原来的20多K变成1032字节(咱就不能变成1024?)

2.比对速度快了很多很多,四线程10万次的比对也只要3秒多钟。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Flexible Rails

Flexible Rails

Peter Armstrong / Manning Publications / 2008-01-23 / USD 44.99

Rails is a fantastic tool for web application development, but its Ajax-driven interfaces stop short of the richness you gain with a tool like Adobe Flex. Simply put, Flex is the most productive way t......一起来看看 《Flexible Rails》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换