Exemplo n.º 1
0
        /// <summary>
        /// 年龄检测
        /// </summary>
        /// <param name="pEngine">引擎Handle</param>
        /// <param name="imageInfo">图像数据</param>
        /// <param name="multiFaceInfo">人脸检测结果</param>
        /// <returns>年龄检测结构体</returns>
        public static ASF_AgeInfo DetectAge(IntPtr pEngine, ImageInfo imageInfo, ASF_MultiFaceInfo multiFaceInfo)
        {
            IntPtr pMultiFaceInfo = UtilToolMemory.Malloc(UtilToolMemory.SizeOf <ASF_MultiFaceInfo>());

            UtilToolMemory.StructureToPtr(multiFaceInfo, pMultiFaceInfo);

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

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

            //获取年龄信息
            IntPtr pAgeInfo = UtilToolMemory.Malloc(UtilToolMemory.SizeOf <ASF_AgeInfo>());

            retCode = ASFFunctions.ASFGetAge(pEngine, pAgeInfo);
            Console.WriteLine("Get Age Result:" + retCode);
            ASF_AgeInfo ageInfo = UtilToolMemory.PtrToStructure <ASF_AgeInfo>(pAgeInfo);

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

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

            ageInfo = new AgeInfo();
            IntPtr pAgeInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_AgeInfo>());

            //调用SDK接口
            retCode = ASFFunctions.ASFGetAge(pEngine, pAgeInfo);
            if (retCode != 0)
            {
                MemoryUtil.Free(pAgeInfo);
                return(retCode);
            }
            //转化结果
            ASF_AgeInfo asfAgeInfo = new ASF_AgeInfo();

            asfAgeInfo  = MemoryUtil.PtrToStructure <ASF_AgeInfo>(pAgeInfo);
            ageInfo.num = asfAgeInfo.num;
            if (ageInfo.num > 0)
            {
                ageInfo.ageArray = new int[ageInfo.num];
                Marshal.Copy(asfAgeInfo.ageArray, ageInfo.ageArray, 0, ageInfo.num);
            }
            MemoryUtil.FreeArray(pAgeInfo);
            return(retCode);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 年龄检测
        /// </summary>
        /// <param name="pEngine">引擎Handle</param>
        /// <param name="imageInfo">图像数据</param>
        /// <param name="multiFaceInfo">人脸检测结果</param>
        /// <returns>年龄检测结构体</returns>
        public static ASF_AgeInfo AgeEstimation(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_AgeInfo());
            }

            //人脸信息处理
            retCode = ASFFunctions.ASFProcess(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_AGE);
            if (retCode == 0)
            {
                //获取年龄信息
                IntPtr pAgeInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_AgeInfo>());
                retCode = ASFFunctions.ASFGetAge(pEngine, pAgeInfo);
                Console.WriteLine("Get Age Result:" + retCode);
                ASF_AgeInfo ageInfo = MemoryUtil.PtrToStructure <ASF_AgeInfo>(pAgeInfo);

                //释放内存
                MemoryUtil.Free(pMultiFaceInfo);
                MemoryUtil.Free(pAgeInfo);
                return(ageInfo);
            }
            else
            {
                return(new ASF_AgeInfo());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Age detection
        /// </summary>
        /// <param name="pEngine">Engine Handle</param>
        /// <param name="imageInfo">Image data</param>
        /// <param name="multiFaceInfo">Face detection results</param>
        /// <returns>Age detection structures</returns>
        public static ASF_AgeInfo AgeEstimation(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_AgeInfo());
            }

            //Face information processing
            int retCode = ASFFunctions.ASFProcess(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_AGE);

            //Get age information
            IntPtr pAgeInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_AgeInfo>());

            retCode = ASFFunctions.ASFGetAge(pEngine, pAgeInfo);
            Console.WriteLine("Get Age Result:" + retCode);
            ASF_AgeInfo ageInfo = MemoryUtil.PtrToStructure <ASF_AgeInfo>(pAgeInfo);

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

            return(ageInfo);
        }
Exemplo n.º 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);
            }
        }