Qt compiles security video surveillance system 37-onvif presets

Qt compiles security video surveillance system 37-onvif presets

I. Introduction

Preset positions are indispensable in the video surveillance system. The prerequisite for responding to the preset position function is to have a PTZ ball machine with preset positions. Some ordinary PTZ dome cameras do not have preset positions. This should be checked. Clearly, if the hardware does not support this function, you will not respond no matter how much you click. In the process of using this video surveillance system, many users will ask this question, why he can't respond when he clicks on the PTZ, the premise is hardware support.

The preset position is a way to link the monitored key area with the operating status of the dome camera. When the user operates the terminal's monitoring pan/tilt to monitor the target through the control device, the operator can set the current monitoring target to a preset position, such as a moving point pan/tilt, which can be rotated in 365 or 360 degrees to monitor; the operator can set a Places that need to be monitored, such as windows, counters, desks, entrances and exits, and car storage, are set as preset positions; the preset preset positions can be operated by the control device software to save the current position on the decoder of the terminal monitoring pan/tilt. When the user needs to quickly monitor a monitoring target; the location that needs to be monitored can be called by the call command of the control device. This is the meaning of the preset function.

The related processing of preset positions includes obtaining preset positions (a collection of preset position information, generally 1-255 preset position numbers with preset position names), calling preset positions (equivalent to actively triggering a preset position, Let the dome take the initiative to move to the position of the preset position), add a preset position (you can input the preset position number and name to add the preset position, or you can replace the position information of the existing preset position), delete Preset position (delete the position information of the existing preset position), set the starting position (the dome generally has a HOME position as the starting position, you can also manually switch the dome to a suitable position and set it to start Start position, so that after the movement changes, first return to the start position), call the start position (take the position information corresponding to the current screen as the start position) The preset number is generally 1-255, and some dome cameras may be able to achieve 1000. The preset name is also equivalent to an alias, which can be in Chinese for easy identification and memory.

Main functions of onvif

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

