Beispiel #1
0
        public void initFaceEngine()
        {
            //初始化视频模式下人脸检测引擎
            uint detectModeVideo   = DetectionMode.ASF_DETECT_MODE_VIDEO;
            int  combinedMaskVideo = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION;

            //Video模式下检测脸部的角度优先值
            int videoDetectFaceOrientPriority = ASF_OrientPriority.ASF_OP_0_HIGHER_EXT;

            //人脸在图片中所占比例,如果需要调整检测人脸尺寸请修改此值,有效数值为2-32
            int detectFaceScaleVal = 16;
            //最大需要检测的人脸个数
            int detectFaceMaxNum = 5;

            int retCode = ASFFunctions.ASFInitEngine(detectModeVideo, videoDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMaskVideo, ref pVideoEngine);


            LoggerService.logger.Info($"初始化视频用人脸识别引擎结果:{retCode}");


            //初始化 用于采集人脸特征的引擎
            uint detectMode = DetectionMode.ASF_DETECT_MODE_IMAGE;
            //Image模式下检测脸部的角度优先值
            int imageDetectFaceOrientPriority = ASF_OrientPriority.ASF_OP_0_ONLY;

            //最大需要检测的人脸个数
            detectFaceMaxNum = 1;

            //引擎初始化时需要初始化的检测功能组合
            int combinedMask = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION;

            retCode = ASFFunctions.ASFInitEngine(detectMode, imageDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pVideoRGBImageEngine);

            LoggerService.logger.Info($"初始化视频用人脸识别引擎结果:{retCode}");
        }
        /// <summary>
        /// 引擎初始化
        /// </summary>
        /// <param name="detectMode">检测模式</param>
        /// <param name="detectFaceOrientPriority">检测脸部的角度优先值</param>
        /// <param name="detectFaceScaleVal">用于数值化表示的最小人脸尺寸</param>
        /// <param name="detectFaceMaxNum">最大需要检测的人脸个数</param>
        /// <param name="combinedMask">用户选择需要检测的功能组合,可单个或多个</param>
        /// <returns>返回0表示正常;其他值请在官网-帮助中心查询</returns>
        public int ASFInitEngine(DetectionMode detectMode, ASF_OrientPriority detectFaceOrientPriority, int detectFaceScaleVal, int detectFaceMaxNum, int combinedMask)
        {
            pEngine = IntPtr.Zero;
            if (detectFaceScaleVal < 2 || detectFaceScaleVal > 32)
            {
                detectFaceScaleVal = 16;
            }
            if (detectFaceMaxNum < 1 || detectFaceMaxNum > 50)
            {
                detectFaceMaxNum = 10;
            }
            int retCode = ASFFunctions.ASFInitEngine(detectMode, detectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pEngine);

            return(retCode);
        }
Beispiel #3
0
        public void initFaceEngine()
        {
            //初始化引擎
            uint detectMode = DetectionMode.ASF_DETECT_MODE_IMAGE;
            //Image模式下检测脸部的角度优先值
            int imageDetectFaceOrientPriority = ASF_OrientPriority.ASF_OP_0_ONLY;
            //人脸在图片中所占比例,如果需要调整检测人脸尺寸请修改此值,有效数值为2-32
            int detectFaceScaleVal = 16;
            //最大需要检测的人脸个数
            int detectFaceMaxNum = 5;
            //引擎初始化时需要初始化的检测功能组合
            int combinedMask = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_AGE | FaceEngineMask.ASF_GENDER | FaceEngineMask.ASF_FACE3DANGLE;
            //初始化引擎,正常值为0,其他返回值请参考http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=19&_dsign=dbad527e
            int result = ASFFunctions.ASFInitEngine(detectMode, imageDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pImageEngine);

            LoggerService.logger.Info($"初始化图片采集用人脸识别引擎结果:{result}");
        }
