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. How to get a Frame image from qcamera ?
Forum Updated to NodeBB v4.3 + New Features

How to get a Frame image from qcamera ?

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 2 Posters 4.4k Views 1 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.
  • M Offline
    M Offline
    Mr Aloof
    wrote on last edited by
    #1

    i'm want to grab a frame from QCamera in Android
    i have get the frame successfully
    but the Object is QVideoFrame
    and the pixmap format is BGR32
    also,even, the map() function in Android will always return false
    so ,i have no idea to convert it to QImage
    anyone can help me ?
    thx very much

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hipersayan_x
      wrote on last edited by
      #2

      For THIS specific case, you can convert from QVideoFrame to QImage with:

      @
      QImage out(videoFrame.size(), QImage::Format_RGB888);

      quint32 *inp = videoFrame.bits();
      quint32 *outp = out.bits();

      int max = videoFrame.width() * videoFrame.height();

      for (int i = 0; i < max; i++) {
      int r = (inp[i] >> 8) & 0xff;
      int g = (inp[i] >> 16) & 0xff;
      int b = (inp[i] >> 24) & 0xff;

      outp[i] = qRgb(r, g, b);
      

      }
      @

      For other pixel formats you must adapt the code for the specific pixel layout.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mr Aloof
        wrote on last edited by
        #3

        thank you

        i have tried your code

        but the videoFrame.bits() function return a NULL value

        how to do about this?

        [quote author="hipersayan_x" date="1413179030"]For THIS specific case, you can convert from QVideoFrame to QImage with:

        @
        QImage out(videoFrame.size(), QImage::Format_RGB888);

        quint32 *inp = videoFrame.bits();
        quint32 *outp = out.bits();

        int max = videoFrame.width() * videoFrame.height();

        for (int i = 0; i < max; i++) {
        int r = (inp[i] >> 8) & 0xff;
        int g = (inp[i] >> 16) & 0xff;
        int b = (inp[i] >> 24) & 0xff;

        outp[i] = qRgb(r, g, b);
        

        }
        @

        For other pixel formats you must adapt the code for the specific pixel layout.
        [/quote]

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hipersayan_x
          wrote on last edited by
          #4

          Ups, a little error, where it says:

          @QImage out(videoFrame.size(), QImage::Format_RGB888);@

          must be:

          @QImage out(videoFrame.size(), QImage::Format_RGB32);@

          [quote author="Mr Aloof" date="1413181295"]thank you

          i have tried your code

          but the videoFrame.bits() function return a NULL value

          how to do about this?
          [/quote]

          What is the code you are using for capturing the frames? Does videoFrame.size() returns a valid value?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr Aloof
            wrote on last edited by
            #5

            videoFrame.size() is return a correct value
            but the videoFrame.bits() return a '0'

            this is my code
            @bool QSGVideoItemSurface::present(const QVideoFrame &frame)
            {
            if (!frame.isValid()) {
            qWarning() << Q_FUNC_INFO << "I'm getting bad frames here...";
            return false;
            }

            m_backend->present(frame);
            
            QVideoFrame cloneFrame(frame);
            if(cloneFrame.map(QAbstractVideoBuffer::ReadOnly));
            //{
            QVideoFrame::PixelFormat v_f=cloneFrame.pixelFormat();
            QImage::Format i_f=QVideoFrame::imageFormatFromPixelFormat(v_f);
            
            int xx=cloneFrame.mappedBytes();
            qDebug()<<"xx "<<xx;
            
            QImage img(cloneFrame.bits(), cloneFrame.width(), cloneFrame.height(), cloneFrame.bytesPerLine(), QImage::Format_RGB32);
            
            QZXing zxing;
            QString qr_ct=zxing.decodeImage(img);
            
            qDebug()<<"QR : "<<qr_ct<<" "<<cloneFrame.width()<<" "<<cloneFrame.height();
            //}
            
            //qDebug()<<"frame get here";
            return true;
            

            }
            @
            [quote author="hipersayan_x" date="1413207765"]Ups, a little error, where it says:

            @QImage out(videoFrame.size(), QImage::Format_RGB888);@

            must be:

            @QImage out(videoFrame.size(), QImage::Format_RGB32);@

            [quote author="Mr Aloof" date="1413181295"]thank you

            i have tried your code

            but the videoFrame.bits() function return a NULL value

            how to do about this?
            [/quote]

            What is the code you are using for capturing the frames? Does videoFrame.size() returns a valid value?
            [/quote]

            [quote author="hipersayan_x" date="1413207765"]Ups, a little error, where it says:

            @QImage out(videoFrame.size(), QImage::Format_RGB888);@

            must be:

            @QImage out(videoFrame.size(), QImage::Format_RGB32);@

            [quote author="Mr Aloof" date="1413181295"]thank you

            i have tried your code

            but the videoFrame.bits() function return a NULL value

            how to do about this?
            [/quote]

            What is the code you are using for capturing the frames? Does videoFrame.size() returns a valid value?
            [/quote]

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hipersayan_x
              wrote on last edited by
              #6

              -How did you implemented the video surface? Did you specified which format do you want to receive?-

              Are you "unmapping":http://qt-project.org/doc/qt-5/qvideoframe.html#unmap the frame after using it?

              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