Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of integrating opencv with java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the method of java integrating opencv". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Introduction to opencv

OpenCV is a cross-platform computer vision library released under the BSD license (open source) that can run on Linux, Windows, Android, and Mac OS operating systems. It is lightweight and efficient-it consists of a series of C functions and a small number of C++ classes, provides interfaces to Python, Ruby, MATLAB and other languages, and implements many general algorithms in image processing and computer vision.

Opencv install Windows

1. Go to the OpenCV website to download the version you need.

two。 Execute opencv-4.4.0-vc14_vc15.exe

3. Configure environment variables

Centos

Install dependency packages

Yum install cmake gcc gcc-c++ gtk+-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devel libpng-devel gstreamer-devel libavc1394-devel libraw1394-devel libdc1394-devel jasper-devel jasper-utils swig python libtool nasm build-essential ant

1. Download opencv-4.4.0.zip and extract it

Wget https://github.com/opencv/opencv/archive/4.4.0.zip

two。 Create a new build folder

Cd opencvmkdir buildcd build

3.Cmake

Cmake-D CMAKE_BUILD_TYPE=RELEASE-D CMAKE_INSTALL_PREFIX=/usr/local-DBUILD_TESTS=OFF..

Note that "to be build" should include "Java", and JAVA_HOME should be configured correctly.

Make

The make command takes a long time to install, so you can play Masters. If the computer is better, it can be executed.

Make-J4

(on multicore hosts, you can use the-j option to speed up the execution of make commands, so don't try on single-core machines.)

Sudo make install

4. After the execution of make install, you need to configure the environment variables.

Cp-r / usr/local/share/java/opencv4/libopencv_java440.so / usr/lib

Reopen the terminal after the configuration is completed to make the configuration effective

Testing of 5.opencv

Ldconfig-v | grep opencv

Check whether opnecv is installed successfully

Java integrated opencv

1. Copy opencv-440.jar into your java project

two。 Copy opencv_java440.dll to the JAVA_HOME\ jre\ bin directory

Java code testing

Import org.opencv.core.Core;import org.opencv.core.CvType;import org.opencv.core.Mat;public class Hello {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 ());}}

Output

Mat = [1,0,0; 0,1,0; 0,0,1] FAQ

No opencv_java440 in java.library.path

This is because it is not loaded into opencv_java440.dll, so just copy the opencv_java440.dll to the JAVA_HOME\ jre\ bin directory.

2. Cmake version is too low

Wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz# decompresses the file tar zxvf cmake-3.9.2.tar.gzcd cmake-3.9.2./configuremakesudo make install

3. It is slow to download ippicv_2020_lnx_intel64_20191018_general.tgz.

# download it with Xunlei first, and specify the directory vim 3rdparty/ippicv/ippicv.cmake with https://raw.githubusercontent.com/opencv/opencv_3rdparty/ippicv/master_20191018/ippicv/ippicv_2020_lnx_intel64_20191018_general.tgz#.

Replace https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/ with the directory where ippicv_2020_lnx_intel64_20191018_general.tgz is located

This is the end of the content of "file:~/ippicv/" # (for reference only, fill in according to your own path) "what is the method of java integrating opencv". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report