Qt writes video surveillance system 72- add, delete, modify and check OSD through onvif

I. Introduction

The original onvif protocol analysis mechanism in the previous monitoring system has been able to meet the needs of most users, such as searching for devices, obtaining and playing video stream addresses, PTZ control, preset position management, picture brightness and color saturation and other parameter settings, etc. Recently, there is another requirement, which is to add, delete, modify and check the OSD of the camera through the onvif international standard protocol. You can add OSD, delete OSD, modify OSD, query all OSD collection information, etc. through the protocol. In the early manufacturers of monitoring equipment , Many manufacturers do not support this protocol, so they have not implemented it. At present, several large manufacturers such as Haikang Dahua Yushi Tiandi Weiye have realized it. It is limited to the equipment that has passed the official standard inspection. If it is some Counterfeit devices, although the background looks very similar or exactly the same, may not be supported. At present, through field tests with various users, it is found that the devices made by some manufacturers are compatible with Hikvision Dahua’s proprietary protocol, and the background is also very similar. It looks like the real thing. In fact, many of them are counterfeit. Basically, they only implement basic functions such as audio and video streaming. When you encounter these devices, you will find that many functions with relatively little demand are actually not available.

Because qsoap and other frameworks are bloated and the api interface is extremely difficult to use, the onvif interaction is deliberately implemented from the underlying protocol analysis. In fact, there are two underlying layers. The search uses udp multicast, and the interaction uses http requests. It is still inseparable, nothing more than udp/tcp, in Qt, udp multicast first binds the specified network card udpSocket->bind(QHostAddress(localIP), 0, QUdpSocket::ShareAddress);, and then specifies the fixed onvif multicast address 239.255.255.250 and port 3702 to send xml Text information in the format, as long as it is a device that supports the onvif protocol in the local area network with the same address as the network card, it will return and inform itself of the device address and other information.

General functions of the onvif protocol:

  1. Search for devices to obtain device information such as manufacturer and model.
  2. Get multiple configuration file information profile of the device.
  3. Obtain the video stream address rtsp of the corresponding configuration file, and parameters such as resolution.
  4. PTZ control, move up and down, left and right, focus zoom in and out, relative and absolute movement.
  5. Obtain preset position information and trigger the preset position.
  6. Subscribe to events and receive various messages from devices, especially alarm events such as IO port alarms.
  7. Grab a picture to get the current picture of the device.
  8. Get, create, delete user information.
  9. Obtain and device network configuration information such as IP address, etc.
  10. Get and set NTP time synchronization and set device time.
  11. Get and set video parameters and picture parameters (brightness, color, saturation).
  12. Reboot the device.
  13. Add, delete, modify, query OSD information.

2. Rendering

insert image description here

3. Experience address

  1. Domestic site: https://gitee.com/feiyangqingyun
  2. International site: https://github.com/feiyangqingyun
  3. Personal works: https://blog.csdn.net/feiyangqingyun/article/details/97565652
  4. Experience address: https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g Extraction code: 01jf File name: bin_video_system.

4. Related codes

//标签信息结构体
struct OnvifOsdInfo {
    
    
    QString token;          //标签标识
    QString config;         //配置名称
    QString positionType;   //位置类型
    QPoint position;        //标签坐标

    int fontSize;           //字体大小
    QColor fontColor;       //字体颜色

    QString textType;       //文字类型
    QString text;           //文字内容
    QString dateFormat;     //日期格式
    QString timeFormat;     //时间格式

    //默认构造函数
    OnvifOsdInfo() {
    
    
        token = "1";
        positionType = "Custom";
        position = QPoint(0, 0);

        fontColor = "#ffffff";
        dateFormat = "yyyy-MM-dd";
        timeFormat = "HH:mm:ss";
    }

    //数据集合
    QVariant data() {
    
    
        QVariantList data;
        data << token;
        data << config;
        data << positionType;
        data << position;

        data << fontSize;
        data << fontColor;

        data << textType;
        data << text;
        data << dateFormat;
        data << timeFormat;
        return data;
    }

    //重载打印输出格式
    friend QDebug operator << (QDebug debug, const OnvifOsdInfo &osdInfo) {
    
    
        QStringList list;
        list << QString("标签标识: %1").arg(osdInfo.token);
        list << QString("配置名称: %1").arg(osdInfo.config);
        list << QString("位置类型: %1").arg(osdInfo.positionType);
        list << QString("标签坐标: [%1, %2]").arg(osdInfo.position.x()).arg(osdInfo.position.y());

        list << QString("字体大小: %1").arg(osdInfo.fontSize);
        list << QString("字体颜色: %1").arg(osdInfo.fontColor.name());

        list << QString("文字类型: %1").arg(osdInfo.textType);
        list << QString("文字内容: %1").arg(osdInfo.text);
        list << QString("日期格式: %1").arg(osdInfo.dateFormat);
        list << QString("时间格式: %1").arg(osdInfo.timeFormat);

        debugx << list.join("\n");
        return debug;
    }
};

