Qt/C++ video surveillance Onvif tool/multicast search/display surveillance screen/picture parameter adjustment/OSD management/ancestral original

I. Introduction

It has always been my pursuit to be able to write components that are simple and easy to use without losing powerful functions. Simplicity is mainly reflected in the ease of use. I cannot make some cumbersome processes and some API interfaces that are extremely difficult to use, or some that are incomprehensible. Function names that are difficult to understand must be as simple as possible. The powerful function is mainly reflected in the completeness of the function. Conventional interfaces are definitely necessary. Then in terms of default values, try to set the values ​​​​to the most commonly used compliant values, and then provide interfaces to modify these values ​​to make them compatible with various Various demand scenarios. For example, if 90% of people want the value of some switches to be off by default, and you set the default value to be on, it will be very confusing. Most users need to actively modify it every time before it can be applied to their own scenarios. During these years of software development, I have followed these principles and logic until today, including various components that have been carefully polished for many years, such as video playback components, Onvif components, etc.

Code usage example:

  1. Step 1: Copy the onvif component source code to your project and put it in the same directory.
  2. Step 2: Introduce the component include ($$PWD/…/core_onvif/core_onvif.pri) into the project pro file.
  3. Step 3: The code file introduces the header file #include "onvifsearch.h" #include "onvifdevice.h", where onvifsearch is used to search for devices, and onvifdevice is used to obtain detailed information about the device such as rtsp video stream address.
  4. Step 4: Search for the device through multicast or unicast and obtain the corresponding onvif address. Each device has a unique onvif address.
//实例化搜索对象并关联信号槽
OnvifSearch *search = new OnvifSearch(this);
connect(search, SIGNAL(receiveDevice(OnvifDeviceInfo)), this, SLOT(receiveDevice(OnvifDeviceInfo)));
//参数1是网卡地址/参数2指定地址则表示单播
search->search("192.168.0.110", "");

void frmSimple::receiveDevice(const OnvifDeviceInfo &deviceInfo)
{
    
    
    QString msg = QString("收到设备: %1").arg(deviceInfo.onvifAddr);
    ui->textEdit->append(msg);

    QListWidgetItem *item = new QListWidgetItem;
    item->setText(deviceInfo.deviceIp);
    item->setData(Qt::UserRole, deviceInfo.onvifAddr);
    ui->listWidget->addItem(item);
}
  1. Step 5: Send an http request to the specified onvif address to obtain detailed information.
//实例化onvif对象实例
OnvifDevice *device = new OnvifDevice(this);
//设置用户信息用于请求的时候认证用
device->setUserInfo("admin", "123456");
//设置请求地址
device->setOnvifAddr("http://192.168.0.64/onvif/device_service");

//先获取服务文件
device->getServices();
//可能为空需要按照另一种方式获取
if (device->getMediaUrl().isEmpty()) {
    
    
    device->getCapabilities();
}

//获取配置文件
QList<OnvifProfileInfo> profiles = device->getProfiles();
foreach (OnvifProfileInfo profile, profiles) {
    
    
    ui->cboxProfiles->addItem(profile.token);
}

//对指定的配置文件获取视频地址
QString token = ui->cboxProfiles->currentText();
QString url = device->getStreamUri(token);
ui->txtStreamUri->setText(url);

2. Effect drawing

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here

3. Experience address

  1. Experience address: https://pan.baidu.com/s/1d7TH_GEYl5nOecuNlWJJ7g Extraction code: 01jf Name: bin_video_onvif
  2. Domestic site: https://gitee.com/feiyangqingyun
  3. International site: https://github.com/feiyangqingyun
  4. Personal homepage: https://blog.csdn.net/feiyangqingyun
  5. Video homepage: https://space.bilibili.com/687803542/

Qt/C++ video surveillance Onvif example (search/PTZ/preset position, etc.)

Qt/C++ monitoring Onvif component Android version/device search/PTZ preset position

4. Functional features

  1. Broadcast search device, supports IPC and NVR, returns in turn.
  2. You can select different network card IPs to search for devices in the corresponding network segment.
  3. Obtain the Onvif address, Media address, Profile file, and Rtsp address in sequence.
  4. The video stream Rtsp address can be obtained for the specified Profile, such as the main stream address and sub-stream address.
  5. Onvif user information can be set for each device for authentication and obtaining detailed information.
  6. Camera images can be previewed in real time.
  7. It supports PTZ control, and can adjust the PTZ up, down, left, and right. It supports three methods of absolute movement, relative movement, and continuous movement, and can zoom in and out of the image.
  8. Supports obtaining preset position collection, calling preset position, adding preset position, deleting preset position, etc.
  9. Supports picture parameter settings, including brightness, contrast, saturation, sharpness, etc.
  10. Supports any Qt version of Qt4 and Qt6 and subsequent Qt versions, personally tested Qt4.7 to Qt6.5.
  11. Supports any compiler, personally tested mingw, msvc, gcc, clang.
  12. Supports any operating system, personally tested xp, win7, win10, android, linux, embedded linux, Raspberry Pi Allwinner H3, etc.
  13. Supports any Onvif camera and NVR, personally tests Hikvision, Dahua, Uniview, Tiandi Weiye, Huawei, HiSilicon chip cores, etc., and can be customized for development.
  14. Supports unicast search for specified IP addresses and onvif addresses, which is very useful for example across network segments.
  15. Supports specifying filter conditions to filter the search for devices, such as only searching for devices on a certain network segment or for devices targeting a certain address.
  16. It supports search interval and search strategy settings to ensure that all devices are searched back, which is very useful in sites with a large number of devices (I have personally tested thousands of camera sites, and the number of devices returned is more accurate than the search tool provided by the camera manufacturer).
  17. You can restart the device, obtain network parameters, etc.
  18. Supports various event subscriptions (intrusion alarm, cross-border alarm, occlusion alarm, etc.), Onvif capture and other operations.
  19. Supports NTP time adjustment and time synchronization settings.
  20. Supports OSD related operations, you can add, delete, modify and check OSD information.
  21. A built-in thread executes the Onvif instruction queue in real time, queues up the corresponding instructions at the maximum speed, and sends out the execution result signal.
  22. The lowest-level TCP+UDP communication mechanism is adopted, the original lowest-level protocol analysis is written purely in QtWidget.
  23. It is super small and lightweight, with a total of about 3,000 lines of code, does not rely on any third-party libraries and components, and is cross-platform.
  24. It encapsulates general data sending and receiving parsing functions, and it is very convenient to expand other Onvif processing by yourself.
  25. The tool provides a text box for sending and receiving data to display the sent and received data for easy viewing and analysis.
  26. Supports all Onvif devices, the code is neat and the interface is friendly, you can directly import pri and use it.

Guess you like

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