Qt compile security video monitoring system 60 - sub module 4 PTZ control

1, Foreword

PTZ control is a very old and basic module. It is one of the necessary special modules in the video monitoring system, It can control the pan tilt of the camera (onvif protocol) of the selected channel, control the movement of the ball machine in all directions, such as up, down, left, right, etc., and adjust the zoom step size. As for zoom and aperture, at present, the corresponding protocol support is not seen in onvif protocol and has not been realized.

There are three strategies for PTZ Mobile: absolute mobile, relative mobile and continuous mobile. The system supports three strategies. Continuous mobile is adopted by default, which is also required in most application scenarios. Press the corresponding direction to move, release and stop moving immediately, which is very humanized.

PTZ description

  • x. The range of y and z is between 0-1.
  • x is a negative number, indicating a left turn, and x is a positive number, indicating a right turn.
  • y is a negative number, indicating downward rotation, and y is a positive number, indicating upward rotation.
  • z is a positive number, which means closer, and z is a negative number, which means farther.
  • Through the combination of x and y, the PTZ control is realized.
  • Focus control is realized through the combination of z.

2, Functional features

(1) Software module

  1. Video monitoring module, various docking small window sub modules, including equipment list, graphic alarm, window information, PTZ control, preset position, cruise setting, equipment control, suspension map, web browsing, etc.
  2. Video playback module, including local playback, remote playback, device playback, picture playback, video upload, etc.
  3. Electronic map module, including picture map, online map, offline map, path planning, etc.
  4. Log query module, including local log, device log, etc.
  5. System setting module, including system setting (basic setting, video parameters, database setting, map configuration, serial port configuration, etc.), VCR management, camera management, polling configuration, user management, etc.

(2) Basic functions

  1. It supports various video streams (rtsp, rtmp, http, etc.), video files (mp4, rmvb, avi, etc.) and local USB camera playback.
  2. Support multi screen switching, including 1, 4, 6, 8, 9, 13, 16, 25, 36 and 64 screen switching.
  3. Full screen switching is supported, including right-click menu, toolbar button and shortcut key (alt+enter full screen, esc exit full screen).
  4. Support video polling, including 1, 4, 9 and 16 picture polling, and set polling packet (polling plan), polling interval, code stream type, etc.
  5. Support onvif protocol, including device search, PTZ control and device control (picture parameters, proofreading time, system restart, capturing pictures, etc.).
  6. Permission management is supported. Different users can correspond to different module permissions, such as deleting logs, shutting down the system, etc.
  7. The database supports a variety of, including sqlite, mysql, sqlserver, postgresql, oracle, NPC gold warehouse, etc.
  8. The local USB camera supports setting parameters such as resolution and frame rate.
  9. All docking modules automatically generate corresponding menus to control display and hiding. Right click in the title bar to pop up.
  10. It supports displaying all modules, hiding all modules, resetting normal layout and resetting full screen layout.
  11. Double click the device to pop up the real-time preview video, which supports picture map, online map, offline map, etc.
  12. Drag the camera node to the corresponding window to play video, and drag local files to play directly.
  13. To delete a video, you can right-click to delete it, close the hoverbar to delete it, and drag it outside the video monitoring panel to delete it.
  14. The device button on the picture map can be dragged freely to automatically save the location information. Baidu map can click to obtain longitude and latitude information to update the device location.
  15. Any channel in the video monitoring panel form supports drag switching and instant response.
  16. It encapsulates Baidu map, view switching, motion track, equipment point position, mouse click to obtain longitude and latitude, etc.
  17. Double click the node, drag the node, drag the window to exchange positions and other operations will automatically update and save the last playback address, and the software will open the automatic application next time.
  18. The volume bar control in the lower right corner is automatically hidden when the focus is lost, and the volume bar has a mute icon.
  19. Support video screenshots. You can specify a single or all channel screenshots. There is also a screenshot button on the bottom small toolbar.
  20. Support timeout automatic hiding of mouse pointer and automatic full screen mechanism.
  21. It supports onvif PTZ control and can move PTZ cameras up, down, left and right, including reset and focal length adjustment.
  22. Support any onvif camera, including but not limited to Haikang, Dahua, Yushi, Tiandi Weiye, Huawei, etc.
  23. Video can be saved, with options of regular storage or single file storage, and optional storage interval.
  24. The video stream communication mode tcp+udp can be set, and the video decoding modes such as speed priority, quality priority and equalization can be set.
  25. The Chinese name, English name, LOGO icon, etc. of the software can be set.
  26. The stored video files can be exported to the specified directory and uploaded to the server in batches.

