/// <summary>
        /// 性别检测
        /// </summary>
        /// <param name="pEngine">引擎Handle</param>
        /// <param name="imageInfo">图像数据</param>
        /// <param name="multiFaceInfo">人脸检测结果</param>
        /// <returns>保存性别检测结果结构体</returns>
        public static ASF_GenderInfo DetectGender(IntPtr pEngine, ImageInfo imageInfo, ASF_MultiFaceInfo multiFaceInfo, out int retCode)
        {
            retCode = -1;
            IntPtr pMultiFaceInfo = UtilToolMemory.Malloc(UtilToolMemory.SizeOf <ASF_MultiFaceInfo>());

            UtilToolMemory.StructureToPtr(multiFaceInfo, pMultiFaceInfo);

            if (multiFaceInfo.faceNum == 0)
            {
                return(new ASF_GenderInfo());
            }

            //人脸信息处理
            retCode = ASFFunctions.ASFProcess(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_GENDER);
            if (retCode == 0)
            {
                //获取性别信息
                IntPtr pGenderInfo = UtilToolMemory.Malloc(UtilToolMemory.SizeOf <ASF_GenderInfo>());
                retCode = ASFFunctions.ASFGetGender(pEngine, pGenderInfo);
                Console.WriteLine("Get Gender Result:" + retCode);
                ASF_GenderInfo genderInfo = UtilToolMemory.PtrToStructure <ASF_GenderInfo>(pGenderInfo);

                //释放内存
                UtilToolMemory.Free(pMultiFaceInfo);
                UtilToolMemory.Free(pGenderInfo);

                return(genderInfo);
            }
            else
            {
                return(new ASF_GenderInfo());
            }
        }
        /// <summary>
        /// 获取性别结果
        /// </summary>
        /// <param name="pEngine">引擎handle</param>
        /// <param name="genderInfo">out 性别结果</param>
        /// <returns>返回0表示正常;返回负数请根据ErrorCodeUtil类注释查看;其他值请在官网-帮助中心查询</returns>
        public int ASFGetGender(out GenderInfo genderInfo)
        {
            int retCode = -1;

            genderInfo = new GenderInfo();
            IntPtr pGenderInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_GenderInfo>());

            //调用SDK接口
            retCode = ASFFunctions.ASFGetGender(pEngine, pGenderInfo);
            if (retCode != 0)
            {
                MemoryUtil.Free(pGenderInfo);
                return(retCode);
            }
            //转化结果
            ASF_GenderInfo asfGenderInfo = new ASF_GenderInfo();

            asfGenderInfo  = MemoryUtil.PtrToStructure <ASF_GenderInfo>(pGenderInfo);
            genderInfo.num = asfGenderInfo.num;
            if (genderInfo.num > 0)
            {
                genderInfo.genderArray = new int[genderInfo.num];
                Marshal.Copy(asfGenderInfo.genderArray, genderInfo.genderArray, 0, genderInfo.num);
            }
            MemoryUtil.FreeArray(pGenderInfo);
            return(retCode);
        }
