实际项目中使用海康SDK进行NVR拍照功能的二次开发
基于Linux环境下采用Qt进行开发,使用海康SDK需先将海康打包的动态库拷贝至/us/lib/下,或者自己根据需要设置调用动态库的路径。
代码如下:
#include "./include/HCNetSDK.h" int Demo_Capture(char* ip,char* userName,char*passwd) { NET_DVR_Init(); NET_DVR_SetLogToFile(3, "./sdkLog"); long lUserID; //login NET_DVR_DEVICEINFO_V30 struDeviceInfo; lUserID = NET_DVR_Login_V30(ip, 8000, userName, passwd, &struDeviceInfo); if (lUserID < 0) { printf("pyd1---Login error, %d\n", NET_DVR_GetLastError()); return -1; } NET_DVR_JPEGPARA strPicPara = {0}; strPicPara.wPicQuality = 2; strPicPara.wPicSize = 0; int iRet; QString timeName = QDateTime::currentDateTime().toString("yyyyMMddhhmmss"); QDir dir("./photo"); if(!dir.exists()) dir.mkdir((dir.currentPath()+"/photo")); QString strPath = QString("./photo/%1.jpeg").arg(timeName); QByteArray charPath = strPath.toLatin1(); iRet = NET_DVR_CaptureJPEGPicture(lUserID, struDeviceInfo.byStartChan, &strPicPara, charPath.data()); if (!iRet) { printf("pyd1---NET_DVR_CaptureJPEGPicture error, %d\n", NET_DVR_GetLastError()); return -1; } //logout NET_DVR_Logout_V30(lUserID); NET_DVR_Cleanup(); return 0; }
时间: 2024-12-15 06:33:52