/// <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); }
/// <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); }
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(); }
private void axHV_OnReceiveVideo1(object sender, EventArgs e) { try { if (_ActiveDevice.VideoID == 1) { AxHVActiveX2Lib.AxHVActiveX2 axHV = sender as AxHVActiveX2Lib.AxHVActiveX2; if (_ActiveDevice != null && _ActiveDevice.IP == (axHV.Tag as DeviceState).IP) { string strName = ""; int iSize = 0; strName = axHV.GetVideoFrameSM(1, ref iSize); if (iSize == 0) { return; } IntPtr irMapFile = IntPtr.Zero; irMapFile = OpenFileMapping(FILE_MAP_READ, false, strName); if (irMapFile == IntPtr.Zero) { return; } IntPtr itData = IntPtr.Zero; itData = MapViewOfFile(irMapFile, FILE_MAP_READ, 0, 0, 0); if (itData == IntPtr.Zero) { CloseHandle(irMapFile); return; } byte[] bData = new byte[iSize]; Marshal.Copy(itData, bData, 0, iSize); ///完成一次接收后调用下面两个函数关闭共享内存(也就是不用内存映射的时候要关闭) UnmapViewOfFile(itData); CloseHandle(irMapFile); using (MemoryStream stream = new MemoryStream(bData)) { video.Image = Image.FromStream(stream); } } } } catch (Exception ex) { //Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } finally { } }
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); } } }
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 ? "已连接" : "未连接"; } }
public void CancelVideo(string ip, VideoRecievedEventHandler callback) { if (_AllDevices.Keys.Contains(ip)) { AxHVActiveX2Lib.AxHVActiveX2 axHV = _AllDevices[ip]; List <VideoRecievedEventHandler> handlers = axHV.Tag as List <VideoRecievedEventHandler>; if (handlers != null) { handlers.Remove(callback); if (handlers.Count == 0) { axHV.Tag = DateTime.Now; } } } }
private void axHV_OnReceiveVideo1(object sender, EventArgs e) { AxHVActiveX2Lib.AxHVActiveX2 axHV = sender as AxHVActiveX2Lib.AxHVActiveX2; IntPtr irMapFile = IntPtr.Zero; IntPtr itData = IntPtr.Zero; string strName = ""; int iSize = 1024 * 1024; try { strName = axHV.GetVideoFrameSM(1, ref iSize); irMapFile = OpenFileMapping(FILE_MAP_READ, false, strName); if (irMapFile == IntPtr.Zero) { return; } itData = MapViewOfFile(irMapFile, FILE_MAP_READ, 0, 0, 0); if (itData == IntPtr.Zero) { CloseHandle(irMapFile); return; } byte[] bData = new byte[iSize]; Marshal.Copy(itData, bData, 0, iSize); List <VideoRecievedEventHandler> handlers = axHV.Tag as List <VideoRecievedEventHandler>; if (handlers != null && handlers.Count > 0) { foreach (VideoRecievedEventHandler handler in handlers) { byte[] data = new byte[iSize]; Array.Copy(bData, data, bData.Length); handler(sender, 1, data); } } } catch (Exception ex) { } finally { ///完成一次接收后调用下面两个函数关闭共享内存(也就是不用内存映射的时候要关闭) UnmapViewOfFile(itData); CloseHandle(irMapFile); } }
public void Init() { List <EntranceInfo> entrances = ParkBuffer.Current.GetEntrances(); if (entrances != null && entrances.Count > 0) { foreach (EntranceInfo entrance in entrances) { if (entrance.VideoSources != null && entrance.VideoSources.Count > 0) { foreach (VideoSourceInfo video in entrance.VideoSources) { if (video.VideoSourceType == (int)VideoServerType.XinLuTong) { if (!_AllDevices.Keys.Contains(video.MediaSource)) { 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 = 0; axHV.RecvPlateImageFlag = 0; axHV.RecvPlateBinImageFlag = 0; axHV.AutoSaveFlag = false; axHV.OnReceiveVideo += new EventHandler(axHV_OnReceiveVideo); axHV.OnReceiveVideo += new EventHandler(axHV_OnReceiveVideo1); _AllDevices.Add(video.MediaSource, axHV); } } } } } } Thread t = new Thread(CloseUnUsedAxHV_Thread); t.IsBackground = true; t.Start(); }
public void RequestVideo(string ip, VideoRecievedEventHandler callback) { if (_AllDevices.Keys.Contains(ip)) { AxHVActiveX2Lib.AxHVActiveX2 axHV = _AllDevices[ip]; if (axHV.GetStatus() != 0) { axHV.ConnectTo(ip); axHV.RecvVideoFlag = 1; } List <VideoRecievedEventHandler> handlers = axHV.Tag as List <VideoRecievedEventHandler>; if (handlers == null) { handlers = new List <VideoRecievedEventHandler>(); } if (!handlers.Any(c => c == callback)) { handlers.Add(callback); } axHV.Tag = handlers; } }
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); } }
private void axHV_OnReceiveVideo(object sender, EventArgs e) { //AxHVActiveX2Lib.AxHVActiveX2 axHV = sender as AxHVActiveX2Lib.AxHVActiveX2; //IntPtr irMapFile = IntPtr.Zero; //IntPtr itData = IntPtr.Zero; //string strName = ""; //int iSize =0; try { AxHVActiveX2Lib.AxHVActiveX2 axHV = sender as AxHVActiveX2Lib.AxHVActiveX2; string strName = ""; int iSize = 0; strName = axHV.GetVideoFrameSM(0, ref iSize); if (iSize == 0) { return; } IntPtr irMapFile = IntPtr.Zero; irMapFile = OpenFileMapping(FILE_MAP_READ, false, strName); if (irMapFile == IntPtr.Zero) { return; } IntPtr itData = IntPtr.Zero; itData = MapViewOfFile(irMapFile, FILE_MAP_READ, 0, 0, 0); if (itData == IntPtr.Zero) { CloseHandle(irMapFile); return; } byte[] bData = new byte[iSize]; Marshal.Copy(itData, bData, 0, iSize); ///完成一次接收后调用下面两个函数关闭共享内存(也就是不用内存映射的时候要关闭) UnmapViewOfFile(itData); CloseHandle(irMapFile); List <VideoRecievedEventHandler> handlers = axHV.Tag as List <VideoRecievedEventHandler>; if (handlers != null && handlers.Count > 0) { foreach (VideoRecievedEventHandler handler in handlers) { handler(sender, 0, bData); //byte[] data = new byte[iSize]; //Array.Copy(bData, data, bData.Length); //handler(sender, 0, data); } } } catch { } //finally //{ // ///完成一次接收后调用下面两个函数关闭共享内存(也就是不用内存映射的时候要关闭) // UnmapViewOfFile(itData); // CloseHandle(irMapFile); //} }