VS2022調試通過??禂z像頭煙火識別SDK的實現(xiàn)
下面是我根據(jù)??倒俜轿臋n代碼,放到VS 2022 版本中調試通過后的代碼:
#include <stdio.h> #include <iostream> #include "Windows.h" #include "HCNetSDK.h" using namespace std; //時間解析宏定義 #define GET_YEAR(_time_) (((_time_)>>26) + 2000) #define GET_MONTH(_time_) (((_time_)>>22) & 15) #define GET_DAY(_time_) (((_time_)>>17) & 31) #define GET_HOUR(_time_) (((_time_)>>12) & 31) #define GET_MINUTE(_time_) (((_time_)>>6) & 63) #define GET_SECOND(_time_) (((_time_)>>0) & 63) BOOL CALLBACK MessageCallback(LONG lCommand, NET_DVR_ALARMER* pAlarmer, char* pAlarmInfo, DWORD dwBufLen, void* pUser) { switch (lCommand) { case COMM_FIREDETECTION_ALARM: //火點檢測報警 { printf("fire192.168.1.31 \n"); NET_DVR_FIREDETECTION_ALARM struFireDetection = { 0 }; memcpy(&struFireDetection, pAlarmInfo, sizeof(NET_DVR_FIREDETECTION_ALARM)); printf("火點檢測報警: RelativeTime:%d, AbsTime:%d, PTZ{PanPos:%d, TiltPos:%d, ZoomPos:%d}, \ PicDataLen:%d, DevInfo{DevIP:%s, Port:%d, Channel:%d, IvmsChannel:%d}, \ FireMaxTemperature:%d, TargetDistance:%d, fireRectInfo{fX:%f,fY:%f,fWidth%f,fHeight%f}, \ fireMaxTemperaturePoint{fX:%f,fY:%f}\n", struFireDetection.dwRelativeTime, \ struFireDetection.dwAbsTime, struFireDetection.wPanPos, struFireDetection.wTiltPos, \ struFireDetection.wZoomPos, struFireDetection.dwPicDataLen, \ struFireDetection.struDevInfo.struDevIP.sIpV4, struFireDetection.struDevInfo.wPort, \ struFireDetection.struDevInfo.byChannel, struFireDetection.struDevInfo.byIvmsChannel, \ struFireDetection.wFireMaxTemperature, struFireDetection.wTargetDistance, \ struFireDetection.struRect.fX, struFireDetection.struRect.fY, struFireDetection.struRect.fWidth, \ struFireDetection.struRect.fHeight, struFireDetection.struPoint.fX, struFireDetection.struPoint.fY); NET_DVR_TIME struAbsTime = { 0 }; struAbsTime.dwYear = GET_YEAR(struFireDetection.dwAbsTime); struAbsTime.dwMonth = GET_MONTH(struFireDetection.dwAbsTime); struAbsTime.dwDay = GET_DAY(struFireDetection.dwAbsTime); struAbsTime.dwHour = GET_HOUR(struFireDetection.dwAbsTime); struAbsTime.dwMinute = GET_MINUTE(struFireDetection.dwAbsTime); struAbsTime.dwSecond = GET_SECOND(struFireDetection.dwAbsTime); //保存報警抓拍圖片 if (struFireDetection.dwPicDataLen > 0 && struFireDetection.pBuffer != NULL) { char cFilename[256] = { 0 }; HANDLE hFile; DWORD dwReturn; char chTime[128]; sprintf_s(chTime, "%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d", struAbsTime.dwYear, struAbsTime.dwMonth, struAbsTime.dwDay, struAbsTime.dwHour, struAbsTime.dwMinute, struAbsTime.dwSecond); sprintf_s(cFilename, "FireDetectionPic[%s][%s].jpg", struFireDetection.struDevInfo.struDevIP.sIpV4, chTime); LPCWSTR tmp; // begin added by zhangchao tmp = L"FireDetectionPic31.jpg"; // end added by zhangchao //printf("%s", tmp); hFile = CreateFile(tmp, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { break; } WriteFile(hFile, struFireDetection.pBuffer, struFireDetection.dwPicDataLen, &dwReturn, NULL); CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; } } break; default: printf("other192.168.1.31 \n"); printf("其他報警,報警信息類型: %d\n", lCommand); break; } return TRUE; } void RunCam(const char* ip) { //--------------------------------------- // 初始化 NET_DVR_Init(); //設置連接時間與重連時間 NET_DVR_SetConnectTime(2000, 1); NET_DVR_SetReconnect(10000, true); //--------------------------------------- // 注冊設備 LONG lUserID; //登錄參數(shù),包括設備地址、登錄用戶、密碼等 NET_DVR_USER_LOGIN_INFO struLoginInfo = { 0 }; struLoginInfo.bUseAsynLogin = 0; //同步登錄方式 strcpy_s(struLoginInfo.sDeviceAddress, ip); struLoginInfo.wPort = 8000; //設備服務端口 strcpy_s(struLoginInfo.sUserName, "your_username"); //設備登錄用戶名 strcpy_s(struLoginInfo.sPassword, "your_password"); //設備登錄密碼 //設備信息, 輸出參數(shù) NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = { 0 }; lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40); if (lUserID < 0) { printf("Login failed, error code: %d\n", NET_DVR_GetLastError()); NET_DVR_Cleanup(); return; } //設置報警回調函數(shù) NET_DVR_SetDVRMessageCallBack_V31(MessageCallback, NULL); //啟用布防 LONG lHandle; NET_DVR_SETUPALARM_PARAM struAlarmParam = { 0 }; struAlarmParam.dwSize = sizeof(struAlarmParam); //火點檢測不需要設置其他報警布防參數(shù),不支持 lHandle = NET_DVR_SetupAlarmChan_V41(lUserID, &struAlarmParam); if (lHandle < 0) { printf("NET_DVR_SetupAlarmChan_V41 error, %d\n", NET_DVR_GetLastError()); NET_DVR_Logout(lUserID); NET_DVR_Cleanup(); return; } Sleep(50000); //等待過程中,如果設備上傳報警信息,在報警回調函數(shù)里面接收和處理報警信息 //撤銷布防上傳通道 if (!NET_DVR_CloseAlarmChan_V30(lHandle)) { printf("NET_DVR_CloseAlarmChan_V30 error, %d\n", NET_DVR_GetLastError()); NET_DVR_Logout(lUserID); NET_DVR_Cleanup(); return; } //注銷用戶 NET_DVR_Logout(lUserID); //釋放SDK資源 NET_DVR_Cleanup(); } void main() { RunCam("192.168.1.31"); return; }
如何配置VS 2022 ?
第一步:打開窗口頂部 【項目】菜單,選中 【<某某項目>屬性】。
第二步:在打開的對話框中,左側菜單選擇 【C/C++】=> 【常規(guī)】,選中右側附加包含目錄中,點擊右側出現(xiàn)的向下箭頭,點擊編輯,在打開的對話框中如下填寫:
其中 D:\ws\vc\emptycam\hkheader 文件夾放著海康的頭文件,分別是: DataType.h、DecodeCardSdk.h、HCNetSDK.h、plaympeg4.h。
第三步:左側菜單選擇 【鏈接器】=> 【常規(guī)】。右側選中附加庫目錄,點擊右側小三角,點擊編輯,打開對話框。
文件夾 D:\ws\vc\emptycam\hkdll 是放??礵ll文件的地方。文件如下圖所示:
第四步:左側菜單選擇 【鏈接器】=> 【輸入】。右側選中【附加依賴項】點擊右側小三角,點擊編輯,打開對話框。內容按照圖片里的文字進行填寫。
到此這篇關于VS2022調試通過??禂z像頭煙火識別SDK的實現(xiàn)的文章就介紹到這了,更多相關VS2022??禂z像頭煙火識別SDK內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
C++命名空間using?namespace?std是什么意思
namespace中文意思是命名空間或者叫名字空間,傳統(tǒng)的C++只有一個全局的namespace,下面這篇文章主要給大家介紹了關于C++命名空間using?namespace?std是什么意思的相關資料,需要的朋友可以參考下2023-01-01