Any example to use libcamera for Qt5 desktop application?
-
@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?
-
You need to read the meson file to see what additional defines and paths/options they use.
Just in case, even if your Qt Creator does not support meson, nothing stops you from using from the command line to build the projet.
-
@SGaist May I ask what are these requirements in the meson file? It is strange to me that Qt Creator complains that DNGWriter is not declared despite the dng_writer.h file is already in the same directory as shown above. Besides, how should I modify the qcam.pro as the following meson file? Thank you.
# SPDX-License-Identifier: CC0-1.0 qt5 = import('qt5') qt5_dep = dependency('qt5', method : 'pkg-config', modules : ['Core', 'Gui', 'Widgets'], required : get_option('qcam'), version : '>=5.4') if not qt5_dep.found() qcam_enabled = false subdir_done() endif qcam_enabled = true qcam_sources = files([ '../cam/image.cpp', '../cam/options.cpp', '../cam/stream_options.cpp', 'format_converter.cpp', 'main.cpp', 'main_window.cpp', 'message_handler.cpp', 'viewfinder_qt.cpp', ]) qcam_moc_headers = files([ 'main_window.h', 'viewfinder_qt.h', ]) qcam_resources = files([ 'assets/feathericons/feathericons.qrc', ]) qcam_deps = [ libatomic, libcamera_public, qt5_dep, ] qt5_cpp_args = ['-DQT_NO_KEYWORDS'] tiff_dep = dependency('libtiff-4', required : false) if tiff_dep.found() qt5_cpp_args += ['-DHAVE_TIFF'] qcam_deps += [tiff_dep] qcam_sources += files([ 'dng_writer.cpp', ]) endif if cxx.has_header_symbol('QOpenGLWidget', 'QOpenGLWidget', dependencies : qt5_dep, args : '-fPIC') qcam_sources += files([ 'viewfinder_gl.cpp', ]) qcam_moc_headers += files([ 'viewfinder_gl.h', ]) qcam_resources += files([ 'assets/shader/shaders.qrc' ]) endif # gcc 9 introduced a deprecated-copy warning that is triggered by Qt until # Qt 5.13. clang 10 introduced the same warning, but detects more issues # that are not fixed in Qt yet. Disable the warning manually in both cases. if ((cc.get_id() == 'gcc' and cc.version().version_compare('>=9.0') and qt5_dep.version().version_compare('<5.13')) or (cc.get_id() == 'clang' and cc.version().version_compare('>=10.0'))) qt5_cpp_args += ['-Wno-deprecated-copy'] endif resources = qt5.preprocess(moc_headers: qcam_moc_headers, qresources : qcam_resources, dependencies: qt5_dep) qcam = executable('qcam', qcam_sources, resources, install : true, dependencies : qcam_deps, cpp_args : qt5_cpp_args)
-
Have a look for why you had to disable the dng_writer part ?