Install openCV in java environment under linux and windows

1. Linux side operation

1. Install the dependency package. If it is not installed, java cannot be called, and the required .jar and .so files cannot be generated.

Type in the linux terminal:

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
2. Go to the official website to download the opencv source code, opencv-2.4.12.zip

3. Upload the OpenCV source code to the server/opencv directory, decompress it

4. Create a build folder under opencv-2.4.12
  cd opencv-2.4.12
  mkdir build
  cd build
5. Enter in the terminal one by one
  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
  make
  sudo make install
  (You need to wait patiently for this process)
6. After the execution, check   whether there are libopencv_java1412.so and opencv-2412.jar files under
  /usr/local/share/OpenCV/java , if successful,   it means that you can call in the java environment 7. Set Copy libopencv_java1412.so to /usr/lib and   use the command 



cp /usr/local/share/OpenCV/java/libopencv_java1412.so /usr/lib/
2.   1.
Download the Windows version of opencv on the official website, preferably the version installed
on    linux


  
<dependency>
     <groupId>org.opencv</groupId>
     <artifactId>opencv</artifactId>
     <version>2.4.12</version>
     <systemPath>D:/Program Files/OpenCV/opencv/build/java/opencv-2412.jar</systemPath>
     <scope>system</scope>
   </dependency>
   Or directly enter the local maven warehouse (it is recommended to enter the local maven warehouse directly, otherwise there is no such jar package under the packaged lib)

   
mvn install:install-file -Dfile=C:\Users\HY\.m2\repository\org\opencv\opencv-2412.jar -DgroupId=org.opencv -      DartifactId=opencv -  Dversion=2.4.12 -Dpackaging=jar -DgeneratePom=true

   (2) Add in pom
      
<dependency>
         <groupId>org.bytedeco</groupId>
         <artifactId>javacv-platform</artifactId>
         <version>1.4.1</version>
      </dependency>
3. Put opencv_java2412.dll in build/java/x64 or x86 (depending on the number of jdk) into the bin directory in the local jdk
4. Compile the project and run

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324584491&siteId=291194637