直接上干货,最终完成的效果图。
接前面博客继续:《9、Haclon图像中字符识别》https://blog.csdn.net/panjinliang066333/article/details/104676302
(1)将已经可以实现车牌识别的Halcon程序,以C#文件格式导出。
(2)创建C# winform 程序工程,按照上一节所讲的进行配置,运行没有报错。
(3)按照效果图进行界面布局。
代码实现:
(1)打开车牌图片。需要注意的是,车牌图片在面板上全屏显示需要额外的进行设置。
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true; //该值确定是否可以选择多个文件
ofd.Title = "请选择文件夹";
ofd.Filter = "所有文件(*.*)|*.*";
if(ofd.ShowDialog()==DialogResult.OK)
{
sPathPic = ofd.FileName;
}
//读取图片
HOperatorSet.ReadImage(out ho_Image, sPathPic);
//适应全屏
HTuple hv_Width,hv_Height;
HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
HOperatorSet.SetPart(hWindowControl1.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
//显示图片
hWindowControl1.HalconWindow.DispObj(ho_Image);
(2)车牌识别。将Halcon导出的C#格式代码,private void action()复制并整理。识别车牌的字符串和准确度,结果为数组型。
//显示车牌的识别结果---字符串保存
string sCarIDs = "";
for (int i = 0; i < hv_Class.TupleLength(); i++)
{
sCarIDs += hv_Class[i];
}
txtCarID.Text = sCarIDs;
//显示车牌每个字符的识别准确度
string sConfidence = "";
for (int i = 0; i < hv_Confidence.TupleLength();i++ )
{
sConfidence += hv_Confidence[i];
sConfidence += "\r\n";
}
txtConfidence.Text = sConfidence;
工程下载链接:https://download.csdn.net/download/panjinliang066333/14040204