Ask Your Question
0

How to solve problem with VideoCapture loading in linux ?

asked 2018-06-11 06:32:11 -0600

azdoud.y gravatar image

updated 2018-06-11 06:50:48 -0600

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 ...
(more)
edit retag flag offensive close merge delete

Comments

opencv version ?

try to cout << getBuildInformation(); and see, what kind of backend support was compiled in. (VideoIO section)

berak gravatar imageberak ( 2018-06-11 06:39:56 -0600 )edit

I did I will but that in the question

azdoud.y gravatar imageazdoud.y ( 2018-06-11 06:49:48 -0600 )edit

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.)

berak gravatar imageberak ( 2018-06-11 06:57:28 -0600 )edit

I can't understand where I missed it, I had followed this reference of Opencv at page 9.

azdoud.y gravatar imageazdoud.y ( 2018-06-11 07:02:10 -0600 )edit

it seems, your opencv libs came from some package manager, and do not have any support for video files.

berak gravatar imageberak ( 2018-06-11 07:04:02 -0600 )edit

and again, the reference is as outdated as your libs.

get something more up-to-date, anything else is a waste of time.

berak gravatar imageberak ( 2018-06-11 07:05:43 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2018-06-20 14:30:48 -0600

azdoud.y gravatar image

updated 2018-06-21 04:28:34 -0600

I solved this issue by installing a new version of opencv3 and I had installed ffmpeg package from another repository.

using root privileges

1 - install EPEL repo on a CentOS 7 server.

#Install EPEL repo
yum -y install epel-release

2 - After enabling epel repo, install repository.

rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm

3 - Install ffmpeg packages, all the libraries needed will be installed.

 yum -y install ffmpeg ffmpeg-devel

4 - finally, check ffmpeg version

# ffmpeg
edit flag offensive delete link more
0

answered 2018-06-11 06:55:15 -0600

berak gravatar image

updated 2018-06-11 07:00:47 -0600

from your cmake output:

GStreamer:                   NO
FFMPEG:                      NO
V4L/V4L2:                    NO/YES

this means, you can use a webcam, but no video files at all.

you'll have to go all the way back and build the opencv libs with either gstreamer or ffmpeg support

edit flag offensive delete link more

Comments

I got problems I think I have to remove

[azdoud@video-processor ~]$ sudo yum install cmake git libgtk2.0-dev pkg-config                                                                                         libavcodec-dev libavformat-dev libswscale-dev 
Package cmake-2.8.12.2-2.el7.x86_64 already installed and latest version
Package git-1.8.3.1-13.el7.x86_64 already installed and latest version
No package libgtk2.0-dev available.
No package pkg-config available.
No package libavcodec-dev available.
No package libavformat-dev available.
No package libswscale-dev available.
Nothing to do
azdoud.y gravatar imageazdoud.y ( 2018-06-11 07:14:31 -0600 )edit

how to remove the cmake and start from the beginning ?

azdoud.y gravatar imageazdoud.y ( 2018-06-11 07:15:27 -0600 )edit

you don't have to remove cmake

No package libavcodec-dev available.

hmm, bad.

berak gravatar imageberak ( 2018-06-11 07:17:34 -0600 )edit

what should I do

azdoud.y gravatar imageazdoud.y ( 2018-06-11 07:19:16 -0600 )edit

get a more modern os

berak gravatar imageberak ( 2018-06-11 07:22:52 -0600 )edit

I have updated cmake from 2.8.12.2 to 3.11.3

[azdoud@video-processor CentOSsimple]$  cmake --version
cmake version 3.11.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

but I still getting

Video I/O:
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      NO
azdoud.y gravatar imageazdoud.y ( 2018-06-11 09:05:59 -0600 )edit

the cmake version was never your problem, lack of video related dependancies is.

berak gravatar imageberak ( 2018-06-11 09:09:50 -0600 )edit

changing the OS is not an option for me, I try to run the code with g++

 g++ `pkg-config --cflags --libs opencv` -std=c++11 main.cpp -o main

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
azdoud.y gravatar imageazdoud.y ( 2018-06-11 09:13:31 -0600 )edit

and again, you have to rebuild the opencv libs now, with dev packages for either gstreamer, ffmpeg, or the av* libs

berak gravatar imageberak ( 2018-06-11 09:19:02 -0600 )edit

I have looked for opencv.pc

[azdoud@video-processor core]$ sudo find / -name "*opencv.pc*"
[sudo] password for azdoud:
/opt/working/opencv/release/unix-install/opencv.pc
/usr/local/lib/pkgconfig/opencv.pc
[azdoud@video-processor core]$

then I set the variable PKG_CONFIG_PATH

[azdoud@video-processor CentOSsimple]$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
[azdoud@video-processor CentOSsimple]$ echo $PKG_CONFIG_PATH
/usr/local/lib/pkgconfig

but I've got another issue

[azdoud@video-processor CentOSsimple]$ g++ `pkg-config --cflags --libs opencv` -std=c++11 main.cpp -o main
[azdoud@video-processor CentOSsimple]$ ./main
./main: error while loading shared libraries: libopencv_calib3d.so.2.4: cannot open shared object file: No such file or directory
azdoud.y gravatar imageazdoud.y ( 2018-06-11 09:55:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-11 06:32:11 -0600

Seen: 2,673 times

Last updated: Jun 21 '18