Integrating Raspberry Pi Camera with Qt application



  • I am making a hobby project of digital still camera based on Raspberry Pi using Qt.

    I have cross compiled Qt on Pi and able to successfully run a normal test Qt application on Pi.
    Also the raspistill and raspivid utilities are running successfully.

    The issue is with integrating the Rasp Pi camera. Before buying it I din't knew that it does not support v4l2.

    I want to show a live view of camera in the Qt application and capture the image when a Button is clicked.

    What are the options except v4l2, for getting the live feed from camera in Qt.



  • "OpenCV":http://opencv.org/about.html is popular for accessing webcam/camera with Qt.



  • there is a driver in uv4l http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14 which i get half-working.
    but, when starting an application employing a qml-camera "hangs" the ui - meaning that the ui is never visible.
    if i leave preview enabled in uv4l, the camera preview is visible and running.
    no matter if preview is visible or not, the ui never shows up.

    i also get the following output when running via "GST_DEBUG="*:3" ./<app>":
    @0:00:08.941350183 3460 0xe03a00 INFO GST_STATES gstelement.c:2460:gst_element_continue_state:<camera_source> completed state change to READY
    0:00:08.944484126 3460 0xe03a00 INFO GST_STATES gstelement.c:2365:_priv_gst_element_state_changed:<camera_source> notifying about state-changed NULL to READY (VOID_PENDING pending)
    0:00:08.951060008 3460 0xe03a00 INFO default camerabingeneral.c:136:gst_camerabin_try_add_element:<camera_source> no unlinked source pad in bin
    0:00:08.953317968 3460 0xe03a00 INFO GST_ELEMENT_PADS gstelement.c:975:gst_element_get_static_pad: found pad camera_source:src
    0:00:08.955501928 3460 0xe03a00 INFO GST_ELEMENT_FACTORY gstelementfactory.c:374:gst_element_factory_create: creating element "ffmpegcolorspace" named "src-colorspace"
    0:00:08.958525875 3460 0xe03a00 INFO GST_ELEMENT_PADS gstelement.c:728:gst_element_add_pad:GstBaseTransform@0x11a6f38 adding pad 'sink'
    0:00:08.961976813 3460 0xe03a00 INFO GST_ELEMENT_PADS gstelement.c:728:gst_element_add_pad:GstBaseTransform@0x11a6f38 adding pad 'src'
    0:00:08.965648747 3460 0xe03a00 INFO GST_ELEMENT_PADS gstutils.c:1698:gst_element_link_pads_full: trying to link element camera_source:(any) to element src-colorspace:(any)
    0:00:08.968530695 3460 0xe03a00 INFO GST_PADS gstutils.c:1032:gst_pad_check_link: trying to link camera_source:src and src-colorspace:sink
    0:00:08.973310609 3460 0xe03a00 INFO v4l2 gstv4l2object.c:1105:gst_v4l2_object_fill_format_list:<camera_source> got 7 format(s):
    0:00:08.976061559 3460 0xe03a00 INFO v4l2 gstv4l2object.c:1111:gst_v4l2_object_fill_format_list:<camera_source> YU12
    0:00:08.979186503 3460 0xe03a00 INFO v4l2 gstv4l2object.c:1111:gst_v4l2_object_fill_format_list:<camera_source> JPEG
    0:00:08.982253448 3460 0xe03a00 INFO v4l2 gstv4l2object.c:1111:gst_v4l2_object_fill_format_list:<camera_source> MJPG
    0:00:08.984377409 3460 0xe03a00 INFO v4l2 gstv4l2object.c:1111:gst_v4l2_object_fill_format_list:<camera_source> YV12 (emulated)
    0:00:08.986682369 3460 0xe03a00 INFO v4l2 gstv4l2object.c:1111:gst_v4l2_object_fill_format_list:<camera_source> BGR3 (emulated)
    0:00:08.988741331 3460 0xe03a00 INFO v4l2 gstv4l2object.c:1111:gst_v4l2_object_fill_format_list:<camera_source> RGB3 (emulated)
    0:00:08.990976291 3460 0xe03a00 INFO v4l2 gstv4l2object.c:1111:gst_v4l2_object_fill_format_list:<camera_source> H264
    @
    after that the program stops, no ui shown, camera light is on.
    looks as if driver and qt can't find a common format ...

    any ideas?



  • Hello,

    Have you found a solution ?
    I'm trying the same, but I can't integrate my Pi Camera in a simple Qt Project...



  • You can use raspican, a library written in C to manage raspberry pi webcam. In the past I tryed it but I had a problem with the red light. Now I use the executable directly.



  • This is old, but in case someone else encounters this error, the fix should be the following:

    sudo rpi-update (once)
    modprobe bcm2835-v4l2 gst_v4l2src_is_broken=1 (every reboot).

    First part of modprobe is to enable the /dev/video0 stream and v4l2, the latter is to prevent camera from hanging application.

    Solution taken from here



  • Try using https://github.com/cedricve/raspicam raspicam to capture camera image. Not sure how to display image on QOpenGLWidget. it works good to capture image from camera but OpenGL scene render not works. Anyone able to render scene using QOpenGLWidget



  • @mrdebug How did you mange to render the camera frame to QT widget? Would you please help me to render scene and display frame on QOpenGLWidget?



  • Hi. Now I'm using the raspicam library to get images and if you want you can use QLabel to display it on a raspberry pi display. OpenGL in not mandatory.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.