600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > C#调用海康威视人脸识别接口

C#调用海康威视人脸识别接口

时间:2023-04-18 16:12:56

相关推荐

C#调用海康威视人脸识别接口

先登录,然后预览。之后打开人脸抓拍即可。

以下为人脸识别的核心代码。**

public Preview(){//// Windows 窗体设计器支持所必需的//InitializeComponent();m_bInitSDK = _DVR_Init();if (m_bInitSDK == false){MessageBox.Show("NET_DVR_Init error!");return;}else{//保存SDK日志 To save the SDK _DVR_SetLogToFile(3, "E:\\SdkLog\\", true);}//// TODO: 在 InitializeComponent 调用后添加任何构造函数代码////设置透传报警信息类型_DVR_LOCAL_GENERAL_CFG struLocalCfg = new _DVR_LOCAL_GENERAL_CFG();struLocalCfg.byAlarmJsonPictureSeparate = 1;//控制JSON透传报警数据和图片是否分离,0-不分离(COMM_VCA_ALARM返回),1-分离(分离后走COMM_ISAPI_ALARM回调返回)Int32 nSize = Marshal.SizeOf(struLocalCfg);IntPtr ptrLocalCfg = Marshal.AllocHGlobal(nSize);Marshal.StructureToPtr(struLocalCfg, ptrLocalCfg, false);if (!_DVR_SetSDKLocalCfg(17, ptrLocalCfg)) //NET_DVR_LOCAL_CFG_TYPE_GENERAL{iLastErr = _DVR_GetLastError();strErr = "NET_DVR_SetSDKLocalCfg failed, error code= " + iLastErr;MessageBox.Show(strErr);}Marshal.FreeHGlobal(ptrLocalCfg);for (int i = 0; i < 200; i++){m_lAlarmHandle[i] = -1;}//设置报警回调函数if (m_falarmData_V31 == null){m_falarmData_V31 = new CHCNetSDK.MSGCallBack_V31(MsgCallback_V31);}_DVR_SetDVRMessageCallBack_V31(m_falarmData_V31, IntPtr.Zero);}public bool MsgCallback_V31(int lCommand, ref _DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser){ProcessCommAlarm_FaceSnap(ref pAlarmer, pAlarmInfo, dwBufLen, pUser);return true; //回调函数需要有返回,表示正常接收到数据}private void ProcessCommAlarm_FaceSnap(ref _DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser){_VCA_FACESNAP_RESULT struFaceSnapInfo = new _VCA_FACESNAP_RESULT();uint dwSize = (uint)Marshal.SizeOf(struFaceSnapInfo);struFaceSnapInfo = (_VCA_FACESNAP_RESULT)Marshal.PtrToStructure(pAlarmInfo, typeof(_VCA_FACESNAP_RESULT));byte eg = struFaceSnapInfo.struFeature.byEyeGlass;float x = struFaceSnapInfo.struRegion.fX;//报警设备IP地址//string strIP = System.Text.Encoding.UTF8.GetString(pAlarmer.sDeviceIP).TrimEnd('\0');string strIP = "192.168.1.64";if ((struFaceSnapInfo.dwBackgroundPicLen != 0) && (struFaceSnapInfo.pBuffer2 != IntPtr.Zero)){DateTime now = DateTime.Now;//保存抓拍图片数据string str = ".\\picture\\FaceSnap_" + now.ToString("yyyyMMddHHmmss") + ".jpg";string _FilePath = String.Format(".\\picture\\{0}", now.ToString("yyyy-MM-dd"));if (!Directory.Exists(_FilePath)){Directory.CreateDirectory(_FilePath);}str = String.Format(".\\picture\\{0}\\FaceSnap_{1}.jpg", now.ToString("yyyy-MM-dd"), now.ToString("HH_mm_ss"));FileStream fs = new FileStream(str, FileMode.CreateNew);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 sJpegPicFileName;//图片保存路径和文件名 the path and file name to savesJpegPicFileName = String.Format(".\\picture\\{0}\\JPEG_test_{1}.jpg", now.ToString("yyyy-MM-dd"), now.ToString("HH_mm_ss")); int lChannel = Int16.Parse(textBoxChannel.Text); //通道号 Channel _DVR_JPEGPARA lpJpegPara = new _DVR_JPEGPARA();lpJpegPara.wPicQuality = 0; //图像质量 Image qualitylpJpegPara.wPicSize = 0xff; //抓图分辨率 Picture size: 2- 4CIF,0xff- Auto(使用当前码流分辨率),抓图分辨率需要设备支持,更多取值请参考SDK文档//JPEG抓图 Capture a JPEG pictureif (!_DVR_CaptureJPEGPicture(m_lUserID, lChannel, ref lpJpegPara, sJpegPicFileName)){iLastErr = _DVR_GetLastError();str = "NET_DVR_CaptureJPEGPicture failed, error code= " + iLastErr;MessageBox.Show(str);return;}else{str = "Successful to capture the JPEG file and the saved file is " + sJpegPicFileName;//MessageBox.Show(str);}iFileNumber++;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。