Beispiel #4
0
        /// <summary>
        /// 激活并初始化引擎
        /// </summary>
        private void ActiveAndInitEngines()
        {
            //读取配置文件中的 APP_ID 和 SDKKEY
            AppSettingsReader reader = new AppSettingsReader();
            string            appId  = (string)reader.GetValue("APP_ID", typeof(string));
            string            sdkKey = (string)reader.GetValue("SDKKEY", typeof(string));
            int retCode = 0;

            //激活引擎
            try
            {
                retCode = ASFFunctions.ASFActivation(appId, sdkKey);
            }
            catch (Exception ex)
            {
                //异常处理
                return;
            }
            #region 图片引擎pImageEngine初始化
            //初始化引擎
            uint detectMode = DetectionMode.ASF_DETECT_MODE_IMAGE;
            //检测脸部的角度优先值
            int detectFaceOrientPriority = ASF_OrientPriority.ASF_OP_0_HIGHER_EXT;
            //人脸在图片中所占比例,如果需要调整检测人脸尺寸请修改此值,有效数值为2-32
            int detectFaceScaleVal = 16;
            //最大需要检测的人脸个数
            int detectFaceMaxNum = 5;
            //引擎初始化时需要初始化的检测功能组合
            int combinedMask = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_AGE | FaceEngineMask.ASF_GENDER | FaceEngineMask.ASF_FACE3DANGLE;
            //初始化引擎,正常值为0,其他返回值请参考http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=19&_dsign=dbad527e
            retCode = ASFFunctions.ASFInitEngine(detectMode, detectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pImageEngine);
            if (retCode == 0)
            {
                this.Text = ("图片引擎初始化成功!\n");
            }
            else
            {
                this.Text = (string.Format("图片引擎初始化失败!错误码为:{0}\n", retCode));
            }
            #endregion
        }
        /// <summary>
        /// 初始化引擎
        /// </summary>
        private void InitEngines()
        {
            //读取配置文件
            AppSettingsReader reader   = new AppSettingsReader();
            string            appId    = (string)reader.GetValue("APP_ID", typeof(string));
            string            sdkKey64 = (string)reader.GetValue("SDKKEY64", typeof(string));
            string            sdkKey32 = (string)reader.GetValue("SDKKEY32", typeof(string));

            var is64CPU = Environment.Is64BitProcess;

            if (is64CPU)
            {
                if (string.IsNullOrWhiteSpace(appId) || string.IsNullOrWhiteSpace(sdkKey64))
                {
                    chooseMultiImgBtn.Enabled = false;
                    matchBtn.Enabled          = false;
                    btnClearFaceList.Enabled  = false;
                    chooseImgBtn.Enabled      = false;
                    MessageBox.Show("请在App.config配置文件中先配置APP_ID和SDKKEY64!");
                    return;
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(appId) || string.IsNullOrWhiteSpace(sdkKey32))
                {
                    chooseMultiImgBtn.Enabled = false;
                    matchBtn.Enabled          = false;
                    btnClearFaceList.Enabled  = false;
                    chooseImgBtn.Enabled      = false;
                    MessageBox.Show("请在App.config配置文件中先配置APP_ID和SDKKEY32!");
                    return;
                }
            }

            //激活引擎    如出现错误,1.请先确认从官网下载的sdk库已放到对应的bin中,2.当前选择的CPU为x86或者x64
            int retCode = 0;

            try
            {
                retCode = ASFFunctions.ASFActivation(appId, is64CPU ? sdkKey64 : sdkKey32);
            }
            catch (Exception ex)
            {
                chooseMultiImgBtn.Enabled = false;
                matchBtn.Enabled          = false;
                btnClearFaceList.Enabled  = false;
                chooseImgBtn.Enabled      = false;
                if (ex.Message.IndexOf("无法加载 DLL") > -1)
                {
                    MessageBox.Show("请将sdk相关DLL放入bin对应的x86或x64下的文件夹中!");
                }
                else
                {
                    MessageBox.Show("激活引擎失败!");
                }
                return;
            }
            Console.WriteLine("Activate Result:" + retCode);

            //初始化引擎
            uint detectMode = DetectionMode.ASF_DETECT_MODE_IMAGE;
            //检测脸部的角度优先值
            int detectFaceOrientPriority = ASF_OrientPriority.ASF_OP_0_HIGHER_EXT;
            //人脸在图片中所占比例,如果需要调整检测人脸尺寸请修改此值,有效数值为2-32
            int detectFaceScaleVal = 16;
            //最大需要检测的人脸个数
            int detectFaceMaxNum = 5;
            //引擎初始化时需要初始化的检测功能组合
            int combinedMask = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_AGE | FaceEngineMask.ASF_GENDER | FaceEngineMask.ASF_FACE3DANGLE;

            //初始化引擎,正常值为0,其他返回值请参考http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=19&_dsign=dbad527e
            retCode = ASFFunctions.ASFInitEngine(detectMode, detectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pEngine);
            Console.WriteLine("InitEngine Result:" + retCode);
            AppendText((retCode == 0) ? "引擎初始化成功!\n" : string.Format("引擎初始化失败!错误码为:{0}\n", retCode));
            if (retCode != 0)
            {
                chooseMultiImgBtn.Enabled = false;
                matchBtn.Enabled          = false;
                btnClearFaceList.Enabled  = false;
                chooseImgBtn.Enabled      = false;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 初始化引擎
        /// </summary>
        private void InitEngines()
        {
            //读取配置文件
            AppSettingsReader reader   = new AppSettingsReader();
            string            appId    = (string)reader.GetValue("APP_ID", typeof(string));
            string            sdkKey64 = (string)reader.GetValue("SDKKEY64", typeof(string));
            string            sdkKey32 = (string)reader.GetValue("SDKKEY32", typeof(string));

            rgbCameraIndex = (int)reader.GetValue("RGB_CAMERA_INDEX", typeof(int));
            irCameraIndex  = (int)reader.GetValue("IR_CAMERA_INDEX", typeof(int));
            //判断CPU位数
            var is64CPU = Environment.Is64BitProcess;

            if (string.IsNullOrWhiteSpace(appId) || string.IsNullOrWhiteSpace(is64CPU ? sdkKey64 : sdkKey32))
            {
                //禁用相关功能按钮
                ControlsEnable(false, chooseMultiImgBtn, matchBtn, btnClearFaceList, chooseImgBtn);
                MessageBox.Show(string.Format("请在App.config配置文件中先配置APP_ID和SDKKEY{0}!", is64CPU ? "64" : "32"));
                return;
            }

            //在线激活引擎    如出现错误,1.请先确认从官网下载的sdk库已放到对应的bin中,2.当前选择的CPU为x86或者x64
            int retCode = 0;

            try
            {
                retCode = ASFFunctions.ASFActivation(appId, is64CPU ? sdkKey64 : sdkKey32);
            }
            catch (Exception ex)
            {
                //禁用相关功能按钮
                ControlsEnable(false, chooseMultiImgBtn, matchBtn, btnClearFaceList, chooseImgBtn);
                if (ex.Message.Contains("无法加载 DLL"))
                {
                    MessageBox.Show("请将sdk相关DLL放入bin对应的x86或x64下的文件夹中!");
                }
                else
                {
                    MessageBox.Show("激活引擎失败!");
                }
                return;
            }
            Console.WriteLine("Activate Result:" + retCode);

            //初始化引擎
            uint detectMode = DetectionMode.ASF_DETECT_MODE_IMAGE;
            //Video模式下检测脸部的角度优先值
            int videoDetectFaceOrientPriority = ASF_OrientPriority.ASF_OP_0_HIGHER_EXT;
            //Image模式下检测脸部的角度优先值
            int imageDetectFaceOrientPriority = ASF_OrientPriority.ASF_OP_0_ONLY;
            //人脸在图片中所占比例,如果需要调整检测人脸尺寸请修改此值,有效数值为2-32
            int detectFaceScaleVal = 16;
            //最大需要检测的人脸个数
            int detectFaceMaxNum = 5;
            //引擎初始化时需要初始化的检测功能组合
            int combinedMask = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_AGE | FaceEngineMask.ASF_GENDER | FaceEngineMask.ASF_FACE3DANGLE;

            //初始化引擎,正常值为0,其他返回值请参考http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=19&_dsign=dbad527e
            retCode = ASFFunctions.ASFInitEngine(detectMode, imageDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pImageEngine);
            Console.WriteLine("InitEngine Result:" + retCode);
            AppendText((retCode == 0) ? "引擎初始化成功!\n" : string.Format("引擎初始化失败!错误码为:{0}\n", retCode));
            if (retCode != 0)
            {
                //禁用相关功能按钮
                ControlsEnable(false, chooseMultiImgBtn, matchBtn, btnClearFaceList, chooseImgBtn);
            }

            //初始化视频模式下人脸检测引擎
            uint detectModeVideo   = DetectionMode.ASF_DETECT_MODE_VIDEO;
            int  combinedMaskVideo = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION;

            retCode = ASFFunctions.ASFInitEngine(detectModeVideo, videoDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMaskVideo, ref pVideoEngine);
            //RGB视频专用FR引擎
            detectFaceMaxNum = 1;
            combinedMask     = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_LIVENESS;
            retCode          = ASFFunctions.ASFInitEngine(detectMode, imageDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pVideoRGBImageEngine);

            //IR视频专用FR引擎
            combinedMask = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_IR_LIVENESS;
            retCode      = ASFFunctions.ASFInitEngine(detectMode, imageDetectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pVideoIRImageEngine);

            Console.WriteLine("InitVideoEngine Result:" + retCode);


            initVideo();
        }
Beispiel #7
0
        public event setResultValue setFormResultValue; //第二步:声明一个委托类型的事件
        /// <summary>
        /// 激活并初始化引擎
        /// </summary>
        private void ActiveAndInitEngines()
        {
            //读取配置文件中的 APP_ID 和 SDKKEY
            AppSettingsReader reader = new AppSettingsReader();
            string            appId  = (string)reader.GetValue("APP_ID", typeof(string));
            string            sdkKey = (string)reader.GetValue("SDKKEY", typeof(string));
            int retCode = 0;

            //激活引擎
            try
            {
                retCode = ASFFunctions.ASFActivation(appId, sdkKey);
            }
            catch (Exception ex)
            {
                //异常处理
                return;
            }
            #region 图片引擎pImageEngine初始化
            //初始化引擎
            uint detectMode = DetectionMode.ASF_DETECT_MODE_IMAGE;
            //检测脸部的角度优先值
            int detectFaceOrientPriority = ASF_OrientPriority.ASF_OP_0_HIGHER_EXT;
            //人脸在图片中所占比例,如果需要调整检测人脸尺寸请修改此值,有效数值为2-32
            int detectFaceScaleVal = 16;
            //最大需要检测的人脸个数
            int detectFaceMaxNum = 5;
            //引擎初始化时需要初始化的检测功能组合
            int combinedMask = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_AGE | FaceEngineMask.ASF_GENDER | FaceEngineMask.ASF_FACE3DANGLE;
            //初始化引擎,正常值为0,其他返回值请参考http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=19&_dsign=dbad527e
            retCode = ASFFunctions.ASFInitEngine(detectMode, detectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pImageEngine);
            if (retCode == 0)
            {
                lbl_msg.Text = ("图片引擎初始化成功!\n");
            }
            else
            {
                lbl_msg.Text = (string.Format("图片引擎初始化失败!错误码为:{0}\n", retCode));
            }
            #endregion

            #region 初始化视频模式下人脸检测引擎
            uint detectModeVideo   = DetectionMode.ASF_DETECT_MODE_VIDEO;
            int  combinedMaskVideo = FaceEngineMask.ASF_FACE_DETECT | FaceEngineMask.ASF_FACERECOGNITION;
            retCode = ASFFunctions.ASFInitEngine(detectModeVideo, detectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMaskVideo, ref pVideoEngine);
            if (retCode == 0)
            {
                lbl_msg.Text = ("视频引擎初始化成功!\n");
            }
            else
            {
                lbl_msg.Text = (string.Format("视频引擎初始化失败!错误码为:{0}\n", retCode));
            }
            #endregion

            #region 视频专用FR引擎
            detectFaceMaxNum = 1;
            combinedMask     = FaceEngineMask.ASF_FACERECOGNITION | FaceEngineMask.ASF_FACE3DANGLE | FaceEngineMask.ASF_LIVENESS;
            retCode          = ASFFunctions.ASFInitEngine(detectMode, detectFaceOrientPriority, detectFaceScaleVal, detectFaceMaxNum, combinedMask, ref pVideoImageEngine);
            Console.WriteLine("InitVideoEngine Result:" + retCode);

            if (retCode == 0)
            {
                lbl_msg.Text = ("视频专用FR引擎初始化成功!\n");
            }
            else
            {
                lbl_msg.Text = (string.Format("视频专业FR引擎初始化失败!错误码为:{0}\n", retCode));
            }
            // 摄像头初始化
            filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            lbl_msg.Text         = (string.Format("摄像头初始化完成...\n"));
            #endregion
        }