项目结构
CMakeLists.txt
cmake_minimum_required(VERSION 3.7)project(CapPictureTest)include_directories(include)link_directories(${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/lib/HCNetSDKCom) add_executable(CapPictureTest ${CMAKE_SOURCE_DIR}/src/CapPictureTest.cpp)target_link_libraries(CapPictureTest hcnetsdk)
CapPictureTest.cpp
#include <stdio.h>
#include <iostream>
#include "../include/HCNetSDK.h"
#include <string.h>
using namespace std;#define HPR_OK 0
#define HPR_ERROR -1void Demo_SDK_Version()
{unsigned int uiVersion = NET_DVR_GetSDKBuildVersion();char strTemp[1024] = {0};sprintf(strTemp, "HCNetSDK V%d.%d.%d.%d\n",(0xff000000 & uiVersion) >> 24,(0x00ff0000 & uiVersion) >> 16,(0x0000ff00 & uiVersion) >> 8,(0x000000ff & uiVersion));printf(strTemp);
}int Demo_Capture(LONG lUserID, NET_DVR_DEVICEINFO_V40 struDeviceInfoV40)
{NET_DVR_JPEGPARA strPicPara = {0};strPicPara.wPicQuality = 2;strPicPara.wPicSize = 0;int iRet;time_t nowtime = time(NULL);struct tm *p;p = gmtime(&nowtime);char filename[256] = {0};sprintf(filename, "./%d-%d-%d %d:%02d:%02d.jpeg", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, 8 + p->tm_hour, p->tm_min, p->tm_sec);iRet = NET_DVR_CaptureJPEGPicture(lUserID, struDeviceInfoV40.struDeviceV30.byStartChan, &strPicPara, filename);if (!iRet){printf("NET_DVR_CaptureJPEGPicture error, %d\n", NET_DVR_GetLastError());return HPR_ERROR;}else{printf("NET_DVR_CaptureJPEGPicture success filename:%s",filename);}return HPR_OK;
}int main()
{NET_DVR_Init();Demo_SDK_Version();NET_DVR_SetLogToFile(3, "./sdkLog");char cUserChoose = 'r';// Login deviceNET_DVR_USER_LOGIN_INFO struLoginInfo = {0};NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};struLoginInfo.bUseAsynLogin = false;struLoginInfo.wPort = 8000;memcpy(struLoginInfo.sDeviceAddress, "11.101.4.247", NET_DVR_DEV_ADDRESS_MAX_LEN);memcpy(struLoginInfo.sUserName, "admin", NAME_LEN);memcpy(struLoginInfo.sPassword, "123456", NAME_LEN);LONG lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);if (lUserID < 0){printf("Login error, %d\n", NET_DVR_GetLastError());printf("Press any key to quit...\n");cin >> cUserChoose;NET_DVR_Cleanup();return HPR_ERROR;}while ('q' != cUserChoose){printf("\n");printf("Input 1, Test Capture Picture\n");printf("Input:");cin >> cUserChoose;switch (cUserChoose){case '1':Demo_Capture(lUserID, struDeviceInfoV40);break;default:break;}}// logoutNET_DVR_Logout_V30(lUserID);NET_DVR_Cleanup();return 0;
}
camke
mkdir build
cd build/
camke ..
make
make
运行 测试
./CapPictureTest
Demo 下载