Skip to content

Commit

Permalink
start updating to OpenCV 3
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidr committed Oct 13, 2015
1 parent 2873852 commit 8d90cdd
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 264 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OpenCV Java Tutorials
============================

Look at the tutorials at the readthedocs link: http://opencv-java-tutorials.readthedocs.org/en/latest/index.html.
Look at the tutorials on using OpenCV with Java (and JavaFX) at: http://opencv-java-tutorials.readthedocs.org/en/latest/index.html
48 changes: 26 additions & 22 deletions docs/source/01 - Installing OpenCV for Java.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ Download the latest Java JDK at the `Oracle link <http://www.oracle.com/technetw
Install the latest Eclispe version.
-----------------------------------
Download the latest Eclipse version at the `Eclipse Download page <https://www.eclipse.org/downloads/>`_ choosing the ``Eclipse IDE for Java Developers`` version (suggested).
Put the downloaded folder wherever you want to. You don't need to install anything.
Extract the downloaded compressed file and put the resulting folder wherever you want to. You don't need to install anything. Alternatively, you can try the Eclipse installer.

Install Open CV 2.4.6 under Windows.
Install OpenCV 3.0 under Windows.
------------------------------------
First of all you should download the OpenCV library (version 2.4.6) from `here <http://opencv.org/downloads.html>`_.
Once you get the folder ``opencv`` put in wherever you prefer.
Now the only two things you will need are: the ``opencv-246.jar`` file located at ``\opencv\build\java`` and the dll library located at ``\opencv\build\java\x64`` (for 64-bit systems) or ``\opencv\build\java\x86`` (for 32-bit systems).
If not present create a ``data`` folder under ``\opencv``.
First of all you should download the OpenCV library (version 3.0) from `here <http://opencv.org/downloads.html>`_.
Then, extract the downloaded OpenCV file in a location of your choice. Once you get the folder ``opencv`` put in wherever you prefer.
Now the only two things that you will need are: the ``opencv-300.jar`` file located at ``\opencv\build\java`` and the ``opencv_java300.dll`` library located at ``\opencv\build\java\x64`` (for 64-bit systems) or ``\opencv\build\java\x86`` (for 32-bit systems).

Install Open CV 2.4.6 under Linux or Mac.
Install OpenCV 3.0 under Linux or Mac.
-----------------------------------------
The following instructions are useful if you wan to compile OpenCV under Windows.
As first step, if you don't have these already, download and install `CMake <http://www.cmake.org/download/>`_ and `Apache Ant <http://ant.apache.org/>`_.
Please, note: the following instructions are also useful if you want to compile OpenCV under Windows.
As first step, download and install `CMake <http://www.cmake.org/download/>`_ and `Apache Ant <http://ant.apache.org/>`_, if you don't have any of these. Download the OpenCV library from the `its website <http://opencv.org/downloads.html>`_.
Extract the downloaded OpenCV file in a location of your choice and open CMake ( cmake-gui ).
Put the location of the extracted OpenCV library in the ``Where is the source code field`` (e.g., /opencv2.4.6.1/) and put the destination directory of your build in the ``Where to build the binaries`` field (e.g., /opencv2.4.6.1/build), at last, check the ``Grouped`` and ``Advanced`` checkboxes.
Put the location of the extracted OpenCV library in the ``Where is the source code field`` (e.g., /opencv/) and insert the destination directory of your build in the ``Where to build the binaries`` field (e.g., /opencv/build).
At last, check the ``Grouped`` and ``Advanced`` checkboxes.

.. image:: _static/01-00.png

Now press ``Configure`` and use the default compilers for ``Unix Makefiles``.
In the ``Ungrouped Entries`` group, insert the path to the Apache Ant executable (e.g., ``/apacheant1.9.2/bin/ant``).
Now press ``Configure`` and use the default compilers for ``Unix Makefiles``. Please, be sure to have installed a C/C++ compiler.
In the ``Ungrouped Entries`` group, insert the path to the Apache Ant executable (e.g., ``/apache-ant-1.9.6/bin/ant``).
In the ``BUILD`` group, unselect:
* ``BUILD_PERF_TESTS``.
* ``BUILD_SHARED_LIBRARY`` to make the Java bindings dynamic library all-sufficient.
Expand All @@ -41,26 +41,30 @@ In the ``BUILD`` group, unselect:

