PDA

View Full Version : No fluid image with QGraphicView and QGraphicScene



GonzoFist
6th April 2010, 14:31
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


bool CameraCalibrator::refreshImage()
{
IplImage* img = mCam->grab();
if (img)
{
mScene->addPixmap(QPixmap::fromImage(IplImageToQImage(img) ));
mScene->update(0,0,mScene->width(),mScene->height());
return true;
}
return false;
}

bool CameraCalibrator::Connect()
{
mCam->vrmLogger();
if (mCam->connect())
{
IplImage* iImage = mCam->grab();
mScene = new QGraphicsScene(this);
mScene->addPixmap(QPixmap::fromImage(IplImageToQImage(iIma ge)));
resize(width()+(mScene->width()- mViewer->width()),height()+(mScene->height()-mViewer->height()));
mViewer->setScene(mScene);
mViewer->setViewportUpdateMode(QGraphicsView::FullViewportU pdate);
mActionLoad->setEnabled(true);
mActionSave->setEnabled(true);
mActionMatch->setEnabled(true);
mTimer = new QTimer();
connect(mTimer, SIGNAL(timeout()), this, SLOT(refreshImage()));
mTimer->start(1000/10);
return true;
}
else
{
mActionLoad->setEnabled(false);
mActionSave->setEnabled(false);
mActionMatch->setEnabled(false);
return false;
}
}


out of CameraCalibrator.h


QTimer* mTimer;
QGraphicsView* mViewer;
QGraphicsScene* mScene;


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

spud
6th April 2010, 15:02
mScene->addPixmap(QPixmap::fromImage(IplImageToQImage(img) ));


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



// Do once:
QGraphicsPixmapItem* pixItem = mScene->addPixmap(QPixmap::fromImage(IplImageToQImage(img) ));


// Update:
pixItem->setPixmap(QPixmap::fromImage(IplImageToQImage(img) ));

No need to call update(). The item takes care of that for itself.

GonzoFist
6th April 2010, 16:00
Thx very much it worked! ;)