Display image sequence



  • Hello everybody,
    I am currently working on an application which uses Qt, OpenCV and dlib to load a movie, split it into frames and analyze the frames via face detection.
    I am able to compute the movie into frames and apply the face detection on each individual frame.
    The problem is that I want to display the computed images - which are augmented with a bounding box around the detected faces - but I am not able to change the displayed image in the Graphicsview/ Graphicsscene.
    Here is the constructor of my main class (the imageView member references the *QGraphicsView *item constructed in the Qt UI Creator):

    qt_3::qt_3(QWidget *parent)
        : QMainWindow(parent)
    {
        ui.setupUi(this);
    
        imageScene = new QGraphicsScene(this);
        imageScene->setSceneRect(0, 0, ui.imageView->width(), ui.imageView->height());
    
        ui.imageView->setScene(imageScene); // the QGraphicsView item
        ui.imageView->fitInView(imageScene->sceneRect(), Qt::KeepAspectRatio);
    
        connect(&faceDetector, SIGNAL(signalImage()), this, SLOT(on_displayImage()));
    }
    

    The imageScene is declared like this in the header file:

    private:
    Ui::qt_3Class ui;
    QGraphicsScene *imageScene;
    

    Here is the method which gets called when the face detection algorithm generated a new image:

    void qt_3::on_displayImage(){
        Mat image = faceDetector.getComputedImage();
    
        if(!image.data){
    	    Functions::LogStr("Failed to display image");
    	    return;
        }else{
    	    Functions::LogStr("Display image");
    
    	    Mat temp;
    	    cvtColor(image, temp, CV_BGR2RGB); 
    	    QImage qImage((const uchar *) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
    	    qImage.bits();
    	
    	    imageScene->clear();
    
    	    imageScene->addPixmap(QPixmap::fromImage(qImage));
    	    imageScene->update();
    	    ui.imageView->update();
        }
    }
    

    When the on_displayImage method is invocted nothing happens, the scene does not even get cleared (I loaded up a test image in the constructor which is displayed fine).
    I would like to thank you very much for your answers and appreciate the help!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you sure that temp does contain a valid image ?



  • Hi,
    first of all thank you very much for your answer.
    I checked if the image is valid via QImage's method isNull and I also checked the Mat object's data before it ist converted, both state that the image data is correct. What confuses me is that the scene is not even cleared; I also tried to load a static image in the on_displayImage method but nothing gets cleared or displayed.


  • Lifetime Qt Champion

    Did you try to move your image at the center of the scene ?



  • @SGaist
    Thanks for the answer.
    I positioned the image at the center of the scene and I also ensured that the scene is active - which it is. It seems that all changes at the scene have no visible effect.


  • Lifetime Qt Champion

    Might be a silly question but are you sure that the getComputedImage function returns a new image each time you call it ?



  • @SGaist
    I checked if a new image was returned by saving each image data to a file before it gets returned and the image seems to be correct.
    I will try to replace the graphicsview/scene by a QLabel, perhaps this will work.


Log in to reply
 

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