In order to run any programs that utilize OpenCV you need to make sure that the OpenCV binary is on the java.library.path
aka. Environment Variable 'Path'
should contain the path to your opencv_java***.dll
file. Whenever java runs an external library it needs to know where to find the binary files for your specific OS. In my case, Windows 10 x64:
D:\software\opencv\build\java\x64\opencv_java420.dll
Make sure to change the directory above to match yours. Ensure you are using the proper binary for your OS.
If you're strictly looking for dependency management go to your OpenCV folder and find the opencv-***.jar
file inside the program directory:
D:\software\opencv\build\java\opencv-420.jar
We need to add this jar file as a dependency in Gradle, so in your build.gradle
file add the following to your dependencies:
compile fileTree(dir: 'D:\\software\\opencv\\build\\java\\', includes: ['*jar'])
Make sure to change the directory name above to match yours.
You can also keep the dependencies inside the project directory, creating a 'libs'
folder in your project root, and changing the above directory to libs
. This can be helpful for organization or maintaining the library version of software you might otherwise update.