其他分享
首页 > 其他分享> > 用摇杆或北通手柄控制海康摄像头

用摇杆或北通手柄控制海康摄像头

作者:互联网

今天没事看到家里有一款海康的网络摄像头,这个摄像头支持上下左右旋转,另外还可以镜头远近缩放。刚好家里又有一款摇杆和一个北通的手柄。想着写一个软件实现用手柄和摇杆控制摄像头运动,

还能将实时画面显示在软件上,最后做出来的效果还是不错的。大概介绍一下这个软件的开发情况,先附上资料。

资料下载:

 

 

开发软件:qt5.14.2

开发语言:c++

测试摇杆:图马斯特(其它xbox摇杆也可以)  链接:http://support.thrustmaster.cn/zh/product/t-flight-hotas-one-zh

测试手柄:北通阿修罗2-无线版

摄像头:海康网络摄像头

 

效果展示:

  

视频展示:

软件介绍:

  1.软件右边是摇杆或手柄键位拨动时读出的数值。

  2.中间部分是手动用鼠标控制摄像头运动,或登录参数设置。

  3.左边实时画面。

 

 部分代码:

手柄类:

class joystick:public QObject
{
public:
    joystick()=delete;
    joystick(QVector<QPushButton*>&btn,QTextEdit *edit,QProgressBar *rpos,QProgressBar *zpos);
    ~joystick();
    void Joyinit();
    void joyInfoUpdate();
    void joyBtnStateClear(void);
    bool readJoyActInfo(JOYINFOEX &info);
private:
    JOYINFOEX now_act;
    QVector<QPushButton*>joyBtnList;
    QTextEdit *textEdit;
    QProgressBar *joy_dwRpos;
    QProgressBar *joy_dwZpos;
};

#endif // joystick

 

void joystick::joyInfoUpdate()
{
    QString str;
    now_act.dwSize = sizeof(typeof(joyinfoex_tag));
    now_act.dwFlags = (int)JOY_RETURNBUTTONS;

    qJoyGetPosEx(JSX, &now_act);
    str.append("dwSize=").append(QString::number(now_act.dwSize)).append("\n");
    str.append("dwFlags=").append(QString::number(now_act.dwFlags)).append("\n");
    str.append("dwXpos=").append(QString::number(now_act.dwXpos)).append("\n");
    str.append("dwYpos=").append(QString::number(now_act.dwYpos)).append("\n");
    str.append("dwZpos=").append(QString::number(now_act.dwZpos)).append("\n");
    str.append("dwRpos=").append(QString::number(now_act.dwRpos)).append("\n");
    str.append("dwUpos=").append(QString::number(now_act.dwUpos)).append("\n");
    str.append("dwVpos=").append(QString::number(now_act.dwVpos)).append("\n");
    str.append("dwButtons=").append(QString::number(now_act.dwButtons)).append("\n");
    str.append("dwButtonNumber=").append(QString::number(now_act.dwButtonNumber)).append("\n");
    str.append("dwPOV=").append(QString::number(now_act.dwPOV)).append("\n");
    str.append("dwReserved1=").append(QString::number(now_act.dwReserved1)).append("\n");
    str.append("dwReserved2=").append(QString::number(now_act.dwReserved2)).append("\n");

    textEdit->setText(str);
    joy_dwRpos->setValue(static_cast<int>(now_act.dwRpos*100/65535));
    joy_dwZpos->setValue(static_cast<int>((65535-now_act.dwZpos)*100/65535));
    for(int i=0;i<joyBtnList.size();i++)
    {
        if(now_act.dwButtons & 0x01 << i)
       {
            joyBtnList[i]->setStyleSheet(jBstate_ON);
        }else
        {
            joyBtnList[i]->setStyleSheet(jBstate_OF);
        }
    }
}

 

海康部分代码

class camera_dialog : public QDialog
{
    Q_OBJECT
public:
    explicit camera_dialog(QWidget *parent = nullptr);
    ~camera_dialog();
    void CurDataUpdate();
    long play(long userID, HWND hWnd, NET_DVR_PREVIEWINFO struPlayInfo);
    void closeplay(long IRealPlayHandle);
    void StartRecord();
    void StopRecord();
    void Net_DevTimeConfig();
    void on_devPlayBtn_clicked();
public slots:
    void CameraInit();
    void on_devLoginBtn_clicked();
    void on_SetCtrlDwSpeed(DWORD value);

    void on_devCloseBtn_clicked();
    void on_RecordBtn_clicked();
    void on_Camera_Up_pressed();
    void on_Camera_Down_pressed();
    void on_Camera_Left_pressed();
    void on_Camera_Right_pressed();
    void on_Camera_Stop_clicked();
    void on_Zoom_Out_pressed();
    void on_Zoom_In_pressed();
    void on_Focus_Near_pressed();
    void on_Focus_Far_pressed();
     void Dev_Ctrl_PTZ( DWORD dwPTZCommand,DWORD dwStop,DWORD dwSpeed);


private:
    Ui::camera_dialog *ui;
    long userID;
    long IRealPlayHandle;
    QTimer *DataTimer;
    QString IP;
    QString Port;
    QString User;
    QString PassWord;
   // DWORD dwStop;
    DWORD dwSpeed=7;
    long m_lPlayHandle;
    BOOL m_bIsRecording;
    NET_DVR_DEVICEINFO_V30 DeviceInfoTmp;
};

 

  

 

标签:或北通,void,海康,摇杆,QString,str,act,now,append
来源: https://www.cnblogs.com/hsbook/p/16167841.html