The problem in the second program is entirely between you and OpenCV, nothing to do with Qt. I cannot offer much help.
First program: Neither. The looping behaviour needs to be replaced with event driven behaviour. It doesn't belong in the main() function. Try plugging your code into something like the framework below. Also, have your conversion function return the QImage by value rather than using the heap.
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
setCentralWidget(label);
// setup OpenCv
connect(&timer, SIGNAL(timeout()), SLOT(capture()));
timer.setInterval(200); // about 5 times per second
timer.start();
}
~MainWindow() {
// tear down OpenCv
}
public slots:
void capture() {
// capture, convert and display image on label
qDebug() << "Capturing";
}
private:
};
int main(int argc, char *argv[])
{
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QLabel *label = new QLabel(this);
setCentralWidget(label);
// setup OpenCv
connect(&timer, SIGNAL(timeout()), SLOT(capture()));
timer.setInterval(200); // about 5 times per second
timer.start();
}
~MainWindow() {
// tear down OpenCv
}
public slots:
void capture() {
// capture, convert and display image on label
qDebug() << "Capturing";
}
private:
QLabel *label;
QTimer timer;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
You can adjust the "sampling" rate or use a single shot timer to run as-fast-as-possible, but most video sources will produce a frame every 30th or 25th of a second.
Bookmarks