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)
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.
You should copy the opencv_ffmpeg DLL in your targetDir, in this case the Debug executable folder, other than the Release one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With