Java OpenCV from Maven

后端 未结 8 1935
别那么骄傲
别那么骄傲 2020-12-01 20:59

Is there any way to get OpenCV from repository? Which artifact should I add to pom.xml? Every tutorial I\'d found is from \'14 and it seems like something chang

相关标签:
8条回答
  • 2020-12-01 21:41

    There is currently no official way to use the official Java bindings for OpenCV as a Maven dependency (as already mentioned in the comments, the Maven artifact was already requested in #4588, but is still unattended). Nevertheless, there are 3 possible approaches to your problem:

    • java.lang.UnsatisfiedLinkError was thrown because you need to install the binding's binaries (that is "opencv_java") separately. Most likely, that unofficial artifact does not include them (or not the ones compatible with your system). In order to build the bindings:

      1. git clone the OpenCV repository.
      2. git checkout the intended version (it appears that you are using version 2.4.9, although more recent versions are available)
      3. Follow the instructions here to build OpenCV and its Java bindings, thus yielding a dynamically linked library ("opencv_java249.dll", "libopencv_java249.so", or something else depending on your OS).
      4. Copy the shared library file to your java.library.path (again, this variable is system-dependent, but can be defined when running your application). At this point you should be ready to use that artifact.
    • An alternative is to use other bindings: the JavaCPP presets for OpenCV seem to work just as nicely as the official ones, and these are registered in maven (binaries for various platforms included!). Just remember that the API may not be exactly the same.

    • This solution may sound too far out, but it has legitimately worked for me in the past. Basically, you can avoid using the bindings: implement your solution in C++, then either link it with the JVM via JNI or make it a separate application, used by the main application via other mechanisms of your system (process spawning, I/O channels, you name it). For instance, I have once made a service component for feature extraction that other programs would connect to via ZeroMQ sockets.

    0 讨论(0)
  • 2020-12-01 21:44

    For those who wants to use OpenCV 3.2 in MacOs environment, you can use following repository definition:

    <repositories>
       <repository>
          <id>kodfarki</id>
          <url>https://raw.githubusercontent.com/kodfarki/repository/master/</url>
       </repository>
    </repositories>
    

    There is also an example project in https://github.com/kodfarki/opencv-example.

    To use this example project, you still need to install OpenCV binaries

    brew tap homebrew/science brew install opencv3 --with-java --with-contrib

    0 讨论(0)
提交回复
热议问题