├── docs ├── source │ ├── _static │ │ ├── 01-00.png │ │ ├── 01-01.png │ │ ├── 01-02.png │ │ ├── 01-03.png │ │ ├── 01-04.png │ │ ├── 01-05.png │ │ ├── 02-00.png │ │ ├── 02-01.png │ │ ├── 02-02.png │ │ ├── 02-03.png │ │ ├── 03-00.png │ │ ├── 03-01.png │ │ ├── 03-02.png │ │ ├── 03-03.png │ │ ├── 03-04.png │ │ ├── 03-05.png │ │ ├── 03-06.png │ │ ├── 03-07.png │ │ ├── 03-08.png │ │ ├── 03-09.png │ │ ├── 04-00.png │ │ ├── 04-01.png │ │ ├── 04-02.png │ │ ├── 05-00.png │ │ ├── 05-01.png │ │ ├── 05-02.png │ │ ├── 05-03.png │ │ ├── 06-00.png │ │ ├── 06-01.png │ │ ├── 06-02.png │ │ ├── 07-00.png │ │ ├── 07-01.png │ │ ├── 07-02.png │ │ ├── 08-00.png │ │ ├── 08-01.png │ │ ├── 08-02.png │ │ ├── 09-00.png │ │ ├── 09-01.png │ │ └── 09-02.png │ ├── index.rst │ ├── 02-first-java-application-with-opencv.rst │ ├── 06-face-detection-and-tracking.rst │ ├── 01-installing-opencv-for-java.rst │ ├── 08-object-detection.rst │ ├── 05-fourier-transform.rst │ ├── 07-image-segmentation.rst │ ├── 09-camera-calibration.rst │ ├── 03-first-javafx-application-with-opencv.rst │ ├── conf.py │ └── 04-opencv-basics.rst ├── make.bat └── Makefile ├── README.md ├── .gitattributes ├── .gitignore └── .readthedocs.yaml /docs/source/_static/01-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/01-00.png -------------------------------------------------------------------------------- /docs/source/_static/01-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/01-01.png -------------------------------------------------------------------------------- /docs/source/_static/01-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/01-02.png -------------------------------------------------------------------------------- /docs/source/_static/01-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/01-03.png -------------------------------------------------------------------------------- /docs/source/_static/01-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/01-04.png -------------------------------------------------------------------------------- /docs/source/_static/01-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/01-05.png -------------------------------------------------------------------------------- /docs/source/_static/02-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/02-00.png -------------------------------------------------------------------------------- /docs/source/_static/02-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/02-01.png -------------------------------------------------------------------------------- /docs/source/_static/02-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/02-02.png -------------------------------------------------------------------------------- /docs/source/_static/02-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/02-03.png -------------------------------------------------------------------------------- /docs/source/_static/03-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-00.png -------------------------------------------------------------------------------- /docs/source/_static/03-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-01.png -------------------------------------------------------------------------------- /docs/source/_static/03-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-02.png -------------------------------------------------------------------------------- /docs/source/_static/03-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-03.png -------------------------------------------------------------------------------- /docs/source/_static/03-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-04.png -------------------------------------------------------------------------------- /docs/source/_static/03-05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-05.png -------------------------------------------------------------------------------- /docs/source/_static/03-06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-06.png -------------------------------------------------------------------------------- /docs/source/_static/03-07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-07.png -------------------------------------------------------------------------------- /docs/source/_static/03-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-08.png -------------------------------------------------------------------------------- /docs/source/_static/03-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/03-09.png -------------------------------------------------------------------------------- /docs/source/_static/04-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/04-00.png -------------------------------------------------------------------------------- /docs/source/_static/04-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/04-01.png -------------------------------------------------------------------------------- /docs/source/_static/04-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/04-02.png -------------------------------------------------------------------------------- /docs/source/_static/05-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/05-00.png -------------------------------------------------------------------------------- /docs/source/_static/05-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/05-01.png -------------------------------------------------------------------------------- /docs/source/_static/05-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/05-02.png -------------------------------------------------------------------------------- /docs/source/_static/05-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/05-03.png -------------------------------------------------------------------------------- /docs/source/_static/06-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/06-00.png -------------------------------------------------------------------------------- /docs/source/_static/06-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/06-01.png -------------------------------------------------------------------------------- /docs/source/_static/06-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/06-02.png -------------------------------------------------------------------------------- /docs/source/_static/07-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/07-00.png -------------------------------------------------------------------------------- /docs/source/_static/07-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/07-01.png -------------------------------------------------------------------------------- /docs/source/_static/07-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/07-02.png -------------------------------------------------------------------------------- /docs/source/_static/08-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/08-00.png -------------------------------------------------------------------------------- /docs/source/_static/08-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/08-01.png -------------------------------------------------------------------------------- /docs/source/_static/08-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/08-02.png -------------------------------------------------------------------------------- /docs/source/_static/09-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/09-00.png -------------------------------------------------------------------------------- /docs/source/_static/09-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/09-01.png -------------------------------------------------------------------------------- /docs/source/_static/09-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencv-java/opencv-java-tutorials/HEAD/docs/source/_static/09-02.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenCV Java Tutorials 2 | ============================ 3 | 4 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 5 | 6 | Look at the tutorials on using OpenCV with Java (and JavaFX) at: http://opencv-java-tutorials.readthedocs.org/en/latest/index.html 7 | 8 | If you are interested in mantaining these repos, please, contact me: https://github.com/orgs/opencv-java/people 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must end with two \r 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | 45 | # ======= 46 | # Other 47 | # ======= 48 | build/ 49 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for Sphinx projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Set the OS, Python version and other tools you might need 8 | build: 9 | os: ubuntu-22.04 10 | tools: 11 | python: "3.11" 12 | # You can also specify other tool versions: 13 | # nodejs: "19" 14 | # rust: "1.64" 15 | # golang: "1.19" 16 | 17 | # Build documentation in the "docs/" directory with Sphinx 18 | sphinx: 19 | configuration: docs/source/conf.py 20 | 21 | # Optionally build your docs in additional formats such as PDF and ePub 22 | # formats: 23 | # - pdf 24 | # - epub 25 | 26 | # Optional but recommended, declare the Python requirements required 27 | # to build your documentation 28 | # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 29 | # python: 30 | # install: 31 | # - requirements: docs/requirements.txt 32 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. OpenCV Java Tutorials documentation master file, created by 2 | sphinx-quickstart on Wed Jun 17 09:26:35 2015. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to OpenCV Java Tutorials documentation! 7 | ================================================= 8 | 9 | .. note:: These tutorials were last updated on 2019: they use OpenCV 3.x and Java 7-8. They are currently unmaintained: if you are interested in maintaining them, contact me on `GitHub `_. 10 | 11 | Contents: 12 | 13 | .. toctree:: 14 | :maxdepth: 2 15 | 16 | 01-installing-opencv-for-java 17 | 02-first-java-application-with-opencv 18 | 03-first-javafx-application-with-opencv 19 | 04-opencv-basics 20 | 05-fourier-transform 21 | 06-face-detection-and-tracking 22 | 07-image-segmentation 23 | 08-object-detection 24 | 09-camera-calibration 25 | 26 | Indices and tables 27 | ================== 28 | 29 | * :ref:`genindex` 30 | * :ref:`modindex` 31 | * :ref:`search` 32 | -------------------------------------------------------------------------------- /docs/source/02-first-java-application-with-opencv.rst: -------------------------------------------------------------------------------- 1 | ======================================= 2 | Your First Java Application with OpenCV 3 | ======================================= 4 | 5 | .. note:: We assume that by now you have already read the previous tutorials. If not, please check previous tutorials at ``_. You can also find the source code and resources at ``_ 6 | 7 | A Java application with OpenCV 8 | ------------------------------ 9 | This tutorial will guide you through the creation of a simple Java console application using the OpenCV library in Eclipse. 10 | 11 | What we will do in this tutorial 12 | -------------------------------- 13 | In this guide, we will: 14 | * Create a new Java Project 15 | * Add a User Library to the project 16 | * Write some OpenCV code 17 | * Build and Run the application 18 | 19 | Create a New Project 20 | -------------------- 21 | Open Eclipse and create a new Java project; open the ``File`` menu, go to ``New`` and click on ``Java Project``. 22 | 23 | .. image:: _static/02-00.png 24 | 25 | In the ``New Java Project`` dialog write the name of your project and click on ``Finish``. 26 | 27 | Add a User Library 28 | ------------------ 29 | 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. 30 | Now you should be ready to add the library to your project. 31 | Inside Eclipse's ``Package Explorer`` just right-click on your project's folder and go to ``Build Path --> Add Libraries...``. 32 | 33 | .. image:: _static/02-01.png 34 | 35 | Select ``User Libraries`` and click on ``Next``, check the checkbox of the OpenCV library and click ``Finish``. 36 | 37 | .. image:: _static/02-02.png 38 | 39 | Create a simple application 40 | --------------------------- 41 | Now add a new Class to your project by right-clicking on your project's folder and go to ``New --> Class``. 42 | Write a name of your choice for both the package and the class then click on ``Finish``. 43 | Now we are ready to write the code of our first application. 44 | Let's start by defining the ``main`` method: 45 | 46 | .. code-block:: java 47 | 48 | public class HelloCV { 49 | public static void main(String[] args){ 50 | System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 51 | Mat mat = Mat.eye(3, 3, CvType.CV_8UC1); 52 | System.out.println("mat = " + mat.dump()); 53 | } 54 | } 55 | 56 | First of all we need to load the OpenCV Native Library previously set on our project. 57 | 58 | .. code-block:: java 59 | 60 | System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 61 | 62 | Then we can define a new Mat. 63 | 64 | .. 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 `_. 65 | 66 | .. code-block:: java 67 | 68 | Mat mat = Mat.eye(3, 3, CvType.CV_8UC1); 69 | 70 | The ``Mat.eye`` represents an identity matrix, we set the dimensions of it (3x3) and the type of its elements. 71 | 72 | As you can notice, if you leave the code just like this, you will get some error; this is due to the fact that eclipse can't resolve some variables. You can locate your mouse cursor on the words that seems to be an error(red underlined line) and wait for a dialog box to pop up and click on the voice ``Import...``. If you do that for all the variables we have added to the code the following rows: 73 | 74 | .. code-block:: java 75 | 76 | import org.opencv.core.Core; 77 | import org.opencv.core.CvType; 78 | import org.opencv.core.Mat; 79 | 80 | We can now try to build and run our application by clicking on the Run button. 81 | You should have the following output: 82 | 83 | .. image:: _static/02-03.png 84 | 85 | The whole source code is available on `GitHub `_. 86 | -------------------------------------------------------------------------------- /docs/source/06-face-detection-and-tracking.rst: -------------------------------------------------------------------------------- 1 | ============================= 2 | Face Detection and Tracking 3 | ============================= 4 | 5 | .. note:: We assume that by now you have already read the previous tutorials. If not, please check previous tutorials at ``_. You can also find the source code and resources at ``_ 6 | 7 | Goal 8 | ---- 9 | In this tutorial we are going to use well-known classifiers that have been already trained and distributed by OpenCV in order to detect and track a moving face into a video stream. 10 | 11 | Cascade Classifiers 12 | ------------------- 13 | The object recognition process (in our case, faces) is usually efficient if it is based on the features take-over which include additional information about the object class to be taken-over. In this tutorial we are going to use the *Haar-like features* and the *Local Binary Patterns* (LBP) in order to encode the contrasts highlighted by the human face and its spatial relations with the other objects present in the picture. 14 | Usually these features are extracted using a *Cascade Classifier* which has to be trained in order to recognize with precision different objects: the faces' classification is going to be much different from the car's classification. 15 | 16 | What we will do in this tutorial 17 | -------------------------------- 18 | In this guide, we will: 19 | * Insert a checkbox to select the Haar Classifier, detect and track a face, and draw a green rectangle around the detected face. 20 | * Insert a checkbox to select the LBP Classifier, detect and track a face, and draw a green rectangle around the detected face. 21 | 22 | Getting Started 23 | --------------- 24 | Let's create a new JavaFX project. In Scene Builder set the windows element so that we have a Border Pane with: 25 | 26 | - on TOP a VBox a HBox and a separator. In the HBox we are goning to need two checkboxes, the first one is to select the Haar Classifier and the second one is to select the LBP Classifier. 27 | 28 | .. code-block:: xml 29 | 30 | 31 | 32 | 33 | - in the CENTRE we are going to put an ImageView for the web cam stream. 34 | 35 | .. code-block:: xml 36 | 37 | 38 | 39 | - on the BOTTOM we can add the usual button to start/stop the stream 40 | 41 | .. code-block:: xml 42 | 43 |