Results 1 to 2 of 2

Thread: opencv multiple videos same time

  1. #1
    Join Date
    Jan 2019
    Posts
    3
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default opencv multiple videos same time

    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();
    }
    }
    }
    Last edited by hnd; 28th January 2019 at 14:45.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,432
    Thanked 264 Times in 259 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: opencv multiple videos same time

    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.

  3. The following user says thank you to Lesiok for this useful post:

    hnd (28th January 2019)

Similar Threads

  1. Replies: 0
    Last Post: 19th June 2016, 07:27
  2. playing multiple videos with sync on phonon?
    By alperyazir in forum Qt Programming
    Replies: 0
    Last Post: 9th July 2015, 08:18
  3. how to execute multiple commands at a time
    By PHANI in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2012, 09:01
  4. Calling Multiple Exes at the same time
    By chandru@080 in forum Newbie
    Replies: 7
    Last Post: 16th December 2010, 22:15
  5. add multiple rows at a time in tablewidgets
    By rk0747 in forum Qt Programming
    Replies: 0
    Last Post: 15th April 2010, 06:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.