'How to load video in OpenCV (Java)
I'm trying to load a video file in OpenCV Java, and have narrowed down my issue to the following code:
import org.opencv.core.Core;
import org.opencv.videoio.VideoCapture;
public class OpenCVTest {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.loadLibrary("opencv_videoio_ffmpeg455_64");
VideoCapture capture = new VideoCapture("myVideoFile.avi");
System.out.println(capture.isOpened());
}
}
Of course, this always prints out "false". Accessing my computer's camera with new VideoCapture(0)
works fine. After scouring the internet, I'm thoroughly confused as to why loading a video won't work. I followed guides that suggested I needed to add "opencv_videoio_ffmpeg455_64.dll" to my path variable and call System.loadLibrary
. I'm new to this, and to be honest, I don't understand what loadLibrary
does, or what could be wrong with my setup and code. Any ideas? Thanks in advance.
Solution 1:[1]
Here is the answer from similar problem
- load the ffmpeg library System.loadLibrary("opencv_ffmpeg300_64");
- Open the file: VideoCapture vC = new VideoCapture("res/video.mp4");
- Copy opencv_ffmpeg300_64.dll from opencv\build\x64\vc11\bin to opencv\build\java\x64
Please note that 64 and .dll may differ from an OS to another, those are for Windows x64
Solution 2:[2]
As it turns out, I was using the wrong file path. I (wrongly) assumed that new VideoCapture("my file")
would search for "my file" in the directory where the compiled .class files are placed, when in fact it searches in the project root directory. There is no need to call System.loadLibrary("opencv_videoio_ffmpeg455_64");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Andrew |