public PlateRecognitionResult Recognize(int parkID, int entranceID) { string dir = TempFolderManager.GetCurrentFolder(); PlateRecognitionResult ret = new PlateRecognitionResult(); try { //EntranceInfo entrance = ParkBuffer.Current.GetEntrance(entranceID); EntranceInfo entrance = ParkBuffer.Current.GetEntrance(parkID, entranceID); if (entrance != null) { foreach (VideoSourceInfo video in entrance.VideoSources) { if (video.IsForCarPlate) { FrmSnapShoter frm = FrmSnapShoter.GetInstance(); string path = Path.Combine(dir, string.Format("{0}_{1}_{2}.jpg", "CarPlate", Guid.NewGuid().ToString(), video.VideoID)); if (frm.SnapShotTo(video, ref path, true, false)) { ret = Recognize(path); } } } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(ret); }
private void RegThread() { try { while (true) { foreach (VideoPanel vp in ucVideoPanelGrid1.VideoPanelCollection) { if (vp.Status == VideoStatus.Playing) { string file = System.IO.Path.Combine(TempFolderManager.GetCurrentFolder(), string.Format("{0}.jpg", DateTime.Now.ToString("yyyyMMddHHmmss"))); if (vp.SnapShotTo(ref file)) { PlateRecognitionResult ret = PlateRecognitionService.CurrentInstance.Recognize(file); ShowResult(ret, file); } System.Threading.Thread.Sleep(1000); } } } } catch (System.Threading.ThreadAbortException) { } catch (Exception) { } }
/// <summary> /// 识别某个通道的车牌号 /// </summary> /// <param name="parkID"></param> /// <param name="entranceID"></param> /// <returns></returns> public PlateRecognitionResult Recognize(int parkID, int entranceID) { PlateRecognitionResult ret = new PlateRecognitionResult(); try { CarPlateDevice device = _Devices.FirstOrDefault(item => item.EntranceID == entranceID && item.VideoSource != null && item.VideoSource.IsForCarPlate); if (device != null) { if (device.EventDateTime == null) { //如果没有上传时间,重新进行抓拍 SnapShotTo(device, true); } ret.CarPlate = device.CarPlate; ret.Color = device.PlateColor; } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(ret); }
/// <summary> /// 通过图片文件识别车牌号 /// </summary> public PlateRecognitionResult Recognize(string path) { PlateRecognitionResult result = new PlateRecognitionResult(); if (!string.IsNullOrEmpty(path)) { try { string plnInfo = string.Empty; if (initSuccess) { short ret = rm.RecognizeImageFile(path, string.Empty, ref plnInfo); if (ret == Success) { result = ExtractPlate(plnInfo); } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } } return(result); }
private void RegThread() { try { foreach (string file in _Files) { PlateRecognitionResult ret = PlateRecognitionService.CurrentInstance.Recognize(file); ShowResult(ret, file); } Action action = delegate() { btnStart.Enabled = true; btnStop.Enabled = false; }; if (this.InvokeRequired) { this.Invoke(action); } else { action(); } } catch (System.Threading.ThreadAbortException) { } catch (Exception) { } }
private PlateRecognitionResult ExtractPlate(string plnInfo) { //plnInfo 的格式形如 [pln|score|坐标|color]只取pln PlateRecognitionResult result = new PlateRecognitionResult(); if (!string.IsNullOrEmpty(plnInfo)) { try { plnInfo = plnInfo.Trim('[', ']'); string[] infoes = plnInfo.Split('|'); if (infoes != null && infoes.Length > 0) { result.CarPlate = infoes[0]; int temp = 0; int.TryParse(infoes[1], out temp); result.Color = GetColorDescr(temp); } } catch { } } return(result); }
/// <summary> /// 通过图片文件识别车牌号 /// </summary> public PlateRecognitionResult Recognize(string path) { int nWidth = 0; int nHeight = 0; PlateRecognitionResult result = new PlateRecognitionResult(); try { if (_Inited) { TH_PlateResult[] pRes = new TH_PlateResult[3]; int RetNum = 1; byte[] pBuffer = LockUnlockBitsExample(path, out nHeight, out nWidth); TH_RECT rect = new TH_RECT(); rect.top = 0; rect.bottom = nHeight; rect.left = 0; rect.right = nWidth; int nResult = -1; lock (_Locker) { nResult = TH_RecogImage(pBuffer, nWidth, nHeight, pRes, ref RetNum, ref rect, ref c_defConfig); } if (nResult == 0) { result.CarPlate = PlateLicense(pRes[0].lic0, (short)pRes[0].lic1, (short)pRes[0].lic2, (short)pRes[0].lic3, (short)pRes[0].lic4);//调用车牌号码转换函数 } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(result); }
private void btnNext_Click(object sender, EventArgs e) { if (_Files.Count > 0 && _CurFileIndex < _Files.Count - 1) { _CurFileIndex++; this.picImage.Image = System.Drawing.Image.FromFile(_Files[_CurFileIndex]); PlateRecognitionResult ret = PlateRecognitionService.CurrentInstance.Recognize(_Files[_CurFileIndex]); ShowResult(ret, _Files[_CurFileIndex]); btnNext.Enabled = (_CurFileIndex < _Files.Count - 1); } }
private void ShowResult(PlateRecognitionResult ret, string file) { Action action = delegate() { this.picImage.Image = System.Drawing.Image.FromFile(file); _Total += 1; int row = this.resultGrid.Rows.Add(); if (row >= (resultGrid.DisplayedRowCount(false) + resultGrid.FirstDisplayedScrollingRowIndex)) { resultGrid.FirstDisplayedScrollingRowIndex = resultGrid.Rows.Count - resultGrid.DisplayedRowCount(false); } this.resultGrid.Rows[row].Tag = file; this.resultGrid.Rows[row].Cells["colFileName"].Value = Path.GetFileName(file); this.resultGrid.Rows[row].Cells["colCarPlate"].Value = ret.CarPlate; this.resultGrid.Rows[row].Cells["colBackColor"].Value = ret.Color; if (!string.IsNullOrEmpty(ret.CarPlate)) { if (!string.IsNullOrEmpty(txtCarplate.Text)) { if (txtCarplate.Text == ret.CarPlate) { _RegCount += 1; } else { this.resultGrid.Rows[row].DefaultCellStyle.BackColor = Color.Yellow; } } else { _RegCount += 1; } } else { this.resultGrid.Rows[row].DefaultCellStyle.ForeColor = Color.Red; } txtTotal.Text = _Total.ToString(); txtRegCount.Text = _RegCount.ToString(); txtPercent.Text = ((double)_RegCount / _Total).ToString("F2"); }; if (this.InvokeRequired) { this.Invoke(action); } else { action(); } }
private PlateRecognitionResult CarPalteRecognize(int parkID, int entranceID) { PlateRecognitionResult result = new PlateRecognitionResult(); if (PlateRecognitionService.CurrentInstance != null) { try { result = PlateRecognitionService.CurrentInstance.Recognize(parkID, entranceID); } catch (Exception ex) { ExceptionPolicy.HandleException(ex); } } return(result); }
/// <summary> /// 识别某个通道的车牌号 /// </summary> /// <param name="parkID"></param> /// <param name="entranceID"></param> /// <returns></returns> public PlateRecognitionResult Recognize(int parkID, int entranceID) { PlateRecognitionResult ret = new PlateRecognitionResult(); try { CarPlateDevice device = _Devices.SingleOrDefault(item => item.EntranceID == entranceID); if (device != null && device.EventDateTime != null) { ret.CarPlate = device.CarPlate; ret.Color = device.PlateColor; } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(ret); }
/// <summary> /// 通过图片文件识别车牌号 /// </summary> public PlateRecognitionResult Recognize(string path) { int nWidth = 0; int nHeight = 0; PlateRecognitionResult result = new PlateRecognitionResult(); try { if (_Inited) { TH_PlateResult[] pRes = new TH_PlateResult[3]; int RetNum = 1; byte[] pBuffer = LockUnlockBitsExample(path, out nHeight, out nWidth); TH_RECT rect = new TH_RECT(); rect.top = 0; rect.bottom = nHeight; rect.left = 0; rect.right = nWidth; int nResult = -1; lock (_Locker) { nResult = TH_RecogImage(pBuffer, nWidth, nHeight, pRes, ref RetNum, ref rect, ref c_defConfig); } if (nResult == 0) { //以下是就版本的结构体转换车牌,使用该结构体转换得到的车牌,如果车牌后包括“港”、“警”等汉字的,转换后会变成“?” //result.CarPlate = PlateLicense(pRes[0].lic0, pRes[0].lic1, pRes[0].lic2, pRes[0].lic3);//调用车牌号码转换函数 //车牌号码转换 Encoding gbkencoding = Encoding.GetEncoding("gbk"); byte[] unicodebuf = Encoding.Convert(gbkencoding, Encoding.Unicode, pRes[0].license); string carplate = Encoding.Unicode.GetString(unicodebuf, 0, unicodebuf.Length); result.CarPlate = carplate.Trim('\0');//去掉结尾的\0符 } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(result); }
private void CarplateRecHandler(CarplateRecReport report) { try { string carPlate = string.Empty; for (int i = 0; i < 10; i++) { PlateRecognitionResult ret = CarPalteRecognize(this.Park.RootParkID, this.EntranceID); if (ret != null && !string.IsNullOrEmpty(ret.CarPlate) && ret.CarPlate != carPlate) { carPlate = ret.CarPlate; FileLog.Log(this.EntranceName, "识别到车牌号 " + ret.CarPlate); //先寻找完全匹配的车牌号,如果启用了允许车牌号有误差,再用较慢的方法寻找相匹配的车牌号 //这样的话只有车牌号不能完全匹配时才影响会多做一步费时的操作。 List <CardInfo> cards = GetCardHasCarplate(ret.CarPlate, 0); if ((cards == null || cards.Count == 0) && UserSetting.Current.MaxCarPlateErrorChar > 0) { cards = GetCardHasCarplate(ret.CarPlate, UserSetting.Current.MaxCarPlateErrorChar); } if (cards != null && cards.Count == 1) { CardReadReport re = new CardReadReport(); re.CardID = cards[0].CardID; re.ParkingData = null; re.ParkID = this.Park.ParkID; re.EntranceID = this.EntranceID; re.EventDateTime = DateTime.Now; re.CannotIgnored = true; re.Reader = Ralid.Park.BusinessModel.Enum.EntranceReader.DeskTopReader; re.LastCarPlate = string.Empty; this.Carplate = ret.CarPlate; this.AddToReportPool(re); break; //退出循环 } else if (cards == null || cards.Count == 0) { AlarmReport alarm = new AlarmReport( this.Park.ParkID, this.EntranceID, DateTime.Now, this.EntranceName, AlarmType.CarPlateFail, "未找到匹配的车牌,识别到的车牌号为:" + ret.CarPlate, string.Empty); if (this.AlarmReporting != null) { this.AlarmReporting(this, alarm); } } else if (cards.Count > 1) { if (AppSettings.CurrentSetting.Debug) { FileLog.Log(this.EntranceName, "多个人员匹配到车牌:" + ret.CarPlate + " 需要手动输入车牌号放行"); } AlarmReport alarm = new AlarmReport( this.Park.ParkID, this.EntranceID, DateTime.Now, this.EntranceName, AlarmType.CarPlateFail, "多个人员匹配到车牌:" + ret.CarPlate + " 需要手动输入车牌号放行", string.Empty); if (this.AlarmReporting != null) { this.AlarmReporting(this, alarm); } } } Thread.Sleep(200); } //end for } catch (ThreadAbortException ex) { } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } }