QCamera capture 8bit gray scale and convert to rgb

  • I am just starting on Qt. I am trying to capture an image from a sensor that generates grey/raw byte image.
    Would like to capture 2592x1944 grey image scale it to 640x360 and convert it to rgb and display it.
    All this with as little CPU involvement as possible.
    I have tried the following:
    QImageEncoderSettings imageSettings;
    imageSettings.setResolution(2592, 1944);

    The only codec supported is jpeg and this in not useful to me.
    Any ideas will be very helpful.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    How is that sensor seen by the system ?
    What version of Qt are you using ?
    What platform are you running on ?

  • The sensor is seen as /dev/video0.
    I am using Qt for device creation v 5.8.
    I am building on linux platform for IMX.6 Q SabreSD.

  • Just some thoughts:

    • If you wish to minimise CPU usage, why do the capture at such high resolution? For supported resolutions, check QCameraImageCapture::supportedResolutions()
    • There might not be no need to convert the image to RGB for display -- Qt should handle grayscale just well
    • Scaling using any scaling functions may be more innefient than creating an empty target image and picking every Nth pixel for it from the source (JPEG buffer converted into QImage -- see QImage::loadFromData()) and calculating for the pixel either grayscale RGB value or indexed grayscale value from the source buffer

  • Thanks for your prompt reply.
    I can't change the resolution at which the sensor is capturing. It is a special sensor and I can't configure for lower resolution.
    I have a test app that does the scaling by doing just that copy/scale (copying only the needed pixels to destination image buffer). The problem is that this is very slow process. It takes 0.6 seconds per frame. This doesn't work for my application this is the reason I was wondering if the scale and image conversion could be done by gpu. I can copy the frame from the camera to a buffer in memory but then I need to somehow hand over the buffer to the gpu and do the scaling/conversion there.

  • Lifetime Qt Champion

    So something like creating a texture from the image and then process it ?

  • yes exactly.

  • Lifetime Qt Champion

    Something like QOpenGLTexture ?

  • @SGaist
    How can I use a that texture class. The camera app seems to handle everything under covers.

  • Lifetime Qt Champion

    Before going further, what will you be using to display the image ? QtWidgets ? QtQuick ?

  • QtQuick 2.4 is imported by the qml. I must be using QtQuick. I am new to Qt.

  • Lifetime Qt Champion

    Then, IIRC, your image is already a texture or something similar if you are using QtQuick with the VideoOutput element.

  • I found this article: http://blog.qt.io/blog/2015/03/20/introducing-video-filters-in-qt-multimedia/
    on video filters. I will give this a try.
    I have another question though since I need to differentiate between preview and capture formats.
    The sensor generates 8 bit gray for preview and then I need to switch to 16bit gray for capture.
    How can this be done by the camera. I don't see an api to specify capture mode or preview mode. I could be wrong though.

  • Lifetime Qt Champion

    Does your camera provide an API for that ?

Log in to reply