1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > ubuntu20.04下开发海康威视网络摄像头sdk(二)云台基本控制(位姿控制)

ubuntu20.04下开发海康威视网络摄像头sdk(二)云台基本控制(位姿控制)

时间:2023-02-10 03:24:51

相关推荐

ubuntu20.04下开发海康威视网络摄像头sdk(二)云台基本控制(位姿控制)

编译运行参考:ubuntu20.04下开发海康威视网络摄像头sdk(一)运行示例程序

然后是控制摄像头转动:

初始化和左转

我直接在这个截图的函数中修改的:

参考博客:/MKraul/article/details/106315701

我改的代码 CapPicture.cpp

/** Copyright(C) ,Hikvision Digital Technology Co., Ltd * * File name CapPicture.cpp* Discription * Version1.0* Author panyd* Create Date _3_25* Modification History */#include <stdio.h>#include <iostream>#include "CapPicture.h"#include "public.h"#include <string.h>#include <unistd.h>#include <vector>using namespace std;//相机的角度参数是十六进制,需要和十进制来回切换int HexToDecMa(int wHex)//十六进制转十进制{return (wHex / 4096) * 1000 + ((wHex % 4096) / 256) * 100 + ((wHex % 256) / 16) * 10 + (wHex % 16);}int DEC2HEX_doc(int x)//十进制转十六进制{return (x / 1000) * 4096 + ((x % 1000) / 100) * 256 + ((x % 100) / 10) * 16 + x % 10;}int Demo_Capture(){NET_DVR_Init(); //初始化SDKlong lUserID;//loginNET_DVR_USER_LOGIN_INFO struLoginInfo = {0};NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};//用户注册设备struLoginInfo.bUseAsynLogin = false; //bUseAsynLogin为0时登录为同步模式 为1时为异步登陆struLoginInfo.wPort = 8000;memcpy(struLoginInfo.sDeviceAddress, "10.102.23.130", NET_DVR_DEV_ADDRESS_MAX_LEN);memcpy(struLoginInfo.sUserName, "admin", NAME_LEN);memcpy(struLoginInfo.sPassword, "xxxxxx", NAME_LEN);//NET_DVR_Login_V40 该接口返回-1表示登录失败,其他值表示返回的用户ID值。用户ID具有唯一性,后续对设备的操作都需要通过此ID实现lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);if (lUserID < 0) //登陆失败{printf("pyd1---Login error, %d\n", NET_DVR_GetLastError());return HPR_ERROR;}//截图功能// NET_DVR_JPEGPARA strPicPara = {0};// strPicPara.wPicQuality = 2;// strPicPara.wPicSize = 0;// int iRet;// iRet = NET_DVR_CaptureJPEGPicture(lUserID, struDeviceInfoV40.struDeviceV30.byStartChan, &strPicPara, "./ssss.jpeg");// if (!iRet)// {//printf("pyd1---NET_DVR_CaptureJPEGPicture error, %d\n", NET_DVR_GetLastError());//return HPR_ERROR;// }//截图完成//读取相机信息NET_DVR_PTZPOS m_ptzPosCurrent;DWORD dwtmp;//获取位姿信息bool a = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_PTZPOS, 0, &m_ptzPosCurrent, sizeof(NET_DVR_PTZPOS), &dwtmp);//wPanPos P参数(水平参数) //wTiltPos T参数(垂直参数) //wZoomPos Z参数(变焦参数)//HexToDecMa 十六进制转换十进制int m_iPara1 = HexToDecMa(m_ptzPosCurrent.wPanPos);int m_iPara2 = HexToDecMa(m_ptzPosCurrent.wTiltPos);int m_iPara3 = HexToDecMa(m_ptzPosCurrent.wZoomPos);vector<int> TempPosture(3);//三个参数代表含义如下cout所示//NET_DVR_PTZPOS 里面获取的参数是实际显示值的10倍 所以要除以10 具体参考开发手册里面的解释TempPosture[0] = m_iPara1 / 10 ;TempPosture[1] = m_iPara2 / 10 ;TempPosture[2] = m_iPara3 / 10 ;cout << "##################当前参数#####################"<< endl;cout << "P水平方向 " << TempPosture[0] << " ##" << endl;cout << "T仰角 " << TempPosture[1] << " ##" << endl;cout << "Z焦距 " << TempPosture[2] << " ##" << endl;cout << "###############################################"<< endl;//开始控制摄像头转动printf("下面控制摄像头转动!\n");// //初始化操作 水平角度为0度 仰角45度// //定义要初始化的参数// vector<int> TargetPosture(3);// TargetPosture[0]=(0);// TargetPosture[1]=(45);// TargetPosture[2]=(1);// //将参数转化为十六进制 记得再乘以10// m_ptzPosCurrent.wPanPos = DEC2HEX_doc(TargetPosture[0]*10);// m_ptzPosCurrent.wTiltPos = DEC2HEX_doc(TargetPosture[1]*10);// m_ptzPosCurrent.wZoomPos = DEC2HEX_doc(TargetPosture[2]*10);// // 开始转动// bool b=NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_PTZPOS, 0, &m_ptzPosCurrent, sizeof(NET_DVR_PTZPOS));// sleep(6);// TempPosture[0] = TargetPosture[0];// TempPosture[1] = TargetPosture[1];// TempPosture[2] = TargetPosture[2];// cout << "##################初始化后参数#####################"<< endl;// cout << "P水平方向 " << TempPosture[0] << " ##" << endl;// cout << "T仰角 " << TempPosture[1] << " ##" << endl;// cout << "Z焦距 " << TempPosture[2] << " ##" << endl;// cout << "###############################################"<< endl;//下面是使相机在本来的基础上左转//设置想要变化的参数值vector<int> Changevalue(3);Changevalue[0]=(45);//degree水平加30度Changevalue[1]=(0);//degree俯仰加0度Changevalue[2]= (0);//焦距加0//将变化值更新vector<int> TargetPosture(3);TargetPosture[0]=TempPosture[0]+Changevalue[0];TargetPosture[1]=TempPosture[1]+Changevalue[1];TargetPosture[2]=TempPosture[2]+Changevalue[2];//将变化后的参数转化为相机自带的十六进制 记得再乘以10m_ptzPosCurrent.wPanPos = DEC2HEX_doc(TargetPosture[0]*10);m_ptzPosCurrent.wTiltPos = DEC2HEX_doc(TargetPosture[1]*10);m_ptzPosCurrent.wZoomPos = DEC2HEX_doc(TargetPosture[2]*10);//将参数传入函数,相机开始调整位置bool c=NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_PTZPOS, 0, &m_ptzPosCurrent, sizeof(NET_DVR_PTZPOS));sleep(4);//更新此时的位置参数 打印出来展示TempPosture[0] = TargetPosture[0];TempPosture[1] = TargetPosture[1];TempPosture[2] = TargetPosture[2];printf("摄像头转动完成!");cout << "####################调整之后#######################"<< endl;cout << "P水平方向 " << TempPosture[0] << " #" << endl;cout << "T仰角 " << TempPosture[1] << " #" << endl;cout << "Z焦距 " << TempPosture[2] << " #" << endl;cout << "###############################################"<< endl;//logoutNET_DVR_Logout_V30(lUserID);//注销设备NET_DVR_Cleanup();//释放SDK资源return HPR_OK;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。