c++ - 在 opencv : no error no output 中播放的视频

标签 c++ opencv

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

int main(int argc, char *argv[])
    {
              if (argc <= 1)
              {
                      printf("Usage: %s video\n", 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 video\n");
                              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 在矩阵中得到了一些值,但是视频窗口没有出现。

最佳答案

您必须在 imshow 之后使用 waitKey 添加一个非常小的延迟。

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

关于c++ - 在 opencv : no error no output 中播放的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21013869/

相关文章:

c++ - 返回指向在不同线程中更新的 QML 的 C++ 指针

C++ WTSQueryUserToken 函数错误

python - 无法使用opencv获得我想要的分辨率

c++ - 如何使用 C++ 和 OpenCV 检测轮廓自相交?

c++ - 是否可以在 C++ 中将父对象转换为子对象?

以 Vector 对象为成员的 C++ Sprite 类

c++ - boost::spirit::qi 和乱序变量

python - Hough Line变换无法正确识别任何线

android - 使用 OpenCV 进行 gabor 边缘检测

c++ - MouseCallback 函数 OpenCV