Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 视频不能连续播放_Qt_Opencv - Fatal编程技术网

Qt 视频不能连续播放

Qt 视频不能连续播放,qt,opencv,Qt,Opencv,我正在使用opencv在Qt中播放视频。我有6个平铺视图摄像头,我正在播放视频。问题是,如果其中一个视频没有播放,即播放结束,GUI将冻结并退出。我得到的错误是,您必须重新实现QApplication::notify(),并在那里捕获异常。如何做到这一点? 我使用的代码如下 函数中的某个地方 void MainWindow::ActivateWindow() { //Some part of code to set Index for stacked widget if(stack

我正在使用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();
   }
}
在插槽中演示插槽

 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;

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


<> P>最好不要混合C++和C接口(我是CV::MAT和IplImage)。

< P>这将改变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;
};

这个插槽
MainWindow::demoSlot()
在很多级别上都是完全错误的!WTF#1
cvWaitkey(20),WTF 2
while(imageTimer->isActive())
,WTF 3
if(imageTimer->isActive())。。。停止()。。。start()
简单地说,我在这个插槽中看不到任何有用的代码,哪怕是一行代码。它只是阻塞了主线程。我怀疑你可以把所有东西都扔掉,除了播放视频的代码(假设你把代码藏在这个地方),这样就行了。显然,我没有写完整的代码。我只是写了这个部分,因为我认为这个问题可能会出现。代码的其余部分只是我们将捕获设置为一个帧并调整大小和设置PixMap的部分。主线程是否由于while循环而阻塞?但是如果我移除while循环,视频就不会播放。播放视频需要一些条件。我是否必须将整个视频放在一个QThread中,并根据需要启动和停止它,或者是否有其他解决方案?显示播放视频的代码。您显示的代码部分没有用处。我应该在什么时候调用startVideo()插槽?让我猜猜:无论何时开始播放视频,谢谢您迄今为止的帮助。我试过了。在我设置索引的地方,我叫startvideo,然后是通常的demoSlot。程序出人意料地完成了,另一个问题是它说没有像vid1.close这样的东西。但是有vid1.open。我从内存中写了这个,要关闭视频,有
release
功能。如何使用openCv播放视频的模式在这里更为重要,我将为您留下详细信息。好的,谢谢。我会尝试,如果这能解决问题,我会给出答案。:)