QPixmap or QImage for JFIF image format



  • Hi all, I have some incoming image data from a camera that is in JFIF APP0 format.
    The first four bytes are: 0xFF, 0xD8, 0xFF, 0xE9.

    Which what I see from https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format (JFIF APP0 marker segment).

    Problem: Looking through the docs, I am unable to find anything that supports JFIF. As the header formats are different than JPEG, I was wondering if anyone has any recommendations on a workaround with either using QPixmap or QImage?

    Alternative: I could also retrieve image data as raw matrix (mat) form and use OpenCV methods, however i was unable to build opencv for my QT 5.1, MSVC2015 64 bit.

    Goal 1: Display image on QLabel or QGraphicsView.
    Goal 2: Video from sequence of images.

    Thanks and hoping to hear from you.


  • Lifetime Qt Champion

    Hi,

    Did you try to force the use of the JPEG plugin to read the image ?
    Can you provide a sample image in that format ?



  • @SGaist Hi yes, I was able to force the JFIF format and found a solution to display my image on a QLabel.

    I was wondering now, how would I be able to play a sequence of images onto the QLabel, like an animation/video.

        for(int x=0;x<10;x++){ //GET 10 IMAGES INTO QList<QPixmap>
            
            BYTE* cameraImage = new BYTE[dwMaxImageBytes];
            DWORD dwImageBytes;
            CaptureImage(cameraImage, dwMaxImageBytes, &dwImageBytes); //API for getting JFIF image
            
            QPixmap pix;
            pix.loadFromData((const uchar*)cameraImage,dwImageBytes,"JFIF");
            *qpixmaplist << pix; //declared in header file as QList<QPixmap>* qpixmaplist
        }
    
        timer.setInterval(1000); //attempting to display one image on a QLabel every 1 sec
        connect(&timer,SIGNAL(timeout()),this,SLOT(procPixmap()));
        timer.start();
    

    The procPixmap slot:

    void MainWindow::procPixmap(){
        if(pixcounter>=10){
            timer.stop();
            disconnect(&timer,SIGNAL(timeout()),this,SLOT(procPixmap()));
        }
        else{
            ui->label->setPixmap(qpixmaplist->at(pixcounter));
            pixcounter++;
        }
    }
    

  • Lifetime Qt Champion

    Something is not clear, do you want to get the images from the camera or from files to show that "video" ?



  • @SGaist
    Thanks for the reply. Basically, from a camera's API "CaptureImage", i store one image in an array of unsigned char bytes.

    CaptureImage(cameraImage, dwMaxImageBytes, &dwImageBytes); 
    

    That one image is loaded as a QPixmap, and fed to a QList of QPixmaps.

    QPixmap pix;
    pix.loadFromData((const uchar*)cameraImage,dwImageBytes,"JFIF");
    qpixmaplist << pix; 
    

    Now, everything works. My images are displayed at a rate determined by the timer interval.

    However, is there a cleaner way to convert these QList <QPixmap> into a more video format, rather than having to physically update images, like a script boy on a TV set.
    ui->label->setPixmap(qpixmaplist[counter]); counter++;


  • Lifetime Qt Champion

    How fast are these images coming ?



  • @SGaist
    Thanks for the reply. For me:

    • Each call to the CaptureImage API takes approximate 6 ms.
    • Loading to the QList<QPixmap> takes an additional 90 ms.

  • Lifetime Qt Champion

    Why create a QList and not do the conversion directly after calling CaptureImage ?

    Otherwise, does the library you are using to get the image provide a streaming API ?


Log in to reply
 

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