Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation for Java + Gradle installation #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions docs/source/01-installing-opencv-for-java.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,99 @@ If you are using IntelliJ, you can specify the location of the library with the

.. image:: _static/01 - 04.png
.. image:: _static/01 - 05.png


Set up OpenCV for Java with Gradle
----------------------------------
Install gradle in your system as described in `Gradle's Website <https://gradle.org/install/>`_.

Create a new directory

.. code-block:: bash

mkdir opencv-with-gradle


Generate a gradle project:

.. code-block:: bash

cd opencv-with-gradle
gradle init


Follow the init wizard. Example:

.. code-block:: bash

Select type of project to generate:
...
2: application

Select implementation language:
...
3: Java

Select build script DSL:
...
2: Kotlin

Select test framework:
...
4: JUnit Jupiter
...
BUILD SUCCESSFUL in 1m 43s
2 actionable tasks: 2 executed

Edit the `build.gradle` file and add the OpenCV dependency in the `dependencies` block. Example:

.. code-block:: bash

dependencies {
...
// This dependency is used by the application.
implementation 'com.google.guava:guava:28.2-jre'

// Add the desired OpenCV version dependency
compile group: 'org.openpnp', name: 'opencv', version: '4.3.0-1'

// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
...
}

At this point the project is ready to be imported in your favorite IDE.

Copy link
Author

@rafacandev rafacandev Apr 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am debating if we should end the Set up OpenCV for Java with Gradle right here because the subsequent part overlaps with the Your First Java Application with OpenCV. The only advantage is that it demonstrates how to run the application with Gradle although most Gradle users should be confortable with that already. Thoughts?

You are also able to run your application directly via Gradle. During initialization, Gradle generated a main file, we can edit that file and test OpenCV integration. Example:

*src/main/java/opencv/with/gradle/App.java*

.. code-block:: java

package opencv.with.gradle;

import nu.pattern.OpenCV;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

public class App {
public static void main(String[] args){
OpenCV.loadShared();
Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("mat = " + mat.dump());
}
}


Run the application:

.. code-block:: bash

gradle run

mat = [ 1, 0, 0;
0, 1, 0;
0, 0, 1]

BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed