Sid411
Sid411

Reputation: 703

Video too fast in Qt using OpenCV

I am playing a video on label in Qt. I am using Open CV for the same. The video is playing but it is too fast. How can I decrease the playback speed. I tried using setCaptureProperty but it is not working. My code is as follows

HeaderFile Declarations:

CvCapture *capture;
IplImge *frame;
cv::Mat source_image;
cv::Mat dest_image;
QTimer *imageTimer;

Button click slot:

void MainWindow::onButtonClick()
{
   capture = cvCaptureFromFile("/mp.mp4");
   while(capture
  {
    frame = cvQueryFrame((capture);
    source_image = frame;
    cv::resize(source_image,source_image,cv::Size(420,180),0,0);
    cv::cvtColor(source_image,source_image,CV_BGR2RGB);
    QImage qimg = QImage((const unsigned char*)source_image.data,source_image.cols,source_imge.rows,QImage::Format_RGB888);
   label->setPixmap(QPixmap::fromImage(qimg));
   label->resize(label->pixmap()->size());
  }
}

Somebody please guide on this...Thank You :)

Upvotes: 2

Views: 1131

Answers (1)

Imbarfar
Imbarfar

Reputation: 351

I use Qtimer in this way,not the while loop,like following:

void on_button_click()
{
    cap.open(0);
    timer->start(50);
}
void readframe()   
{
    //display image in label 
    cap>>frame;
    Mat2QImage(); // convert mat to QImage;
    ...
    //setpixmap();
    ...
}

and in the main window,

connet(timer,timeout(),this,readframe());

Upvotes: 1

Related Questions