Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Qt Onvif Snapshot Picture

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to realize Qt Onvif snapping pictures". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to capture pictures with Qt Onvif".

I. Preface

Capture is a very important function, for example, in the alarm video linkage needs a real-time picture, many SDK does not provide capture function, but through the preview snapshot, the picture is no longer real-time, so how to get real-time picture? The current IPC basically supports the ONVIF protocol. In addition to providing the URL of RTSP, the ONVIF protocol also provides the snapped URL, which is obtained from the GetSnapshotUri of Media.

In the past, I didn't know that onvif could also do capture function, until recently, when I re-tested with Onvif Device Test Tool tool, I found that there was still an interface for capturing images, so I ran and analyzed the data to be sent and received, and then added it to my encapsulated onvif operation class. This capture scenario has an application scenario that captures images directly through onvif after giving an alarm, without the need to open real-time video streams, which basically does not take up any resources.

Another application scenario is as an intelligent image detection service to collect the online operation status of the surveillance camera, capture the surveillance image and upload it to the cloud service platform regularly, analyze the image manually or intelligently, and detect the situation of the surveillance image. for example, whether the position is incorrect, whether the black picture is black, whether the illuminance is enough, etc., send maintenance personnel to repair in time after finding the problem, and after the monitoring information is lost. Can also immediately inform maintenance personnel to check the scene, etc., which requires onvif capture, how to detect whether the equipment is running, there are many methods, in fact, you can use onvif protocol to read the date and time, normal words will return a time, of course, you can also regularly search all devices, and then compare with the previously stored devices, how many times in a row less which one is considered offline.

Process of capturing pictures:

Send GetSnapshotUri to get the screenshot path to the corresponding token.

Request this path through get. Note that it is recommended to bring user information here.

The returned data is the data of the picture, which can be loaded with QImage's loadFromData after receiving.

The main functions of onvif:

Search for equipment and get information about the equipment, such as manufacturer, model, etc.

Get multiple profile information profile for the device.

Get parameters such as video stream address rtsp and resolution of the corresponding configuration file.

Head control, moving up and down, left and right, focal length magnified and reduced, relative and absolute movement.

Get the preset information and trigger the preset.

Subscribe to events and receive all kinds of messages from the device, especially alarm events such as the alarm of the IO port.

Capture the picture to get the current picture of the device.

Get, create, and delete user information.

Get and device network configuration information such as IP address.

Gets and sets NTP time synchronization and sets device time.

Gets and sets video and picture parameters (brightness, color, saturation).

Restart the device.

The processing flow of onvif:

Bind a multicast IP (239.255.255.250) and a port (3702) to send a data search device in a fixed xml format.

The received data is parsed in xml format to get the Onvif address of the device.

Send the corresponding data to the Onvif address, receive the data and take out the corresponding node data.

Request Onvif address to obtain Media address and Ptz address. Media address is used to obtain detailed configuration files, and Ptz address is used for cloud control.

Ptz control is to send the corresponding data to the Ptz address.

Set up the need for user authentication to organize the user token information to be sent together, and each time it needs to be authenticated.

The data received is not standard xml data and can not be processed according to normal node parsing, so it can only be done with QXmlQuery.

The data returned by each manufacturer's equipment may not be completely consistent, but they are basically inconsistent, so it is necessary to fuzzy find the node value.

Specially uses the underlying protocol parsing, because soap is too bloated and the function name is too alternative, so it is specially lightweight.

Two must-have tools, Onvif Device Manager and Onvif Device Test Tool.

II. Functional features

Broadcast search equipment, support IPC and NVR, return in turn, you can choose different network card IP.

Get the Onvif address, Media address, Profile file, and Rtsp address in turn.

The video stream Rtsp address, such as the main stream substream address, can be obtained for the specified Profile.

Onvif user information can be set for each device, which can be used for authentication to obtain details.

Camera images can be previewed in real time.

Support head control, adjust head up and down, left and right, support absolute movement and relative movement, you can put and reduce the distance of the image.

Any Qt version of Qt4 and Qt5 is supported, and Qt4.7.0 to Qt5.14.2 is tested.

Support any compiler, test mingw, msvc, gcc, clang.

Support any operating system, test xp, win7, win10, android, linux, embedded linux, raspberry pie H3, etc.

Support any Onvif camera and NVR, test Haikang, Dahua, Yushi, Huawei, Hayes chip cores, etc., can be customized and developed.

Unicast search for specified IP addresses and onvif addresses is supported, for example, in the case of cross-network segments.

Support to specify filter criteria to filter search devices.

Support the search interval setting to ensure that all devices are searched back, which is very useful in a large number of equipment sites.

The picture parameters (brightness, color, saturation) can be set.

Support NTP timing and time synchronization settings.

Written by pure Qt, super compact and lightweight, a total of about 2000 lines of code, does not rely on any third-party libraries and components, cross-platform.

Encapsulated the general functions of data sending and receiving parsing, it is very convenient to expand other Onvif processing.

The sending and receiving data text box is provided on the tool to display the sending and receiving data, which is convenient for viewing and analysis.

Support all Onvif devices, neat code, friendly interface, directly introduced into pri can be used.

Third, effect picture

Core code # include "onvifsnap.h" # include "onvifhelper.h" # include "onvifrequest.h" # include "onvifquery.h" OnvifSnap::OnvifSnap (QObject * parent): QObject (parent) {device = 0;} void OnvifSnap::setDevice (OnvifDevice * device) {this- > device = device;} QString OnvifSnap::getSnapshotUri (const QString & profileToken) {if (device- > mediaUrl.isEmpty ()) {return QString () } QString file = OnvifHelper::getFile (": / send/getSnapshotUri.xml"); file = file.arg (device- > request- > getUserToken ()) .arg (profileToken); QByteArray dataSend = file.toUtf8 (); QNetworkReply * reply = device- > request- > post (device- > mediaUrl, dataSend); emit sendData (dataSend, device- > mediaUrl); QByteArray dataReceive; bool ok = device- > checkData (reply, dataReceive, "request Screenshot"); if (ok) {OnvifQuery query Query.setData (dataReceive); device- > snapUrl = query.getSnapUrl (); if (! device- > snapUrl.isEmpty ()) {/ / add user authentication, and authenticated emit receiveInfo (QString ("screenshot address->% 1") .arg (device- > snapUrl) is required to take the image. QString userInfo = QString ("http://%1:%2@").arg(device->userName).arg(device->userPwd); device- > snapUrl = device- > snapUrl.replace (" http://", userInfo);}} return device- > snapUrl;} QImage OnvifSnap::snapImage (const QString & profileToken) {/ / filter can also be considered here. For example, if snapUrl already exists, you do not need to obtain the address getSnapshotUri (profileToken). QImage image; if (! device- > snapUrl.isEmpty ()) {/ / request for image data reply 1080p probably requires 600ms / / synchronous blocking acquisition is used by default, and there is no card main interface QNetworkReply * reply = device- > request- > get (device- > snapUrl); QByteArray dataReceive; bool ok = device- > checkData (reply, dataReceive, "receive Screenshot", false) If (ok) {/ / the following line of code is very time-consuming 1080p pictures probably need 80ms if you need frequent screenshots suggested to put into the thread processing image.loadFromData (dataReceive);}} return image;} so far, I believe you have a deeper understanding of "how to achieve Qt Onvif screenshots", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report