Professional Documents
Culture Documents
Textbook Java Image Processing Recipes With Opencv and JVM 1St Edition Nicolas Modrzyk Ebook All Chapter PDF
Textbook Java Image Processing Recipes With Opencv and JVM 1St Edition Nicolas Modrzyk Ebook All Chapter PDF
https://textbookfull.com/product/java-image-processing-recipes-
with-opencv-and-jvm-modrzyk/
https://textbookfull.com/product/image-processing-dealing-with-
texture-second-edition-maria-petrou/
https://textbookfull.com/product/building-telegram-bots-develop-
bots-in-12-programming-languages-using-the-telegram-bot-api-1st-
edition-nicolas-modrzyk/
https://textbookfull.com/product/r2dbc-revealed-reactive-
relational-database-connectivity-for-java-and-jvm-
programmers-1st-edition-robert-hedgpeth/
Learning OpenCV 3 Computer Vision in C with the OpenCV
Library 1st Edition Adrian Kaehler
https://textbookfull.com/product/learning-opencv-3-computer-
vision-in-c-with-the-opencv-library-1st-edition-adrian-kaehler/
https://textbookfull.com/product/natural-language-processing-
with-java-community-experience-distilled-1st-edition-reese-
richard-m/
https://textbookfull.com/product/image-operators-image-
processing-in-python-1st-edition-jason-m-kinser/
https://textbookfull.com/product/image-operators-image-
processing-in-python-first-edition-kinser/
https://textbookfull.com/product/learn-to-program-with-kotlin-
from-the-basics-to-projects-with-text-and-image-processing-1st-
edition-tim-lavers/
Contents
1. Cover
2. Front Matter
3. 1. OpenCV on the JavaVM
4. 2. OpenCV with Origami
5. 3. Imaging Techniques
6. 4. Real-Time Video
7. Back Matter
Landmarks
1. Cover
2. Table of Contents
3. Body Matter
Nicolas Modrzyk
This work is subject to copyright. All rights are reserved by the Publisher,
whether the whole or part of the material is concerned, specifically the rights
of translation, reprinting, reuse of illustrations, recitation, broadcasting,
reproduction on microfilms or in any other physical way, and transmission or
information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than
use a trademark symbol with every occurrence of a trademarked name, logo,
or image we use the names, logos, and images only in an editorial fashion and
to the benefit of the trademark owner, with no intention of infringement of the
trademark. The use in this publication of trade names, trademarks, service
marks, and similar terms, even if they are not identified as such, is not to be
taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and
accurate at the date of publication, neither the authors nor the editors nor the
publisher can accept any legal responsibility for any errors or omissions that
may be made. The publisher makes no warranty, express or implied, with
respect to the material contained herein.
“Well, son, you know, it’s not only about the right tool, it’s
about the right tool at the right time.”
The road of this first chapter will take you to the door of the
similarly JVM-based language Clojure, which will give your
OpenCV code instant visual feedback for great creativity. That will
be for Chapter 2.
SOLUTION
Leiningen is a build tool targeting (mostly) the JavaVM. It is
similar in that sense to other famous ones like (Remember? The)
Ant, (Oh My God) Maven, and (it used to work) Gradle.
Once the leiningen command is installed, you can use it to
create new JavaVM projects based on templates, and run them
without the usual headaches.
This recipe shows how to install Leiningen quickly and run
your first Java program with it.
HOW IT WORKS
You will start by simply installing Leiningen where you need it,
and then creating a blank Java project with it.
NOTE Installing Leiningen requires Java 8 to be installed on
your machine. Note also that due to the fact that Java 9 is
solving old problems by breaking current solutions, we will
choose to keep Java 8 for now.
Installing Leiningen
The Leiningen web site itself is hosted and can be found at
https://leiningen.org/
At the top of the Leiningen page, you can find the four easy
steps to install the tool manually yourself.
So here it goes, on macOS and Unix :
1 Download the lein script
. 1. https://raw.githubusercontent.com/technomancy
/leiningen/stable/bin/lein
2
Place it on your $PATH where your shell can find it (e.g., ~/bin)
.
3
Set it to be executable (chmod a+x ~/bin/lein)
.
4
Run it from a terminal, lein, and it will download the self-install
.
package
And on Windows:
1 Download the lein.bat batch script
. 1. https://raw.githubusercontent.com/technomancy
/leiningen/stable/bin/lein.bat
2
Place it on your C:/Windows/System32 folder, using admin
.
permission
3
Open a command prompt and run it, lein, and it will download the
.
self-install package
1 directory, 2 files
For peace of mind, we will keep the code of this first Java
example pretty simple.
public class Hello {
public static void main(String[] args) {
System.out.println("beginning of a
journey");
}
}
Now let’s see the content of the text file named project.clj in a
bit of detail:
(defproject hellojava "0.1"
:java-source-paths ["java"]
:dependencies [[org.clojure/clojure "1.8.0"]]
:main Hello)
This is actually Clojure code, but let’s simply think of it as a
domain specific language (DSL), a language to describe a project
in simple terms.
For convenience, each term is described in Table 1-1.
Word Usage
:main The name of the Java class that will be executed by default
.
├── dev
├── java
│ └── Hello.java
├── project.clj
├── src
├── target
│ ├── classes
│ │ ├── Hello.class
You may ask: “What if I have multiple Java files, and want to
run a different one than the main one?”
This is a very valid question, as you will be probably doing
that a few times in this first chapter to write and run the different
code samples.
Say you write a second Java class in a file named Hello2.java in
the same Java folder, along with some updated journey content.
import static java.lang.System.out;
public class Hello2 {
public static void main(String[] args) {
String[] text = new String[]{
"Sometimes it's the journey that ",
"teaches you a lot about your
destination.",
"--",
"- Drake"};
for(String t : text) out.println(t);
}
}
To run that exact main method from the Hello2.java file , you
would call lein run with the optional –m option, where m stands
for main, and then the name of the main Java class to use.
lein run –m Hello2
SOLUTION
Recipe 1-1 presented Leiningen to help you with all the basic
required setup. From there, you can add a dependency on the
OpenCV C++ library and its Java wrapper.
HOW IT WORKS
For this first OpenCV example, we will get set up with a Leiningen
project template , where the project.clj file and the project folders
are already defined for you. Leiningen project templates do not
have to be downloaded separately and can be called upon to
create new projects using Leiningen’s integrated new command.
To create this project on your local machine, on the command
line , let’s call the command of lein.
Whether on Windows or Mac, the command gives
lein new jvm-opencv hellocv
That does not seem too impressive, but actually those are
almost the same as the two files from the previous recipe: a
project descriptor and a Java file.
The project.clj content is a slightly modified version from
before:
(defproject hellocv "0.1.0-SNAPSHOT"
:java-source-paths ["java"]
:main HelloCv
:repositories [
["vendredi"
"http://hellonico.info:8081/repository/hellonico/"]]
:dependencies [[org.clojure/clojure "1.8.0"]
[opencv/opencv "3.3.1"]
[opencv/opencv-native "3.3.1"]])