Domanda

I need to build the project, which involv an OpenCV. It would be great, but libraries don't get into the library java.library.path for some reason. And when I try to run the code using the library I get this error:

*java.lang.UnsatisfiedLinkError: no jniopencv_highgui in java.library.path*

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>ru.intemsys.reget.server</groupId>
  <artifactId>reget-server</artifactId>
  <version>0.1-alpha</version>
  <packaging>jar</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.build.timestamp.format>yyyyMMddhhmm</maven.build.timestamp.format>
    <platform.name>${os.name}-${os.arch}</platform.name>
    <product.year>2014</product.year>
    <jdkVersion>1.6</jdkVersion>
    <javacpp.version>0.7</javacpp.version>
    <javacv.version>0.7</javacv.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>commons-daemon</groupId>
        <artifactId>commons-daemon</artifactId>
        <version>1.0.10</version>
    </dependency>

      <dependency>
          <groupId>com.googlecode.javacpp</groupId>
          <artifactId>javacpp</artifactId>
          <version>${javacpp.version}</version>
      </dependency>
      <dependency>
          <groupId>com.googlecode.javacv</groupId>
          <artifactId>javacv</artifactId>
          <version>${javacv.version}</version>
      </dependency>
      <dependency>
          <groupId>com.googlecode.javacv</groupId>
          <artifactId>javacv</artifactId>
          <version>${javacv.version}</version>
          <classifier>linux-x86</classifier>
      </dependency>

      <dependency>
          <groupId>com.googlecode.javacv</groupId>
          <artifactId>javacv</artifactId>
          <version>${javacv.version}</version>
          <classifier>linux-x86_64</classifier>
      </dependency>

    <dependency>
        <groupId>com.xeiam.xchart</groupId>
        <artifactId>xchart</artifactId>
        <version>2.3.1</version>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
  </dependencies>

  <repositories>
      <repository>
          <id>javacpp</id>
          <name>JavaCPP</name>
          <url>http://maven2.javacpp.googlecode.com/git/</url>
      </repository>
      <repository>
          <id>javacv</id>
          <name>JavaCV</name>
          <url>http://maven2.javacv.googlecode.com/git/</url>
      </repository>
  </repositories>

  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${jdkVersion}</source>
                    <target>${jdkVersion}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>compile</includeScope>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <classpathLayoutType>simple</classpathLayoutType>
                            <mainClass>ru.intemsys.reget.server.App</mainClass>
                            <packageName>ru.intemsys.reget.server</packageName>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <finalName>${artifactId}-${version}</finalName>
                </configuration>
            </plugin>
        </plugins>
  </build>

    <profiles>
        <profile>
            <id>linux</id>
            <activation>
                <os><name>linux</name></os>
            </activation>
            <properties>
                <os.name>linux</os.name>
            </properties>
        </profile>
        <profile>
            <id>macosx</id>
            <activation>
                <os><name>mac os x</name></os>
            </activation>
            <properties>
                <os.name>macosx</os.name>
            </properties>
        </profile>
        <profile>
            <id>windows</id>
            <activation>
                <os><family>windows</family></os>
            </activation>
            <properties>
                <os.name>windows</os.name>
            </properties>
        </profile>
        <profile>
            <id>i386</id>
            <activation>
                <os><arch>i386</arch></os>
            </activation>
            <properties>
                <os.arch>x86</os.arch>
            </properties>
        </profile>
        <profile>
            <id>i486</id>
            <activation>
                <os><arch>i486</arch></os>
            </activation>
            <properties>
                <os.arch>x86</os.arch>
            </properties>
        </profile>
        <profile>
            <id>i586</id>
            <activation>
                <os><arch>i586</arch></os>
            </activation>
            <properties>
                <os.arch>x86</os.arch>
            </properties>
        </profile>
        <profile>
            <id>i686</id>
            <activation>
                <os><arch>i686</arch></os>
            </activation>
            <properties>
                <os.arch>x86</os.arch>
            </properties>
        </profile>
        <profile>
            <id>amd64</id>
            <activation>
                <os><arch>amd64</arch></os>
            </activation>
            <properties>
                <os.arch>x86_64</os.arch>
            </properties>
        </profile>
        <profile>
            <id>x86-64</id>
            <activation>
                <os><arch>x86-64</arch></os>
            </activation>
            <properties>
                <os.arch>x86_64</os.arch>
            </properties>
        </profile>
    </profiles>
</project>

mvn -version

Apache Maven 3.0.4 Maven home: /usr/share/maven Java version: 1.7.0_25, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-7-openjdk-i386/jre Default locale: ru_RU, platform encoding: UTF-8 OS name: "linux", version: "3.11.0-14-generic", arch: "i386", family: "unix"

uname -a

Linux PC-1 3.11.0-14-generic #21-Ubuntu SMP Tue Nov 12 17:07:40 UTC 2013 i686 i686 i686 GNU/Linux

È stato utile?

Soluzione

There is a solution. All libs are in javacv-0.6-cppjars.zip

Altri suggerimenti

How install OpenCV on Linux in 2023

Install and build OpenCV

# Install minimal prerequisites (Ubuntu 18.04 as reference)
sudo apt update && sudo apt install -y cmake g++ wget unzip

# Download and unpack sources
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.x.zip

unzip opencv.zip
unzip opencv_contrib.zip

# Create build directory and switch into it
mkdir -p build && cd build

# Configure
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x

# Build
cmake --build .

# Install
sudo make install

By default OpenCV will be installed to the /usr/local directory.

➤  tree /usr/local/share/java/opencv4
/usr/local/share/java/opencv4
├── libopencv_java470.so
└── opencv-470.jar


0 directories, 2 files

So now you can use java bindings that you built or add maven pom.xml dependency. It's better to match versions, 4.7.0 and 4.7.0, but in my case version in maven repo was behind

        <dependency>
            <groupId>org.openpnp</groupId>
            <artifactId>opencv</artifactId>
            <version>4.6.0-0</version>
        </dependency>

Run java with environment parameter LD_LIBRARY_PATH

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/share/java/opencv4/

and load OpenCV from Java with

System.loadLibrary("opencv_java470"); // If bindings version match use System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top