Git Product home page Git Product logo

opencv's Introduction

OpenCV 2.4.9 (packaged by Pattern)

Build Status

OpenCV Java bindings packaged with native libraries, seamlessly delivered as a turn-key Maven dependency.

Deprecation Notice

Due to time constraints, this package is not actively maintained. As of December 29, 2015, it's strongly recommended users migrate to OpenPnP's excellent fork of this project, generously and regularly maintained by Jason von Nieda.

Usage

Project

Pattern's OpenCV package is added to your project as any other dependency.

<project>
  
  <!-- ... -->
  
  <dependencies>
    
    <!-- ... -->
    
    <dependency>
      <groupId>nu.pattern</groupId>
      <artifactId>opencv</artifactId>
      <version>2.4.9-7</version>
    </dependency>
    
    <!-- ... -->
    
  </dependencies>
  
  <!-- ... -->
  
</project>
// ...

libraryDependencies += "nu.pattern" % "opencv" % "2.4.9-7"

// ...

API

Typically, using the upstream OpenCV Java bindings involves loading the native library as follows:

static {
  System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
}

Fortunately, this is unchanged except for one caveat. To use the native libraries included with this package, first call nu.pattern.OpenCV.loadShared().

This call will—exactly once per class loader—first attempt to load from the system-wide installation (exactly as if System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME); were called without any preceding steps). If that fails, the loader will select a binary from the package appropriate for the runtime environment's operating system and architecture. It will write that native library to a temporary directory (also defined by the environment), add that directory to java.library.path. This involves writing to disk, so consider the implications. Temporary files will be garbage-collected on clean shutdown.

This approach keeps most clients decoupled from Pattern's package and loader. As long as this is done sufficiently early in execution, any library using the OpenCV Java bindings can use the usual load call as documented by the OpenCV project.

There are, however, cases where Java class loaders are frequently changing (e.g., application servers, SBT projects, Scala worksheets), and spurious attempts to load the native library will result in JNI errors. As a partial work-around, this package offers an alternative API, nu.pattern.OpenCV.loadLocal(), which—also exactly once per class loader—extracts the binary appropriate for the runtime platform, and passes it to System#load(String). Ultimately, this may eventually load the library redundantly in the same JVM, which could be unsafe in production. Use with caution and understand the implications.

It's recommended developers using any JNI library read further:

Debugging

Java logging is used to produce log messages from nu.pattern.OpenCV.

Rationale

Developers wishing to use the Java API for OpenCV would typically go through the process of building the project, and building it for each platform they wished to support (e.g., 32-bit Linux, OS X). This project provides those binaries for inclusion as a typical dependency in Maven, Ivy, and SBT projects.

Apart from testing, this package deliberately specifies no external dependencies. It does, however, make use of modern Java APIs (such as Java NIO).

Contributing

Producing native binaries is the most cumbersome process in maintaining this package. If you can contribute binaries for the current version, please make a pull request including the build artifacts and any platform definitions in nu.pattern.OpenCV.

Support

The following platforms are supported by this package:

OS Architecture
OS X x86_32
OS X x86_64
Linux x86_64
Linux x86_32

If you can help create binaries for additional platforms, please see notes under Contributing.

Credits

This package is maintained by Michael Ahlers.

Acknowledgements

opencv's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencv's Issues

Can't Load with JDK 7

OpenCV classes were built with JDK 8, which is not backwards compatible with JDK 7.

Unable to delete temporary DLL file in Windows due to AccessDeniedException

Hi Michael, I made a fork of this project at https://github.com/mscarlett/opencv/tree/windows-patch (which I can submit as a pull request) and was able to use the library successfully on Windows. However if the OpenCV.loadLocally() method is called, the TemporaryDirectory.delete() method throws an AccessDeniedError when the JVM is terminating due to not having permission to delete the DLL file in the temporary directory. As a result the binaries still reside in the temporary directory after the program terminates. This issue does not occur in Linux so it appears Windows specific.

