VS2022調(diào)試通過海康攝像頭煙火識(shí)別SDK的實(shí)現(xiàn)
下面是我根據(jù)??倒俜轿臋n代碼,放到VS 2022 版本中調(diào)試通過后的代碼:
#include <stdio.h>
#include <iostream>
#include "Windows.h"
#include "HCNetSDK.h"
using namespace std;
//時(shí)間解析宏定義
#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: //火點(diǎn)檢測(cè)報(bào)警
{
printf("fire192.168.1.31 \n");
NET_DVR_FIREDETECTION_ALARM struFireDetection = { 0 };
memcpy(&struFireDetection, pAlarmInfo, sizeof(NET_DVR_FIREDETECTION_ALARM));
printf("火點(diǎn)檢測(cè)報(bào)警: 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);
//保存報(bào)警抓拍圖片
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("其他報(bào)警,報(bào)警信息類型: %d\n", lCommand);
break;
}
return TRUE;
}
void RunCam(const char* ip) {
//---------------------------------------
// 初始化
NET_DVR_Init();
//設(shè)置連接時(shí)間與重連時(shí)間
NET_DVR_SetConnectTime(2000, 1);
NET_DVR_SetReconnect(10000, true);
//---------------------------------------
// 注冊(cè)設(shè)備
LONG lUserID;
//登錄參數(shù),包括設(shè)備地址、登錄用戶、密碼等
NET_DVR_USER_LOGIN_INFO struLoginInfo = { 0 };
struLoginInfo.bUseAsynLogin = 0; //同步登錄方式
strcpy_s(struLoginInfo.sDeviceAddress, ip);
struLoginInfo.wPort = 8000; //設(shè)備服務(wù)端口
strcpy_s(struLoginInfo.sUserName, "your_username"); //設(shè)備登錄用戶名
strcpy_s(struLoginInfo.sPassword, "your_password"); //設(shè)備登錄密碼
//設(shè)備信息, 輸出參數(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è)置報(bào)警回調(diào)函數(shù)
NET_DVR_SetDVRMessageCallBack_V31(MessageCallback, NULL);
//啟用布防
LONG lHandle;
NET_DVR_SETUPALARM_PARAM struAlarmParam = { 0 };
struAlarmParam.dwSize = sizeof(struAlarmParam);
//火點(diǎn)檢測(cè)不需要設(shè)置其他報(bào)警布防參數(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è)備上傳報(bào)警信息,在報(bào)警回調(diào)函數(shù)里面接收和處理報(bào)警信息
//撤銷布防上傳通道
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 ?
第一步:打開窗口頂部 【項(xiàng)目】菜單,選中 【<某某項(xiàng)目>屬性】。
第二步:在打開的對(duì)話框中,左側(cè)菜單選擇 【C/C++】=> 【常規(guī)】,選中右側(cè)附加包含目錄中,點(diǎn)擊右側(cè)出現(xiàn)的向下箭頭,點(diǎn)擊編輯,在打開的對(duì)話框中如下填寫:

其中 D:\ws\vc\emptycam\hkheader 文件夾放著??档念^文件,分別是: DataType.h、DecodeCardSdk.h、HCNetSDK.h、plaympeg4.h。
第三步:左側(cè)菜單選擇 【鏈接器】=> 【常規(guī)】。右側(cè)選中附加庫目錄,點(diǎn)擊右側(cè)小三角,點(diǎn)擊編輯,打開對(duì)話框。

文件夾 D:\ws\vc\emptycam\hkdll 是放海康dll文件的地方。文件如下圖所示:

第四步:左側(cè)菜單選擇 【鏈接器】=> 【輸入】。右側(cè)選中【附加依賴項(xiàng)】點(diǎn)擊右側(cè)小三角,點(diǎn)擊編輯,打開對(duì)話框。內(nèi)容按照?qǐng)D片里的文字進(jìn)行填寫。

到此這篇關(guān)于VS2022調(diào)試通過海康攝像頭煙火識(shí)別SDK的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)VS2022??禂z像頭煙火識(shí)別SDK內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++實(shí)現(xiàn)中綴表達(dá)式轉(zhuǎn)后綴表達(dá)式
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)中綴表達(dá)式轉(zhuǎn)后綴表達(dá)式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04
C語言復(fù)數(shù)的加減及輸出結(jié)構(gòu)體
大家好,本篇文章主要講的是C語言復(fù)數(shù)的加減及輸出結(jié)構(gòu)體,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下2022-02-02
C++命名空間using?namespace?std是什么意思
namespace中文意思是命名空間或者叫名字空間,傳統(tǒng)的C++只有一個(gè)全局的namespace,下面這篇文章主要給大家介紹了關(guān)于C++命名空間using?namespace?std是什么意思的相關(guān)資料,需要的朋友可以參考下2023-01-01
vscode不同項(xiàng)目使用不同的插件的實(shí)現(xiàn)
本文主要介紹了vscode不同項(xiàng)目使用不同的插件的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07

