private Image GetImageFromBytes(byte[] photo) { try { if (photo != null) { string path = Path.Combine(TempFolderManager.GetCurrentFolder(), string.Format("{0}_{1}.jpg", "Staff", Guid.NewGuid().ToString())); using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) { fs.Write(photo, 0, photo.Length); } Image img = Image.FromFile(path); return(img); } else { return(null); } } catch { return(null); } }
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); }
/// <summary> /// 对通道进行图片抓拍,要求此通道有一个用于车牌识别的摄像机 /// </summary> /// <param name="parkID"></param> /// <param name="entranceID"></param> /// <returns>抓拍图片的地址,返回空时表示抓拍失败</returns> public string SnapShot(int parkID, int entranceID) { string dir = TempFolderManager.GetCurrentFolder(); try { EntranceInfo entrance = ParkBuffer.Current.GetEntrance(entranceID); if (entrance != null) { foreach (VideoSourceInfo video in entrance.VideoSources) { if (video.IsForCarPlate) { string path = Path.Combine(dir, string.Format("{0}_{1}_{2}.jpg", "SnapShot", Guid.NewGuid().ToString(), video.VideoID)); if (SnapShotTo(video, ref path, false, false)) { return(path); } } } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(string.Empty); }
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) { } }
private void mnu_ExportMonthCardPaymentReport_Click(object sender, EventArgs e) { try { DataGridViewRow row = GridView.SelectedRows[0]; OperatorSettleLog optLog = row.Tag as OperatorSettleLog; if (optLog != null) { string path = string.Empty; string modal = System.IO.Path.Combine(Application.StartupPath, @"ReportModal\MonthCardPaymentReportModal.xls"); path = System.IO.Path.Combine(TempFolderManager.GetCurrentFolder(), Guid.NewGuid().ToString() + ".xls"); ExcelExport.MonthCardReportToExcel ose = null; if (System.IO.File.Exists(modal)) { ose = new ExcelExport.MonthCardReportToExcel(modal); ose.Export(optLog, path); System.Diagnostics.Process.Start(path); } else { MessageBox.Show(Resources.Resource1.FrmOperatorLogReport_NotFind, Resources.Resource1.Form_Alert); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.Resource1.Form_Alert); Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } }
/// <summary> /// 保存抓拍图片 /// </summary> /// <param name="buf"></param> /// <returns>保存路径</returns> public string SaveSnapImage(byte[] buf) { string dir = TempFolderManager.GetCurrentFolder(); string path = Path.Combine(dir, Guid.NewGuid().ToString() + ".jpg"); if (SaveSnapImage(path, buf)) { return(path); } return(string.Empty); }
/// <summary> /// 识别某个通道的车牌号 /// </summary> /// <param name="parkID"></param> /// <param name="entranceID"></param> /// <returns></returns> public PlateRecognitionResult Recognize(int parkID, int entranceID) { string dir = TempFolderManager.GetCurrentFolder(); 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); }
public void ProcessReport(ReportBase r) { ParkInfo park = ParkBuffer.Current.GetPark(r.ParkID); if (park != null && park.RootParkID > 0) { park = ParkBuffer.Current.GetPark(park.RootParkID); } if (park == null) { return; } if (park.HostWorkstation == WorkStationInfo.CurrentStation.StationID) //如果本机是停车场的通讯主机,则它要负责抓拍图片 { EntranceInfo entrance = ParkBuffer.Current.GetEntrance(r.EntranceID); if (entrance != null) { foreach (VideoSourceInfo video in entrance.VideoSources) { if (r is CarSenseReport) { CarSenseReport cp = r as CarSenseReport; if (cp.InOrOutFlag == 1) //车到时打开视频 { VideoPanel vp = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video)); if (vp != null) { if (UserSetting.Current.SnapshotWhenCarArrive) //车压地感时抓拍图片 { string path = Path.Combine(TempFolderManager.GetCurrentFolder(), string.Format("{0}_{1}_{2}.jpg", "CarArrive", Guid.NewGuid().ToString(), video.VideoID)); if (SnapShotTo(video, ref path, false, false)) { SnapShot shot = new SnapShot(cp.EventDateTime, video.VideoID, string.Empty, path); string master = AppSettings.CurrentSetting.ImageDBConnStr; string standby = AppSettings.CurrentSetting.CurrentStandbyConnect; CommandResult result = (new SnapShotBll(master)).Insert(shot); if (result.Result != ResultCode.Successful && !string.IsNullOrEmpty(standby)) { (new SnapShotBll(standby)).Insert(shot); } //(new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } else { if (AppSettings.CurrentSetting.Debug) { string logmsg = string.Format("【{0}】车压地感时抓拍图片失败 ", vp.VideoSource.VideoName); Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg); } } } else { vp.OpenForSnapshot(true); } } } else { if (AppSettings.CurrentSetting.Optimized) //启用视频优化车走时关闭视频 { VideoPanel vp = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video)); if (vp != null) { vp.Close(); } } } } else if (r is CardEventReport) { CardEventReport cardEvent = r as CardEventReport; if (cardEvent.EventStatus == CardEventStatus.Valid) { VideoPanel vp = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video)); if (vp != null) //如果视频已经抓拍了一张,则此次用同一张图 { object tag = null; lock (_TagLocker) //加锁是防止多个线程同时写 { tag = vp.Tag; vp.Tag = null; } if (tag != null) { string path = tag.ToString(); if (path != "fail") { SnapShot shot = new SnapShot(cardEvent.EventDateTime, video.VideoID, cardEvent.CardID, path); string master = AppSettings.CurrentSetting.ImageDBConnStr; string standby = AppSettings.CurrentSetting.CurrentStandbyConnect; CommandResult result = (new SnapShotBll(master)).Insert(shot); if (result.Result != ResultCode.Successful && !string.IsNullOrEmpty(standby)) { (new SnapShotBll(standby)).Insert(shot); } //(new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } else { if (AppSettings.CurrentSetting.Debug) { string logmsg = string.Format("【{0}】刷卡事件之前的视频抓拍失败,无图片 ", vp.VideoSource.VideoName); Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg); } } } else { string path = Path.Combine(TempFolderManager.GetCurrentFolder(), string.Format("{0}_{1}_{2}.jpg", "CardEvent", Guid.NewGuid().ToString(), video.VideoID)); if (SnapShotTo(video, ref path, false, false)) { SnapShot shot = new SnapShot(cardEvent.EventDateTime, video.VideoID, cardEvent.CardID, path); string master = AppSettings.CurrentSetting.ImageDBConnStr; string standby = AppSettings.CurrentSetting.CurrentStandbyConnect; CommandResult result = (new SnapShotBll(master)).Insert(shot); if (result.Result != ResultCode.Successful && !string.IsNullOrEmpty(standby)) { (new SnapShotBll(standby)).Insert(shot); } //(new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } else { if (AppSettings.CurrentSetting.Debug) { string logmsg = string.Format("【{0}】刷卡事件抓拍图片失败 ", vp.VideoSource.VideoName); Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg); } } } vp.ClearSnapShot();//清空抓拍图片信息 } } } else if (r is AlarmReport) { AlarmReport ar = r as AlarmReport; if (ar.AlarmType == Ralid.Park.BusinessModel.Enum.AlarmType.Opendoor || ar.AlarmType == Ralid.Park.BusinessModel.Enum.AlarmType.GateAlarm) { string path = Path.Combine(TempFolderManager.GetCurrentFolder(), string.Format("{0}_{1}_{2}.jpg", "OpenDoor", Guid.NewGuid().ToString(), video.VideoID)); if (SnapShotTo(video, ref path, false, true)) { //这里清除抓拍图片信息,是因为使用信路通或大华进行抓拍时,会保存抓拍图片和识别到的车牌,如果不清除,有可能会用到下一辆车上 ClearSnapShot(video); SnapShot shot = new SnapShot(ar.EventDateTime, video.VideoID, string.Empty, path); string master = AppSettings.CurrentSetting.ImageDBConnStr; string standby = AppSettings.CurrentSetting.CurrentStandbyConnect; CommandResult result = (new SnapShotBll(master)).Insert(shot); if (result.Result != ResultCode.Successful && !string.IsNullOrEmpty(standby)) { (new SnapShotBll(standby)).Insert(shot); } //(new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } else { if (AppSettings.CurrentSetting.Debug) { string logmsg = string.Format("【{0}】报警抓拍图片失败 ", video.VideoName); Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg); } } } } } } } }
/// <summary> /// 保存车牌小图:大华早期交通抓拍机,设备不传单独的车牌小图文件,只传车牌在大图中的坐标;由应用来自行裁剪。2014年后,陆续有设备版本,支持单独传车牌小图,小图附录在pBuffer后面。 /// </summary> /// <param name="plateObj">分析物</param> /// <param name="pBuffer">数据偏移</param> /// <param name="buf">图片数据</param> /// <returns>保存路径</returns> public string SavePlateJpg(DH_MSG_OBJECT plateObj, IntPtr pBuffer, byte[] buf) { if ((plateObj.bPicEnble == 1)) //根据pBuffer中数据偏移保存小图图片文件 { // 记录车牌小图文件 if (plateObj.stPicInfo.dwFileLenth > 0) { byte[] bufs = new byte[plateObj.stPicInfo.dwFileLenth]; // Marshal. IntPtr pSmapic = (IntPtr)(pBuffer.ToInt32() + (int)(plateObj.stPicInfo.dwOffSet)); Marshal.Copy(pSmapic, bufs, 0, bufs.Length); string dir = TempFolderManager.GetCurrentFolder(); string sfile = Path.Combine(dir, @"PlateNumber_" + Guid.NewGuid().ToString() + ".jpg"); using (System.IO.FileStream fs = System.IO.File.Create(sfile)) { fs.Write(bufs, 0, bufs.Length); fs.Close(); } return(sfile); } } else //根据大图中的坐标偏移计算显示车牌小图 { if (plateObj.BoundingBox.bottom == 0 && plateObj.BoundingBox.top == 0) { return(string.Empty); } DH_RECT dhRect = plateObj.BoundingBox; //1.BoundingBox的值是在8192*8192坐标系下的值,必须转化为图片中的坐标 //2.OSD在图片中占了64行,如果没有OSD,下面的关于OSD的处理需要去掉(把OSD_HEIGHT置为0) const int OSD_HEIGHT = 64; const int HIMETRIC_INCH = 2540; System.IO.MemoryStream memo = new System.IO.MemoryStream(buf); Image im = Image.FromStream(memo); long nWidth = im.Width; long nHeight = im.Height; //此处有会引起Error creating window handle错误,而且句柄创建后也没有使用,所以这里注销了 by Jan 2015-05-25 //System.Windows.Forms.Panel p = new System.Windows.Forms.Panel(); //System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle); //IntPtr hdc = g.GetHdc(); nHeight = nHeight - OSD_HEIGHT; if ((nWidth <= 0) || (nHeight <= 0)) { return(string.Empty); } DH_RECT dstRect = new DH_RECT(); dstRect.left = (int)Math.Ceiling(((double)(nWidth * dhRect.left)) / 8192.0); dstRect.right = (int)Math.Ceiling((double)(nWidth * dhRect.right) / 8192.0); dstRect.bottom = (int)Math.Ceiling((double)(nHeight * dhRect.bottom) / 8192.0); dstRect.top = (int)Math.Ceiling((double)(nHeight * dhRect.top) / 8192.0); int x = (int)((double)dstRect.left); int y = (int)((double)(dstRect.top + OSD_HEIGHT)); int w = (int)((double)(dstRect.right - dstRect.left)); int h = (int)((double)(dstRect.bottom - dstRect.top)); Bitmap bi = (Bitmap)im.Clone(); Rectangle rect = new Rectangle(x, y, w, h); Bitmap carIM = bi.Clone(rect, bi.PixelFormat); string dir = TempFolderManager.GetCurrentFolder(); string sfile = Path.Combine(dir, @"PlateNumber_" + Guid.NewGuid().ToString() + ".jpg"); carIM.Save(sfile); return(sfile); } return(string.Empty); }
private void axHV_OnReceivePlate(object sender, EventArgs e) { try { AxHVActiveX2Lib.AxHVActiveX2 axHV = sender as AxHVActiveX2Lib.AxHVActiveX2; int videoID = axHV.GetVideoID(); DeviceState info = axHV.Tag as DeviceState; info.State = 0; foreach (CarPlateDevice device in _Devices) { if (device.IP == info.IP && device.VideoID == videoID) { device.ResetResult(); device.CarPlate = axHV.GetPlate(); device.EventDateTime = DateTime.Now; device.PlateColor = axHV.GetPlateColor(); string dir = TempFolderManager.GetCurrentFolder(); string path; path = Path.Combine(dir, Guid.NewGuid().ToString() + ".jpg"); if (axHV.SaveSnapImage(path) == 0) { device.SnapPath = path; } else { device.SnapPath = string.Empty; } path = Path.Combine(dir, Guid.NewGuid().ToString() + ".jpg"); if (axHV.SavePlateImage(path) == 0) { device.PlatePath = path; } else { device.PlatePath = string.Empty; } Action action = delegate() { foreach (DataGridViewRow row in dataGridView1.Rows) { CarPlateDevice d = row.Tag as CarPlateDevice; if (d.IP == device.IP && d.VideoID == device.VideoID) { ShowItemOnRow(device, row); } } if (_ActiveDevice != null && _ActiveDevice.IP == (axHV.Tag as DeviceState).IP && videoID == _ActiveDevice.VideoID) { this.picPlate.Image = Properties.Resources.NoImage; if (!string.IsNullOrEmpty(device.PlatePath)) { this.picPlate.Image = Image.FromFile(device.PlatePath); } } }; if (this.InvokeRequired) { this.Invoke(action); } else { action(); } } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } }
public void ProcessReport(ReportBase r) { ParkInfo park = ParkBuffer.Current.GetPark(r.ParkID); if (park != null && park.RootParkID > 0) { park = ParkBuffer.Current.GetPark(park.RootParkID); } if (park == null) { return; } if (park.HostWorkstation == WorkStationInfo.CurrentStation.StationID) //如果本机是停车场的通讯主机,则它要负责抓拍图片 { EntranceInfo entrance = ParkBuffer.Current.GetEntrance(r.EntranceID); if (entrance != null) { foreach (VideoSourceInfo video in entrance.VideoSources) { if (r is CarSenseReport) { CarSenseReport cp = r as CarSenseReport; if (cp.InOrOutFlag == 1) //车到时打开视频 { VideoPanel vp = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video)); if (vp != null) { if (UserSetting.Current.SnapshotWhenCarArrive) //车压地感时抓拍图片 { string path = Path.Combine(TempFolderManager.GetCurrentFolder(), string.Format("{0}_{1}_{2}.jpg", "CarArrive", Guid.NewGuid().ToString(), video.VideoID)); vp.Play(false); if (vp.Status == VideoStatus.Playing && vp.SnapShotTo(path)) { SnapShot shot = new SnapShot(cp.EventDateTime, video.VideoID, string.Empty, path); (new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } } else { vp.Play(true); } } } else { if (AppSettings.CurrentSetting.Optimized) //启用视频优化车走时关闭视频 { VideoPanel vp = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video)); if (vp != null) { vp.Close(); } } } } else if (r is CardEventReport) { CardEventReport cardEvent = r as CardEventReport; if (cardEvent.EventStatus == CardEventStatus.Valid) { VideoPanel vp = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video)); if (vp != null) //如果视频已经抓拍了一张,则此次用同一张图 { object tag = null; lock (_TagLocker) //加锁是防止多个线程同时写 { tag = vp.Tag; vp.Tag = null; } if (tag != null) { string path = tag.ToString(); if (path != "fail") { SnapShot shot = new SnapShot(cardEvent.EventDateTime, video.VideoID, cardEvent.CardID, path); (new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } } else { string path = Path.Combine(TempFolderManager.GetCurrentFolder(), string.Format("{0}_{1}_{2}.jpg", "CardEvent", Guid.NewGuid().ToString(), video.VideoID)); if (SnapShotTo(video, path, false)) { SnapShot shot = new SnapShot(cardEvent.EventDateTime, video.VideoID, cardEvent.CardID, path); (new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } } } } } else if (r is AlarmReport) { AlarmReport ar = r as AlarmReport; if (ar.AlarmType == Ralid.Park.BusinessModel.Enum.AlarmType.Opendoor) { string path = Path.Combine(TempFolderManager.GetCurrentFolder(), string.Format("{0}_{1}_{2}.jpg", "OpenDoor", Guid.NewGuid().ToString(), video.VideoID)); if (SnapShotTo(video, path, false)) { SnapShot shot = new SnapShot(ar.EventDateTime, video.VideoID, string.Empty, path); (new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } } } } } } }