Results 1 to 3 of 3

Thread: No fluid image with QGraphicView and QGraphicScene

  1. #1
    Join Date
    Mar 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default No fluid image with QGraphicView and QGraphicScene

    Hi together, so I got a little problem.

    I got a webcam, and the with many other tutorials I managed to convert its OpenCv Image to an QImage. For displaying it to the desktop I use a GraphicsView.
    The QImage gets put into a QGraphicsScene, and this finally gets showed in the GraphicsView.
    A QTimer which is activated every 100ms, catchs a Image from the Wcam, transfers it to a QImage. And then it gets showed.
    But now the Problem is that the picture in the viewer isn't fluid. The transfering from OpenCv to QImage isnt a problem. I think theres a problem with updating the qimage,scene or viewer.

    out of CameraCalibrator.cpp
    Qt Code:
    1. bool CameraCalibrator::refreshImage()
    2. {
    3. IplImage* img = mCam->grab();
    4. if (img)
    5. {
    6. mScene->addPixmap(QPixmap::fromImage(IplImageToQImage(img)));
    7. mScene->update(0,0,mScene->width(),mScene->height());
    8. return true;
    9. }
    10. return false;
    11. }
    12.  
    13. bool CameraCalibrator::Connect()
    14. {
    15. mCam->vrmLogger();
    16. if (mCam->connect())
    17. {
    18. IplImage* iImage = mCam->grab();
    19. mScene = new QGraphicsScene(this);
    20. mScene->addPixmap(QPixmap::fromImage(IplImageToQImage(iImage)));
    21. resize(width()+(mScene->width()- mViewer->width()),height()+(mScene->height()-mViewer->height()));
    22. mViewer->setScene(mScene);
    23. mViewer->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    24. mActionLoad->setEnabled(true);
    25. mActionSave->setEnabled(true);
    26. mActionMatch->setEnabled(true);
    27. mTimer = new QTimer();
    28. connect(mTimer, SIGNAL(timeout()), this, SLOT(refreshImage()));
    29. mTimer->start(1000/10);
    30. return true;
    31. }
    32. else
    33. {
    34. mActionLoad->setEnabled(false);
    35. mActionSave->setEnabled(false);
    36. mActionMatch->setEnabled(false);
    37. return false;
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

    out of CameraCalibrator.h
    Qt Code:
    1. QTimer* mTimer;
    2. QGraphicsView* mViewer;
    3. QGraphicsScene* mScene;
    To copy to clipboard, switch view to plain text mode 

    These are the two important functions. Does anyone else see the failure?
    I really dont get it.

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: No fluid image with QGraphicView and QGraphicScene

    Qt Code:
    1. mScene->addPixmap(QPixmap::fromImage(IplImageToQImage(img)));
    To copy to clipboard, switch view to plain text mode 

    You should only call addPixmap() once. Otherwise all the previous frames remain in the scene behind the current frame.
    Keep a reference instead:

    Qt Code:
    1. // Do once:
    2. QGraphicsPixmapItem* pixItem = mScene->addPixmap(QPixmap::fromImage(IplImageToQImage(img)));
    3.  
    4.  
    5. // Update:
    6. pixItem->setPixmap(QPixmap::fromImage(IplImageToQImage(img)));
    To copy to clipboard, switch view to plain text mode 
    No need to call update(). The item takes care of that for itself.

  3. #3
    Join Date
    Mar 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: No fluid image with QGraphicView and QGraphicScene

    Thx very much it worked!

Similar Threads

  1. Which is the best way to make a fluid user interface in QT?
    By Kevin Hoang in forum Qt Programming
    Replies: 5
    Last Post: 9th March 2010, 12:37
  2. Qgraphicscene - rendering
    By jsmith in forum Qt Programming
    Replies: 0
    Last Post: 22nd July 2009, 13:08
  3. my QGraphicView problem
    By irmakci in forum Qt Programming
    Replies: 3
    Last Post: 19th July 2008, 18:40
  4. QGraphicScene to stream
    By phannent in forum Newbie
    Replies: 2
    Last Post: 28th June 2008, 09:43
  5. QGraphicScene MousePressEvent
    By Spitz in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2007, 21:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.