Use OpenCV_Contrib (ArUco) in Java! (Part 1-Build) (OpenCV-3.4.4)

Introduction (?)

In my research, I came across a situation where it would be better to use AR markers, so I searched for a library that could recognize AR markers and came across something called ArUco. This article shows you how to get started with the ArUco library. I'm using Java because I can't use C / C ++ / C #.

I also declare that using OpenCV in Java can be a hassle. It seems that very few people are using it. There are few code examples and questions even in English. However, it runs faster than Python, so I think it has many uses.

OpenCV OpenCV is an open source library for image processing and is fairly widely used. The ideas are so broadly covered that you can generally combine functions.

OpenCV_Contrib OpenCV_Contrib is a library that focuses on the latest technology in OpenCV and is treated as an auxiliary. Also, if you only use the main body, you do not need to build. You can get it by downloading from OpenCV.org (official page). However, it seems that OpenCV_Contrib needs to be built by myself probably because it is treated as an auxiliary. This page describes how to build this

ArUco A library that can do AR. You can generate and recognize AR markers. (The code etc. will be described next time.)

Preparation

download

What to download Description
OpenCV project source Be sure to match the version with Conrib.
I am Version: 3.4.I'm using 4.
OpenCV_Contrib project source Be sure to match the version with Conrib.
I am Version: 3.4.I'm using 4.
CMake Appropriately.
Visual Studio I used Visual Studio Community 2017.(C++I think I had to put in a compiler ...)
Python You probably need it even when using Java.
I am Version: 3.7.I'm using 1.
JDK I am using Java8u191.
Ant I am Version: 1.10.I am using 5.

Installation

Expand the project source of OpenCV and OpenCV_Contrib. Please install CMake and Visual Studio by yourself.

Java, Ant environment variables

Is this a songwriter unexpectedly? So, if you do not set it correctly, you will not be able to build. (I was addicted here)

What to download Description
ANT_HOME The extracted Ant folder.
(ex: C:\SOFT_File\apache-ant-1.10.5)
JAVA_HOME The folder where Java is installed.
(ex: C:\Program Files\Java\jdk1.8.0_191)
Path The following contentsadd toplease.
C:\Program Files\CMake\bin, %ANT_HOME%\bin, %JAVA_HOME%\bin
(ex: C:\Program Files\CMake\bin;%ANT_HOME%\bin;%JAVA_HOME%\bin; )

Run CMake

It seems that you have to prepare for the build with CMake before building, so I will do it.

item value
Where is the source code Specify the path of the extracted folder.
(ex: C:/SOFT_File/opencv-3.4.4)
Where to build the binaries I created a build folder under the extracted main library and specified the path of this folder.
(ex: C:/SOFT_File/opencv-3.4.4/build)

After specifying these, press "Configure". At this time, specify the compiler. This time we will use Visual Studio for the build, so let's specify Visual Studio (the one that matches the version). (I chose "Visual Studio 2017 Win64")

Then, a red one pops out, but don't worry. Enable both the "Grouped" and "Advanced" checkboxes.

item value
OPENCV_EXTRA_MODULES_PATH Deployed OpenCV_In the parent folder of ContribModules belowIs specified.
(Deployed OpenCV_Not the parent folder of Contrib)

Press Configure again.

Disable the "BUILD_SHARED_LIBS" checkbox. (Reference: http://answers.opencv.org/question/189941/java-cant-find-dependent-libraries/)

Press Configure again.

Please enable the check box of "BUILD_FAT_JAVA_LIB".

Press Configure again.

At this time, if there is no red object, it is OK. If so, please correct it.

Now check the log output. In particular, make sure that Java is as follows. (It's just an example)

  Java:                          export all functions
    ant:                         C:/SOFT_File/apache-ant-1.10.5/bin/ant.bat (ver 1.10.5)
    JNI:                         C:/Program Files/Java/jdk1.8.0_191/include C:/Program Files/Java/jdk1.8.0_191/include/win32 C:/Program Files/Java/jdk1.8.0_191/include
    Java wrappers:               YES
    Java tests:                  YES

Full text: https://pastebin.com/u2Qiy5EL

If there is no problem, Press "Generate".

When you're done, press "Open Project". This will launch Visual Studio. (To the next section)

Build with Visual Studio

Wait for a while to read various things. Set "Release" / "Debug" in the middle to "Release". Also, please set the next one to "x64". Press "Build"-> "Batch Build" on the menu bar above. Check both ʻALL_BUILD and ʻINSTALL and execute.

If you wait for a while (about 1h?), It should be created in the folder specified by Where to build the binaries in CMake (ex: (OpenCV extraction folder) / build / install).

SC_java_2018-12-8_0-25-40_No-00.png

If it's not generated, or if you have problems with this article, please leave a comment.

reference

-OpenCV 3.4.1 and opencv_contrib environment construction on Windows 10 Recommended because it has new content and many images are used.

Building OpenCV Using MinGW on Windows --You, Myself and CommunityBuilding Java Wrapper For OpenCV --You, Myself and Community ↑ It was the easiest to understand as a Java version.

OpenCV environment construction (OpenCV 3.0 / 3.1) --Build InsiderFirst OpenCV development-Customization of OpenCV using CMake [OpenCV 3.1.0] --Build Insider ) -Installing OpenCV for Java — OpenCV Java Tutorials 1.0 documentationOpenCV.org (official page)OpenCV --WikipediaIntroduction to OpenCV for Java

next time

Next time, I would like to actually run a light program.

Use OpenCV_Contrib (ArUco) in Java! (Part 2-Programming)

Recommended Posts

Use OpenCV_Contrib (ArUco) in Java! (Part 1-Build) (OpenCV-3.4.4)
Use OpenCV_Contrib (ArUco) in Java! (Part 2-Programming)
Use OpenCV in Java
Use PreparedStatement in Java
Use Redis Stream in Java
Let's use Twilio in Java! (Introduction)
[Java] Do not use "+" in append!
Use composite keys in Java Map.
How to use classes in Java?
Creating lexical analysis in Java 8 (Part 2)
Java + OpenCV 3.X in IntelliJ IDEA
Do you use Stream in Java?
Creating lexical analysis in Java 8 (Part 1)
JSON in Java and Jackson Part ③ Embed JSON in HTML and use it from JavaScript
Multilingual Locale in Java How to use Locale
[Java] Use cryptography in the standard library
Use "Rhino" which runs JavaScript in Java
I did OpenCV camera calibration in Java
Build OpenCV with Java Wrapper on Ubuntu 18.04
Creating a matrix class in Java Part 1
Detect similar videos in Java and OpenCV rev.2
[Gradle] Build operations often performed in Java projects
[Java] Use of final in local variable declaration
Detect similar videos in Java and OpenCV rev.3
What I learned in Java (Part 2) What are variables?
[JAVA] [Spring] [MyBatis] Use IN () with SQL Builder
Detect similar videos in Java and OpenCV rev.1
Why use setters/getters instead of public/private in Java
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
java practice part 1
[Java] Use Collectors.collectingAndThen
Pi in Java
FizzBuzz in Java
[LeJOS] Let's program mindstorm-EV3 in Java [Environment construction part 2]
A quick review of Java learned in class part4
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
What I learned in Java (Part 3) Instruction execution statement
A quick review of Java learned in class part3
A quick review of Java learned in class part2
[JAVA] [Spring] [MyBatis] Use GROUP BY in SQL Builder
Use of Abstract Class and Interface properly in Java
Notes on how to use regular expressions in Java