OnvifOsdInfo OnvifVideo::getOsd(const QString &osdToken, const QSize &videoSize)
{
    
    
    OnvifOsdInfo osd;
    if (device->imageUrl.isEmpty() || osdToken.isEmpty()) {
    
    
        return osd;
    }

    //读取文件传入带用户认证的通用头部数据和其他参数构建要发送的数据
    QString file = OnvifHelper::getFile(":/onvifsend/OsdGetOSD.xml");
    file = file.arg(device->getHeadData()).arg(osdToken);

    //发送请求数据
    QByteArray dataSend = file.toUtf8();
    QNetworkReply *reply = device->request->post(device->mediaUrl, dataSend);

    //拿到请求结果并处理数据
    QByteArray dataReceive;
    bool ok = device->checkData(reply, dataReceive, "获取OSD信息");
    if (ok) {
    
    
        //解析OSD信息
        OnvifQuery query;
        if (query.setData(dataReceive)) {
    
    
            osd = query.getOsd(videoSize);
        }
    }

    return osd;
}

QList<OnvifOsdInfo> OnvifVideo::getOsds(const QString &videoSource, const QSize &videoSize)
{
    
    
    QList<OnvifOsdInfo> osds;
    if (device->imageUrl.isEmpty() || videoSource.isEmpty()) {
    
    
        return osds;
    }

    //读取文件传入带用户认证的通用头部数据和其他参数构建要发送的数据
    QString file = OnvifHelper::getFile(":/onvifsend/OsdGetOSDs.xml");
    file = file.arg(device->getHeadData()).arg(videoSource);

    //发送请求数据
    QByteArray dataSend = file.toUtf8();
    QNetworkReply *reply = device->request->post(device->mediaUrl, dataSend);

    //拿到请求结果并处理数据
    QByteArray dataReceive;
    bool ok = device->checkData(reply, dataReceive, "获取OSD集合");
    if (ok) {
    
    
        //解析OSD信息集合
        OnvifQuery query;
        if (query.setData(dataReceive)) {
    
    
            osds = query.getOsds(videoSize);
        }
    }

    return osds;
}

bool OnvifVideo::deleteOsd(const QString &osdToken)
{
    
    
    if (device->imageUrl.isEmpty() || osdToken.isEmpty()) {
    
    
        return false;
    }

    //读取文件传入带用户认证的通用头部数据和其他参数构建要发送的数据
    QString file = OnvifHelper::getFile(":/onvifsend/OsdDeleteOSD.xml");
    file = file.arg(device->getHeadData()).arg(osdToken);

    //发送请求数据
    QByteArray dataSend = file.toUtf8();
    QNetworkReply *reply = device->request->post(device->imageUrl, dataSend);

    //拿到请求结果并处理数据
    QByteArray dataReceive;
    return device->checkData(reply, dataReceive, "删除OSD");
}

5. Features

5.1 Software modules

  1. Video monitoring module, various docking small window sub-modules, including device list, graphic alarm information, window information, PTZ control, preset position, cruise setting, device control, floating 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 logs, device logs, etc.
  5. System settings module, including system settings (basic settings, video parameters, database settings, map configuration, serial port configuration, etc.), video recorder management, camera management, polling configuration, recording plan, user management, etc.

