//批量处理列表文件 private void AutoProcessImage(object sender, EventArgs e) { if (this.showTypes != UserSetting.ShowTypes.PLATE) { MessageBox.Show("当前列表打开图片不对!"); return; } if (this.listInputImage.Items.Count == 0) { MessageBox.Show("请先导入图片"); return; } MessageBox.Show(" 请选择保存路径,处理过程中请不要进行其他操作!"); string savePath; if (this.inputImageFolder.ShowDialog() == DialogResult.OK) { savePath = this.inputImageFolder.SelectedPath; } else { return; } List <string> files = new List <string>(); for (int i = 0; i < this.listInputImage.Items.Count; i++) { files.Add(this.listInputImage.Items[i].Text); } PlateLocator.AutoProcessImageByColor(files, parameterList, savePath); MessageBox.Show("处理完成"); }
//车牌识别 public static string PlateRecognite(Mat matIn) { string plate = null; if (!PlateCategorySVM.IsReady) { return("车牌识别库没有准备好"); } if (!CharCategorySVM.IsReady) { return("字符识别库没有准备好"); } //获取车牌 List <Mat> roiPlates = PlateLocator.PlateLocateByColor(matIn); //疑似区域 List <Mat> matPlates = new List <Mat>(); //车牌区域 for (int index = 0; index < roiPlates.Count; index++) { Mat mat = roiPlates[index]; if (PlateCategory.车牌 != PlateCategorySVM.Test(mat)) { continue; } else { matPlates.Add(mat); } } //颜色不行就用sobel if (matPlates.Count == 0) { roiPlates.Clear(); roiPlates = PlateLocator.PlateLocateBySobel(matIn); for (int index = 0; index < roiPlates.Count; index++) { Mat mat = roiPlates[index]; if (PlateCategory.车牌 != PlateCategorySVM.Test(mat)) { continue; } else { matPlates.Add(mat); } } } if (matPlates.Count == 0) { return("无识别出车牌"); } //下面根据识别出的车牌进行字符识别 for (int index = 0; index < matPlates.Count; index++) { Mat mat = matPlates[index]; List <Mat> roiChars = new List <Mat>(); roiChars = CharSegement.SplitePlateByOriginal(mat); if (roiChars.Count == 0) { return("无识别字符"); } for (int i = 0; i < roiChars.Count; i++) { plate = plate + CharCategorySVM.Test(roiChars[i]).ToString(); } } plate = plate.Replace("_", ""); plate = plate.Replace("非字符", ""); return(plate); }
//展示最终结果 private void ProcessAndShowResult(Mat matIn) { currentTabCount = 0; AddTag("原图", matIn); this.listShowSplitImage.Items.Clear(); this.imgListSplitImage.Images.Clear(); this.imgListSplitImage.ImageSize = new System.Drawing.Size(192, 64); List <Mat> roiPlates = PlateLocator.PlateLocateByColor(matIn); //疑似区域 List <Mat> matPlates = new List <Mat>(); //车牌区域 for (int index = 0; index < roiPlates.Count; index++) { Mat mat = roiPlates[index]; if (PlateCategory.车牌 != PlateCategorySVM.Test(mat)) { continue; } else { matPlates.Add(mat); } } //颜色不行就用sobel if (matPlates.Count == 0) { roiPlates.Clear(); roiPlates = PlateLocator.PlateLocateBySobel(matIn); for (int index = 0; index < roiPlates.Count; index++) { Mat mat = roiPlates[index]; if (PlateCategory.车牌 != PlateCategorySVM.Test(mat)) { continue; } else { matPlates.Add(mat); } } } if (matPlates.Count == 0) { MessageBox.Show("没有识别出车牌"); return; } //下面根据识别出的车牌进行字符识别 for (int index = 0; index < matPlates.Count; index++) { string plate = null; Mat mat = matPlates[index]; List <Mat> roiChars = new List <Mat>(); roiChars = CharSegement.SplitePlateByOriginal(mat); if (roiChars.Count == 0) { continue; } for (int i = 0; i < roiChars.Count; i++) { plate = plate + CharCategorySVM.Test(roiChars[i]).ToString(); } plate = plate.Replace("_", ""); plate = plate.Replace("非字符", ""); this.imgListSplitImage.Images.Add(mat.ToBitmap()); this.listShowSplitImage.Items.Add(plate); this.listShowSplitImage.Items[index].ImageIndex = index; } //MessageBox.Show(PlateRecognition.PlateRecognite(matIn)); }