/// <summary> /// 抓拍图片 /// </summary> /// <param name="device">要抓拍的摄像机</param> /// <param name="force">是否强制重新抓拍,不管之前有没有抓拍到图片</param> /// <returns></returns> private bool SnapShotTo(CarPlateDevice device, bool force) { if (device != null) { if (!force && !string.IsNullOrEmpty(device.SnapPath)) { //如果不强制重新抓拍,之前已经有抓拍图片了,就不再需要抓拍图片了 return(true); } AxHVActiveX2Lib.AxHVActiveX2 axHV = _HVS.SingleOrDefault(item => (item.Tag as DeviceState).IP == device.IP); if (axHV != null) { device.ResetResult(); axHV.ForceSendEx(device.VideoID); int wait = 0; //最多等待1秒来等待抓拍图片 while (wait < 1000) { Thread.Sleep(100); if (!string.IsNullOrEmpty(device.SnapPath)) { return(true); } wait += 100; } } } return(false); }
private void ShowCarPlateInfo(CarPlateDevice device) { Action action = delegate() { this.pictureBoxCar.Image = null; this.pictureBoxSnapshot.Image = null; if (!string.IsNullOrEmpty(device.PlatePath)) { this.pictureBoxCar.Image = Image.FromFile(device.PlatePath); } if (!string.IsNullOrEmpty(device.SnapPath)) { this.pictureBoxSnapshot.Image = Image.FromFile(device.SnapPath); } this.textBoxPlate.Text = device.CarPlate; this.textBoxPlateColor.Text = device.PlateColor; this.textBoxAutoColor.Text = device.CarColor; this.textBoxLane.Text = device.Lane.ToString(); this.textBoxTime.Text = device.DeviceSnapTime.HasValue ? device.DeviceSnapTime.Value.ToString() : string.Empty; }; if (this.InvokeRequired) { this.BeginInvoke(action); } else { action(); } }
/// <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> /// <param name="device">要抓拍的摄像机</param> /// <param name="force">是否强制重新抓拍,不管之前有没有抓拍到图片</param> /// <returns></returns> private bool SnapShotTo(CarPlateDevice device, bool force) { if (device != null) { if (!force && !string.IsNullOrEmpty(device.SnapPath)) { //如果不强制重新抓拍,之前已经有抓拍图片了,就不再需要抓拍图片了 return(true); } ManualSnap(device); int wait = 0; //最多等待1秒来等待抓拍图片 while (wait < 1000) { Thread.Sleep(100); if (!string.IsNullOrEmpty(device.SnapPath)) { return(true); } wait += 100; } } return(false); }
/// <summary> /// 对通道进行图片抓拍,要求此通道有一个用于车牌识别的摄像机 /// </summary> /// <param name="parkID"></param> /// <param name="entranceID"></param> /// <returns>抓拍图片的地址,返回空时表示抓拍失败</returns> public string SnapShot(int parkID, int entranceID) { try { CarPlateDevice device = _Devices.SingleOrDefault(item => item.EntranceID == entranceID); if (device != null) { AxHVActiveX2Lib.AxHVActiveX2 axHV = _HVS.SingleOrDefault(item => (item.Tag as DeviceState).IP == device.IP); if (axHV != null) { device.ResetResult(); axHV.ForceSendEx(device.VideoID); int wait = 0; //最多等待1秒来等待抓拍图片 while (wait < 1000) { Thread.Sleep(100); if (!string.IsNullOrEmpty(device.SnapPath)) { return(device.SnapPath); } wait += 100; } } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(string.Empty); }
private void ShowItemOnRow(CarPlateDevice device, DataGridViewRow row) { Action action = delegate() { row.Tag = device; row.Cells["colEntranceName"].Value = device.EntranceName; row.Cells["colIP"].Value = device.IP; row.Cells["colVideoID"].Value = device.VideoID; row.Cells["colCarPlate"].Value = device.CarPlate; row.Cells["colEventDate"].Value = device.EventDateTime; if (device.State == 1) { row.Cells["colState"].Value = Resources.Resource1.Connected; } else if (device.State == 1) { row.Cells["colState"].Value = Resources.Resource1.Disconnect; } else { row.Cells["colState"].Value = Resources.Resource1.Unconnected; } }; if (this.InvokeRequired) { this.BeginInvoke(action); } else { action(); } }
private void RealPlay(CarPlateDevice device) { if (device != null && device.m_nLoginID != 0) { //启动监视 device.m_realPlayH = DHClient.DHRealPlay(device.m_nLoginID, device.VideoID, this.pictureBoxImg.Handle); } }
private void StopRealPlay(CarPlateDevice device) { if (device != null && device.m_nLoginID != 0 && device.m_realPlayH != 0) { //停止监视 DHClient.DHStopRealPlay(device.m_realPlayH); device.m_realPlayH = 0; this.pictureBoxImg.Image = null; } }
public void Init() { foreach (ParkInfo park in ParkBuffer.Current.Parks) { if (park.IsRootPark && park.HostWorkstation == WorkStationInfo.CurrentStation.StationID) { List <EntranceInfo> entrances = park.GetEntrances(true); foreach (EntranceInfo entrance in entrances) { if (!string.IsNullOrEmpty(entrance.CarPlateIP)) { if (!_HVS.Exists(item => (item.Tag as DeviceState).IP == entrance.CarPlateIP)) { AxHVActiveX2Lib.AxHVActiveX2 axHV = new AxHVActiveX2Lib.AxHVActiveX2(); ((System.ComponentModel.ISupportInitialize)(axHV)).BeginInit(); this.Controls.Add(axHV); axHV.Visible = false; ((System.ComponentModel.ISupportInitialize)(axHV)).EndInit(); axHV.RecvSnapImageFlag = 1; axHV.RecvPlateImageFlag = 1; axHV.RecvPlateBinImageFlag = 0; axHV.RecvVideoFlag = 0; axHV.AutoSaveFlag = false; axHV.OnReceivePlate += new EventHandler(axHV_OnReceivePlate); axHV.OnReceiveVideo += new EventHandler(axHV_OnReceiveVideo); axHV.Tag = new DeviceState() { IP = entrance.CarPlateIP, State = -1 }; _HVS.Add(axHV); } CarPlateDevice device = new CarPlateDevice() { IP = entrance.CarPlateIP, VideoID = entrance.VideoID != null ? entrance.VideoID.Value : 0, EntranceID = entrance.EntranceID, EntranceName = entrance.EntranceName }; _Devices.Add(device); } } ShowItemsOnGrid(_Devices); if (_Devices.Count > 0) { _ActiveDevice = _Devices[0]; } dataGridView1_CellMouseDown(this.dataGridView1, new DataGridViewCellMouseEventArgs(0, 0, 0, 0, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0))); } } Thread t = new Thread(ConnectAllDevices); t.IsBackground = true; t.Start(); }
public void Init() { if (_Inited) { return; //已经初始化的,返回 } _Inited = true; _Devices.Clear(); foreach (ParkInfo park in ParkBuffer.Current.Parks) { if (park.IsRootPark && park.HostWorkstation == WorkStationInfo.CurrentStation.StationID) { List <EntranceInfo> entrances = park.GetEntrances(true); foreach (EntranceInfo entrance in entrances) { foreach (VideoSourceInfo video in entrance.VideoSources) { if (video.VideoSourceType == (int)VideoServerType.DaHua) { CarPlateDevice device = new CarPlateDevice() { IP = video.MediaSource, VideoID = video.Channel, EntranceID = video.EntranceID, EntranceName = entrance.EntranceName, VideoSource = video }; _Devices.Add(device); } } } ShowItemsOnGrid(_Devices); } } //初始化SDK if (initialized == false) { //这里不直接使用DHClient初始化,是因为DHClient的disConnect和onlineMsg只支持一个事件回调, //所以这里使用管理器的事件处理,在管理器中使用DHClient初始化 DaHuaSDKManager.GetInstance().DisConnectEventHandle -= disConnect; DaHuaSDKManager.GetInstance().DisConnectEventHandle += disConnect; DaHuaSDKManager.GetInstance().OnlineMsgEventHandle -= onlineMsg; DaHuaSDKManager.GetInstance().OnlineMsgEventHandle += onlineMsg; DaHuaSDKManager.GetInstance().InitSDK(); initialized = true; } if (_ConnectThread == null) { _ConnectThread = new Thread(ConnectAllDevices); _ConnectThread.IsBackground = true; _ConnectThread.Start(); } }
private void btnForceSnap_Click(object sender, EventArgs e) { if (this.dataGridView1.SelectedRows != null && this.dataGridView1.SelectedRows.Count == 1) { CarPlateDevice device = this.dataGridView1.SelectedRows[0].Tag as CarPlateDevice; AxHVActiveX2Lib.AxHVActiveX2 axHV = _HVS.SingleOrDefault(item => (item.Tag as DeviceState).IP == device.IP); if (axHV != null) { device.ResetResult(); axHV.ForceSendEx(device.VideoID); } } }
/// <summary> /// 自动重连成功事件 /// </summary> /// <param name="lLoginID"></param> /// <param name="pchDVRIP"></param> /// <param name="nDVRPort"></param> /// <param name="dwUser"></param> private void OnlineEvent(int lLoginID, StringBuilder pchDVRIP, int nDVRPort, IntPtr dwUser) { CarPlateDevice device = _Devices.SingleOrDefault(d => d.m_nLoginID == lLoginID); if (device != null) { //自动重连成功事件后,发起订阅设备事件消息 device.m_nRealLoadPic = DHClient.DHRealLoadPicture(device.m_nLoginID, device.VideoID, EventIvs.EVENT_IVS_ALL, anaCallback, 0); device.State = 1; } }
private void ShowItemOnRow(CarPlateDevice device, DataGridViewRow row) { row.Tag = device; row.Cells["colEntranceName"].Value = device.EntranceName; row.Cells["colIP"].Value = device.IP; row.Cells["colVideoID"].Value = device.VideoID; row.Cells["colCarPlate"].Value = device.CarPlate; row.Cells["colEventDate"].Value = device.EventDateTime; AxHVActiveX2Lib.AxHVActiveX2 ax = _HVS.SingleOrDefault(item => (item.Tag as DeviceState).IP == device.IP); if (ax != null) { row.Cells["colState"].Value = (ax.Tag as DeviceState).State == 0 ? "已连接" : "未连接"; } }
/// <summary> /// 触发手动抓拍 /// </summary> /// <param name="device"></param> private void ManualSnap(CarPlateDevice device) { device.ResetResult(); //触发手动抓拍测试 MANUAL_SNAP_PARAMETER snap = new MANUAL_SNAP_PARAMETER(); snap.nChannel = device.VideoID; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(snap)); Marshal.StructureToPtr(snap, ptr, false); bool bRet = DHClient.DHControlDevice(device.m_nLoginID, CtrlType.DH_MANUAL_SNAP, ptr, 1000); System.Runtime.InteropServices.Marshal.FreeHGlobal(ptr); }
private bool _Inited = false; //窗体是否已进行初始化了 #endregion #region 回调事件 /// <summary> /// 设备离线事件 /// </summary> /// <param name="lLoginID"></param> /// <param name="pchDVRIP"></param> /// <param name="nDVRPort"></param> /// <param name="dwUser"></param> private void DisConnectEvent(int lLoginID, StringBuilder pchDVRIP, int nDVRPort, IntPtr dwUser) { CarPlateDevice device = _Devices.SingleOrDefault(d => d.m_nLoginID == lLoginID); if (device != null) { //设备离线消息;设备非正常关机,SDK可以检测到;需要取消订阅,当重新在线消息时,再发起订阅事件 if (device.m_nRealLoadPic != 0) { DHClient.DHStopLoadPic(device.m_nRealLoadPic); device.m_nRealLoadPic = 0; } device.State = 2; } }
private void FrmCarPlateOfDaHua_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { //停止监控和清空上传事件显示 if (this.btnStopRealPlay.Enabled) { btnStopRealPlay_Click(this.btnStopRealPlay, EventArgs.Empty); } _ActiveDevice = null; ClearCarPlateInfo(); this.Hide(); e.Cancel = true; } }
/// <summary> /// 抓拍图片 /// </summary> /// <param name="info">摄像机</param> /// <param name="force">是否强制重新抓拍,不管之前有没有抓拍到图片</param> /// <returns>抓拍图片的地址,返回空时表示抓拍失败</returns> public string CapturePicture(VideoSourceInfo info, bool force) { try { CarPlateDevice device = _Devices.FirstOrDefault(item => item.IP == info.MediaSource); if (SnapShotTo(device, force)) { return(device.SnapPath); } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(string.Empty); }
/// <summary> /// 对通道进行图片抓拍,要求此通道有一个用于车牌识别的摄像机 /// </summary> /// <param name="parkID"></param> /// <param name="entranceID"></param> /// <returns>抓拍图片的地址,返回空时表示抓拍失败</returns> public string SnapShot(int parkID, int entranceID) { try { CarPlateDevice device = _Devices.FirstOrDefault(item => item.EntranceID == entranceID && item.VideoSource != null && item.VideoSource.IsForCarPlate); if (SnapShotTo(device, false)) { return(device.SnapPath); } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(string.Empty); }
/// <summary> /// 清除抓拍图片信息 /// </summary> /// <param name="info">摄像机</param> public void ClearCapture(VideoSourceInfo info) { try { CarPlateDevice device = _Devices.FirstOrDefault(item => item.IP == info.MediaSource); if (device != null) { lock (device) { device.ResetResult(); } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } }
/// <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); }
public void ProcessReport(ReportBase r) { ParkInfo park = ParkBuffer.Current.GetPark(r.ParkID); foreach (DataGridViewRow row in this.dataGridView1.Rows) { CarPlateDevice device = row.Tag as CarPlateDevice; if (device.EntranceID == r.EntranceID) { if (r is CardEventReport) { CardEventReport cardEvent = r as CardEventReport; if (cardEvent.EventStatus == CardEventStatus.Valid && !string.IsNullOrEmpty(device.SnapPath)) { EntranceInfo entrace = ParkBuffer.Current.GetEntrance(r.EntranceID); int videoSourceID = -1; if (entrace != null) { VideoSourceInfo videoSource = entrace.VideoSources.FirstOrDefault(item => item.MediaSource == device.IP && item.Channel == device.VideoID); if (videoSource != null) { videoSourceID = videoSource.VideoID; } } if (videoSourceID == -1) { videoSourceID = r.EntranceID * 1000 + device.VideoID; //没有找到视频ID的,手动生成一个,通道id*1000+视频路数 } SnapShot shot = new SnapShot(cardEvent.EventDateTime, videoSourceID, cardEvent.CardID, device.SnapPath); string master = AppSettings.CurrentSetting.CurrentMasterConnect; 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); } } } } }
public void ProcessReport(ReportBase r) { ParkInfo park = ParkBuffer.Current.GetPark(r.ParkID); foreach (DataGridViewRow row in this.dataGridView1.Rows) { CarPlateDevice device = row.Tag as CarPlateDevice; if (device.EntranceID == r.EntranceID) { if (r is CardEventReport) { CardEventReport cardEvent = r as CardEventReport; if (cardEvent.EventStatus == CardEventStatus.Valid && !string.IsNullOrEmpty(device.SnapPath)) { SnapShot shot = new SnapShot(cardEvent.EventDateTime, r.EntranceID, device.SnapPath, cardEvent.CardID); (new SnapShotBll(AppSettings.CurrentSetting.ParkConnect)).Insert(shot); } } } } }
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex >= 0) { CarPlateDevice device = dataGridView1.Rows[e.RowIndex].Tag as CarPlateDevice; if (device != null) { if (_ActiveDevice != device) { //如果停止监控按钮可以使用,表示正在监控,先停止当前监控,再切换到选择的摄像机进行监控 if (this.btnStopRealPlay.Enabled) { StopRealPlay(_ActiveDevice); RealPlay(device); } ShowCarPlateInfo(device); _ActiveDevice = device; } } } }
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex >= 0) { CarPlateDevice device = dataGridView1.Rows[e.RowIndex].Tag as CarPlateDevice; if (device != null) { foreach (AxHVActiveX2Lib.AxHVActiveX2 axHV in _HVS) { if ((axHV.Tag as DeviceState).IP == device.IP) { axHV.RecvVideoFlag = chkVideo.Checked ? 1 : 0; } else { axHV.RecvVideoFlag = 0; } } _ActiveDevice = device; } } }
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); } }
/// <summary> /// 开始智能交通设备实时上传--回调 /// </summary> /// <param name="lAnalyzerHandle"></param> /// <param name="dwAlarmType"></param> /// <param name="pAlarmInfo"></param> /// <param name="pBuffer"></param> /// <param name="dwBufSize"></param> /// <param name="dwUser"></param> /// <param name="nSequence"></param> /// <param name="reserved"></param> /// <returns></returns> private int AnalyzerDataCallBackEvent(Int32 lAnalyzerHandle, UInt32 dwAlarmType, IntPtr pAlarmInfo, IntPtr pBuffer, UInt32 dwBufSize, UInt32 dwUser, Int32 nSequence, IntPtr reserved) { if (dwBufSize == 0) { return(1); } try { CarPlateDevice device = _Devices.SingleOrDefault(d => d.m_nRealLoadPic == lAnalyzerHandle); if (device != null) { // 记录文件 byte[] buf = new byte[dwBufSize]; Marshal.Copy(pBuffer, buf, 0, (int)dwBufSize); DH_MSG_OBJECT plateObj = new DH_MSG_OBJECT(); DH_MSG_OBJECT VehicleObj = new DH_MSG_OBJECT(); NET_TIME_EX utc = new NET_TIME_EX(); int lane = 0; string strMsg; bool bret = DaHuaSDKManager.GetInstance().GetStuObject(dwAlarmType, pAlarmInfo, out plateObj, out VehicleObj, out utc, out lane, out strMsg); device.ResetResult(); if (plateObj.szText != null) { device.CarPlate = Encoding.GetEncoding("gb2312").GetString(plateObj.szText); } if (!string.IsNullOrEmpty(device.CarPlate)) { device.CarPlate = device.CarPlate.TrimEnd('\0'); //去除结束符\0 } device.EventDateTime = DateTime.Now; if (plateObj.bColor == 1) { device.PlateColor = DaHuaSDKManager.GetInstance().GetColorString(plateObj.rgbaMainColor); } if (VehicleObj.bColor == 1) { device.CarColor = DaHuaSDKManager.GetInstance().GetColorString(VehicleObj.rgbaMainColor); } device.Lane = lane; try { device.DeviceSnapTime = new DateTime((int)utc.dwYear, (int)utc.dwMonth, (int)utc.dwDay, (int)utc.dwHour, (int)utc.dwMinute, (int)utc.dwSecond, (int)utc.dwMillisecond); } catch { } device.SnapPath = DaHuaSDKManager.GetInstance().SaveSnapImage(buf); device.PlatePath = DaHuaSDKManager.GetInstance().SavePlateJpg(plateObj, pBuffer, buf); foreach (DataGridViewRow row in dataGridView1.Rows) { CarPlateDevice d = row.Tag as CarPlateDevice; if (d != null) { if (d.m_nRealLoadPic == device.m_nRealLoadPic) { ShowItemOnRow(device, row); } } } if (_ActiveDevice != null && _ActiveDevice.m_nRealLoadPic == device.m_nRealLoadPic) { ShowCarPlateInfo(device); } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(1); }