5.2 Basic functions

  1. Support various video streams (rtsp, rtmp, http, etc.), video files (mp4, rmvb, avi, etc.), local USB camera playback.
  2. Support multi-screen switching, including 1, 4, 6, 8, 9, 13, 16, 25, 36, 64 screen switching.
  3. Support full screen switching, a variety of switching methods including the right mouse button menu, toolbar buttons, shortcut keys (alt+enter full screen, esc to exit full screen).
  4. Support video polling, including 1, 4, 9, 16 screen polling, and can set polling group (polling plan), polling interval, code stream type, etc.
  5. Support onvif protocol, including device search, PTZ control, preset position, device control (picture parameters, proofreading time, system restart, snapshot pictures, etc.).
  6. Support permission management, different users can correspond to different module permissions, such as deleting logs, shutting down the system, etc.
  7. Various databases are supported, including sqlite, mysql, sqlserver, postgresql, oracle, Renda Jincang, 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 hide, which can be popped up by right clicking on the title bar.
  10. Support display all modules, hide all modules, reset normal layout, reset full screen layout.
  11. Double-click the device to pop up a real-time preview video, supporting image maps, online maps, offline maps, etc.
  12. Drag the camera node to the corresponding window to play the video, and support dragging local files to play directly.
  13. Deleting videos supports multiple methods such as right mouse button deletion, suspension bar closing deletion, dragging to the outside of the video monitoring panel to delete, etc.
  14. The device button on the picture map can be dragged freely, and the location information is automatically saved. On the Baidu map, you can click the mouse to obtain the latitude and longitude information, which is used to update the device location.
  15. Any channel in the video monitoring panel window supports dragging and switching, and responds instantly.
  16. It encapsulates Baidu map, view switching, movement track, equipment point, mouse press to obtain latitude and longitude, etc.
  17. Operations such as double-clicking a node, dragging a node, or dragging a window to exchange positions, etc., will automatically update and save the last playback address, which will be automatically applied next time the software is opened.
  18. The volume bar control in the lower right corner, loses focus and automatically hides, and the volume bar has a mute icon.
  19. Support video screenshot, you can specify a single or screenshot of all channels, and there is also a screenshot button in the small toolbar at the bottom.
  20. Support overtime automatically hide the mouse pointer, automatic full screen mechanism.
  21. Support onvif PTZ control, you can move the PTZ camera up, down, left, and right, including reset and focus adjustment.
  22. Support onvif preset position, you can add, delete, modify the preset position, you can call the start position.
  23. Support onvif image parameter settings, including brightness, contrast, saturation, sharpness, etc.
  24. Support other operations of onvif, including image capture, network settings, time adjustment, restart, event subscription, etc.
  25. Support any onvif camera, including but not limited to Hikvision, Dahua, Uniview, Tiandiweiye, Huawei, etc.
  26. Video can be saved, with optional timing storage or single file storage, and optional storage interval.
  27. You can set the video stream communication mode tcp+udp, and you can set the video decoding speed priority, quality priority, balance, etc.
  28. You can set the software Chinese name, English name, LOGO icon, etc.
  29. Stored video files can be exported to a specified directory and uploaded to the server in batches.
  30. Perfect recording plan settings, support for each channel 7 * 24 hours every half hour to set whether to store recordings.

5.3 Features

  1. The main interface adopts the docking form mode, and various components are added in the form of small modules, and any module can be customized.
  2. The docking module can be dragged anywhere to embed and float, and it supports maximizing full screen and multiple screens.
  3. Dual layout file storage mechanism, normal mode and full-screen mode correspond to different layout schemes, automatically switch and save, for example, full-screen mode can highlight several modules and display them transparently in the designated position, which is more sci-fi and modern.
  4. The original onvif protocol mechanism adopts the underlying protocol analysis (udp broadcast search + http request execution command), which is lighter, easier to understand and easier to learn and expand, and does not rely on any third-party components such as gsoap.
  5. Original data import, export, and print mechanisms, cross-platform without relying on any components, and instantly export data.
  6. Multiple built-in original components, super value in the universe, including data import and export components (export to xls, pdf, printing), database components (database management thread, automatic cleaning data thread, universal paging, data request, etc.), map components , video monitoring components, multi-threaded file sending and receiving components, onvif communication components, common browser kernel components, etc.
  7. Custom information box + error box + inquiry box + prompt box in the lower right corner (including multiple formats), etc.
  8. Exquisite skinning, up to 17 sets of skin styles can be changed at will, all styles are unified, including menus, etc.
  9. The video control floating bar can add multiple buttons by itself, and the small toolbar at the bottom of the monitoring interface can also add buttons by itself.
  10. Double-click the camera node to automatically play the video, double-click the node to automatically add videos in sequence, and automatically jump to the next one, double-click the parent node to automatically add all videos under the node. Optional main stream and sub stream.
  11. Video recorder management, camera management, can add, delete, modify, import, export and print information, and immediately apply the new device information to generate a tree list without restarting.
  12. A variety of kernels can be selected to switch freely, ffmpeg, vlc, mpv, etc., can be set in pro. It is recommended to use ffmpeg, which is the most cross-platform, and the compiled libraries on the linux and mac platforms are provided by default.
  13. Support hard decoding, you can set the hard decoding type (qsv, dxva2, d3d11va, etc.).
  14. By default, opengl is used to draw video, ultra-low CPU resource usage, supports yuyv and nv12 two formats of drawing, and the performance is explosive.
  15. Labels and graphic information support three drawing methods, drawing to the mask layer, drawing to the picture, and drawing from the source (corresponding information can be stored in a file).
  16. Highly customizable, users can easily derive their own functions on this basis, such as adding custom modules, adding operation modes, robot monitoring, drone monitoring, excavator monitoring, etc.
  17. Support xp, win7, win10, win11, linux, mac, various domestic systems (UOS, Winning Kirin, Galaxy Kirin, etc.), embedded linux and other systems.
  18. The comments are complete, the project structure is clear, the super detailed and complete user development manual is accurate to the function description of each code file, and the version is continuously iterated.

Guess you like

Origin blog.csdn.net/feiyangqingyun/article/details/130635033