How to solve problem with VideoCapture loading in linux ?
Hi,
I've written the following code so as to load a mp4 video into VideoCapture, however, when I check the capture with isOpened()
I get false . I'm 100% sure that the mp4 file is within the folder but my code is not able to open the capture.
#include <iostream> // for standard I/O
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
#include <thread>
#include <future>
using namespace std;
using namespace cv;
int loadVideo( VideoCapture cap1, int seek_step,int thrd){
int frameNum = 0;
Mat frame;
char c;
cap1.set(CV_CAP_PROP_POS_FRAMES, seek_step );
while (1){
cap1 >> frame;
if (frame.empty())
{
cout << " < < < Channel stream ended! > > > ";
break;
}
cout << frameNum << endl;
++frameNum;
}
return frameNum;
}
int main(int argc, char *argv[])
{
string sourceVideoPath;
sourceVideoPath = "/home/azdoud/case1_320_200/case320_200fps20.mp4";
// sourceVideoPath = "case320_240fps20.mp4";
// sourceVideoPath = "C:\\opencvVid\\case1_320_240\\vid320_240fps25.mp4";
// sourceVideoPath = argv[1];
//start a new VideoCapture object in each of your 4 threads
VideoCapture cap1(sourceVideoPath);
cout << "Stream frame numbre : " << cap1.get(CV_CAP_PROP_FRAME_COUNT)<<endl;
if (!cap1.isOpened())
{
cout << "Could not open video " << sourceVideoPath << endl;
return -1;
}
loadVideo(cap1,0,1);
return 0;
}
I've put the video in the same folder but no good results.
[azdoud@video-processor CentOSsimple]$ cmake -DCMAKE_CXX_FLAGS="-std=c++11"
-- Configuring done
-- Generating done
-- Build files have been written to: /home/azdoud/CentOSsimple
[azdoud@video-processor CentOSsimple]$ make
Scanning dependencies of target main
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
Linking CXX executable main
[100%] Built target main
[azdoud@video-processor CentOSsimple]$ ./main
Stream frame numbre : 0
Could not open video case320_240fps20.mp4
in I tested this code it works well, the image is in the same folder too
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace std;
using namespace cv;
int main()
{
Mat src;
/// Load image
src = imread( "/home/azdoud/im.jpg");
// src = imread( "C:\\opencvVid\\images\\1.png" );
cout << "Width : " << src.size().width << endl;
cout << "Height: " << src.size().height << endl;
return 0;
}
this the result
[azdoud@video-processor CentOSsimple]$ cmake -DCMAKE_CXX_FLAGS="-std=c++11"
-- Configuring done
-- Generating done
-- Build files have been written to: /home/azdoud/CentOSsimple
[azdoud@video-processor CentOSsimple]$ make
Scanning dependencies of target main
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
Linking CXX executable main
[100%] Built target main
[azdoud@video-processor CentOSsimple]$ ./main
Width : 0
Height: 0
you may tell is a probelm of permission, I've checked that too by setting chmod to 666 on the folder and on mp4 file. How can you explain this, I can't understand why
any help thank you in advance.
here the getBuildInformation()
output
[azdoud@video-processor CentOSsimple]$ cmake -DCMAKE_CXX_FLAGS="-std=c++11"
-- Configuring done
-- Generating done
-- Build files have been written to: /home/azdoud/CentOSsimple
[azdoud@video-processor CentOSsimple]$ make
Scanning dependencies of target main
[100%] Building CXX object ...
opencv version ?
try to
cout << getBuildInformation();
and see, what kind of backend support was compiled in. (VideoIO section)I did I will but that in the question
also, 2.4.8 is stone age. please rather use latest 3.4 (a lot of work has been done on the video io recently.)
I can't understand where I missed it, I had followed this reference of Opencv at page 9.
it seems, your opencv libs came from some package manager, and do not have any support for video files.
and again, the reference is as outdated as your libs.
get something more up-to-date, anything else is a waste of time.