QVideoFrames pixel format to Camera_Raw : for processing frames realtime.



  • Hi Friends

    I am working on a project that requires me to use the Macbook Camera. The idea is to process the video frames as they come.

    I read through the following document :
    http://doc.qt.io/qt-5/cameraoverview.html

    which tells me that :

    "For advanced usage (like processing viewfinder frames as they come, to detect objects or patterns), you can also derive from QAbstractVideoSurface and set that as the viewfinder for the QCamera object. In this case you will need to render the viewfinder image yourself."

    Hence, I create a class CameraFrameGrabber which looks like this :

    #include "cameraframegrabber.h"
    
    CameraFrameGrabber::CameraFrameGrabber(QObject *parent) :
        QAbstractVideoSurface(parent)
    {
    
    }
    
    QList<QVideoFrame::PixelFormat> CameraFrameGrabber::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
    {
    //    Q_UNUSED(handleType);
    
        if (handleType == QAbstractVideoBuffer::NoHandle) {
                return QList<QVideoFrame::PixelFormat>()
                        << QVideoFrame::Format_CameraRaw;
            }
    
        return QList<QVideoFrame::PixelFormat>()
              << QVideoFrame::Format_RGB24;
    }
    
    bool CameraFrameGrabber::present(const QVideoFrame &frame)
    {
        if (frame.isValid()) {
            QVideoFrame cloneFrame(frame);
            QAbstractVideoBuffer::HandleType handleType;
            cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
            qDebug()<<cloneFrame;
    
              const QImage image(cloneFrame.bits(),
                             cloneFrame.width(),
                              cloneFrame.height(),
                              QVideoFrame::imageFormatFromPixelFormat(cloneFrame .pixelFormat()));
                   
            emit frameAvailable(image);
            cloneFrame.unmap();
    
            return true;
        }
        return false;
    }
    

    My issue is I need the images in Camera_Raw format. But I only end up getting the pixel format of the QVideoFrame as RGB_32. I am not able to change the QVideoFrame format. Can you please help me solve this?

    Thank you

    Regards


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK, you need to go lower level in order to modify the type of the generated image



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.