Onvif processing flow

  1. Bind multicast IP ( and port (3702), and send fixed xml format data to search equipment.
  2. The received data in xml format is parsed to obtain the Onvif address of the device.
  3. Send the corresponding data to the Onvif address, and take out the corresponding node data when the data is received.
  4. Request the Onvif address to obtain the Media address and Ptz address. The Media address is used to obtain detailed configuration files, and the Ptz address is used to control the PTZ.
  5. Ptz control is to send the corresponding data to the Ptz address.
  6. If user authentication is set, the user token information needs to be sent together, and authentication processing is required every time.
  7. The received data is not standard xml data, and it cannot be processed according to normal node analysis. It can only be done with QXmlQuery.
  8. The data returned by each manufacturer's equipment may not be completely consistent, and are basically inconsistent. Fuzzy search for node values is required.
  9. The underlying protocol is deliberately resolved, because soap is too bloated and the function name is too alternative, and it is deliberately lightweight.
  10. Two necessary tools, Onvif Device Manager and Onvif Device Test Tool.

2. Features

(1) Software module

  1. Video monitoring module, various docking small form sub-modules, including device list, graphic alarm information, window information, pan/tilt 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 log, device log, etc.
  5. System settings module, including system settings (basic settings, video parameters, database settings, map configuration, serial port configuration, etc.), recorder management, camera management, polling configuration, user management, etc.

(2) Basic functions

  1. Support 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, 64 screen switching.
  3. Support full-screen switching, multiple switching methods including mouse right-click menu, toolbar button, shortcut key (alt+enter full screen, esc exit full screen).
  4. Support video polling, including 1, 4, 9, 16 screen polling, polling group (polling plan), polling interval, stream type, etc. can be set.
  5. Support onvif protocol, including device search, PTZ control, device control (picture parameters, proofreading time, system restart, snap pictures, etc.).
  6. Support rights management, different users can correspond to different module rights, such as deleting logs, shutting down the system, etc.
  7. The database supports many kinds, including sqlite, mysql, sqlserver, postgresql, oracle, renda gold warehouse, etc.
  8. The local USB camera supports setting resolution, frame rate and other parameters.
  9. All docking modules automatically generate corresponding menus to control display and hide. Right-click on the title bar to pop up.
  10. Supports displaying all modules, hiding all modules, resetting the normal layout, and resetting the full-screen layout.
  11. Double-click the device to pop up a real-time preview video, support image maps, online maps, offline maps, etc.
  12. The camera node is dragged to the corresponding window to play the video, and local files are supported for direct playback at the same time.
  13. Deleting videos supports multiple methods such as right-mouse deletion, floating bar closing deletion, and dragging to delete outside the video surveillance panel.
  14. The device buttons on the picture map can be dragged freely and the location information is automatically saved. The latitude and longitude information can be obtained with a mouse click on the Baidu map to update the location of the device.
  15. Any channel in the video monitoring panel window supports drag-and-drop exchange, and it responds instantly.
  16. Encapsulates Baidu map, view switching, motion trajectory, device position, and mouse click to obtain latitude and longitude, etc.
  17. Operations such as double-clicking a node, dragging a node, and dragging a window to swap positions will automatically update and save the last playback address, and the software will be automatically applied next time the software is opened.
  18. The volume bar control in the lower right corner, automatically hides when the focus is lost, and the volume bar has a mute icon.
  19. Support video screenshots, you can specify a single or all channels to screenshot, there is a screenshot button in the small toolbar at the bottom.
  20. Supports automatic hiding of the mouse pointer and automatic full-screen mechanism over time.
  21. Support onvif PTZ control, can move PTZ camera up, down, left and right, including reset and focus adjustment.
  22. Support any onvif camera, including but not limited to Haikang, Dahua, Univision, Tiandiweiye, Huawei, etc.
  23. Video can be saved, timing storage or single file storage is optional, and storage interval is optional.
  24. You can set the video stream communication method tcp+udp, and you can set the video decoding to be speed priority, quality priority, equalization, etc.
  25. The software Chinese name, English name, LOGO icon, etc. can be set.
  26. The stored video files can be exported to a specified directory and batch upload to the server.

(3) Features

  1. The main interface adopts the docking window mode, various components are added in the form of small modules, and any module can be customized to join.
  2. The docking module can be dragged to any position to embed and hover, support full-screen maximized, and support 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 designated locations, which is more modern and sci-fi.
  4. Original onvif protocol mechanism, using underlying protocol analysis (udp broadcast search + http request execution command) is lighter and easier to understand, easy to learn and expand, and does not rely on any third-party components such as gsoap.
  5. Original data import and export mechanism, cross-platform does not rely on any components, export data instantly.
  6. Built-in multiple original components, super value in the universe, including data import and export components (export to xls, pdf, print), database components (database management thread, automatic data cleaning thread, universal paging, data request, etc.), map component , Video monitoring components, file multi-threaded transceiver components, onvif communication components, general 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 skin change, up to 17 sets of skin styles can be changed at will, all styles are unified, including menus, etc.
  9. Multiple buttons can be added to the floating bar of the video control, 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 the video, double-click the node to automatically add videos one by one, and it will automatically skip to the next one. Double-click the parent node to automatically add all the videos under the node. Optional main stream and sub stream.
  11. Recorder management, camera management, you can add, delete, modify, import and export print information, and immediately apply the new device information to generate a tree list without restarting.
  12. Optional multiple kernels to switch freely, ffmpeg, vlc, mpv, etc., can be set in pro. It is recommended to use ffmpeg, which is the most cross-platform. The compiled libraries on 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, which has ultra-low CPU resource consumption. It supports drawing in 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 operating modes, robot monitoring, drone monitoring, excavator monitoring, etc.
  16. Support xp, win7, win10, linux, mac, various domestic systems (UOS, Kylin, Galaxy Kylin, etc.), embedded linux and other systems.
  17. The annotations are complete, the project structure is clear, the super detailed and complete use and development manual is accurate to the function description of each code file, and the version is continuously iterated.

3. Experience address

  1. Experience address: pan.baidu.com/s/1d7TH_GEY... Extraction code: 01jf File name: bin_video_system.zip.
  2. Domestic site: gitee.com/feiyangqing...
  3. International site: github.com/feiyangqing...
  4. Personal homepage: blog.csdn.net/feiyangqing...
  5. Zhihu Homepage: www.zhihu.com/people/feiy...
  6. Online document: feiyangqingyun.gitee.io/qwidgetdemo...

4. renderings

5. the core code

# include "onvifptz.h" OnvifPtz:: OnvifPtz (QObject *parent): QObject (parent) { device = 0 ; } void OnvifPtz::setDevice (OnvifDevice *device) { this ->device = device; } bool OnvifPtz::ptzControl (quint8 type, const QString &profileToken, double x, double y, double z) { QString name = "PtzStop" ; QString flag = "The PTZ stops moving" ; if (type == 1 ) { name = "PtzAbsoluteMove" ; flag = "The PTZ moves absolutely" ; } else if (type == 2 ) { //xy=0 means to control the focus zoom at this time if (x == 0.0 && y == 0.0 ) { name = "PtzRelativeMoveZoom" ; flag = "Relative focal length of PTZ" ; } else { name = "PtzRelativeMove" ; flag = "The relative movement of the PTZ" ; } } else if (type == 3 ) { //xy=0 means to control the focus zoom at this time if (x == 0.0 && y == 0.0 ) { name = "PtzContinuousMoveZoom" ; flag = "PTZ continuous focal length" ; } else { name = "PtzContinuousMove" ; flag = "The PTZ moves continuously" ; } } QString file = OnvifHelper:: getFile ( QString ( ":/onvifsend/%1.xml" ). arg (name)); QString userToken = device-> getUserToken (); if (type == 1 ) { file = file. arg (userToken). arg (profileToken). arg (x). arg (y). arg (z); } else if (type == 2 || type == 3 ) { if (name. endsWith ( "Zoom" )) { file = file. arg (userToken). arg (profileToken). arg (z); } else { file = file. arg (userToken). arg (profileToken). arg (x). arg (y); } } else { file = file. arg (userToken). arg (profileToken); } QByteArray dataSend = file. toUtf8 (); QNetworkReply *reply = device->request-> post (device->ptzUrl, dataSend); QByteArray dataReceive; bool ok = device-> checkData (reply, dataReceive, flag); return ok; } bool OnvifPtz::ptzPreset (quint8 type, const QString &profileToken, const QString &presetToken, const QString &presetName) { QString name = "PtzGotoPreset" ; QString flag = "Call preset" ; if (type == 1 ) { name = "PtzSetPreset" ; flag = "Add preset position" ; } else if (type == 2 ) { name = "PtzRemovePreset" ; flag = "Delete preset" ; } else if (type == 3 ) { name = "PtzGotoHomePosition" ; flag = "Call start bit" ; } else if (type == 4 ) { name = "PtzSetHomePosition" ; flag = "Set the start bit" ; } QString file = OnvifHelper:: getFile ( QString ( ":/onvifsend/%1.xml" ). arg (name)); if (type == 1 ) { file = file. arg (device-> getUserToken ()). arg (profileToken). arg (presetToken). arg (presetName); } else if (type == 0 || type == 2 ) { file = file. arg (device-> getUserToken ()). arg (profileToken). arg (presetToken); } else if (type == 3 || type == 4 ) { file = file. arg (device-> getUserToken ()). arg (profileToken); } QByteArray dataSend = file. toUtf8 (); QNetworkReply *reply = device->request-> post (device->ptzUrl, dataSend); QByteArray dataReceive; bool ok = device-> checkData (reply, dataReceive, flag); return ok; } QList<OnvifPresetInfo> OnvifPtz::getPresets ( const QString &profileToken) { QList<OnvifPresetInfo> presets; if (device->mediaUrl. isEmpty ()) { return presets; } QString file = OnvifHelper:: getFile ( ":/onvifsend/PtzGetPresets.xml" ); file = file. arg (device-> getUserToken ()). arg (profileToken); QByteArray dataSend = file. toUtf8 (); QNetworkReply *reply = device->request-> post (device->mediaUrl, dataSend); QByteArray dataReceive; bool ok = device-> checkData (reply, dataReceive, "Get preset position" ); if (ok) { //Analyze preset position information OnvifQuery query; if (query. setData (dataReceive)) { presets = query. getPresets (); } } return presets; } Copy code