資源簡介
【實(shí)例簡介】
比較簡陋的車輛牌照識別,起個拋磚引玉的作用
需要引用百度AipSdk,Newtonsoft.Json,自行在網(wǎng)上下載
API_KEY和SECRET_KEY 自行申請
【核心代碼】
richTextBox6.Text = "";
var client = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY);
filePath = FileDialogHelper.OpenImage();
if (!string.IsNullOrEmpty(filePath))
{
pictureBox1.Image = Image.FromFile(filePath);
var image = File.ReadAllBytes(filePath);
pictureBox1.Refresh();
// 如果有可選參數(shù)
var options = new Dictionary<string, object>
{
{"multi_detect", "true"}
};
var result = client.LicensePlate(image, options);
LicensePlate.RootObject rb = JsonConvert.DeserializeObject<LicensePlate.RootObject>(result.ToString());
List<LicensePlate.Words_result> Result_info = rb.words_result;
string value = "";
richTextBox6.Text = "";
List<LicensePlate.Vertexes_location> mylocation = new List<LicensePlate.Vertexes_location>();
if (Result_info == null)
{
richTextBox6.Text = "無法識別車輛牌照";
return;
}
value = "共識別到" Result_info.Count.ToString() "個車牌" "\r\n";
for (int i = 0; i < Result_info.Count; i )
{
mylocation = Result_info[i].vertexes_location;
DrawLine(mylocation[0].x, mylocation[0].y, mylocation[1].x, mylocation[1].y, pictureBox1);
pictureBox1.Refresh();
DrawLine(mylocation[1].x, mylocation[1].y, mylocation[2].x, mylocation[2].y, pictureBox1);
pictureBox1.Refresh();
DrawLine(mylocation[2].x, mylocation[2].y, mylocation[3].x, mylocation[3].y, pictureBox1);
pictureBox1.Refresh();
DrawLine(mylocation[3].x, mylocation[3].y, mylocation[0].x, mylocation[0].y, pictureBox1);
pictureBox1.Refresh();
value = "第" (i 1).ToString() "個" Result_info[i].color " " Result_info[i].number "\r\n";
richTextBox6.Text = richTextBox6.Text "\r\n" value;
}
pictureBox1.Refresh();
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?Baidu.Aip.Ocr;
using?WHC.framework.Commons;
using?System.IO;
using?Newtonsoft.Json.Linq;
using?Newtonsoft.Json;
namespace?車牌識別
{
????public?partial?class?Form1?:?Form
????{
????????
????????string?filePath;
????????string?API_KEY?=?“你的API_KEY“;
????????string?SECRET_KEY?=?“你的SECRET_KEY“;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????richTextBox6.Text?=?““;
????????????var?client?=?new?Baidu.Aip.Ocr.Ocr(API_KEY?SECRET_KEY);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????41984??2019-05-14?12:35??車牌識別\身份證識別.v12.suo
?????文件??????57344??2019-05-10?11:28??車牌識別\車輛牌照識別\AipSdk.dll
?????文件??????66381??2019-05-10?11:28??車牌識別\車輛牌照識別\AipSdk.xm
?????文件????????187??2019-05-10?11:30??車牌識別\車輛牌照識別\App.config
?????文件??????57344??2019-05-10?11:28??車牌識別\車輛牌照識別\bin\Debug\AipSdk.dll
?????文件??????66381??2019-05-10?11:28??車牌識別\車輛牌照識別\bin\Debug\AipSdk.xm
?????文件?????525824??2017-06-18?13:56??車牌識別\車輛牌照識別\bin\Debug\Newtonsoft.Json.dll
?????文件?????215392??2017-06-18?13:56??車牌識別\車輛牌照識別\bin\Debug\Newtonsoft.Json.pdb
?????文件?????527790??2017-06-18?13:56??車牌識別\車輛牌照識別\bin\Debug\Newtonsoft.Json.xm
?????文件?????821248??2019-05-07?09:58??車牌識別\車輛牌照識別\bin\Debug\WHC.fr
?????文件????1004436??2014-12-19?20:29??車牌識別\車輛牌照識別\bin\Debug\WHC.fr
?????文件??????13312??2019-05-14?12:44??車牌識別\車輛牌照識別\bin\Debug\身份證識別.exe
?????文件????????187??2019-05-10?11:30??車牌識別\車輛牌照識別\bin\Debug\身份證識別.exe.config
?????文件??????36352??2019-05-14?12:44??車牌識別\車輛牌照識別\bin\Debug\身份證識別.pdb
?????文件??????23168??2019-05-14?12:44??車牌識別\車輛牌照識別\bin\Debug\身份證識別.vshost.exe
?????文件????????187??2019-05-10?11:30??車牌識別\車輛牌照識別\bin\Debug\身份證識別.vshost.exe.config
?????文件????????490??2013-03-18?17:00??車牌識別\車輛牌照識別\bin\Debug\身份證識別.vshost.exe.manifest
?????文件???????4034??2019-05-14?12:46??車牌識別\車輛牌照識別\Form1.cs
?????文件???????4105??2019-05-14?12:44??車牌識別\車輛牌照識別\Form1.Designer.cs
?????文件???????5817??2019-05-14?12:31??車牌識別\車輛牌照識別\Form1.resx
?????文件????????971??2019-05-14?12:44??車牌識別\車輛牌照識別\LicensePlate.cs
?????文件?????525824??2017-06-18?13:56??車牌識別\車輛牌照識別\Newtonsoft.Json.dll
?????文件?????215392??2017-06-18?13:56??車牌識別\車輛牌照識別\Newtonsoft.Json.pdb
?????文件?????527790??2017-06-18?13:56??車牌識別\車輛牌照識別\Newtonsoft.Json.xm
?????文件????????865??2019-05-10?11:30??車牌識別\車輛牌照識別\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7483??2019-05-14?12:38??車牌識別\車輛牌照識別\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????????0??2019-05-10?11:30??車牌識別\車輛牌照識別\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件??????????0??2019-05-10?11:30??車牌識別\車輛牌照識別\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件??????????0??2019-05-10?11:30??車牌識別\車輛牌照識別\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????文件???????3686??2019-05-14?12:35??車牌識別\車輛牌照識別\obj\Debug\身份證識別.csproj.FileListAbsolute.txt
............此處省略29個文件信息
評論
共有 條評論