Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Video capture from file won't open successfully

Tags:

c++

opencv

I've written this in C++ (VS2012) using the OpenCV library (2.4.6).

#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>    
int main(){
    Mat image;
    VideoCapture cap;
    cap.open("test.avi");
    if(!cap.isOpened()){
        cout<< "Capture not open \n";
        cin.get();
    }
    cvNamedWindow("Video Output");
    while(1){
        cap >> image;
        imshow("Video Output",image);
        waitKey(30);
    }
}

Running it, the video capture fails to open. test.avi is located in the same directory as the executable, and running it ind Debug/Release/outside the IDE makes no difference. The OpenCv DLLs and the video file are here: https://www.dropbox.com/sh/16c04d97iw90gtk/88fQ4BLbfl#/ What could I be doing wrong?

EDIT: As seen in questions on the OpenCV Q&A site, I've copied the opencv_ffmpeg DLL to the folder with my executable. Now it only works outside the IDE (VS2012)

like image 760
Tim Avatar asked Jan 15 '14 05:01

Tim


People also ask

How do I access video on OpenCV?

In OpenCV, a video can be read either by using the feed from a camera connected to a computer or by reading a video file. The first step towards reading a video file is to create a VideoCapture object. Its argument can be either the device index or the name of the video file to be read.


1 Answers

You should copy the opencv_ffmpeg DLL in your targetDir, in this case the Debug executable folder, other than the Release one

like image 57
Michele Avatar answered Oct 31 '22 02:10

Michele