【问题标题】:Video too fast in Qt using OpenCV使用 OpenCV 在 Qt 中视频太快
【发布时间】:2013-07-19 09:50:26
【问题描述】:

我在 Qt 的标签上播放视频。我也在使用 Open CV。视频正在播放,但速度太快。如何降低播放速度。我尝试使用 setCaptureProperty 但它不起作用。我的代码如下

头文件声明:

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

按钮点击槽:

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());
  }
}

请有人指导...谢谢:)

【问题讨论】:

  • 在每一帧中使用cvWaitKey(100);。它增加了 100 毫秒的延迟。
  • 试过了...不行...我用while循环写的...

标签: qt opencv video


【解决方案1】:

我以这种方式使用 Qtimer,而不是 while 循环,如下所示:

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

在主窗口中,

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

【讨论】:

    猜你喜欢
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多