Hi all,
I try to get the output of my webcam with opencv and display it through qt. Therefore I convert the IplImage into a QImage and call the function setPixmap() to draw the image onto a QLabel. Afterwards I repaint the QLabel to update it. Generally the output works fine but the program isn't responsive to any command. I can't close it by push esc or clicking on the "X" to close the window. My last option is to break the program by "ctrl-alt-del".
Does anybody has a hint or know where the problem lie?
I would be very excited for any help.
Thanks in advance and kind regards,
Saul
Thats my whole code:
// main.cpp
#include "webcam.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
Webcam w;
w.show();
return a.exec();
}
// main.cpp
#include "webcam.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Webcam w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
// webcam.h
#ifndef WEBCAM_H
#define WEBCAM_H
#include <QtGui/QMainWindow>
#include "ui_webcam.h"
#include "cv.h"
#include "highgui.h"
{
Q_OBJECT
public:
Webcam
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~Webcam();
private:
Ui::WebcamClass ui;
public slots:
void showWebcam();
};
#endif // WEBCAM_H
// webcam.h
#ifndef WEBCAM_H
#define WEBCAM_H
#include <QtGui/QMainWindow>
#include "ui_webcam.h"
#include "cv.h"
#include "highgui.h"
class Webcam : public QMainWindow
{
Q_OBJECT
public:
Webcam(QWidget *parent = 0, Qt::WFlags flags = 0);
~Webcam();
private:
Ui::WebcamClass ui;
public slots:
void showWebcam();
};
#endif // WEBCAM_H
To copy to clipboard, switch view to plain text mode
// webcam.cpp
#include "webcam.h"
{
ui.setupUi(this);
connect(ui.actionStart, SIGNAL(triggered()), this, SLOT(showWebcam()));
}
Webcam::~Webcam() { }
void Webcam::showWebcam()
{
IplImage *image;
CvCapture *capture;
capture = cvCaptureFromCAM(0);
int esc = 0;
while(true)
{
image = cvQueryFrame(capture);
cvCvtColor(image, image,CV_BGR2RGB);
QImage qimg
((const uchar
*)image
->imageData, image
->width, image
->height,
QImage::Format_RGB888);
ui.
label->setPixmap
(QPixmap::fromImage(qimg
));
ui.label->repaint();
esc = cvWaitKey(10);
if (esc == 27) break;
}
cvReleaseCapture(&capture);
}
// webcam.cpp
#include "webcam.h"
Webcam::Webcam(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
{
ui.setupUi(this);
connect(ui.actionStart, SIGNAL(triggered()), this, SLOT(showWebcam()));
}
Webcam::~Webcam() { }
void Webcam::showWebcam()
{
IplImage *image;
CvCapture *capture;
capture = cvCaptureFromCAM(0);
int esc = 0;
while(true)
{
image = cvQueryFrame(capture);
cvCvtColor(image, image,CV_BGR2RGB);
QImage qimg((const uchar *)image->imageData, image->width, image->height, QImage::Format_RGB888);
ui.label->setPixmap(QPixmap::fromImage(qimg));
ui.label->repaint();
esc = cvWaitKey(10);
if (esc == 27) break;
}
cvReleaseCapture(&capture);
}
To copy to clipboard, switch view to plain text mode
Bookmarks