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
->addPixmap
(QPixmap::fromImage(IplImageToQImage
(iImage
)));
resize(width()+(mScene->width()- mViewer->width()),height()+(mScene->height()-mViewer->height()));
mViewer->setScene(mScene);
mViewer
->setViewportUpdateMode
(QGraphicsView::FullViewportUpdate);
mActionLoad->setEnabled(true);
mActionSave->setEnabled(true);
mActionMatch->setEnabled(true);
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;
}
}
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(iImage)));
resize(width()+(mScene->width()- mViewer->width()),height()+(mScene->height()-mViewer->height()));
mViewer->setScene(mScene);
mViewer->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
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;
}
}
To copy to clipboard, switch view to plain text mode
out of CameraCalibrator.h
QTimer* mTimer;
QGraphicsView* mViewer;
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.
Bookmarks