(3) Characteristic function

  1. The main interface adopts docked form mode, and various components are added in the form of small modules, which can be added by any module.
  2. The docking module can drag any position to embed and suspend, and supports maximizing the full screen and multi screen.
  3. Dual layout file storage mechanism. The normal mode and full screen mode correspond to different layout schemes and are automatically switched and saved. For example, the full screen mode can highlight several modules and display them transparently in the specified position, which is more sci-fi and modern.
  4. The original onvif protocol mechanism adopts the underlying protocol parsing (udp broadcast search + http request execution command), which is lighter, easy to understand, easy to learn and expand, and does not rely on any third-party components, such as gsoap.
  5. The original data import and export mechanism can export data instantly without relying on any components across platforms.
  6. Built in multiple original components, the universe is super valuable, including data import and export components (export to xls, pdf, printing), database components (database management thread, automatic data cleaning thread, universal paging, data request, etc.), map components, video monitoring components, file multithreading transceiver components, onvif communication components, general browser kernel components, etc.
  7. User defined information box + error box + query box + prompt box in the lower right corner (including multiple formats), etc.
  8. Exquisite skin change, up to 17 sets of skin styles can be changed at will, and all styles are unified, including menu, etc.
  9. Multiple buttons can be added to the video control suspension bar, and buttons can also be added to the small toolbar at the bottom of the monitoring interface.
  10. Double click the camera node to automatically play videos. Double click the node to automatically add videos one by one. You will automatically skip to the next node. Double click the parent node to automatically add all videos under the node. Main code stream and sub code stream can be selected.
  11. For video recorder management and camera management, you can add, delete, modify, import and export printing information, and immediately apply the new equipment information to generate a tree list without restarting.
  12. A variety of cores can be freely switched. ffmpeg, vlc, mpv, etc. can be set in pro. ffmpeg is recommended, with the most cross platforms. The libraries compiled on linux and mac platforms are provided by default.
  13. Hard decoding is supported, and hard decoding types (qsv, dxva2, d3d11va, etc.) can be set.
  14. opengl is used to draw video by default, with ultra-low CPU resource occupation. It supports yuyv and nv12 formats, which is very awesome.
  15. Highly customizable, users can easily derive their own functions on this basis, such as adding custom modules, adding operation modes, robot monitoring, UAV monitoring, excavator monitoring, etc.
  16. Support xp, win7, win10, linux, mac, various domestic systems (UOS, bid winning Kirin, Galaxy Kirin, etc.), embedded linux and other systems.
  17. Complete notes, clear project structure, super detailed and complete use and development manual, accurate to the functional description of each code file, and continuously iterative versions.

3, Experience address

  1. Experience address: https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g Extraction code: 01jf file name: bin_video_system.zip.
  2. Domestic sites: https://gitee.com/feiyangqingyun
  3. International sites: https://github.com/feiyangqingyun
  4. Personal homepage: https://blog.csdn.net/feiyangqingyun
  5. Zhihu homepage: https://www.zhihu.com/people/feiyangqingyun/
  6. Online documentation: https://feiyangqingyun.gitee.io/qwidgetdemo/video_system/

4, Renderings

5, Core code

#include "frmipcptz.h"
#include "ui_frmipcptz.h"
#include "quihelper.h"
#include "devicehelper.h"
#include "deviceonvif.h"

frmIpcPtz::frmIpcPtz(QWidget *parent) : QWidget(parent), ui(new Ui::frmIpcPtz)
{
    ui->setupUi(this);
    this->initForm();
    this->initIcon();
}

frmIpcPtz::~frmIpcPtz()
{
    delete ui;
}

bool frmIpcPtz::eventFilter(QObject *watched, QEvent *event)
{
    //Press the mouse to specify that the release will stop automatically
    if (event->type() == QEvent::MouseButtonPress) {
        int position = 255;
        if (watched == ui->btnPtzZoomIn) {
            position = 9;
        } else if (watched == ui->btnPtzZoomOut) {
            position = 10;
        } else if (watched == ui->btnPtzFocusIn) {
            position = 11;
        } else if (watched == ui->btnPtzFocusOut) {
            position = 12;
        } else if (watched == ui->btnPtzApertureIn) {
            position = 13;
        } else if (watched == ui->btnPtzApertureOut) {
            position = 14;
        }

        QMetaObject::invokeMethod(this, "ptzControl", Qt::QueuedConnection, Q_ARG(int, position));
    } else if (event->type() == QEvent::MouseButtonRelease) {
        QMetaObject::invokeMethod(this, "ptzControl", Qt::QueuedConnection, Q_ARG(int, 255));
    }

    return QWidget::eventFilter(watched, event);
}

