Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Any example to use libcamera for Qt5 desktop application?
Forum Updated to NodeBB v4.3 + New Features

Any example to use libcamera for Qt5 desktop application?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
29 Posts 7 Posters 6.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rollyng
    wrote on last edited by rollyng
    #20

    @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!2022-07-10-123925_2560x1440_scrot.png

    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? 2022-07-10-202425_2560x1440_scrot.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #21

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        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.

        R Offline
        R Offline
        rollyng
        wrote on last edited by rollyng
        #22

        @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)
        
        
        1 Reply Last reply
        0
        • R Offline
          R Offline
          rollyng
          wrote on last edited by
          #23

          @SGaist Hi, I have finally successful to compile qcam as my first Qt GUI code. What I did is removing the dng_writer.h and dng_writer.cpp from the project. Plz have a look, thank you!
          2022-07-11-114052_2560x1440_scrot.png

          A 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #24

            Have a look for why you had to disable the dng_writer part ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            R 1 Reply Last reply
            0
            • SGaistS SGaist

              Have a look for why you had to disable the dng_writer part ?

              R Offline
              R Offline
              rollyng
              wrote on last edited by rollyng
              #25

              @SGaist said in Any example to use libcamera for Qt5 desktop application?:

              Have a look for why you had to disable the dng_writer part ?

              Qt Creator seems unable to pickup dng_writer.h although it is included in the project.

              This is due to a special definition in the dng_writer.h and I am including the file here for your quick look.

              /* SPDX-License-Identifier: LGPL-2.1-or-later */
              /*
               * Copyright (C) 2020, Raspberry Pi (Trading) Ltd.
               *
               * dng_writer.h - DNG writer
               */
              
              #pragma once
              
              #ifdef HAVE_TIFF /* what is this for? */
              #define HAVE_DNG
              
              #undef signals
              #undef slots
              #undef emit
              #undef foreach
              
              #include <libcamera/camera.h>
              #include <libcamera/controls.h>
              #include <libcamera/framebuffer.h>
              #include <libcamera/stream.h>
              
              class DNGWriter
              {
              public:
                  static int write(const char *filename, const libcamera::Camera *camera,
                                   const libcamera::StreamConfiguration &config,
                                   const libcamera::ControlList &metadata,
                                   const libcamera::FrameBuffer *buffer,
                                   const void *data);
              };
              
              #endif /* HAVE_TIFF, this is going to break the definition for DNGWriter above*/
              

              This is very strange to me whether to include the HAVE_TIFF option or not?
              Thanks,
              rolly

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #26

                It's a define that you can add to the DEFINES variable. The meson project defines it if memory serves well.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                R 1 Reply Last reply
                0
                • SGaistS SGaist

                  It's a define that you can add to the DEFINES variable. The meson project defines it if memory serves well.

                  R Offline
                  R Offline
                  rollyng
                  wrote on last edited by
                  #27

                  @SGaist Thank you and I have decided not to include the dng_writer function as it is not my concern. Best, rolly

                  1 Reply Last reply
                  0
                  • R rollyng

                    @SGaist Hi, I have finally successful to compile qcam as my first Qt GUI code. What I did is removing the dng_writer.h and dng_writer.cpp from the project. Plz have a look, thank you!
                    2022-07-11-114052_2560x1440_scrot.png

                    A Offline
                    A Offline
                    AlexKN
                    wrote on last edited by
                    #28

                    @rollyng Dear rollyng! Could you share a working qt project that you have successfully compiled and launched?

                    P 1 Reply Last reply
                    0
                    • A AlexKN

                      @rollyng Dear rollyng! Could you share a working qt project that you have successfully compiled and launched?

                      P Offline
                      P Offline
                      p1ng
                      wrote on last edited by
                      #29

                      @AlexKN here is the qt project. i did it myself.

                      https://github.com/henrihallik/myqam

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved