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
QtWS25 Last Chance

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.
  • V Offline
    V Offline
    vein
    wrote on 29 Jul 2015, 15:22 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Jul 2015, 21:01 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
      • V Offline
        V Offline
        vein
        wrote on 30 Jul 2015, 06:27 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 30 Jul 2015, 20:28 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

          V 1 Reply Last reply 31 Jul 2015, 10:03
          0
          • S SGaist
            30 Jul 2015, 20:28

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

            V Offline
            V Offline
            vein
            wrote on 31 Jul 2015, 10:03 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 31 Jul 2015, 20:47 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

              V 1 Reply Last reply 3 Aug 2015, 12:19
              0
              • S SGaist
                31 Jul 2015, 20:47

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

                V Offline
                V Offline
                vein
                wrote on 3 Aug 2015, 12:19 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

                5/7

                31 Jul 2015, 10:03

                • Login

                • Login or register to search.
                5 out of 7
                • First post
                  5/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved