Skip to content

Commit 384fc32

Browse files
authored
Add info about use in Gradle build scripts and as a Java library
1 parent 518f10f commit 384fc32

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,65 @@ linux64
5858
```
5959
java -jar opencv-installer --version <version> --platform <platform> --java --jni --headers --natives --overwrite
6060
```
61+
62+
## Using the installer in Gradle build scripts
63+
64+
```groovy
65+
buildscript {
66+
repositories {
67+
maven {
68+
url 'https://github.com/SamCarlberg/opencv-maven/raw/mvn-repo'
69+
}
70+
}
71+
dependencies {
72+
classpath group: 'edu.wpi.first.wpilib.opencv', name: 'opencv-installer', version: '+'
73+
}
74+
}
75+
76+
import edu.wpi.first.wpilib.opencv.installer.PlatformDetector
77+
78+
def openCvPlatform = PlatformDetector.getPlatform()
79+
def openCvVersion = "3.1.0"
80+
81+
dependencies {
82+
compile group: 'org.opencv', name: 'opencv-java', version: openCvVersion
83+
runtime group: 'org.opencv', name: 'opencv-jni', version: "${openCvPlatform}-${openCvVersion}"
84+
...
85+
}
86+
```
87+
88+
## Using the installer as Java library
89+
90+
First, add
91+
92+
```groovy
93+
repositories {
94+
maven {
95+
url 'https://github.com/SamCarlberg/opencv-maven/raw/mvn-repo'
96+
}
97+
}
98+
dependencies {
99+
compile group: 'edu.wpi.first.wpilib.opencv', name: 'opencv-installer', version: '+'
100+
}
101+
```
102+
103+
to your `build.gradle` file.
104+
105+
Then to make sure that OpenCV is installed prior to using any OpenCV code:
106+
107+
```java
108+
import edu.wpi.first.wpilib.opencv.installer.Installer;
109+
import org.opencv.core.Core;
110+
111+
class Main {
112+
113+
static {
114+
Installer.setVersion(Core.VERSION);
115+
Installer.installJni();
116+
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
117+
}
118+
119+
}
120+
```
121+
122+
This will install OpenCV on the current system if the JNI bindings are available for it. If there aren't any JNI bindings, a `FileNotFoundException` will be thrown by the call to `Installer.installJni()` (you may wrap this in a `try-catch` block if you want to do something with this exception, such as logging it)

0 commit comments

Comments
 (0)