@@ -13,8 +13,6 @@ We will use either `Eclipse <http://eclipse.org/>`_, `Apache Ant <http://ant.apa
13
13
`Simple Build Tool (SBT) <http://www.scala-sbt.org/ >`_ to build the application.
14
14
15
15
For further reading after this guide, look at the :ref: `Android_Dev_Intro ` tutorials.
16
- The interfaces for desktop Java and Android are nearly identical. You may also consult the
17
- `Java wiki page <http://code.opencv.org/projects/opencv/wiki/Java_API_howto >`_.
18
16
19
17
What we'll do in this guide
20
18
***************************
@@ -39,15 +37,13 @@ The most simple way to get it is downloading the appropriate package of **versio
39
37
40
38
.. note :: Windows users can find the prebuilt files needed for Java development in the
41
39
:file: `opencv/build/java/ ` folder inside the package.
42
- Other OSes users (and Windows ones optionally) can build OpenCV from sources locally .
40
+ For other OSes it's required to build OpenCV from sources.
43
41
44
- Another option to get OpenCV sources is to clone OpenCV git repository,
45
- either the primary one at ``git://code.opencv.org/opencv.git `` or
46
- its `Github mirror <https://github.com/Itseez/opencv/ >`_.
47
- Be aware that Java is currently only supported on the ``2.4 `` git branch and not yet merged to the ``master ``.
42
+ Another option to get OpenCV sources is to clone `OpenCV git repository
43
+ <https://github.com/Itseez/opencv/> `_.
48
44
In order to build OpenCV with Java bindings you need :abbr: `JDK ( Java Development Kit ) `
49
45
(we recommend `Oracle/Sun JDK 6 or 7 <http://www.oracle.com/technetwork/java/javase/downloads/ >`_),
50
- `Apache Ant <http://ant.apache.org/ >`_ and `` Python ` ` v2.6 or higher to be installed.
46
+ `Apache Ant <http://ant.apache.org/ >`_ and `Python ` v2.6 or higher to be installed.
51
47
52
48
Build OpenCV
53
49
############
@@ -110,7 +106,7 @@ Create a simple Java sample and an Ant build file for it
110
106
.. note ::
111
107
The described sample is provided with OpenCV library in the :file: `opencv/samples/java/ant ` folder.
112
108
113
- * Create a folder where you'll create this sample application.
109
+ * Create a folder where you'll develop this sample application.
114
110
115
111
* In this folder create an XML file with the following content using any text editor:
116
112
@@ -180,7 +176,7 @@ Create a simple Java sample and an Ant build file for it
180
176
See `Ant documentation <http://ant.apache.org/manual/ >`_ for detailed description
181
177
of its build file format.
182
178
183
- * Create an :file: `src ` folder nect to the :file: `build.xml ` file and a :file: `SimpleSample.java ` file in it.
179
+ * Create an :file: `src ` folder next to the :file: `build.xml ` file and a :file: `SimpleSample.java ` file in it.
184
180
185
181
* Put the following Java code into the :file: `SimpleSample.java ` file:
186
182
.. code-block :: java
@@ -205,7 +201,7 @@ Create a simple Java sample and an Ant build file for it
205
201
206
202
}
207
203
208
- * run the following command in console in the folder containing :file: `build.xml `:
204
+ * Run the following command in console in the folder containing :file: `build.xml `:
209
205
.. code-block :: bash
210
206
211
207
ant -DocvJarDir=path/to/dir/containing/opencv-244.jar -DocvLibDir=path/to/dir/containing/opencv_java244/native/library
@@ -226,6 +222,8 @@ Create a simple Java sample and an Ant build file for it
226
222
Create a simple Java project in Eclipse
227
223
***************************************
228
224
225
+ Now let's look at the possiblity of using OpenCV in Java when developing in Eclipse IDE.
226
+
229
227
* Create a new Eclipse workspace
230
228
* Create a new Java project via :guilabel: `File --> New --> Java Project `
231
229
@@ -292,7 +290,7 @@ Create a simple Java project in Eclipse
292
290
:alt: Eclipse: Main class
293
291
:align: center
294
292
295
- * Put a simple OpenCV calls there, e.g.:
293
+ * Put some simple OpenCV calls there, e.g.:
296
294
.. code-block :: java
297
295
298
296
import org.opencv.core.CvType ;
@@ -306,7 +304,7 @@ Create a simple Java project in Eclipse
306
304
}
307
305
}
308
306
309
- * Press :guilabel: `Run ` button and see the identity matrix content in the Eclipse ``Console `` window.
307
+ * Press :guilabel: `Run ` button and find the identity matrix content in the Eclipse ``Console `` window.
310
308
311
309
.. image :: images/eclipse_run.png
312
310
:alt: Eclipse: run
@@ -320,7 +318,7 @@ those unfamiliar with this build tool. We're using SBT because it is particularl
320
318
321
319
First, download and install `SBT <http://www.scala-sbt.org/ >`_ using the instructions on its `web site <http://www.scala-sbt.org/ >`_.
322
320
323
- Next, navigate to a new directory where you'd like the application source to live (outside opencv).
321
+ Next, navigate to a new directory where you'd like the application source to live (outside :file: ` opencv ` dir ).
324
322
Let's call it "JavaSample" and create a directory for it:
325
323
326
324
.. code-block :: bash
@@ -384,11 +382,11 @@ You should see something like this:
384
382
:alt: SBT output
385
383
:align: center
386
384
387
- You can now import the SBT project using :guilabel: `Import ... -> Existing projects into workspace ` from Eclipse .
385
+ You can now import the SBT project to Eclipse using :guilabel: `Import ... -> Existing projects into workspace `.
388
386
Whether you actually do this is optional for the guide;
389
- we'll be using SBT to build the project, so if you choose to use Eclipse it will just be as a text editor.
387
+ we'll be using SBT to build the project, so if you choose to use Eclipse it will just serve as a text editor.
390
388
391
- To test everything is working, create a simple "Hello OpenCV" application.
389
+ To test that everything is working, create a simple "Hello OpenCV" application.
392
390
Do this by creating a file :file: `src/main/java/HelloOpenCV.java ` with the following contents:
393
391
394
392
.. code-block :: java
@@ -432,10 +430,11 @@ Next, create the directory src/main/resources and download this Lena image into
432
430
:alt: Lena
433
431
:align: center
434
432
435
- Make sure it's called :file: `"lena.bmp " `.
433
+ Make sure it's called :file: `"lena.png " `.
436
434
Items in the resources directory are available to the Java application at runtime.
437
435
438
- Next, copy :file: `lbpcascade_frontalface.xml ` into the resources directory:
436
+ Next, copy :file: `lbpcascade_frontalface.xml ` from :file: `opencv/data/ ` into the :file: `resources `
437
+ directory:
439
438
440
439
.. code-block :: bash
441
440
@@ -465,7 +464,7 @@ Now modify src/main/java/HelloOpenCV.java so it contains the following Java code
465
464
// Create a face detector from the cascade file in the resources
466
465
// directory.
467
466
CascadeClassifier faceDetector = new CascadeClassifier (getClass(). getResource(" /lbpcascade_frontalface.xml" ). getPath());
468
- Mat image = Highgui . imread(getClass(). getResource(" /lena.bmp " ). getPath());
467
+ Mat image = Highgui . imread(getClass(). getResource(" /lena.png " ). getPath());
469
468
470
469
// Detect faces in the image.
471
470
// MatOfRect is a special container class for Rect.
@@ -518,3 +517,7 @@ It should also write the following image to :file:`faceDetection.png`:
518
517
.. image :: images/faceDetection.png
519
518
:alt: Detected face
520
519
:align: center
520
+
521
+ You're done!
522
+ Now you have a sample Java application working with OpenCV, so you can start the work on your own.
523
+ We wish you good luck and many years of joyful life!
0 commit comments