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. [Question] Android Camera Example

[Question] Android Camera Example

Scheduled Pinned Locked Moved Solved Mobile and Embedded
11 Posts 7 Posters 3.7k Views
  • 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.
  • G Offline
    G Offline
    gargax
    wrote on 11 Nov 2019, 00:20 last edited by
    #1

    Hello!! Just a quick question regarding the camera example (https://doc.qt.io/archives/qt-5.11/qtmultimedia-multimediawidgets-camera-example.html).

    I successfully built and deployed the app to my android Huawei RIO L03 (I'm using Qt Creator 4.8.2). The app seems to work, for the most part. However, I'm not seeing any camera live preview on the default viewfinder.

    In fact, it only shows the captured frame (or video) when I press the Capture Photo / Record buttons. My question: Is this the way it is supposed to work?

    I'm only seeing a big black rectangle, no preview. Just like this image:

    alt text

    Thanks!

    J M 2 Replies Last reply 11 Nov 2019, 06:56
    0
    • G gargax
      11 Nov 2019, 00:20

      Hello!! Just a quick question regarding the camera example (https://doc.qt.io/archives/qt-5.11/qtmultimedia-multimediawidgets-camera-example.html).

      I successfully built and deployed the app to my android Huawei RIO L03 (I'm using Qt Creator 4.8.2). The app seems to work, for the most part. However, I'm not seeing any camera live preview on the default viewfinder.

      In fact, it only shows the captured frame (or video) when I press the Capture Photo / Record buttons. My question: Is this the way it is supposed to work?

      I'm only seeing a big black rectangle, no preview. Just like this image:

      alt text

      Thanks!

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 11 Nov 2019, 06:56 last edited by
      #2

      hi @gargax and welcome

      Sadly, that's not unexpected, the widget implementation of Camera does not work properly on android.

      I would suggest testing the QML version, that one should work out of the box!


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      G 1 Reply Last reply 11 Nov 2019, 07:48
      1
      • G gargax
        11 Nov 2019, 00:20

        Hello!! Just a quick question regarding the camera example (https://doc.qt.io/archives/qt-5.11/qtmultimedia-multimediawidgets-camera-example.html).

        I successfully built and deployed the app to my android Huawei RIO L03 (I'm using Qt Creator 4.8.2). The app seems to work, for the most part. However, I'm not seeing any camera live preview on the default viewfinder.

        In fact, it only shows the captured frame (or video) when I press the Capture Photo / Record buttons. My question: Is this the way it is supposed to work?

        I'm only seeing a big black rectangle, no preview. Just like this image:

        alt text

        Thanks!

        M Offline
        M Offline
        mvuori
        wrote on 11 Nov 2019, 07:17 last edited by
        #3

        This is because in Android the preview frames usually come as QVideoFrame::Format_NV21 and the example doesn´t handle it. You need to add it into the list returned by QListQVideoFrame::PixelFormat VideoSurface::supportedPixelFormats() and also add missing code to convert frames as they come to VideoSurface::present() into QImage - you need to google for code for that as Qt doesn't include such.

        ...This is yet another example of how Qt treats Android...

        1 Reply Last reply
        3
        • J J.Hilk
          11 Nov 2019, 06:56

          hi @gargax and welcome

          Sadly, that's not unexpected, the widget implementation of Camera does not work properly on android.

          I would suggest testing the QML version, that one should work out of the box!

          G Offline
          G Offline
          gargax
          wrote on 11 Nov 2019, 07:48 last edited by
          #4

          @J-Hilk said in [Question] Android Camera Example:

          hi @gargax and welcome

          Sadly, that's not unexpected, the widget implementation of Camera does not work properly on android.

          I would suggest testing the QML version, that one should work out of the box!

          Thanks, @J-Hilk . Sadly, this is part of a larger project that uses OpenCV and C++. I need an implementation of the camera preview in C++, as far as I am aware.

          Thanks, @mvuori ! Oh, boy, I haven’t even started integrating this with my project and I already have problems. Ok, so my understanding is that the android camera preview (in C++) is not supported out of the box by Qt Creator. But, apparently, it can, with some googling and extra code. Ok, do you have any link that can guide me through this?

          In my project (which uses OpenCV) I need to preview the camera feed. I was thinking in trying to achieve this using Qt Creator’s C++ android interface , I’m also considering using java and calling my camera methods from C++ via JNI.

          Do you have any suggestions for me? Any piece of advice/link or other resource will help me!

          P 1 Reply Last reply 11 Nov 2019, 14:50
          0
          • G gargax
            11 Nov 2019, 07:48

            @J-Hilk said in [Question] Android Camera Example:

            hi @gargax and welcome

            Sadly, that's not unexpected, the widget implementation of Camera does not work properly on android.

            I would suggest testing the QML version, that one should work out of the box!

            Thanks, @J-Hilk . Sadly, this is part of a larger project that uses OpenCV and C++. I need an implementation of the camera preview in C++, as far as I am aware.

            Thanks, @mvuori ! Oh, boy, I haven’t even started integrating this with my project and I already have problems. Ok, so my understanding is that the android camera preview (in C++) is not supported out of the box by Qt Creator. But, apparently, it can, with some googling and extra code. Ok, do you have any link that can guide me through this?

            In my project (which uses OpenCV) I need to preview the camera feed. I was thinking in trying to achieve this using Qt Creator’s C++ android interface , I’m also considering using java and calling my camera methods from C++ via JNI.

            Do you have any suggestions for me? Any piece of advice/link or other resource will help me!

            P Offline
            P Offline
            Pablo J. Rogina
            wrote on 11 Nov 2019, 14:50 last edited by
            #5

            @gargax said in [Question] Android Camera Example:

            not supported out of the box by Qt Creator
            using Qt Creator’s C++ android interface

            Just in case, Qt Creator is an IDE while Qt framework are the libraries supporting application development (being C++ or QML; for Linux, Windows, Mac, Android, etc.)
            So you can create an Android application using Qt but without even opening Qt Creator...

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            G J 2 Replies Last reply 11 Nov 2019, 23:50
            0
            • P Pablo J. Rogina
              11 Nov 2019, 14:50

              @gargax said in [Question] Android Camera Example:

              not supported out of the box by Qt Creator
              using Qt Creator’s C++ android interface

              Just in case, Qt Creator is an IDE while Qt framework are the libraries supporting application development (being C++ or QML; for Linux, Windows, Mac, Android, etc.)
              So you can create an Android application using Qt but without even opening Qt Creator...

              G Offline
              G Offline
              gargax
              wrote on 11 Nov 2019, 23:50 last edited by
              #6

              @Pablo-J-Rogina Ah Yeah, I meant to write Qt Framework, thanks.

              jsulmJ 1 Reply Last reply 12 Nov 2019, 05:32
              0
              • G gargax
                11 Nov 2019, 23:50

                @Pablo-J-Rogina Ah Yeah, I meant to write Qt Framework, thanks.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on 12 Nov 2019, 05:32 last edited by
                #7

                @gargax You can mix QML and C++, see: https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gargax
                  wrote on 14 Nov 2019, 02:41 last edited by gargax
                  #8

                  Well, after a couple of days of playing with this, I managed to modify the camera example to show the live preview (All in C++). I basically did what @mvuori suggested. I included support for QVideoFrame::Format_NV21 and used Open CV to convert the YUV frame to cv:Mat and QImage.

                  Basically, I wrote a "Capture Buffer" that acts as view finder, performs the conversions and produces a "Frame Available" signal. This signal contains the frame in CV Mat format. I run some image processing algorithms on it and convert it back to QImage and display it in a label.

                  This solution works fairly well. Working at 1280 x 960 I get around a processing frame rate of 15-20 fps. At 640 x 480 I get very close to 30 fps.

                  Here's a screen shot working at the latter resolution. Note that the preview is smaller in comparison to the widget:

                  alt text

                  So far so good. I had a couple of problems converting the YUV frame to BGR (Open CV's RGB format). The Red and Blue channels were interchanged and the frame was rotated 180°, but I solved it directly in the conversion stage.

                  P M 2 Replies Last reply 14 Nov 2019, 14:38
                  3
                  • G gargax
                    14 Nov 2019, 02:41

                    Well, after a couple of days of playing with this, I managed to modify the camera example to show the live preview (All in C++). I basically did what @mvuori suggested. I included support for QVideoFrame::Format_NV21 and used Open CV to convert the YUV frame to cv:Mat and QImage.

                    Basically, I wrote a "Capture Buffer" that acts as view finder, performs the conversions and produces a "Frame Available" signal. This signal contains the frame in CV Mat format. I run some image processing algorithms on it and convert it back to QImage and display it in a label.

                    This solution works fairly well. Working at 1280 x 960 I get around a processing frame rate of 15-20 fps. At 640 x 480 I get very close to 30 fps.

                    Here's a screen shot working at the latter resolution. Note that the preview is smaller in comparison to the widget:

                    alt text

                    So far so good. I had a couple of problems converting the YUV frame to BGR (Open CV's RGB format). The Red and Blue channels were interchanged and the frame was rotated 180°, but I solved it directly in the conversion stage.

                    P Offline
                    P Offline
                    Pablo J. Rogina
                    wrote on 14 Nov 2019, 14:38 last edited by
                    #9

                    @gargax said in [Question] Android Camera Example:

                    So far so good

                    Would you call the issue solved? If so, please don't forget to mark your post as such. Thanks.

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • G gargax
                      14 Nov 2019, 02:41

                      Well, after a couple of days of playing with this, I managed to modify the camera example to show the live preview (All in C++). I basically did what @mvuori suggested. I included support for QVideoFrame::Format_NV21 and used Open CV to convert the YUV frame to cv:Mat and QImage.

                      Basically, I wrote a "Capture Buffer" that acts as view finder, performs the conversions and produces a "Frame Available" signal. This signal contains the frame in CV Mat format. I run some image processing algorithms on it and convert it back to QImage and display it in a label.

                      This solution works fairly well. Working at 1280 x 960 I get around a processing frame rate of 15-20 fps. At 640 x 480 I get very close to 30 fps.

                      Here's a screen shot working at the latter resolution. Note that the preview is smaller in comparison to the widget:

                      alt text

                      So far so good. I had a couple of problems converting the YUV frame to BGR (Open CV's RGB format). The Red and Blue channels were interchanged and the frame was rotated 180°, but I solved it directly in the conversion stage.

                      M Offline
                      M Offline
                      MartinGU
                      wrote on 27 May 2022, 09:31 last edited by
                      #10

                      @gargax Code please! Have been looking for a solution for a long time!

                      1 Reply Last reply
                      0
                      • P Pablo J. Rogina
                        11 Nov 2019, 14:50

                        @gargax said in [Question] Android Camera Example:

                        not supported out of the box by Qt Creator
                        using Qt Creator’s C++ android interface

                        Just in case, Qt Creator is an IDE while Qt framework are the libraries supporting application development (being C++ or QML; for Linux, Windows, Mac, Android, etc.)
                        So you can create an Android application using Qt but without even opening Qt Creator...

                        J Online
                        J Online
                        JoeCFD
                        wrote on 27 May 2022, 13:30 last edited by JoeCFD
                        #11

                        @Pablo-J-Rogina True. But Qt Creator does generate helpful Makefile with proper Android settings. I basically copy the settings in the Makefile generated from Qt Creator for my cmake files in another Android project.

                        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