In the ``CMAKE`` group, set to ``Debug`` (or ``Release``) the ``CMAKE_BUILD_TYPE``
In the ``JAVA`` group:
insert the Java AWT include path (e.g., ``/usr/lib/jvm/java7oracle/include/``)
insert the Java include path (e.g., ``/usr/lib/jvm/java7oracle/include/``)
insert the alternative Java include path (e.g., ``/usr/lib/jvm/java7oracle/include/linux``)
Once we have pressed ``Generate`` twice the CMake window should appear with a white background. Now close CMake.
insert the Java AWT include path (e.g., ```/usr/lib/jvm/java-1.8.0/include/``)
insert the Java AWT library path (e.g., ``/usr/lib/jvm/java-1.8.0/include/jawt.h``)
insert the Java include path (e.g., ``/usr/lib/jvm/java-1.8.0/include/``)
insert the alternative Java include path (e.g., ``/usr/lib/jvm/java-1.8.0/include/linux``)
insert the JVM library path (e.g., ``/usr/lib/jvm/java-1.8.0/include/jni.h``)

Press ``Configure`` twice, and the CMake window should appear with a white background. Now, press ``Generate`` and close CMake.

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

Now open the terminal , go to the ``build`` folder of OpenCV and build everything with the command: ``make -j8`` (wait for the process to be completed...).
If everything went well you should have ``opencv-246.jar`` and ``libopencv_java246.so`` files in the ``/opencv-2.4.6.1/build/bin`` directory and the ``data`` folder in the ``/opencv-2.4.6.1/`` directory.
Now open the terminal, go to the ``build`` folder of OpenCV and compile everything with the command: ``make -j``. Notice that the `-j` flag tells `make` to run in parallel with the maximum number of allowed job threads, which makes the build theoretically faster.
Wait for the process to be completed...
If everything went well you should have ``opencv-300.jar`` in the ``/opencv/build/bin`` directory and ``libopencv_java300.so`` in the ``/opencv/build/lib`` directory. This is everything you need.

Set up OpenCV for Java in Eclipse
---------------------------------
Open Eclipse and select a workspace of your choice. Create a User Library, ready to be used on all the next projects: go to ``Window > Preferences...``.
Open Eclipse and select a workspace of your choice. Create a User Library, ready to be used on all your next projects: go to ``Window > Preferences...``.

.. image:: _static/01 - 02.png

From the menu navigate under ``Java > Build Path > User Libraries`` and choose ``New...``.
Enter a name for the library (e.g., opencv246) and select the newly created user library.
Choose ``Add External JARs...``, browse to select ``opencv246.jar``.
After adding the jar, extend it and select ``Native library location`` and press ``Edit...``.
Enter a name for the library (e.g., opencv) and select the newly created user library.
Choose ``Add External JARs...``, browse to select ``opencv-300.jar`` from your computer.
After adding the jar, extend it, select ``Native library location`` and press ``Edit...``.

.. image:: _static/01 - 03.png

Expand Down
39 changes: 12 additions & 27 deletions docs/source/02 - First Java Application with OpenCV.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
==================================
First Java Application with OpenCV
==================================
=======================================
Your First Java Application with OpenCV
=======================================

.. note:: We assume that by now you have already read the previous tutorials. If not, please check previous tutorials at `<http://opencv-java-tutorials.readthedocs.org/en/latest/index.html>`_. You can also find the source code and resources at `<https://github.com/opencv-java/>`_

Introduction to a OpenCV application with Java
----------------------------------------------
This tutorial will guide you through the creation of a simple Java console application using the OpenCV library by mean of Eclipse.
A Java application with OpenCV
------------------------------
This tutorial will guide you through the creation of a simple Java console application using the OpenCV library in Eclipse.

What we will do in this tutorial
--------------------------------
In this guide, we will:
* Create a new Java Project
* Add a User Library to the project
* Write some OpenCV code
* Build and Run the application

Create a New Project
Expand All @@ -25,7 +26,7 @@ In the ``New Java Project`` dialog write the name of your project and click on `

Add a User Library
------------------
If you followed the previous tutorial (``Installing OpenCV for Java``), you should already have the OpenCV library set in your workspace's user libraries, if not please check out the previous tutorial.
If you followed the previous tutorial (``Installing OpenCV for Java``), you should already have the OpenCV library set in your workspace's user libraries; if not please check out the previous tutorial.
Now you should be ready to add the library to your project.
Inside Eclipse's ``Package Explorer`` just right-click on your project's folder and go to ``Build Path --> Add Libraries...``.

Expand All @@ -44,23 +45,23 @@ Let's start by define the ``main`` method:

.. code-block:: java
public class MyFirstApp {
public class HelloCV {
public static void main(String[] args){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("mat = " + mat.dump());
}
}
First of all we need to load the Native Library previously set on our project.
First of all we need to load the OpenCV Native Library previously set on our project.

.. code-block:: java
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Then we can define a new Mat.

.. note:: The class **Mat** represents an n-dimensional dense numerical single-channel or multi-channel array. It can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms. For more details check out the OpenCV `page <http://docs.opencv.org/modules/core/doc/basic_structures.html>`_.
.. note:: The class **Mat** represents an n-dimensional dense numerical single-channel or multi-channel array. It can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms. For more details check out the OpenCV `page <http://docs.opencv.org/3.0.0/dc/d84/group__core__basic.html>`_.

.. code-block:: java
Expand All @@ -81,20 +82,4 @@ You should have the following output:

.. image:: _static/02-03.png

Here I put the whole source `code <https://github.com/opencv-java/getting-started/blob/master/HelloCV/src/it/polito/elite/teaching/cv/HelloCV.java>`_:

.. code-block:: java
package mypackage;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class MyFirstApp {
public static void main(String[] args){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("mat = " + mat.dump());
}
}
The whole source code is available on `GitHub <https://github.com/opencv-java/getting-started/blob/master/HelloCV/>`_.

0 comments on commit 8d90cdd

Please sign in to comment.