Beispiel #3
0
        /// <summary>
        /// 性别检测
        /// </summary>
        /// <param name="pEngine">引擎Handle</param>
        /// <param name="imageInfo">图像数据</param>
        /// <param name="multiFaceInfo">人脸检测结果</param>
        /// <returns>保存性别估计结果结构体</returns>
        public static ASF_GenderInfo GenderEstimation(IntPtr pEngine, ImageInfo imageInfo, ASF_MultiFaceInfo multiFaceInfo)
        {
            IntPtr pMultiFaceInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_MultiFaceInfo>());

            MemoryUtil.StructureToPtr(multiFaceInfo, pMultiFaceInfo);

            if (multiFaceInfo.faceNum == 0)
            {
                return(new ASF_GenderInfo());
            }

            //人脸信息处理
            int retCode = ASFFunctions.ASFProcess(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_GENDER);

            //获取性别信息
            IntPtr pGenderInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_GenderInfo>());

            retCode = ASFFunctions.ASFGetGender(pEngine, pGenderInfo);
            Console.WriteLine("Get Gender Result:" + retCode);
            ASF_GenderInfo genderInfo = MemoryUtil.PtrToStructure <ASF_GenderInfo>(pGenderInfo);

            //释放内存
            MemoryUtil.Free(pMultiFaceInfo);
            MemoryUtil.Free(pGenderInfo);

            return(genderInfo);
        }
        /// <summary>
        /// Gender tests
        /// </summary>
        /// <param name="pEngine">Engine Handle</param>
        /// <param name="imageInfo">Image data</param>
        /// <param name="multiFaceInfo">Face detection results</param>
        /// <returns>Save the gender detection result structure</returns>
        public static ASF_GenderInfo GenderEstimation(IntPtr pEngine, ImageInfo imageInfo, ASF_MultiFaceInfo multiFaceInfo, out int retCode)
        {
            retCode = -1;
            IntPtr pMultiFaceInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_MultiFaceInfo>());

            MemoryUtil.StructureToPtr(multiFaceInfo, pMultiFaceInfo);

            if (multiFaceInfo.faceNum == 0)
            {
                return(new ASF_GenderInfo());
            }

            //Face information processing
            retCode = ASFFunctions.ASFProcess(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_GENDER);
            if (retCode == 0)
            {
                //Access to gender information
                IntPtr pGenderInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_GenderInfo>());
                retCode = ASFFunctions.ASFGetGender(pEngine, pGenderInfo);
                Console.WriteLine("Get Gender Result:" + retCode);
                ASF_GenderInfo genderInfo = MemoryUtil.PtrToStructure <ASF_GenderInfo>(pGenderInfo);

                //Release memory
                MemoryUtil.Free(pMultiFaceInfo);
                MemoryUtil.Free(pGenderInfo);

                return(genderInfo);
            }
            else
            {
                return(new ASF_GenderInfo());
            }
        }
Beispiel #5
0
        /// <summary>
        /// 获取人脸信息列表
        /// </summary>
        /// <param name="pEngine"></param>
        /// <param name="bitmap"></param>
        /// <returns></returns>
        public static List <FaceInfoModel> GetFaceInfos(IntPtr pEngine, Image bitmap)
        {
            List <FaceInfoModel> listRet = new List <FaceInfoModel>();

            try
            {
                List <int> AgeList    = new List <int>();
                List <int> GenderList = new List <int>();
                //检测人脸,得到Rect框
                ASF_MultiFaceInfo multiFaceInfo  = FaceUtil.DetectFace(pEngine, bitmap);
                MultiFaceModel    multiFaceModel = new MultiFaceModel(multiFaceInfo);
                //人脸信息处理
                ImageInfo imageInfo = ImageUtil.ReadBMP(bitmap);
                int       retCode   = ASFFunctions.ASFProcess(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, ref multiFaceInfo, FaceEngineMask.ASF_AGE | FaceEngineMask.ASF_GENDER);
                //获取年龄信息
                ASF_AgeInfo ageInfo = new ASF_AgeInfo();
                retCode = ASFFunctions.ASFGetAge(pEngine, ref ageInfo);
                AgeList = ageInfo.PtrToAgeArray(ageInfo.ageArray, ageInfo.num);
                //获取性别信息
                ASF_GenderInfo genderInfo = new ASF_GenderInfo();
                retCode    = ASFFunctions.ASFGetGender(pEngine, ref genderInfo);
                GenderList = genderInfo.PtrToGenderArray(genderInfo.genderArray, genderInfo.num);

                for (int i = 0; i < multiFaceInfo.faceNum; i++)
                {
                    FaceInfoModel faceInfo = new FaceInfoModel();
                    faceInfo.age        = AgeList[i];
                    faceInfo.gender     = GenderList[i];
                    faceInfo.faceRect   = multiFaceModel.FaceInfoList[i].faceRect;
                    faceInfo.feature    = ExtractFeature(pEngine, bitmap, multiFaceModel.FaceInfoList[i]);//提取单人脸特征
                    faceInfo.faceOrient = multiFaceModel.FaceInfoList[i].faceOrient;
                    listRet.Add(faceInfo);
                }
                return(listRet);//返回多人脸信息
            }
            catch {
                return(listRet);
            }
        }