linux C++ 海康截图Demo

项目结构

linux C++ 海康截图Demo_第1张图片

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 
#include 
#include "../include/HCNetSDK.h"
#include 
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 ..

linux C++ 海康截图Demo_第2张图片 make

make

 

运行 测试

./CapPictureTest 

linux C++ 海康截图Demo_第3张图片

linux C++ 海康截图Demo_第4张图片

Demo 下载

你可能感兴趣的:(C/C++,linux,c++,海康截图Demo)