ONVIF PTZ控制海康云台相机

这篇博客介绍了如何在NVIDIA XAIVER平台上使用ONVIF协议和gsoap库控制海康云台相机,特别强调了ONVIF PTZ控制的实现和鉴权过程,适合于无人车系统的开发者。
摘要由CSDN通过智能技术生成

之前帮一个算法朋友弄的 ONVIF PTZ控制海康云台相机代码在无人车上的应用.

主要是鉴权没弄过,折腾onvif的人肯定会碰到,所以特别记录一下.

开始本来是在X64的WIN32或ubuntu工控机平台弄海康摄像头控制的,因为有SDK的直接支持.

结果无人车主控选的是NVIDIA XAIVER arm下控制云台,这就想起了用ONVIF了.

ONVIF无非就是用gsoap+rtsp来折腾的 就把gsoap库先下载和onvif官方下载对应的文件wsdl接口.如果是搞过webservice的活应该有所了解, gsoap 我不多说 百度一下应该好多讲的只管下载. 

版本没有太大的要求, 下面文件有些我可能删除了. 我保留主要文件 .

onvif标准接口也是下载 一堆wsdl文件  PTZ在下面

主要作用类的封装:

class OnvifSDK
{
public:
    std::string MediaAddr;
    std::string PTZAddr;
public:
    static struct soap* NewSoap(const char* ip);
    OnvifSDK(struct soap* soap_, const char* username, const char* password);
    virtual ~OnvifSDK();
    bool GetDeviceInfo(char* url);
    bool GetCapabilities(char* url);
    bool GetProfiles();
    std::string GetUri(enum tt__TransportProtocol transtype);
    bool GetStstus(float* pvalue, float* tvalue, float* zvalue);
    //连续控制
    void ControlPTZ(int control, bool control_type, int speed);
    //绝对控制
    void SetPTZ(float pvalue, float tvalue, float zvalue);
    //相对控制
    void SetMoveStep(ptz_common commond, float move_step);
protected:
#ifdef WITH_OPENSSL
#else
    void calc_nonce(struct soap* soap, char nonce[SOAP_WSSE_NONCELEN]);
    struct _wsse__Security* soap_wsse_add_Security(struct soap* soap);
    int soap_wsse_add_UsernameTokenText(struct soap* soap, const char* id, const char* username, const char* password);
    int soap_wsse_add_UsernameTokenDigest(struct soap* soap, const char* id, const char* username, const char* password);
    void calc_digest(struct soap* soap, const char* created,const char* nonce, int noncelen, const char* password, char hash[SOAP_SMD_SHA1_SIZE]);
    void TokenTimestmap(struct soap* pSoap, time_t lifetime = TOKEN_TIMESTAMP);
    int soap_wsse_add_Timestamp(struct soap* soap, const char* id, time_t lifetime);
#endif
private:
    std::string UserName;
    std::string PassWord;
    std::string Band;
    enum xsd__boolean TrueFlag;
    struct tt__PTZSpeed PTZSpeed;
    struct tt__Vector2D PTZVectorPT;
    struct tt__Vector1D PTZVectorZ;
    struct tt__PTZVector VectorABSPTZ;
    struct soap* soap;
    struct _tds__GetCapabilities capa_req;
    struct _tds__GetCapabilitiesResponse capa_resp;
    struct _trt__GetProfiles trt__GetProfiles;
    struct _trt__GetProfilesResponse trt__GetProfilesResponse;
    struct _trt__GetStreamUri trt__GetStreamUri;
    struct _trt__GetStreamUriResponse trt__GetStreamUriResponse;
    struct _tptz__GetStatus tptz__GetStatus;
    struct _tptz__GetStatusResponse tptz__GetStatusResponse;
    struct _tptz__ContinuousMove tptz__ContinuousMove;
    struct _tptz__ContinuousMoveResponse tptz__ContinuousMoveResponse;
    struct _tptz__Stop tptz__Stop;
    struct _tptz__StopResponse tptz__StopResponse;
    struct _tds__GetDeviceInformation tds__GetDeviceInformation;
    struct _tds__GetDeviceInformationResponse tds__GetDeviceInformationResponse;
    struct _tptz__AbsoluteMove tptz__AbsoluteMove;
    struct _tptz__AbsoluteMoveResponse tptz__AbsoluteMoveResponse;
    struct _tptz__RelativeMove tptz__RelativeMove;
    struct _tptz__RelativeMoveResponse tptz__RelativeMoveResponse;
};

实现部分(ptz控制方法):

bool OnvifSDK::GetDeviceInfo(char* url)
{
    soap_wsse_add_UsernameTokenDigest(soap, "", UserName.c_str(), PassWord.c_str());
    int ret = soap_call___tds__GetDeviceInformation(soap, url, NULL, &tds__GetDeviceInformation, &tds__GetDeviceInformationResponse);
    if (ret != SOAP_OK)
        return false;
    if (soap->error)
        return false;
    else
    {
        Band = std::string(tds__GetDeviceInformationResponse.Manufacturer);
        return true;
    }
}

bool OnvifSDK::GetCapabilities(char* url)
{
    capa_req.__sizeCategory = 1;
    capa_req.Category =  (enum tt__CapabilityCategory*)malloc(sizeof(enum tt__CapabilityCategory));
    enum tt__CapabilityCategory temp_category = tt__CapabilityCategory__All;
    capa_req.Category = &temp_category;
    capa_resp.Capabilities =  (struct tt__Capabilities*)malloc(sizeof(struct tt__Capabilities)) ;
    soap_wsse_add_UsernameTokenDigest(soap, "", UserName.
  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值