Any example to use libcamera for Qt5 desktop application?
-
Hi,
I am new to Qt and I was writing simple C++ code to capture raw image data via the libcamera/libcamera-apps on a Raspberry Pi 4B with 8GB ram and the 64bit Bullseye OS.
I have installed OpenCV 4.5.2 as well and I would like to write a Qt GUI desktop application where I can view the camera (HQCam IMX477) and save raw data to a SSD as fast as possible.
Are there any example to view the Raspberry Pi camera in Bullseye with Qt GUI desktop application? I am aware of the old example but it does not work libcamera in Bullseye.
link text -
Hi and welcome to devnet,
Can you explain what you mean by "does not work" ?
-
The error is pretty explicit: you seem to lack memory.
What else is running on your Pi ?
What kind of camera are you using ?
What are the specs of your Pi ?
What are the specs of your camera ? -
@SGaist said in Any example to use libcamera for Qt5 desktop application?:
The error is pretty explicit: you seem to lack memory.
What else is running on your Pi ? Nothing special except I have Qt creator running
What kind of camera are you using ? Official Raspberry Pi HQCam
What are the specs of your Pi ? 8GB RAM and 32GB SD running Linux RaspberryPi 5.15.45-v8+ #1562 SMP PREEMPT Thu Jun 9 13:59:40 BST 2022 aarch64 GNU/Linux
What are the specs of your camera ? 640*480 running okay with GStreamer as attached.
-
What if you start the application without Qt Creator running at the same time ?
-
@SGaist
Hi, these are the error message produced in Qt Creator.
09:37:40: Starting /home/pi/code/libcamera-qt5/build-camera-Desktop-Release/camera ...
Unable to query the parameter info: QCameraImageProcessingControl::WhiteBalancePreset : "Inappropriate ioctl for device"
Unable to query the parameter info: QCameraImageProcessingControl::ColorTemperature : "Inappropriate ioctl for device"
Unable to query the parameter info: QCameraImageProcessingControl::ContrastAdjustment : "Inappropriate ioctl for device"
Unable to query the parameter info: QCameraImageProcessingControl::SaturationAdjustment : "Inappropriate ioctl for device"
Unable to query the parameter info: QCameraImageProcessingControl::BrightnessAdjustment : "Inappropriate ioctl for device"
Unable to query the parameter info: QCameraImageProcessingControl::SharpeningAdjustment : "Inappropriate ioctl for device"
CameraBin error: "Failed to allocate required memory."
09:38:34: /home/pi/code/libcamera-qt5/build-camera-Desktop-Release/camera exited with code 0
-
Which version of Qt are you using on your Pi ?
-
Depending on your application goal, you can use a custom GStreamer pipeline.
-
@SGaist said in Any example to use libcamera for Qt5 desktop application?:
Depending on your application goal, you can use a custom GStreamer pipeline.
Hi SGaist, I would like to show the real-time image in a Qt application for preview. May I know how can I modify the camera example to do that? How can I add the GStreamer pipeline to the camera example? Thank you.
-
Hi SGaist,
I have also take a look at the libcamera examples. There is the "qcam" code which made use of Qt but it is not a GUI application from my understanding.
link text
Do you suggest that I can implement the "qcam" example into Qt Creator for my application? How can I start with such?
Thanks,
rolly -
You can try to use qt gstreamer to add your pipeline. Gstreamer with lower versions has pretty large memory leaks when camera is switched. If you do not switch camera often, it is ok. But it is better to install 1.20 or above in your machine. Build Qt Gstreamer with Qt 5.15.2 and higher version of gstreamer. Qt gstreamer has some examples for how to make pipelines. If you have any issues in build, post them here.
https://gstreamer.freedesktop.org/data/doc/gstreamer/head/qt-gstreamer/html/annotated.html
-
If memory serves well, Qt Creator has support for meson however yours might be too old.
Otherwise you can generate a minimal .pro file using
qmake -project
. -
@SGaist said in Any example to use libcamera for Qt5 desktop application?:
If memory serves well, Qt Creator has support for meson however yours might be too old.
Otherwise you can generate a minimal .pro file using
qmake -project
.Hi SGaist, thank you and I did that. Now I can open the libcamera project in Qt Creator. But some of the Qt include definitions are missing? Please take a look.
#include <QComboBox> for example?By the way, How can I build and run qcam in Qt Creator? Simple compilation failed at once.
02:00:30: Running steps for project libcamera...
02:00:30: Starting: "/usr/lib/qt5/bin/qmake" /home/pi/code/libcamera/libcamera.pro -spec linux-g++ CONFIG+=qtquickcompiler
Info: creating stash file /home/pi/code/build-libcamera-Desktop-Release/.qmake.stash
02:00:31: The process "/usr/lib/qt5/bin/qmake" exited normally.
02:00:31: Starting: "/usr/bin/make" -f /home/pi/code/build-libcamera-Desktop-Release/Makefile qmake_all
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1750: warning: overriding recipe for target 'main.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1674: warning: ignoring old recipe for target 'main.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1793: warning: overriding recipe for target 'delayed_controls.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1476: warning: ignoring old recipe for target 'delayed_controls.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1805: warning: overriding recipe for target 'fence.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1488: warning: ignoring old recipe for target 'fence.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1817: warning: overriding recipe for target 'geometry.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1497: warning: ignoring old recipe for target 'geometry.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1912: warning: overriding recipe for target 'main.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1750: warning: ignoring old recipe for target 'main.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2078: warning: overriding recipe for target 'controls.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1790: warning: ignoring old recipe for target 'controls.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2087: warning: overriding recipe for target 'formats.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1808: warning: ignoring old recipe for target 'formats.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2106: warning: overriding recipe for target 'camera3_hal.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1563: warning: ignoring old recipe for target 'camera3_hal.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2133: warning: overriding recipe for target 'camera_metadata.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1597: warning: ignoring old recipe for target 'camera_metadata.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2270: warning: overriding recipe for target 'ipa_context.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2171: warning: ignoring old recipe for target 'ipa_context.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2301: warning: overriding recipe for target 'file.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1491: warning: ignoring old recipe for target 'file.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2304: warning: overriding recipe for target 'flags.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1494: warning: ignoring old recipe for target 'flags.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2310: warning: overriding recipe for target 'message.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1506: warning: ignoring old recipe for target 'message.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2316: warning: overriding recipe for target 'object.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1515: warning: ignoring old recipe for target 'object.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2325: warning: overriding recipe for target 'signal.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1530: warning: ignoring old recipe for target 'signal.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2331: warning: overriding recipe for target 'timer.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1542: warning: ignoring old recipe for target 'timer.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2337: warning: overriding recipe for target 'utils.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:1548: warning: ignoring old recipe for target 'utils.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2382: warning: overriding recipe for target 'algorithm.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2182: warning: ignoring old recipe for target 'algorithm.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2395: warning: overriding recipe for target 'histogram.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2188: warning: ignoring old recipe for target 'histogram.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2402: warning: overriding recipe for target 'agc.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2363: warning: ignoring old recipe for target 'agc.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2406: warning: overriding recipe for target 'awb.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2367: warning: ignoring old recipe for target 'awb.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2410: warning: overriding recipe for target 'blc.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2371: warning: ignoring old recipe for target 'blc.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2424: warning: overriding recipe for target 'ipu3.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2179: warning: ignoring old recipe for target 'ipu3.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2431: warning: overriding recipe for target 'raspberrypi.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2267: warning: ignoring old recipe for target 'raspberrypi.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2437: warning: overriding recipe for target 'rkisp1.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2277: warning: ignoring old recipe for target 'rkisp1.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2452: warning: overriding recipe for target 'vimc.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2280: warning: ignoring old recipe for target 'vimc.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2466: warning: overriding recipe for target 'agc.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2402: warning: ignoring old recipe for target 'agc.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2488: warning: overriding recipe for target 'awb.o'
/home/pi/code/build-libcamera-Desktop-Release/Makefile:2406: warning: ignoring old recipe for target 'awb.o'
make: Nothing to be done for 'qmake_all'.
02:00:31: The process "/usr/bin/make" exited normally.
02:00:31: Starting: "/usr/bin/make" -j4
Makefile:1750: warning: overriding recipe for target 'main.o'
Makefile:1674: warning: ignoring old recipe for target 'main.o'
Makefile:1793: warning: overriding recipe for target 'delayed_controls.o'
Makefile:1476: warning: ignoring old recipe for target 'delayed_controls.o'
Makefile:1805: warning: overriding recipe for target 'fence.o'
Makefile:1488: warning: ignoring old recipe for target 'fence.o'
Makefile:1817: warning: overriding recipe for target 'geometry.o'
Makefile:1497: warning: ignoring old recipe for target 'geometry.o'
Makefile:1912: warning: overriding recipe for target 'main.o'
Makefile:1750: warning: ignoring old recipe for target 'main.o'
Makefile:2078: warning: overriding recipe for target 'controls.o'
Makefile:1790: warning: ignoring old recipe for target 'controls.o'
Makefile:2087: warning: overriding recipe for target 'formats.o'
Makefile:1808: warning: ignoring old recipe for target 'formats.o'
Makefile:2106: warning: overriding recipe for target 'camera3_hal.o'
Makefile:1563: warning: ignoring old recipe for target 'camera3_hal.o'
Makefile:2133: warning: overriding recipe for target 'camera_metadata.o'
Makefile:1597: warning: ignoring old recipe for target 'camera_metadata.o'
Makefile:2270: warning: overriding recipe for target 'ipa_context.o'
Makefile:2171: warning: ignoring old recipe for target 'ipa_context.o'
Makefile:2301: warning: overriding recipe for target 'file.o'
Makefile:1491: warning: ignoring old recipe for target 'file.o'
Makefile:2304: warning: overriding recipe for target 'flags.o'
Makefile:1494: warning: ignoring old recipe for target 'flags.o'
Makefile:2310: warning: overriding recipe for target 'message.o'
Makefile:1506: warning: ignoring old recipe for target 'message.o'
Makefile:2316: warning: overriding recipe for target 'object.o'
Makefile:1515: warning: ignoring old recipe for target 'object.o'
Makefile:2325: warning: overriding recipe for target 'signal.o'
Makefile:1530: warning: ignoring old recipe for target 'signal.o'
Makefile:2331: warning: overriding recipe for target 'timer.o'
Makefile:1542: warning: ignoring old recipe for target 'timer.o'
Makefile:2337: warning: overriding recipe for target 'utils.o'
Makefile:1548: warning: ignoring old recipe for target 'utils.o'
Makefile:2382: warning: overriding recipe for target 'algorithm.o'
Makefile:2182: warning: ignoring old recipe for target 'algorithm.o'
Makefile:2395: warning: overriding recipe for target 'histogram.o'
Makefile:2188: warning: ignoring old recipe for target 'histogram.o'
Makefile:2402: warning: overriding recipe for target 'agc.o'
Makefile:2363: warning: ignoring old recipe for target 'agc.o'
Makefile:2406: warning: overriding recipe for target 'awb.o'
Makefile:2367: warning: ignoring old recipe for target 'awb.o'
Makefile:2410: warning: overriding recipe for target 'blc.o'
Makefile:2371: warning: ignoring old recipe for target 'blc.o'
Makefile:2424: warning: overriding recipe for target 'ipu3.o'
Makefile:2179: warning: ignoring old recipe for target 'ipu3.o'
Makefile:2431: warning: overriding recipe for target 'raspberrypi.o'
Makefile:2267: warning: ignoring old recipe for target 'raspberrypi.o'
Makefile:2437: warning: overriding recipe for target 'rkisp1.o'
Makefile:2277: warning: ignoring old recipe for target 'rkisp1.o'
Makefile:2452: warning: overriding recipe for target 'vimc.o'
Makefile:2280: warning: ignoring old recipe for target 'vimc.o'
Makefile:2466: warning: overriding recipe for target 'agc.o'
Makefile:2402: warning: ignoring old recipe for target 'agc.o'
Makefile:2488: warning: overriding recipe for target 'awb.o'
Makefile:2406: warning: ignoring old recipe for target 'awb.o'
g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../libcamera -I. -I../libcamera -I/usr/include/aarch64-linux-gnu/qt5 -I/usr/include/aarch64-linux-gnu/qt5/QtGui -I/usr/include/aarch64-linux-gnu/qt5/QtCore -I. -I/usr/lib/aarch64-linux-gnu/qt5/mkspecs/linux-g++ -o bayer-format.o ../libcamera/test/bayer-format.cpp
g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../libcamera -I. -I../libcamera -I/usr/include/aarch64-linux-gnu/qt5 -I/usr/include/aarch64-linux-gnu/qt5/QtGui -I/usr/include/aarch64-linux-gnu/qt5/QtCore -I. -I/usr/lib/aarch64-linux-gnu/qt5/mkspecs/linux-g++ -o byte-stream-buffer.o ../libcamera/test/byte-stream-buffer.cpp
g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../libcamera -I. -I../libcamera -I/usr/include/aarch64-linux-gnu/qt5 -I/usr/include/aarch64-linux-gnu/qt5/QtGui -I/usr/include/aarch64-linux-gnu/qt5/QtCore -I. -I/usr/lib/aarch64-linux-gnu/qt5/mkspecs/linux-g++ -o camera-sensor.o ../libcamera/test/camera-sensor.cpp
g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I../libcamera -I. -I../libcamera -I/usr/include/aarch64-linux-gnu/qt5 -I/usr/include/aarch64-linux-gnu/qt5/QtGui -I/usr/include/aarch64-linux-gnu/qt5/QtCore -I. -I/usr/lib/aarch64-linux-gnu/qt5/mkspecs/linux-g++ -o delayed_controls.o ../libcamera/src/libcamera/delayed_controls.cpp
../libcamera/src/libcamera/delayed_controls.cpp:8:10: fatal error: libcamera/internal/delayed_controls.h: No such file or directory
8 | #include "libcamera/internal/delayed_controls.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:1793: delayed_controls.o] Error 1
make: *** Waiting for unfinished jobs....
../libcamera/test/bayer-format.cpp:10:10: fatal error: libcamera/transform.h: No such file or directory
10 | #include <libcamera/transform.h>
| ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:1467: bayer-format.o] Error 1
../libcamera/test/camera-sensor.cpp:13:10: fatal error: libcamera/base/utils.h: No such file or directory
13 | #include <libcamera/base/utils.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:1473: camera-sensor.o] Error 1
../libcamera/test/byte-stream-buffer.cpp:11:10: fatal error: libcamera/internal/byte_stream_buffer.h: No such file or directory
11 | #include "libcamera/internal/byte_stream_buffer.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:1470: byte-stream-buffer.o] Error 1
02:00:32: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project libcamera (kit: Desktop)
When executing step "Make"
02:00:32: Elapsed time: 00:02. -
The -project options does not do deep dependencies inspection. You need to add the modules your project uses. In your case, the widgets module.
As for the rest, check the meson project and pick there the paths you need for the includes, librairies, etc.
-
@SGaist said in Any example to use libcamera for Qt5 desktop application?:
widgets module
Hi SGaist, Thank you and I add the widgets and include path to the libcamera.pro file. I can see the missing header files are now found. But I have the private header error, and I have no idea how to resolve these. Please take a look. Thank you!
I believe it only necessary to build the "qcam" example in Qt Creator for my purpose, so I copy "qcam" and did some modification to the qcam.pro file. But it seems unable to resolve the declaration in its own folder? as it failed to find DNGWriter which is declared in the dng_writer.h?