目录
项目结构
编辑
CMakeLists.txt
代码
camke
编辑 make
运行 测试
下载
项目结构
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)
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)
代码
#include <stdio.h>
#include <iostream>
#include "../include/HCNetSDK.h"
#include <string.h>
using namespace std;
#define HPR_OK 0
#define HPR_ERROR -1
void 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 device
NET_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;
}
}
// logout
NET_DVR_Logout_V30(lUserID);
NET_DVR_Cleanup();
return 0;
}
#include <stdio.h>
#include <iostream>
#include "../include/HCNetSDK.h"
#include <string.h>
using namespace std;
#define HPR_OK 0
#define HPR_ERROR -1
void 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 device
NET_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;
}
}
// logout
NET_DVR_Logout_V30(lUserID);
NET_DVR_Cleanup();
return 0;
}
camke
mkdir build
cd build/
camke ..
mkdir build
cd build/
camke ..
make
make
运行 测试
./CapPictureTest
文章来源:https://www.toymoban.com/news/detail-690217.html
下载
Demo 下载文章来源地址https://www.toymoban.com/news/detail-690217.html
到了这里,关于linux C++ 海康截图Demo的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!