PDA

View Full Version : opencv multiple videos same time



hnd
28th January 2019, 13:21
im a newbie and hi to all.
okay. i ve got 2 graphicsViews and 2 buttons.
i can play 2 different videos with 2 different graphicsViews.
My question is;
when i click pushbutton1, movie starting to play and click pushbutton2 2.movie starting to play but first movie paused.
i want to play both at the same time..

i used win10 and qt 5.12.0,mingw64, opencv 2.4.13

sorry for my english.thanks

here is my code;

#include "opencv2/opencv.hpp"

ui->setupUi(this);
ui->graphicsView->setScene(new QGraphicsScene(this));
ui->graphicsView->scene()->addItem(&pixmap);

ui->graphicsView_2->setScene(new QGraphicsScene(this));
ui->graphicsView_2->scene()->addItem(&pixmap2);

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{


video2.open("/Sample.avi");

if(video2.isOpened())
{
ui->label->setText("video open..");
fps2=video2.get(CV_CAP_PROP_FPS);
cv::Mat frame2;
while(video2.isOpened())
{
video2 >> frame2;
if(!frame2.empty())
{

QImage qimg2(frame2.data, frame2.cols, frame2.rows, frame2.step, QImage::Format_RGB888);
pixmap2.setPixmap( QPixmap::fromImage(qimg2.rgbSwapped()) );
ui->graphicsView_2->scene()->addItem(&pixmap2);
ui->graphicsView_2->fitInView(&pixmap2, Qt::KeepAspectRatio);
}
qApp->processEvents();
}


}


else
{
ui->label->setText("cant open video");
}



}



void MainWindow::on_pushButton_2_clicked()
{


video.open("/Sample2.avi");

if(video.isOpened())
{
ui->label_2->setText("video2 open..");
fps=video.get(CV_CAP_PROP_FPS);
cv::Mat frame;
while(video.isOpened())
{
video >> frame;
if(!frame.empty())
{


QImage qimg(frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
pixmap.setPixmap( QPixmap::fromImage(qimg.rgbSwapped()) );
ui->graphicsView->scene()->addItem(&pixmap);
ui->graphicsView->fitInView(&pixmap, Qt::KeepAspectRatio);
}
qApp->processEvents();
}
}
}

Lesiok
28th January 2019, 14:37
A while loop in the running slot causes the slot to not finish. You should create a method that displays one frame and run it through QTimer :: singleShot with timeout 0.