public JObject Idcard(string imageFilename, string idCardSide = "front") { JObject result = null; if (imageFilename != null) { var image = File.ReadAllBytes(imageFilename); // 调用通用文字识别, 图片参数为本地图片,可能会抛出网络等异常,请使用try/catch捕获 try{ result = client.Idcard(image, idCardSide); }catch (Exception e) { Debug.Log("异常:" + e); } } return(result); }
/// <summary> /// Automatic Recognition 开始自动识别 /// </summary> private void IDRecognition() { string apiKey = ConfigurationHelper.GetConfig(ConfigItemName.baiduApiKey.ToString()); string apiScret = ConfigurationHelper.GetConfig(ConfigItemName.baiduApiSecretKey.ToString()); Ocr ocr = new Ocr(apiKey, apiScret); Newtonsoft.Json.Linq.JObject ob = ocr.Idcard(FileHelper.GetBytes(imagePath), "front"); //BaiduLicenseRecognition baiduLicense = BaiduAipHelper.getLicenseRecognition(ob); ConsoleHelper.writeLine(ob.ToString()); MessageBox.Show(ob.ToString()); }
private void button3_Click(object sender, EventArgs e) { if (textBox1.Text == null || textBox1.Text == "") { MessageBox.Show("请选择图片"); return; } var image = File.ReadAllBytes(textBox1.Text); // 调用网络图片文字识别, 图片参数为本地图片,可能会抛出网络等异常,请使用try/catch捕获 JObject result = null; String printresult = ""; //身份证 if (radioButton4.Checked || radioButton5.Checked) { if (radioButton4.Checked) { result = client.Idcard(image, "front"); } else { result = client.Idcard(image, "back"); } JObject jo = (JObject)result["words_result"]; if (jo["姓名"] != null) { printresult = printresult + ("姓名:" + Convert.ToString(jo["姓名"]["words"]) + "\n"); } if (jo["性别"] != null) { printresult = printresult + ("性别:" + Convert.ToString(jo["性别"]["words"]) + "\n"); } if (jo["民族"] != null) { printresult = printresult + ("民族:" + Convert.ToString(jo["民族"]["words"]) + "\n"); } if (jo["出生"] != null) { printresult = printresult + ("出生:" + Convert.ToString(jo["出生"]["words"]) + "\n"); } if (jo["住址"] != null) { printresult = printresult + ("地址:" + Convert.ToString(jo["住址"]["words"]) + "\n"); } if (jo["公民身份号码"] != null) { printresult = printresult + ("公民身份号码:" + Convert.ToString(jo["公民身份号码"]["words"]) + "\n"); } } //银行卡 if (radioButton6.Checked) { result = client.Bankcard(image); printresult = printresult + "银行名称:" + Convert.ToString(result["result"]["bank_name"]) + "\n"; printresult = printresult + "银行卡号:" + Convert.ToString(result["result"]["bank_card_number"]) + "\n"; } //驾驶证识别 if (radioButton8.Checked) { result = client.DrivingLicense(image); printresult = printresult + "证号:" + Convert.ToString(result["words_result"]["证号"]["words"]) + "\n"; printresult = printresult + "有效期限:" + Convert.ToString(result["words_result"]["有效期限"]["words"]) + "\n"; printresult = printresult + "准驾车型:" + Convert.ToString(result["words_result"]["准驾车型"]["words"]) + "\n"; printresult = printresult + "有效起始日期:" + Convert.ToString(result["words_result"]["有效起始日期"]["words"]) + "\n"; printresult = printresult + "姓名:" + Convert.ToString(result["words_result"]["姓名"]["words"]) + "\n"; printresult = printresult + "国籍:" + Convert.ToString(result["words_result"]["国籍"]["words"]) + "\n"; printresult = printresult + "出生日期:" + Convert.ToString(result["words_result"]["出生日期"]["words"]) + "\n"; printresult = printresult + "性别:" + Convert.ToString(result["words_result"]["性别"]["words"]) + "\n"; printresult = printresult + "初次领证日期:" + Convert.ToString(result["words_result"]["初次领证日期"]["words"]) + "\n"; } //营业执照识别 if (radioButton7.Checked) { // 调用营业执照识别,可能会抛出网络等异常,请使用try/catch捕获 result = client.BusinessLicense(image); printresult = printresult + "单位名称:" + Convert.ToString(result["words_result"]["单位名称"]["words"]) + "\n"; printresult = printresult + "法人:" + Convert.ToString(result["words_result"]["法人"]["words"]) + "\n"; printresult = printresult + "地址:" + Convert.ToString(result["words_result"]["地址"]["words"]) + "\n"; printresult = printresult + "有效期:" + Convert.ToString(result["words_result"]["有效期"]["words"]) + "\n"; printresult = printresult + "证件编号:" + Convert.ToString(result["words_result"]["证件编号"]["words"]) + "\n"; printresult = printresult + "社会信用代码:" + Convert.ToString(result["words_result"]["社会信用代码"]["words"]) + "\n"; } //行驶证 if (radioButton8.Checked) { // 调用营业执照识别,可能会抛出网络等异常,请使用try/catch捕获 result = client.VehicleLicense(image); printresult = printresult + "品牌型号:" + Convert.ToString(result["words_result"]["品牌型号"]["words"]) + "\n"; printresult = printresult + "发证日期:" + Convert.ToString(result["words_result"]["发证日期"]["words"]) + "\n"; printresult = printresult + "使用性质:" + Convert.ToString(result["words_result"]["使用性质"]["words"]) + "\n"; printresult = printresult + "发动机号码:" + Convert.ToString(result["words_result"]["发动机号码"]["words"]) + "\n"; printresult = printresult + "号牌号码:" + Convert.ToString(result["words_result"]["号牌号码"]["words"]) + "\n"; printresult = printresult + "所有人:" + Convert.ToString(result["words_result"]["所有人"]["words"]) + "\n"; printresult = printresult + "住址:" + Convert.ToString(result["words_result"]["住址"]["words"]) + "\n"; printresult = printresult + "注册日期:" + Convert.ToString(result["words_result"]["注册日期"]["words"]) + "\n"; printresult = printresult + "车辆识别代号:" + Convert.ToString(result["words_result"]["车辆识别代号"]["words"]) + "\n"; printresult = printresult + "车辆类型:" + Convert.ToString(result["words_result"]["车辆类型"]["words"]) + "\n"; } //车牌 if (radioButton9.Checked) { // 调用营业执照识别,可能会抛出网络等异常,请使用try/catch捕获 result = client.LicensePlate(image); printresult = printresult + "颜色:" + Convert.ToString(result["words_result"]["color"]) + "\n"; printresult = printresult + "车牌号:" + Convert.ToString(result["words_result"]["number"]) + "\n"; } richTextBox3.Text = printresult; }