/// <summary> /// 抓拍图片 /// </summary> /// <param name="video">要抓拍的摄像机</param> /// <param name="path">抓拍图片路径,如摄像机自动抓拍,返回抓拍到的图片路径</param> /// <param name="optimized">如果启用优化,则发现视频没有打开时不再尝试打开视频,而是直接返回</param> /// <returns></returns> public bool SnapShotTo(VideoSourceInfo video, ref string path, bool optimized, bool force) { bool success = false; VideoPanel vp = videoGrid.VideoPanelCollection.SingleOrDefault(v => (v.VideoSource == video)); if (vp != null) { //如果没有启用视频抓拍性能优化功能,则在抓拍时如果视频没有打开,会先尝试打开视频,启用优化后,视频由地感检测车到时打开,在抓拍时就不负责打开视频 //这样的话如果系统中存在有问题的视频,也不会影响软件的处理速度 if (!vp.IsReadyForSnapshot && !optimized) { vp.OpenForSnapshot(false); } if (vp.IsReadyForSnapshot) { success = vp.SnapShotTo(ref path, 1000, force); if (optimized) { lock (_TagLocker) { vp.Tag = success ? path : "fail"; //抓拍失败时也要通知下一次不要再继续抓拍了 } } } } return(success); }
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); } } } } } } } }