在 OpenCV 中播放视频:无错误无输出

video playing in opencv: no error no output

本文关键字:无错误 输出 视频 OpenCV 播放      更新时间:2023-10-16

我编写了一个程序来显示存储的视频文件,使用 opencv .我附上了下面的代码。我在构建它时没有收到任何错误,但没有显示输出。

int main(int argc, char *argv[])
    {
              if (argc <= 1)
              {
                      printf("Usage: %s videon", argv[0]);
                      return -1;
              }

              VideoCapture capture(argv[1]);
              namedWindow("display",cv::WINDOW_AUTOSIZE);
              capture.set(cv::CAP_PROP_FRAME_WIDTH, 640);
              capture.set(cv::CAP_PROP_FRAME_HEIGHT, 480); 

              if(!capture.isOpened())
              {
                              printf("Failed to open the videon");
                              return -1;
               }
               int i;
               for(i=0;i<390;i++)
               {
                          Mat frame;

                          capture >> frame; // get a new frame from camera
                          cout << "frame =" << endl << " " <<  frame << endl << endl; 
                          imshow("display",frame);
                }
                }

我在末尾包含cout行以检查帧是否获得任何值。所以 a 在矩阵中得到了许多值,但视频窗口没有出现。

您必须

在使用waitKey imshow后添加非常小的延迟。

imshow("display",frame);
waitKey(10); //Wait 10 milliseconds before showing next frame.