VS2022调试通过海康摄像头烟火识别SDK的实现
程序员文章站
2022-03-01 13:29:15
下面是我根据海康官方文档代码,放到vs 2022 版本中调试通过后的代码:#include #include #include "wind...
下面是我根据海康官方文档代码,放到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; //登录参数,包括设备地址、登录用户、密码等 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"); //设备登录密码 //设备信息, 输出参数 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; } //设置报警回调函数 net_dvr_setdvrmessagecallback_v31(messagecallback, null); //启用布防 long lhandle; net_dvr_setupalarm_param strualarmparam = { 0 }; strualarmparam.dwsize = sizeof(strualarmparam); //火点检测不需要设置其他报警布防参数,不支持 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); //等待过程中,如果设备上传报警信息,在报警回调函数里面接收和处理报警信息 //撤销布防上传通道 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++】=> 【常规】,选中右侧附加包含目录中,点击右侧出现的向下箭头,点击编辑,在打开的对话框中如下填写:
其中 d:\ws\vc\emptycam\hkheader 文件夹放着海康的头文件,分别是: datatype.h、decodecardsdk.h、hcnetsdk.h、plaympeg4.h。
第三步:左侧菜单选择 【链接器】=> 【常规】。右侧选中附加库目录,点击右侧小三角,点击编辑,打开对话框。
文件夹 d:\ws\vc\emptycam\hkdll 是放海康dll文件的地方。文件如下图所示:
第四步:左侧菜单选择 【链接器】=> 【输入】。右侧选中【附加依赖项】点击右侧小三角,点击编辑,打开对话框。内容按照图片里的文字进行填写。
到此这篇关于vs2022调试通过海康摄像头烟火识别sdk的实现的文章就介绍到这了,更多相关vs2022海康摄像头烟火识别sdk内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!