Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

How to display Video in opencv-Qt ?

$
0
0
After following some answers in the stackoverflow, I understood how to use timer to display videos in qt. But Still my program doesn't even get to the function that will be called repeatedly. I am not understanding what I am doing wrong. Here's my code - VideoCapture cap(0); QTimer *imageTimer; Mat frame; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); const int imagePeriod = 1000 / 25; // ms imageTimer = new QTimer(this); imageTimer->setInterval(imagePeriod); connect(imageTimer, SIGNAL(timeout()), this, SLOT(showVideo())); } MainWindow::~MainWindow() { } QImage MainWindow::getQImage(cv::Mat &timage){ static QVector colorTable; if (colorTable.isEmpty()){ for (int i = 0; i < 256; i++){ colorTable.push_back(qRgb(i, i, i)); } } if (timage.type() == CV_8UC3){ QImage temp = QImage((const unsigned char*)(timage.data), timage.cols, timage.rows, timage.step, QImage::Format_RGB888); return temp.rgbSwapped(); } else if (timage.type() == CV_8UC1){ QImage temp = QImage((const unsigned char*)(timage.data), timage.cols, timage.rows, timage.step, QImage::Format_Indexed8); temp.setColorTable(colorTable); return temp; } } void MainWindow::on_startButton_pressed(){ imageTimer->start(10); } void MainWindow::showVideo(){ cap.read(frame); ui.videoFeed->setScaledContents(true); ui.videoFeed->setPixmap(QPixmap::fromImage(getQImage(frame))); ui.videoFeed->resize(ui.videoFeed->pixmap()->size()); this->update(); } void MainWindow::on_stopButton_pressed(){ imageTimer->stop(); }> This is the Header FIle class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); QImage MainWindow::getQImage(cv::Mat &timage); private: Ui::MainWindowClass ui; private slots: void on_startButton_pressed(); void on_stopButton_pressed(); public slots: void MainWindow::showVideo(); };

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>