#include <QApplication>
#include <QtWidgets/QWidget>
#include <QtWidgets/QLabel>
#include <QtGui/QImage>
#include <QtGui/QPixmap>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
int main(int argc,char **argv)
{
QApplication app(argc,argv);
QLabel labelxxx;
Mat imagexxx, rgbxxx;
QImage qimgxxx;
VideoCapture cap(0);
while(1)
{
cap >> imagexxx;
if(imagexxx.channels()==3)
{
cv::cvtColor(imagexxx,rgbxxx,CV_BGR2RGB);
qimgxxx = QImage((const unsigned char*)(rgbxxx.data),
rgbxxx.cols,rgbxxx.rows,
rgbxxx.cols*rgbxxx.channels(),
QImage::Format_RGB888);
}
else
{
qimgxxx = QImage((const unsigned char*)(imagexxx.data),
imagexxx.cols,imagexxx.rows,
imagexxx.cols*imagexxx.channels(),
QImage::Format_RGB888);
}
labelxxx.setPixmap(QPixmap::fromImage(qimgxxx));
labelxxx.resize(labelxxx.pixmap()->size());
labelxxx.show();
qApp->processEvents(QEventLoop::AllEvents);
}
app.exec();
}