void frmIpcPtz::initForm()
{
    //Install event filter recognition release automatic stop
    ui->btnPtzZoomIn->installEventFilter(this);
    ui->btnPtzZoomOut->installEventFilter(this);

    //Bind PTZ instrument panel press and release events
    ui->gaugeCloud->setAutoRepeat(false);
    connect(ui->gaugeCloud, SIGNAL(mousePressed(int, QString)), this, SLOT(mousePressed(int, QString)));
    connect(ui->gaugeCloud, SIGNAL(mouseReleased(int, QString)), this, SLOT(mouseReleased(int, QString)));

    //Associated style change signal auto reset Icon
    connect(AppEvent::Instance(), SIGNAL(changeStyle()), this, SLOT(initIcon()));
}

void frmIpcPtz::initIcon()
{
    //Set graphic font
    int fontSize = 15;
    IconHelper::setIcon(ui->btnPtzZoomIn, 0xf067, fontSize);
    IconHelper::setIcon(ui->btnPtzZoomOut, 0xf068, fontSize);
    IconHelper::setIcon(ui->btnPtzFocusIn, 0xf067, fontSize);
    IconHelper::setIcon(ui->btnPtzFocusOut, 0xf068, fontSize);
    IconHelper::setIcon(ui->btnPtzApertureIn, 0xf067, fontSize);
    IconHelper::setIcon(ui->btnPtzApertureOut, 0xf068, fontSize);
}

void frmIpcPtz::mousePressed(int position, const QString &strPosition)
{
    DeviceHelper::addMsg(QString("Press PTZ %1").arg(strPosition));
    QMetaObject::invokeMethod(this, "ptzControl", Qt::QueuedConnection, Q_ARG(int, position));
}

void frmIpcPtz::mouseReleased(int position, const QString &strPosition)
{
    DeviceHelper::addMsg(QString("Loosen the pan tilt %1").arg(strPosition));
    QMetaObject::invokeMethod(this, "ptzControl", Qt::QueuedConnection, Q_ARG(int, 255));
}

void frmIpcPtz::ptzControl(int position)
{
    //Calculate speed, convert to decimal
    double step = (double)ui->sliderPtzStep->value() / 10;

    //Send PTZ control command according to different pressed parts
    //1. The range of X, y and z is between 0-1.
    //2. x is a negative number, indicating left turn, and x is a positive number, indicating right turn.
    //3. y is a negative number, indicating downward rotation, and y is a positive number, indicating upward rotation.
    //4. z is a positive number, which means closer, and z is a negative number, which means farther.
    //5. Realize PTZ control through the combination of x and y.
    //6. Focus control is realized through the combination of z.

    //0-8 indicates bottom / lower left corner / left / upper left corner / top / upper right corner / right / lower right corner / middle in turn
    if (position == 0) {
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, 0.0, -step, 0.0);
    } else if (position == 1) {
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, -step, -step, 0.0);
    } else if (position == 2) {
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, -step, 0.0, 0.0);
    } else if (position == 3) {
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, -step, step, 0.0);
    } else if (position == 4) {
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, 0.0, step, 0.0);
    } else if (position == 5) {
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, step, step, 0.0);
    } else if (position == 6) {
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, step, 0.0, 0.0);
    } else if (position == 7) {
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, step, -step, 0.0);
    } else if (position == 8) {
        //Stop before reset
        DeviceOnvif::ptzControl(0, AppData::CurrentUrl, 0.0, 0.0, 0.0);
        //DeviceOnvif::ptzControl(1, AppData::CurrentUrl, 0.0, 0.0, 0.0);
    } else if (position == 9) {
        //Zoom+
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, 0.0, 0.0, step);
    } else if (position == 10) {
        //Zoom-
        DeviceOnvif::ptzControl(3, AppData::CurrentUrl, 0.0, 0.0, -step);
    } else if (position == 11) {
        //Zoom+
    } else if (position == 12) {
        //Zoom-
    } else if (position == 13) {
        //Aperture+
    } else if (position == 14) {
        //Aperture-
    } else {
        //stop it
        DeviceOnvif::ptzControl(0, AppData::CurrentUrl, 0.0, 0.0, 0.0);
    }
}

Added by ruddernz on Mon, 20 Dec 2021 13:18:05 +0200