0

我正在使用 opencv 在 Qt 中播放视频。我有 6 个平铺视图摄像机,我正在从中播放视频。问题是,如果其中一个视频没有播放,即播放完毕,则 GUI 冻结并退出。我得到的错误是你必须重新实现 QApplication::notify() 并在那里捕获异常。这个怎么做?我正在使用的代码如下。

函数中的某处

 void MainWindow::ActivateWindow()
{
  //Some part of code to set Index for stacked widget

   if(stackWidget->currentIndex()==9)
   {
      const int imagePeriod == 1000/25;
      imageTimer->setInterval(imagePeriod);
      connect(imageTimer,SIGNAL(timeout()),this,SLOT(demoSlot());
      imageTimer->start();
   }
}

在插槽 demoSlot

 void MainWindow::demoSlot()
{
   captureCamera1 cvCaptureFromFile("/root/mp.mp4");
   captureCamera2 cvCaptureFromFile("/root/mp.mp4");
   captureCamera3 cvCaptureFromFile("/root/mp.mp4");

   while(imageTimer->isActive())
   {
      frameCamera1 = cvQueryFrame(captureCamera1);
      frameCamera2 = cvQueryFrame(captureCamera2);
      frameCamera3 = cvQueryFrame(captureCamera2);

      sourceImageCam1 = frameCamera1;
      sourceImageCam2 = frameCamera2;
      sourceImageCam3 = frameCamera3;

      cv::resize(sourceImageCam1,sourceImageCam1,cv::size(400,100),0,0);
      cv::resize(sourceImageCam1,sourceImageCam1,cv::size(400,100),0,0);
      cv::resize(sourceImageCam1,sourceImageCam1,cv::size(400,100),0,0);

      cv::cvtColor(sourceImageCam1,sourceImageCam2,CV_BGR2RGB);
      cv::cvtColor(sourceImageCam2,sourceImageCam2,CV_BGR2RGB);
      cv::cvtColor(sourceImageCam2,sourceImageCam2,CV_BGR2RGB);

      QImage tempImage1 = QImage((const unsigned char* sourceImageCam1.data,sourceImageCam1.cols,sourceImageCam2.rows,QImage::Format_RG888);
      QImage tempImage2 = QImage((const unsigned char* sourceImageCam2.data,sourceImageCam2.cols,sourceImageCam2.rows,QImage::Format_RG888);
      QImage tempImage3 = QImage((const unsigned char* sourceImageCam3.data,sourceImageCam3.cols,sourceImageCam3.rows,QImage::Format_RG888);

      labelCameraCapture1->setPixmap(QPixmap::fromImage(tempImage1));     //label to display video
      labelCameraCapture2->setPixmap(QPixmap::fromImage(tempImage2));
      labelCameraCapture3->setPixmap(QPixmap::fromImage(tempImage3));

      lblCameraCapture1->resize(lblCameraCapture1->Pixmap->size());
      lblCameraCapture1->resize(lblCameraCapture1->Pixmap->size());
      lblCameraCapture1->resize(lblCameraCapture1->Pixmap->size());

      cvWaitkey(20);
      qApp->processEvents();
    }
 if(imageTimer->isActive())
 {
   imageTimer->stop();
 }
 else
 {
   imageTimer->start();
 }
}

在头文件中

   cvCapture *captureCamera1;
   cvCapture *captureCamera1;
   cvCapture *captureCamera1;

   IplImage frameCamera1;
   IplImage frameCamera2;
   IplImage frameCamera3;

   cv::Mat sourceImageCam1;
   cv::Mat sourceImageCam2;
   cv::Mat sourceImageCam3;
4

2 回答 2

1

这将完成将其更改为 3 部电影的技巧很简单。

class MainWindow : public QMainWindow {
Q_OBJECT

   explicit QMainWindow(QWidget *parent) ....
   // prepare timer and so on

public slots:
   void startVideo() {
      vid1.close();
      vid1.open("/root/mp.mp4");
      imageTimer->start();
   }

   void demoSlot() {
      cv::Mat frame;
      vid1 >> frame;
      cv::cvtColor(frame,frame,CV_BGR2RGB);
      QImage img((uchar*) frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
      label1->setPixmap(QPixmap::fromImage(img));
   }

private:
   ...
   QTimer *imageTimer;
   cv::VideoCapture vid1;
};
于 2013-08-21T21:02:46.773 回答
0

检查从相机捕获的帧是否为 NULL。然后只需跳过此相机的处理步骤。

最好不要混合 C++ 和 C 接口(我的意思是 cv::Mat 和 IplImage)。

于 2013-08-21T20:15:47.070 回答