private void ProcessCommFace(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) { try { CHCNetSDK.NET_VCA_FACESNAP_RESULT jpFacedetectAlarm = new CHCNetSDK.NET_VCA_FACESNAP_RESULT(); uint dwSize = (uint)Marshal.SizeOf(jpFacedetectAlarm); jpFacedetectAlarm = (CHCNetSDK.NET_VCA_FACESNAP_RESULT)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_FACESNAP_RESULT)); if (jpFacedetectAlarm.dwFacePicLen > 0) { int iLen = (int)jpFacedetectAlarm.dwFacePicLen; byte[] by = new byte[iLen]; Marshal.Copy(jpFacedetectAlarm.pBuffer1, by, 0, iLen); MemoryStream ms = new MemoryStream(by); Image imgStream = Image.FromStream(ms); Monitor.Enter(catchFaceImageMap); AddToCatchFaceImageMap(imgStream, jpFacedetectAlarm.dwFacePicID); Monitor.Exit(catchFaceImageMap); // Bitmap imgClone= (Bitmap) imgStream; // faceImg = imgClone.Clone(new Rectangle(0,0, imgStream.Width, imgStream.Height), imgStream.PixelFormat); // imgStream.Dispose(); // ms.Close(); } } catch (Exception ex) { ShowMsgEvent("ProcessCommFace Get Image From CHC Error:", ex); } }
private void ProcessCommAlarm_FaceSnap(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser, string commType) { CHCNetSDK.NET_VCA_FACESNAP_RESULT struFaceSnapInfo = new CHCNetSDK.NET_VCA_FACESNAP_RESULT(); uint dwSize = (uint)Marshal.SizeOf(struFaceSnapInfo); struFaceSnapInfo = (CHCNetSDK.NET_VCA_FACESNAP_RESULT)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_FACESNAP_RESULT)); //报警设备IP地址 string strIP = pAlarmer.sDeviceIP; string strFilePath = null; if (struFaceSnapInfo.dwFacePicLen != 0 && (struFaceSnapInfo.dwFaceScore >= _traceFaceScore * 100D)) { if (!Directory.Exists(m_OutputDir + strIP + "\\")) { Directory.CreateDirectory(m_OutputDir + strIP + "\\"); } strFilePath = m_OutputDir + strIP + "\\" + DateTime.Now.ToString("yyyyMMddHHmissfff") + "_Score_" + struFaceSnapInfo.dwFaceScore + ".jpg"; FileStream fs = new FileStream(strFilePath, FileMode.Create); int iLen = (int)struFaceSnapInfo.dwFacePicLen; byte[] by = new byte[iLen]; Marshal.Copy(struFaceSnapInfo.pBuffer1, by, 0, iLen); fs.Write(by, 0, iLen); fs.Close(); Log4NetHelper.Instance.Info("图像存储文件:" + strFilePath); } else { return; } //报警时间:年月日时分秒 string strTimeYear = ((struFaceSnapInfo.dwAbsTime >> 26) + 2000).ToString(); string strTimeMonth = ((struFaceSnapInfo.dwAbsTime >> 22) & 15).ToString("d2"); string strTimeDay = ((struFaceSnapInfo.dwAbsTime >> 17) & 31).ToString("d2"); string strTimeHour = ((struFaceSnapInfo.dwAbsTime >> 12) & 31).ToString("d2"); string strTimeMinute = ((struFaceSnapInfo.dwAbsTime >> 6) & 63).ToString("d2"); string strTimeSecond = ((struFaceSnapInfo.dwAbsTime >> 0) & 63).ToString("d2"); string strTime = strTimeYear + "-" + strTimeMonth + "-" + strTimeDay + " " + strTimeHour + ":" + strTimeMinute + ":" + strTimeSecond; Rectangle rectFace = new Rectangle((int)(struFaceSnapInfo.struRect.fX * 100D), (int)(struFaceSnapInfo.struRect.fY * 100D), (int)(struFaceSnapInfo.struRect.fWidth * 100D), (int)(struFaceSnapInfo.struRect.fHeight * 100D)); // string stringAlarm = "人脸抓拍结果,前端设备:" + struFaceSnapInfo.struDevInfo.struDevIP.sIpV4 + ",报警时间:" + strTime; if (NoticeFaceSnapEvent != null) { string cstrTime = ObjectCopier.Clone <string>(strTime); string cstrIP = ObjectCopier.Clone <string>(strIP); string cstrFilePath = ObjectCopier.Clone <string>(strFilePath); Rectangle crectangle = ObjectCopier.Clone <Rectangle>(rectFace); NoticeFaceSnapEvent(cstrTime, cstrIP, cstrFilePath, crectangle); } }
//人脸抓拍结果信息 private void ProcessCommAlarm_FaceSnap(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) { CHCNetSDK.NET_VCA_FACESNAP_RESULT struFaceSnapInfo = new CHCNetSDK.NET_VCA_FACESNAP_RESULT(); uint dwSize = (uint)Marshal.SizeOf(struFaceSnapInfo); struFaceSnapInfo = (CHCNetSDK.NET_VCA_FACESNAP_RESULT)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_FACESNAP_RESULT)); //报警设备IP地址 string strIP = ip; //保存抓拍图片数据 if ((struFaceSnapInfo.dwBackgroundPicLen != 0) && (struFaceSnapInfo.pBuffer2 != IntPtr.Zero)) { iPicNumber++; string str = ".\\picture\\FaceSnap_CapPic_[" + strIP + "]_lUerID_[" + pAlarmer.lUserID + "]_" + iPicNumber + ".jpg"; FileStream fs = new FileStream(str, FileMode.Create); int iLen = (int)struFaceSnapInfo.dwBackgroundPicLen; byte[] by = new byte[iLen]; Marshal.Copy(struFaceSnapInfo.pBuffer2, by, 0, iLen); fs.Write(by, 0, iLen); fs.Close(); } //报警时间:年月日时分秒 string strTimeYear = ((struFaceSnapInfo.dwAbsTime >> 26) + 2000).ToString(); string strTimeMonth = ((struFaceSnapInfo.dwAbsTime >> 22) & 15).ToString("d2"); string strTimeDay = ((struFaceSnapInfo.dwAbsTime >> 17) & 31).ToString("d2"); string strTimeHour = ((struFaceSnapInfo.dwAbsTime >> 12) & 31).ToString("d2"); string strTimeMinute = ((struFaceSnapInfo.dwAbsTime >> 6) & 63).ToString("d2"); string strTimeSecond = ((struFaceSnapInfo.dwAbsTime >> 0) & 63).ToString("d2"); string strTime = strTimeYear + "-" + strTimeMonth + "-" + strTimeDay + " " + strTimeHour + ":" + strTimeMinute + ":" + strTimeSecond; string stringAlarm = "人脸抓拍结果,前端设备IP:" + strIP + ",抓拍时间:" + strTime; /* * if (InvokeRequired) * { * object[] paras = new object[3]; * paras[0] = DateTime.Now.ToString(); //当前PC系统时间 * paras[1] = strIP; * paras[2] = stringAlarm; * listViewAlarmInfo.BeginInvoke(new UpdateListBoxCallback(UpdateClientList), paras); * } * else * { * //创建该控件的主线程直接更新信息列表 * UpdateClientList(DateTime.Now.ToString(), strIP, stringAlarm); * } */ }
private void ProcessCommFace(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) { uint faceId = 0; Image faceImg = null; try { CHCNetSDK.NET_VCA_FACESNAP_RESULT jpFacedetectAlarm = new CHCNetSDK.NET_VCA_FACESNAP_RESULT(); uint dwSize = (uint)Marshal.SizeOf(jpFacedetectAlarm); jpFacedetectAlarm = (CHCNetSDK.NET_VCA_FACESNAP_RESULT)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_FACESNAP_RESULT)); if (jpFacedetectAlarm.dwFacePicLen > 0) { faceId = jpFacedetectAlarm.dwFacePicID; int iLen = (int)jpFacedetectAlarm.dwFacePicLen; byte[] by = new byte[iLen]; Marshal.Copy(jpFacedetectAlarm.pBuffer1, by, 0, iLen); MemoryStream ms = new MemoryStream(by); Image imgStream = Image.FromStream(ms); faceImg = imgStream; // Bitmap imgClone= (Bitmap) imgStream; // faceImg = imgClone.Clone(new Rectangle(0,0, imgStream.Width, imgStream.Height), imgStream.PixelFormat); // imgStream.Dispose(); // ms.Close(); } } catch (Exception ex) { ShowMsgEvent("ProcessCommFace Get Image From CHC Error:", ex); } if (null != faceImg) { Monitor.Enter(catchFaceImageMap); if (catchFaceImageMap.ContainsKey(faceId)) { CatchFaceInfo catchInfo = catchFaceImageMap[faceId]; if (catchInfo.faceImgSet.Count < detectImgCount) { catchInfo.faceImgSet.Add(faceImg); } } else { CatchFaceInfo catchInfo = new CatchFaceInfo(); catchInfo.faceImgSet = new List <Image>(); catchInfo.faceImgSet.Add(faceImg); catchInfo.catchTime = DateTime.Now; //放入队列 catchFaceImageMap.Add(faceId, catchInfo); // countCHC++; // ShowCountEvent(2, countCHC); ShowCountEvent(4, catchFaceImageMap.Count); } Monitor.Exit(catchFaceImageMap); } }