Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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 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="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);
        }
 /// <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)
        {
            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;
                    device.ResetResult();
                }
            }
            catch (Exception ex)
            {
                Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
            }
            return(ret);
        }
        /// <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);
        }