/// <summary>
        /// 识别操作
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="id_card_side">身份证 正面还是背面</param>
        /// <param name="detect_direction"></param>
        /// <param name="detect_risk"></param>
        public void Distinguish(string filePath, string id_card_side = "front", bool detect_direction = false, string detect_risk = "false")
        {
            DoTime();//主线程执行进度条,子线程进行数据请求操作
            t1 = new Thread(new ThreadStart(() =>
            {
                var temp = BaiduAIAPI.Access_Token.GetAccessToken();
                if (temp.IsSuccess)
                {
                    string data  = "";
                    string error = "";
                    var result   = IDCardRecognition.GetIdcardRecognitionString(temp.SuccessModel.access_token, filePath, ref data, out error, id_card_side, detect_direction, detect_risk);
                    this.Invoke(new Action(() =>
                    {
                        tb_showInfo.AppendText("\r\n -----------------------------------------------------------------");
                    }));

                    if (result.state)
                    {
                        this.Invoke(new Action(() =>
                        {
                            tb_showInfo.AppendText("\r\n ---------------------------识别成功-------------------------------");
                            tb_showInfo.AppendText("\r\n" + result.successModel.ToJson() + "\r\n");
                        }));
                    }
                    else
                    {
                        this.Invoke(new Action(() =>
                        {
                            tb_showInfo.AppendText("\r\n-----------------------------识别失败!--------------------------------");
                            tb_showInfo.AppendText("\r\n" + result.successModel.ToJson() + result.errorMsg + "\r\n");
                        }));
                    }
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        AttrMessage.ErrorMsg(temp.ErrorModel.error);
                    }));
                }

                this.Invoke(new Action(() =>
                {
                    progressBar_ToReadDistinguish.Value = 100;
                    timer1.Enabled = false;
                    progressBar_ToReadDistinguish.Value = 0;
                }));
            }));

            t1.IsBackground = true;
            t1.Start();
        }
Exemple #2
0
        private void btn_IDCardRecognition_Click(object sender, EventArgs e)
        {
            var temp = BaiduAIAPI.Access_Token.GetAccessToken();

            if (temp.IsSuccess)
            {
                tb_AccessToken.Text = temp.SuccessModel.access_token;
                string startPath = "C:\\";
                string fileType  = "图片|*.jpg;*.png;*.bmp;";

                string path  = DialogHelper.OpenDialog(openFileDialog1, startPath, fileType);
                string data  = "";
                string error = "";
                IDCardRecognition.GetIdcardRecognitionString(temp.SuccessModel.access_token, path, ref data, out error);
                tb_Result.Text = data;
            }
        }