/// <summary>
        /// 获取IR活体结果
        /// </summary>
        /// <param name="livenessInfo">IR活体结果</param>
        /// <returns>返回0表示正常;返回负数请根据ErrorCodeUtil类注释查看;其他值请在官网-帮助中心查询</returns>
        public int ASFGetLivenessScore_IR(out LivenessInfo livenessInfo)
        {
            int retCode = -1;

            livenessInfo = new LivenessInfo();
            IntPtr pLiveness = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_LivenessInfo>());

            //调用SDK接口
            retCode = ASFFunctions.ASFGetLivenessScore_IR(pEngine, pLiveness);
            if (retCode != 0)
            {
                MemoryUtil.Free(pLiveness);
                return(retCode);
            }
            //转化结果
            ASF_LivenessInfo asfLivenessInfo = new ASF_LivenessInfo();

            asfLivenessInfo  = MemoryUtil.PtrToStructure <ASF_LivenessInfo>(pLiveness);
            livenessInfo.num = asfLivenessInfo.num;
            if (asfLivenessInfo.num > 0)
            {
                livenessInfo.isLive = new int[asfLivenessInfo.num];
                Marshal.Copy(asfLivenessInfo.isLive, livenessInfo.isLive, 0, asfLivenessInfo.num);
            }
            MemoryUtil.FreeArray(pLiveness);
            return(retCode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 红外活体检测
        /// </summary>
        /// <param name="pEngine">引擎Handle</param>
        /// <param name="imageInfo">图像数据</param>
        /// <param name="multiFaceInfo">活体检测结果</param>
        /// <returns>保存活体检测结果结构体</returns>
        public static ASF_LivenessInfo LivenessInfo_IR(IntPtr pEngine, ImageInfo imageInfo, ASF_MultiFaceInfo multiFaceInfo, out int retCode)
        {
            IntPtr pMultiFaceInfo = UtilToolMemory.Malloc(UtilToolMemory.SizeOf <ASF_MultiFaceInfo>());

            UtilToolMemory.StructureToPtr(multiFaceInfo, pMultiFaceInfo);

            if (multiFaceInfo.faceNum == 0)
            {
                retCode = -1;
                //释放内存
                UtilToolMemory.Free(pMultiFaceInfo);
                return(new ASF_LivenessInfo());
            }

            try
            {
                //人脸信息处理
                retCode = ASFFunctions.ASFProcess_IR(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_IR_LIVENESS);
                if (retCode == 0)
                {
                    //获取活体检测结果
                    IntPtr pLivenessInfo = UtilToolMemory.Malloc(UtilToolMemory.SizeOf <ASF_LivenessInfo>());
                    retCode = ASFFunctions.ASFGetLivenessScore_IR(pEngine, pLivenessInfo);
                    Console.WriteLine("Get Liveness Result:" + retCode);
                    ASF_LivenessInfo livenessInfo = UtilToolMemory.PtrToStructure <ASF_LivenessInfo>(pLivenessInfo);

                    //释放内存
                    UtilToolMemory.Free(pMultiFaceInfo);
                    UtilToolMemory.Free(pLivenessInfo);
                    return(livenessInfo);
                }
                else
                {
                    //释放内存
                    UtilToolMemory.Free(pMultiFaceInfo);
                    return(new ASF_LivenessInfo());
                }
            }
            catch
            {
                retCode = -1;
                //释放内存
                UtilToolMemory.Free(pMultiFaceInfo);
                return(new ASF_LivenessInfo());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Infrared in vivo detection
        /// </summary>
        /// <param name="pEngine">Engine Handle</param>
        /// <param name="imageInfo">Image data</param>
        /// <param name="multiFaceInfo">In vivo test results</param>
        /// <returns>Preserve the structure of in vivo detection results</returns>
        public static ASF_LivenessInfo LivenessInfo_IR(IntPtr pEngine, ImageInfo imageInfo, ASF_MultiFaceInfo multiFaceInfo, out int retCode)
        {
            IntPtr pMultiFaceInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_MultiFaceInfo>());

            MemoryUtil.StructureToPtr(multiFaceInfo, pMultiFaceInfo);

            if (multiFaceInfo.faceNum == 0)
            {
                retCode = -1;
                //Release memory
                MemoryUtil.Free(pMultiFaceInfo);
                return(new ASF_LivenessInfo());
            }

            try
            {
                //Face information processing
                retCode = ASFFunctions.ASFProcess_IR(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_IR_LIVENESS);
                if (retCode == 0)
                {
                    //Obtain in vivo test results
                    IntPtr pLivenessInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_LivenessInfo>());
                    retCode = ASFFunctions.ASFGetLivenessScore_IR(pEngine, pLivenessInfo);
                    Console.WriteLine("Get Liveness Result:" + retCode);
                    ASF_LivenessInfo livenessInfo = MemoryUtil.PtrToStructure <ASF_LivenessInfo>(pLivenessInfo);

                    //Release memory
                    MemoryUtil.Free(pMultiFaceInfo);
                    MemoryUtil.Free(pLivenessInfo);
                    return(livenessInfo);
                }
                else
                {
                    //Release memory
                    MemoryUtil.Free(pMultiFaceInfo);
                    return(new ASF_LivenessInfo());
                }
            }
            catch
            {
                retCode = -1;
                //Release memory
                MemoryUtil.Free(pMultiFaceInfo);
                return(new ASF_LivenessInfo());
            }
        }