Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

[Question] Android Camera Example



  • 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!


  • Moderators

    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!



  • 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...



  • @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!



  • @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...



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


  • Qt Champions 2018



  • 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.



  • @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.


Log in to reply