The error is likely due to the JVM locking this file once the DLL file is loaded, but I was unable to find documentation regarding why it happens.

Here is the full stack trace in case it helps:

Exception in thread "Thread-1" java.lang.RuntimeException: java.nio.file.AccessDeniedException: C:\Users\Michael\AppData\Local\Temp\5989570558901519688\nu\pattern\opencv\windows\x86_64\libopencv_java249.dll
at nu.pattern.OpenCV$TemporaryDirectory.delete(OpenCV.java:146)
at nu.pattern.OpenCV$TemporaryDirectory$1.run(OpenCV.java:117)
Caused by: java.nio.file.AccessDeniedException: C:\Users\Michael\AppData\Local\Temp\5989570558901519688\nu\pattern\opencv\windows\x86_64\libopencv_java249.dll
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source)
at java.nio.file.Files.deleteIfExists(Unknown Source)
at nu.pattern.OpenCV$TemporaryDirectory$2.visitFile(OpenCV.java:141)
at nu.pattern.OpenCV$TemporaryDirectory$2.visitFile(OpenCV.java:1)
at java.nio.file.Files.walkFileTree(Unknown Source)
at java.nio.file.Files.walkFileTree(Unknown Source)
at nu.pattern.OpenCV$TemporaryDirectory.delete(OpenCV.java:130)

FFMPEG

Is it possible to use somehow ffmpeg for decoding video files with your binary library?

Loading Issues with Multiple Class Loaders

Particularly when working in hosted environments (like IDEs), where different class loaders may be used between one run and the next, developers will encounter errors like the following:

java.lang.UnsatisfiedLinkError: Native Library /private/var/folders/d1/3323g01s4bn3ntx1g_yzm_dc0000gn/T/1621396069368823549/nu/pattern/opencv/osx/x86_64/libopencv_java249.dylib already loaded in another classloader
    at java.lang.ClassLoader.loadLibrary0(test.sc5011658132463706269.tmp:1891)
    at java.lang.ClassLoader.loadLibrary(test.sc5011658132463706269.tmp:1843)
    at java.lang.Runtime.loadLibrary0(test.sc5011658132463706269.tmp:866)
    at java.lang.System.loadLibrary(test.sc5011658132463706269.tmp:1115)
    at nu.pattern.OpenCV$Loader.loadLibrary(test.sc5011658132463706269.tmp:221)
    at nu.pattern.OpenCV$Loader.access$100(test.sc5011658132463706269.tmp:156)
    at nu.pattern.OpenCV.loadLibrary(test.sc5011658132463706269.tmp:153)
    at #worksheet#.get$$instance$$res1(test.sc5011658132463706269.tmp:5)
    at #worksheet#.#worksheet#(test.sc5011658132463706269.tmp:27)

X86_32 missing valid Windows pattern for os.arch

New versions of Oracle's 32-bit JRE for Windows often have os.arch set to x86 (x86_64 being the 64-bit version). It appears "x86" needs to be added to the list of patterns in this line:

X86_32("i386", "i686"),
. This is causing an UnsupportedOperationException to be thrown even in cases where the OS and architecture actually are supported, e.g. on both 32-bit and 64-bit Windows with 32-bit Oracle JRE:

Caused by: java.lang.UnsupportedOperationException: Architecture "x86" is not supported. at nu.pattern.OpenCV$Arch.getCurrent(OpenCV.java:88) at nu.pattern.OpenCV.extractNativeBinary(OpenCV.java:291) at nu.pattern.OpenCV.access$100(OpenCV.java:22) at nu.pattern.OpenCV$SharedLoader.(OpenCV.java:178) at nu.pattern.OpenCV$SharedLoader.(OpenCV.java:162) at nu.pattern.OpenCV$SharedLoader$Holder.(OpenCV.java:202) ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.