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. Custom Camera on Android
Qt 6.11 is out! See what's new in the release blog

Custom Camera on Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 3 Posters 125 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote last edited by Andy314
    #1

    Hello,
    I use Qt 6.7.3 for Android on a Zebra-phone. The integrated camera app is not very usefull (e.g. always vertical preview of taken photos). Therefore I need a special camera modul with some feature on the video-preview:
    3x3 Grid and cutting of some pixel-lines at to top and buttom of the video-preview.

    On the right side of the dialog is a Button frame for control, on the left side I will sie the video.

    I tried 3 methods, but every had problems.

    1. Manipulate Vidoestream:

       VideoSurface = new TMyVideoSurface(this); // derived from QAbstractVideoSurface
        connect(VideoSurface, &TMyVideoSurface::frameReceived,
        this, &Camera_Frame::updateVideoPicture);
    

    This worked on Windows very good, but on Android its to slow - the video is delayed.
    The slow part should be, datatransfer from "Camera-RAM" to nommal RAM.

    2. Widget over the QVideoWidget

    m_overlay= new TMyCameraOverlay(m_videoWidget);
    

    I see no overlay. I heared that the QVideoWidget "overdraws" all.

    3. Use QGraphicsScene:

    //  Main part of the code
    m_graphicsScene = new QGraphicsScene(this);
       m_graphicsView = new QGraphicsView(m_graphicsScene, this);
       m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
       m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    
       m_videoItem = new QGraphicsVideoItem();
       m_graphicsScene->addItem(m_videoItem);
       // 3. Create  Custom-Overlay and put it in the Szene
       m_overlay = new TCameraOverlay();
       // Proxy makes normal Widget visible
       QGraphicsProxyWidget *proxy = m_graphicsScene->addWidget(m_overlay);
       proxy->setZValue(1); // Overlay in den forground !
       
       // Pack View in the Layout
       ui->ViewLayout->addWidget(m_graphicsView, 0, 0);
    
       // 4. Connect Camera (Set VideoItem as VideoOutput)
       m_captureSession = new QMediaCaptureSession(this);
       m_imageCapture = new QImageCapture(this);
       connect(m_imageCapture, &QImageCapture::imageCaptured,
               this, &Camera_Frame::processCapturedImage);
    
       m_captureSession->setCamera(m_camera);
       m_captureSession->setVideoOutput(m_videoItem); // Important: videoItem instead of videoWidget!
       m_captureSession->setImageCapture(m_imageCapture);
    

    But here I get a very strange effect. The whole window especialy the control-buttons do react on touch evens no more.

    Who has experiences with a camera modul on Android ?

    Ronel_qtmasterR 1 Reply Last reply
    0
    • M Offline
      M Offline
      mvuori
      wrote last edited by
      #2

      It seems that QCamera in Qt 6 is pretty much lacking, as you can't even adjust preview fps. It could slow because

      1. the camera might give you 30 fps, which the app cant handle. You'd need some own code to throttle it
      2. similarly, the camera may use a way too large resolution #slow. That you can set in somewhere - first get a list of supported resolutions and select from there

      And when it comes to drawing a grid etc., you can always show the output in a regular widget and draw anything you wish on top of every frame.

      1 Reply Last reply
      0
      • Andy314A Andy314

        Hello,
        I use Qt 6.7.3 for Android on a Zebra-phone. The integrated camera app is not very usefull (e.g. always vertical preview of taken photos). Therefore I need a special camera modul with some feature on the video-preview:
        3x3 Grid and cutting of some pixel-lines at to top and buttom of the video-preview.

        On the right side of the dialog is a Button frame for control, on the left side I will sie the video.

        I tried 3 methods, but every had problems.

        1. Manipulate Vidoestream:

           VideoSurface = new TMyVideoSurface(this); // derived from QAbstractVideoSurface
            connect(VideoSurface, &TMyVideoSurface::frameReceived,
            this, &Camera_Frame::updateVideoPicture);
        

        This worked on Windows very good, but on Android its to slow - the video is delayed.
        The slow part should be, datatransfer from "Camera-RAM" to nommal RAM.

        2. Widget over the QVideoWidget

        m_overlay= new TMyCameraOverlay(m_videoWidget);
        

        I see no overlay. I heared that the QVideoWidget "overdraws" all.

        3. Use QGraphicsScene:

        //  Main part of the code
        m_graphicsScene = new QGraphicsScene(this);
           m_graphicsView = new QGraphicsView(m_graphicsScene, this);
           m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
           m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        
           m_videoItem = new QGraphicsVideoItem();
           m_graphicsScene->addItem(m_videoItem);
           // 3. Create  Custom-Overlay and put it in the Szene
           m_overlay = new TCameraOverlay();
           // Proxy makes normal Widget visible
           QGraphicsProxyWidget *proxy = m_graphicsScene->addWidget(m_overlay);
           proxy->setZValue(1); // Overlay in den forground !
           
           // Pack View in the Layout
           ui->ViewLayout->addWidget(m_graphicsView, 0, 0);
        
           // 4. Connect Camera (Set VideoItem as VideoOutput)
           m_captureSession = new QMediaCaptureSession(this);
           m_imageCapture = new QImageCapture(this);
           connect(m_imageCapture, &QImageCapture::imageCaptured,
                   this, &Camera_Frame::processCapturedImage);
        
           m_captureSession->setCamera(m_camera);
           m_captureSession->setVideoOutput(m_videoItem); // Important: videoItem instead of videoWidget!
           m_captureSession->setImageCapture(m_imageCapture);
        

        But here I get a very strange effect. The whole window especialy the control-buttons do react on touch evens no more.

        Who has experiences with a camera modul on Android ?

        Ronel_qtmasterR Offline
        Ronel_qtmasterR Offline
        Ronel_qtmaster
        wrote last edited by
        #3

        @Andy314 solution one is the right answer but you're missing few things.
        You should not process the camera streams on the main thread, you need to create another thread for gettig the camera frames and sending them to the Ui

        Moreover, after getting the camera frame and display it, you should free the memory space consumed by it. otherwise it will be slower and take too much ram

        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