0
votes

I am compiling on Ubuntu 14.04 using OpenCV 3.1. When trying to open a video file it gives this error:

"Cannot open the video file"

I installed everything i could install : ffmpeg etc. Haven't found a solution checking out similar questions on StackOF.

What do ?

cv::VideoCapture cap(argv[1]);

Where argv[1] is the file name in the same directory as the executable.

1
@ΦXocę웃Пepeúpaツ postededd
can you tell me what is argv[1]?ΦXocę 웃 Пepeúpa ツ
argv[1] is a pointer to a string representing the file name i want to open @ΦXocę웃Пepeúpaツedd
try passing full qualified path as argv[1].ZdaR
jap, I can guess, but i want to know, is that string holding empty spaces?ΦXocę 웃 Пepeúpa ツ

1 Answers

0
votes

In case your constructor is failing, you may want to use the .open() method. So, if you want to open a file that is called "myVideo.mp4" that is in the folder of your project, you would do the following:

cv::VideoCapture cap;
cap.open("myVideo.mp4"); 

For more detailed informations about this method, check this documentation link Also, the book Learning OpenCV 3, from the O'Rilley media, on page 26 gives you a good example. Here is a Gist that I made to give you as an example.

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

int main() {
  cv::VideoCapture cap;
  cap.open("myVideo.mp4" );
  cv::namedWindow( "myVideo", cv::WINDOW_AUTOSIZE );
  cv::Mat frame;
  while(true) {
    cap >> frame;
    if( frame.empty() ){
      std::cout << "Could not load the video frames. \n";
      break;
    }
    cv::imshow( "myVideo", frame );
    if( cv::waitKey(27) >= 0 ){
      std::cout << "Escape pressed \n";
      break;
    }
  }
  return 0; 
}