在opencv中播放视频:无错误无输出 [英] video playing in opencv: no error no output

查看:82
本文介绍了在opencv中播放视频:无错误无输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have written a program to display a stored video file using opencv. I attached the code below. I am not getting any errors while building it but no output is displayed.

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行,以检查框架是否获得任何值.因此,矩阵中有很多值,但是视频窗口没有出现.

I included the cout line at the end to check if the frame is getting any value or not. So a got a number of values in a matrix, but the video window is not appearing.

推荐答案

imshow之后,您必须使用waitKey添加非常小的延迟.

You have to add a very small delay after imshow by using waitKey.

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

这篇关于在opencv中播放视频:无错误无输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