[QT Basic Example 2] gcc9.3.0-QT5.12.12 USB Camera Example

One Preface

A simple USB camera preview program was implemented based on the QT5.12.12 framework, which was originally intended for multi camera capture on the X3pi (as also reflected in the program, up to 4 cameras can be turned on). Later, it was discovered that the X3pi only has one USB controller, and only supports one USB camera at most. Therefore, this example can still be used as a basic X3pi QT application example.

Two Environment settings

Need to compile the first QT program to run smoothly

The GitHub address is: https://github.com/307321587/MultiCameraViewer_arm

Need to decompress the compressed file ffmpeg arm. tar. xz to the current directory, where the ffmpeg arm folder and MultiCameraViewer folder are at the same level

Three Code parsing

The code file path is mainly as follows:

MultiCameraViewer_arm
         --- ffmpeg-arm 
     --- MultiCameraViewer 
        --- drawwidget.cpp 
                --- ffmpegdecode.cpp ffmepg
                --- main.cpp 
                --- mainwindow.cpp 
                --- ui_camerawidget.cpp 

The logic of the entire code is relatively simple, which is to open the USB camera to capture images through ffmpeg and display them in Interactive View. Interactive View is a custom class used for displaying images, zooming, saving, etc.

Four Compile and Run

Unzip MultiCameraViewer.arm.tar.xz and use QT creator to open MultiCameraViewer-MultiCameraViewr.pro on the Ubuntu 20.04 host. After opening the project, it is shown as follows:

Be sure to select the configured cross compilation toolchain as the compilation tool for the code after opening, otherwise compilation will fail

3.1 Preparation before operation This project uses QT’s built-in remote deployment method to directly send the ffmpeg library to the board/opt directory. To specify the folder to be sent, add the following description to the pro file:

After adding, the sent library link will automatically appear in the project’s Run, where the project’s execution files and libraries will be sent to the/opt directory:

After completing the library sending, it is necessary to add the path to search for the library in the variables on the board side, as shown in the following figure:

LD_LIBRARY_PATH  /opt/MultiCameraViewer/lib/lib

4.2 Operation After completing the settings, click the run button, and the camera example will be displayed on the host computer. Click Add Window to add a USB window:

Select the recognized USB camera, click on Open and Start to preview the image. In addition, right-click on the image to save the image rotation image, etc. As it is projected to the host computer through x11 forwarding for display, the image may feel sluggish. In actual use, it is best to run it on HDMI

4.3 Direct operation of board end HDMI As mentioned earlier, the program has been sent to the board through qt creator. To run it directly on the board HDMI, enter the following statement in the board console

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/MultiCameraViewer/lib/lib
/opt/MultiCameraViewer/bin/MultiCameraViewer

Input as shown in the following figure:

After startup, as shown in the following figure:

Preview: