Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display image sequence

Display image sequence

Scheduled Pinned Locked Moved General and Desktop
imagegraphics scene
7 Posts 2 Posters 5.5k Views
  • 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.
  • veinV Offline
    veinV Offline
    vein
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi and welcome to devnet,

      Are you sure that temp does contain a valid image ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • veinV Offline
        veinV Offline
        vein
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          veinV 1 Reply Last reply
          0
          • SGaistS SGaist

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

            veinV Offline
            veinV Offline
            vein
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              veinV 1 Reply Last reply
              0
              • SGaistS SGaist

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

                veinV Offline
                veinV Offline
                vein
                wrote on last edited by
                #7

                @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.

                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