Esempio n. 1
0
        /// <summary>
        /// 注册并激活 虹软人脸识别SDK引擎
        ///
        /// 需要获取APP_ID,SDKKEY64(从虹软官网申请)
        /// </summary>
        /// <returns>返回执行结果</returns>
        public static int InitARCFaceEngine()
        {
            //读取App.config文件
            AppSettingsReader appSetting = new AppSettingsReader();
            string            appId      = (string)appSetting.GetValue("APP_ID", typeof(string));
            string            sdkKey64   = (string)appSetting.GetValue("SDKKEY64", typeof(string));
            string            sdkKet32   = (string)appSetting.GetValue("SDKKEY32", typeof(string));

            //判断运行的CPU位数
            var is64CPU = Environment.Is64BitProcess;

            if (string.IsNullOrWhiteSpace(appId) || string.IsNullOrWhiteSpace(is64CPU?sdkKey64:sdkKet32))
            {
                MessageBox.Show($"请在App.Config配置文件中先配置APP_ID和SDKKEY{(is64CPU ? 64:32)}");
                return(-1);
            }

            //用来存储 人脸识别SDK 申请激活后的结果
            int result = 0;

            try
            {
                result = ASFFunctions.ASFActivation(appId, is64CPU ? sdkKey64 : sdkKet32);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("无法加载DLL"))
                {
                    MessageBox.Show("请将sdk相关DLL放入bin对应的x86或x64下的文件夹中!");
                }
                else
                {
                    MessageBox.Show("引擎初始化失败!");
                }

                return(-2);
            }

            LoggerService.logger.Info("人脸识别引擎激活成功。");

            return(result);
        }
Esempio n. 2
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;
            }
        }
Esempio n. 4
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();
        }
 /// <summary>
 /// 激活接口
 /// </summary>
 /// <param name="appId">appId</param>
 /// <param name="appKey">appKey</param>
 /// <returns>返回0表示正常;其他值请在官网-帮助中心查询</returns>
 public int ASFActivation(string appId, string appKey)
 {
     return(ASFFunctions.ASFActivation(appId, appKey));
 }
Esempio n. 6
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
        }