openpnp / opencv Goto Github PK
View Code? Open in Web Editor NEWThis project forked from patternconsulting/opencv
OpenCV Java bindings packaged with native libraries, seamlessly delivered as a turn-key Maven dependency.
License: Other
This project forked from patternconsulting/opencv
OpenCV Java bindings packaged with native libraries, seamlessly delivered as a turn-key Maven dependency.
License: Other
Hello,
Are there any plans towards adding ARM support (Raspberry PI) ?
Hi,
im currently working on object detection and it seems like all tracker classes are missing, respectively, the whole tracking api.
See: https://docs.opencv.org/3.1.0/d9/df8/group__tracking.html
Problem:
The latest JAR-File published on mavenCentral (3.2.0-1) is missing the ARM package. Hence using this dependency on an ARM architecture is missing dependencies. Building this version locally, the package is included and the library works fine. Hower I would prefer not maintaining a local build.
Solution: re-upload the latest build to the central repository
Hi all,
I'm using the latest 3.4.2-1 release and looks like some classes are missing.
Ex:
org.opencv.xfeatures2d.SIFT
But those are part of 3.4.2 javadoc.
Am I doing something wrong?
Hey,
I am using your project to include opencv 3.2.0 in my project
I am using maven in my project.
The issue that I am facing is that when i use "mvn install" to generate a jar file and then run the jar file "java -jar app.jar" i get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: nu/pattern/OpenCV
at com.example.Application.<clinit>(Application.java:21)
Caused by: java.lang.ClassNotFoundException: nu.pattern.OpenCV
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
below is an extract of my pom.xml file
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<mainClass>com.example.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
and below is an extract of my class that has the main method:
public class Application {
static {
OpenCV.loadShared();
}
public Application() throws Exception {
// some code here
}
public static void main(String[] args) {
new Application();
}
any idea what might be causing this to happen and how to solve it?
Thanks
Starting from Maven:
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.4.2-0</version>
</dependency>
nu.pattern.OpenCV.loadShared()
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java343 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at nu.pattern.OpenCV$SharedLoader.<init>(OpenCV.java:208)
at nu.pattern.OpenCV$SharedLoader.<init>(OpenCV.java:189)
at nu.pattern.OpenCV$SharedLoader$Holder.<clinit>(OpenCV.java:229)
at nu.pattern.OpenCV$SharedLoader.getInstance(OpenCV.java:233)
at nu.pattern.OpenCV.loadShared(OpenCV.java:183)
at src.main.kotlin.MainKt.main(Main.kt:27)
at src.main.kotlin.MainKt.main(Main.kt)
nu.pattern.OpenCV.loadLocally()
/Library/Java/JavaVirtualMachines/default/Contents/Home/bin/java -Xmx12g "-javaagent:/Users/benhill/Applications/IntelliJ IDEA 2018.3 EAP.app/Contents/lib/idea_rt.jar=53128:/Users/benhill/Applications/IntelliJ IDEA 2018.3 EAP.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/default/Contents/Home/lib/tools.jar:/Users/benhill/Documents/workspace/facesnap/target/classes:/Users/benhill/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.0/kotlin-stdlib-jdk8-1.3.0.jar:/Users/benhill/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.3.0/kotlin-stdlib-1.3.0.jar:/Users/benhill/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.3.0/kotlin-stdlib-common-1.3.0.jar:/Users/benhill/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar:/Users/benhill/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.3.0/kotlin-stdlib-jdk7-1.3.0.jar:/Users/benhill/.m2/repository/org/bytedeco/javacv/1.4.3/javacv-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp/1.4.3/javacpp-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/flycapture/2.11.3.121-1.4.3/flycapture-2.11.3.121-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/libdc1394/2.2.5-1.4.3/libdc1394-2.2.5-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/libfreenect/0.5.3-1.4.3/libfreenect-0.5.3-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/libfreenect2/0.2.0-1.4.3/libfreenect2-0.2.0-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/librealsense/1.12.1-1.4.3/librealsense-1.12.1-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/videoinput/0.200-1.4.3/videoinput-0.200-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/artoolkitplus/2.3.1-1.4.3/artoolkitplus-2.3.1-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/flandmark/1.07-1.4.3/flandmark-1.07-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/leptonica/1.76.0-1.4.3/leptonica-1.76.0-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/tesseract/4.0.0-rc2-1.4.3/tesseract-4.0.0-rc2-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/opencv/3.4.3-1.4.3/opencv-3.4.3-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg-platform/4.0.2-1.4.3/ffmpeg-platform-4.0.2-1.4.3.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-android-arm.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-android-arm64.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-android-x86.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-android-x86_64.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-linux-x86.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-linux-x86_64.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-linux-armhf.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-linux-ppc64le.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-macosx-x86_64.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-windows-x86.jar:/Users/benhill/.m2/repository/org/bytedeco/javacpp-presets/ffmpeg/4.0.2-1.4.3/ffmpeg-4.0.2-1.4.3-windows-x86_64.jar:/Users/benhill/.m2/repository/org/openpnp/opencv/3.4.2-0/opencv-3.4.2-0.jar:/Users/benhill/.m2/repository/com/natpryce/konfig/1.6.10.0/konfig-1.6.10.0.jar:/Users/benhill/.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.3.0/kotlin-reflect-1.3.0.jar:/Users/benhill/.m2/repository/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar:/Users/benhill/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/Users/benhill/.m2/repository/io/github/microutils/kotlin-logging/1.6.10/kotlin-logging-1.6.10.jar:/Users/benhill/.m2/repository/io/github/microutils/kotlin-logging-common/1.6.10/kotlin-logging-common-1.6.10.jar src.main.kotlin.MainKt
Exception in thread "main" java.lang.UnsatisfiedLinkError: /private/var/folders/yf/n2ww6hgn0_vghpv9jb289pd8006t9p/T/opencv_openpnp6473975923817250546/nu/pattern/opencv/osx/x86_64/libopencv_java342.dylib: dlopen(/private/var/folders/yf/n2ww6hgn0_vghpv9jb289pd8006t9p/T/opencv_openpnp6473975923817250546/nu/pattern/opencv/osx/x86_64/libopencv_java342.dylib, 1): Library not loaded: /usr/local/opt/ffmpeg/lib/libavcodec.58.dylib
Referenced from: /private/var/folders/yf/n2ww6hgn0_vghpv9jb289pd8006t9p/T/opencv_openpnp6473975923817250546/nu/pattern/opencv/osx/x86_64/libopencv_java342.dylib
Reason: image not found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at nu.pattern.OpenCV$LocalLoader.<init>(OpenCV.java:298)
at nu.pattern.OpenCV$LocalLoader.<init>(OpenCV.java:294)
at nu.pattern.OpenCV$LocalLoader$Holder.<clinit>(OpenCV.java:304)
at nu.pattern.OpenCV$LocalLoader.getInstance(OpenCV.java:308)
at nu.pattern.OpenCV.loadLocally(OpenCV.java:291)
at src.main.kotlin.MainKt.main(Main.kt:27)
at src.main.kotlin.MainKt.main(Main.kt)
Anything special I should be doing beyond the POM dependency?
We should take the time to go through the most common OpenCV capture drivers (dshow, v4l, avfoundation, I think) and add support, if possible, to control exposure and codec. The results should be submitted as a pull request to OpenCV.
For OpenPnP, the two biggest limiting factors for cameras with regards to OpenCV are controlling the auto exposure / exposure settings and being able to set the video codec format. Most of the OpenCV capture drivers do not support these settings, but it appears that that is due to just not having the code more than technical reasons.
For instance, simply copying the exposure code from the iOS driver (cap_avfoundation.mm) to the Mac one (cap_avfoundation_mac.mm) seems to work fine.
Reference Material:
https://developer.apple.com/reference/avfoundation/avcapturedevice
/**
* Camera dispatching method: index is the camera number.
* If given an index from 0 to 99, it tries to find the first
* API that can access a given camera index.
* Add multiples of 100 to select an API.
*/
CV_IMPL CvCapture * cvCreateCameraCapture (int index)
enum
{
CV_CAP_ANY =0, // autodetect
CV_CAP_MIL =100, // MIL proprietary drivers
CV_CAP_VFW =200, // platform native
CV_CAP_V4L =200,
CV_CAP_V4L2 =200,
CV_CAP_FIREWARE =300, // IEEE 1394 drivers
CV_CAP_FIREWIRE =300,
CV_CAP_IEEE1394 =300,
CV_CAP_DC1394 =300,
CV_CAP_CMU1394 =300,
CV_CAP_STEREO =400, // TYZX proprietary drivers
CV_CAP_TYZX =400,
CV_TYZX_LEFT =400,
CV_TYZX_RIGHT =401,
CV_TYZX_COLOR =402,
CV_TYZX_Z =403,
CV_CAP_QT =500, // QuickTime
CV_CAP_UNICAP =600, // Unicap drivers
CV_CAP_DSHOW =700, // DirectShow (via videoInput)
CV_CAP_MSMF =1400, // Microsoft Media Foundation (via videoInput)
CV_CAP_PVAPI =800, // PvAPI, Prosilica GigE SDK
CV_CAP_OPENNI =900, // OpenNI (for Kinect)
CV_CAP_OPENNI_ASUS =910, // OpenNI (for Asus Xtion)
CV_CAP_ANDROID =1000, // Android - not used
CV_CAP_ANDROID_BACK =CV_CAP_ANDROID+99, // Android back camera - not used
CV_CAP_ANDROID_FRONT =CV_CAP_ANDROID+98, // Android front camera - not used
CV_CAP_XIAPI =1100, // XIMEA Camera API
CV_CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API)
CV_CAP_GIGANETIX = 1300, // Smartek Giganetix GigEVisionSDK
CV_CAP_INTELPERC = 1500, // Intel Perceptual Computing
CV_CAP_OPENNI2 = 1600, // OpenNI2 (for Kinect)
CV_CAP_GPHOTO2 = 1700,
CV_CAP_GSTREAMER = 1800, // GStreamer
CV_CAP_FFMPEG = 1900, // FFMPEG
CV_CAP_IMAGES = 2000, // OpenCV Image Sequence (e.g. img_%02d.jpg)
CV_CAP_ARAVIS = 2100 // Aravis GigE SDK
};
Hi
We use your Maven Project and it runs very well.
We use the Maven Project:
org.openpnp
opencv
3.2.0-0
And Initialize the OpenCV Libraries like that
/**
From the documentation on the github mainpage I understand, that when the vm starts it copies the libraries to some temp location.
Could it be that if we start two Java VM's on the same Windows Server that there is some overriding? Or is there any other restriction?
Basically the stacktrace we get is:
2019-10-28 12:48:31,654 ERROR ch.helsana.unifygate.consumer.GenericConsumer [pool-1-thread-2] APP1_20190813_01469153: error on process -
ch.helsana.unifygate.processor.ProcessorException: java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path
at ch.helsana.unifygate.processor.AdaptiveThresholdProcessor.process(AdaptiveThresholdProcessor.java:115)
at ch.helsana.unifygate.consumer.GenericConsumer.consume(GenericConsumer.java:35)
at ch.helsana.unifygate.consumer.AbstractConsumer.run(AbstractConsumer.java:93)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at nu.pattern.OpenCV$SharedLoader.(OpenCV.java:204)
at nu.pattern.OpenCV$SharedLoader.(OpenCV.java:185)
at nu.pattern.OpenCV$SharedLoader$Holder.(OpenCV.java:225)
at nu.pattern.OpenCV$SharedLoader.getInstance(OpenCV.java:229)
at nu.pattern.OpenCV.loadShared(OpenCV.java:179)
at ch.helsana.unifygate.utils.ImageUtils.(ImageUtils.java:33)
at ch.helsana.unifygate.processor.AdaptiveThresholdProcessor.createAdaptiveThresholdFile(AdaptiveThresholdProcessor.java:161)
at ch.helsana.unifygate.processor.AdaptiveThresholdProcessor.process(AdaptiveThresholdProcessor.java:82)
... 5 common frames omitted
Any help on how to run multiple VM's on the same server would help.
Regards Michel Riondel
I added the opencv's native library for windows.
but, how can I add the opencv's native library for both linux 32 bit and 64 bit?
How to use Opencv with java for linux ?
Hi,
I'm developing a system using your lib version 3.2.0-1, Java 1.8.0_51 and OSX 10.11.6 but I have an error when the video capture objects are release.
My code is:
if (this.videoCapture.isOpened()) {
this.videoCapture.release();
}
When the object is release java crash and a log is generated (attached)
hs_err_pid13503.log
I replaced your lib with opencv 3.3.1 jar and the same happens so I suppose that it's not related with your lib.
Which version of opencv are you using? Is the last one? if not, are you going to update it?
Do you have this release problem too?
thanks in advantage
Mariela
The latest OpenSUSE only ships GLIBC 2.26. No plans to ship 2.27 or newer in any 15.x release, and no supported way to upgrade.
Would be wonderful to have OpenCV 3 packaged as nicely as this repo does it. OpenCV 3 is faster and contains more complete Java bindings than 2.
All I am doing is create a VideoCapture instance, passing the URI to the video file
but VideoCapture::isOpened
returns false.
This seems to happen no matter which video file I use.
2.4.13 contains v4l bug fixes that are very important on Linux.
This is a placeholder for updating the binary loader to the JNA loader used in e.g. https://github.com/openpnp/openpnp-capture-java. This fixes a number of issues, so I wanted to collect them all in one place.
It should fix:
are there any plans to support the opencv 4.0 releases?
Loading of native libraries fail in Java 10 as the format for the UnsatisfiedLinkError
exception message has changed slightly.
Instead of:
no opencv_java320 in java.library.path
it is now:
no opencv_java320 in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
This will cause the check here to fail:
opencv/src/main/java/nu/pattern/OpenCV.java
Line 198 in a25eb08
Add workflow for CI using Jenkins or GitHub Actions to automate stuffs.
The repo is getting pretty slow with all these huge binaries in it. We should switch to LFS:
https://help.github.com/articles/working-with-large-files/
https://git-lfs.github.com
Hi
As discussed here:
https://groups.google.com/d/msg/openpnp/p2xiolO3pf0/XeOrKAXfBQAJ
we cannot use OpenJDK+OpenJ9 for OpenPNP due to some class loader issue with OpenCV.
I found the reason.
nu.pattern.OpenCV.SharedLoader.SharedLoader()
diagnoses the exception by looking at the message. The message is slightly different with OpenJ9, therefore the exception is not correctly recognized and therefore falsely propagated:
opencv/src/main/java/nu/pattern/OpenCV.java
Lines 190 to 201 in fed49ee
The OpenJ9 VM generates this message:
opencv_java342 (Not found in java.library.path)
Suggestion:
/* Only update the library path and load if the original error indicates it's missing from the library path. */
String errorFragment = String.format("no %s in java.library.path", );
if (ule == null || !(ule.getMessage().contains(Core.NATIVE_LIBRARY_NAME)
&& ule.getMessage().contains("java.library.path"))) {
logger.log(Level.FINEST, String.format("Encountered unexpected loading error."), ule);
throw ule;
}
I don't know how to bypass maven dependencies locally therefore I made no PR.
_Mark
I'm using your lib version 3.2.0-1, Java 1.8.0_51 and I test my app in OSX 10.11.6 and Windows 10
I use this line:
videoCapture.get(Videoio.CAP_PROP_FPS);
to get the webcamera fps. In OSX, it works fine but in Windows 10, it returns 0.
Why? is there other way to get it?
Thanks
Hey,
I am facing the following issue with VideoCapture.open(url)
VIDEOIO(cvCreateFileCapture_AVFoundation (filename)): raised unknown C++ exception!
when I built opencv using cmake and then make and then make install that problem was not there.
only when i switched to using maven that this problem appeared.
what might be the issue?
When calling OpenCV.loadShared();
:
java.lang.ExceptionInInitializerError
at nu.pattern.OpenCV$SharedLoader.getInstance(OpenCV.java:232)
at nu.pattern.OpenCV.loadShared(OpenCV.java:181)
Caused by: java.lang.RuntimeException: Failed to get field handle to set library path
at nu.pattern.OpenCV$SharedLoader.addLibraryPath(OpenCV.java:258)
at nu.pattern.OpenCV$SharedLoader.<init>(OpenCV.java:206)
at nu.pattern.OpenCV$SharedLoader.<init>(OpenCV.java:187)
at nu.pattern.OpenCV$SharedLoader$Holder.<clinit>(OpenCV.java:228)
I think the problem lies in this line but I'm not entirely sure how to fix it.
Is this a known issue?
Hello,
are there any possibilities for packaged versions including the extra modules in the near future?
For instance, those available at https://github.com/opencv/opencv_contrib ?
Thank you
VideoCapture.open works fine with your lib version 3.2.0-1, Java 1.8.0_51 and OSX 10.11.6 but when I run it in Windows 10, it always returns false.
The code line is
boolean open = this.videoCapture.open(cameraId);
I tested it with cameraId 0 and 1 (integrated camera and webcam) and in both cases returns false.
When I debug in Eclipse, the camera blinks and videoCapture returns false.
The cameras works fine in Windows with other applications.
Should I add something for windows?
Hi,
I was facing the below error while trying to use Highgui.imread(String) function:
"java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_1".
On searching, I found out that I might have to use "System.loadLibrary(Core.NATIVE_LIBRARY_NAME);" to load the library. But now, it gives the below error:
"java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path"
The jar file contains opencv_java320.dll for 64bit windows machine but the value for Core.NATIVE_LIBRARY_NAME is "opencv_java320". Is this the reason why I am getting this error? Also, can you help me on how to resolve this above error also I'm receiving?
Issue Found in below Maven Dependency:
org.openpnp
opencv
3.2.0-1
Hi,
is there anybody who can give me a hint whats the reason for the following error:
[2018-09-03 22:46:12,335]-[Hotswap] ERROR quattro.App - An error occurred while starting the application:
java.lang.UnsatisfiedLinkError: no opencv_java342 in java.library.path: [/Users/martin/Library/Java/Extensions, /Library/Java/Extensions, /Network/Library/Java/Extensions, /System/Library/Java/Extensions, /usr/lib/java, .]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2654)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:876)
my test class has
static{
nu.pattern.OpenCV.loadShared();
//nu.pattern.OpenCV.loadLocally();
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
my pom.xml references
<!-- https://mvnrepository.com/artifact/org.openpnp/opencv -->
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.4.2-0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openpnp/openpnp-capture-java -->
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>openpnp-capture-java</artifactId>
<version>0.0.12</version>
</dependency>
the relevant code seems to be
capture=new OpenPnpCapture();
devices = capture.getDevices();
faceCascade = new CascadeClassifier();
CascadeClassfiers are part of opencv aren't they?
Looks similar to #24, I'm using java 10
Hi,
I was trying your 3.2.0-1 packaging (thanks so much for that !) and I noticed once again, like any opencv java binding I ever tried, huge memory consumption. I looked around and it seems that some patches have been proposed to fix this issue with java bindings :
https://github.com/sgjava/install-opencv#install-opencv pointing to https://github.com/sgjava/opencvmem
A patch is proposed in the same repository : https://github.com/sgjava/install-opencv/blob/master/scripts/install-opencv.sh#L80
I take a closer look and see if i can add this patch to this packaging
Correct me if I'm wrong @vonnieda, but this seems like a mistake. Usually the "default" branch is the trunk, the branch where things that were approved are going into.
However, you have develop - which makes a confusing name for a master branch - as your default one. And also, master seems to be more up-to-date than develop, which further confuses me.
The Linux lib is not built using video framework when looking at the cmake.log, resulting no video can be used:
-- Video I/O:
-- DC1394: NO
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
You should build with ffmpeg, gstreamer and DC1394 support (like this on Ubuntu 18.04):
-- Video I/O:
-- DC1394: YES (2.2.5)
-- FFMPEG: YES
-- avcodec: YES (57.107.100)
-- avformat: YES (57.83.100)
-- avutil: YES (55.78.100)
-- swscale: YES (4.8.100)
-- avresample: YES (3.7.0)
-- GStreamer: YES (1.14.5)
-- v4l/v4l2: YES (linux/videodev2.h)
From time to time people have trouble getting the opencv binaries working on Linux due to either libc incompatibility or just different distros. Currently a user is having trouble running the 2.4.11 distribution under Wheezy 32 bit because Wheezy uses eglibc and we're expecting libc 6.
I'd like to determine if it's possible to static link everything into the opencv binaries so we can avoid this in the future.
Hello,
I have added maven dependency in a servlet, generated a war file and deployed it on tomcat running in AWS EC2 instance. I loaded the library by calling: nu.pattern.OpenCV.loadShared();
But I'm getting the following warning at the time loading the shared library.
OpenJDK 64-Bit Server VM warning: You have loaded library /var/cache/tomcat8/temp/opencv_openpnp8944603593498400654/nu/pattern/opencv/linux/x86_64/libopencv_java320.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c ', or link it with '-z noexecstack'.
When I deploy the war to my local instance of tomcat, its working perfectly.
I want to use the library for detecting and cropping faces in image using haarcascade classifiers.
I use the following OpenCV Java JNA wrapper:
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-1</version>
</dependency>
According to the application logic, I need very often to convert Mat
to BufferedImage
and viсe versa. In order to do this - I use the following functions:
private BufferedImage mat2BufferedImage(Mat matrix) throws Exception {
MatOfByte mob = new MatOfByte();
Imgcodecs.imencode(".png", matrix, mob);
byte ba[] = mob.toArray();
return ImageIO.read(new ByteArrayInputStream(ba));
}
private Mat bufferedImageToMat(BufferedImage bi) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bi, "png", byteArrayOutputStream);
byteArrayOutputStream.flush();
return Imgcodecs.imdecode(new MatOfByte(byteArrayOutputStream.toByteArray()), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
}
Right now I faced a huge memory leak during the application execution on image processing step where these functions are involved.
So my question is - do I need to manually call MatOfByte.release()
in both of these functions(before return
statement) in order to try to prevent the memory leak?
And the same question for the objects of the following classes:
import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfPoint2f;
Do I need to manually call release()
for them also?
This issue is alive and well on every version of Windows: PatternConsulting#10.
Please import Javadoc documentation for bindings from original C++ API, like https://mvnrepository.com/artifact/org.bytedeco/javacv/1.3.1 did.
With version 3.4.2-1 I'm getting a UnsatisfiedLinkError.
In my code I have tried OpenCV.loadShared();
and OpenCV.loadLocally();
Note that it is working fine on a Windows 8.1 but on Windows Server 2012 R2 (x64) the exception occurs, probably due to some libraries that are not present ona server system, similar to the ffmpeg bug(?).
Java version is 1.8.0_191.
Occurs every time when starting the java application using opencv version 3.4.2-1.
Caused by: java.lang.UnsatisfiedLinkError: C:\...\AppData\Local\Temp\opencv_openpnp5624012180889590870\nu\pattern\opencv\windows\x86_64\opencv_java342.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at nu.pattern.OpenCV$LocalLoader.<init>(OpenCV.java:297)
at nu.pattern.OpenCV$LocalLoader.<init>(OpenCV.java:293)
at nu.pattern.OpenCV$LocalLoader$Holder.<clinit>(OpenCV.java:303)
at nu.pattern.OpenCV$LocalLoader.getInstance(OpenCV.java:307)
at nu.pattern.OpenCV.loadLocally(OpenCV.java:290)
... 86 more
Edit: The missing dlls (left: Win 8.1; right: Win Server):
Edit 2: Apparently the Media Feature Pack for N and KN versions is needed. Just wondering if this dependency is something you plan to "fix"/remove or if I should look for another workaround?
Is it possible to load extra modules like the Face Analysis one?
Great project by the way!
when my app call org.opencv.core.MatOfByte.toArray(),occured an error lead to jvm crash.
Problematic frame:
C [libc.so.6+0x1543e5] __memcpy_ssse3_back+0x45
Reported by @phrack at PatternConsulting#11
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: https://github.com/PatternConsulting/opencv/blob/58d13dfb7f724c041dcf8af4f62ed2a8c2da6fd1/src/main/java/nu/pattern/OpenCV.java#L65. 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) ...
See discussion on openpnp/openpnp#395 (comment). Adding these libraries may make video capture on Linux more robust. Need to determine if these can be statically linked in.
"Unrecognized or unsupported array type in function cvGetMat":
Caused by: CvException [org.opencv.core.CvException: cv::Exception: /Users/jason/Projects/openpnp/opencv/opencv/opencv-3.2.0/modules/core/src/array.cpp:2501: error: (-206) Unrecognized or unsupported array type in function cvGetMat
]
at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method)
at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:159)
Source (Kotlin):
val faceGrayMat = gray.submat(faceRect)
var drects = MatOfRect()
eyeLeftCascade.detectMultiScale(faceGrayMat, drects)
What is strange is that that code has been called thousands of times for the images of the same format, but the exception occurs only from time to time.
I get this error when running my OpenCV project:
Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library /tmp/opencv_openpnp6038665475955000750/nu/pattern/opencv/linux/x86_64/libopencv_java320.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/opencv_openpnp6038665475955000750/nu/pattern/opencv/linux/x86_64/libopencv_java320.so: /tmp/opencv_openpnp6038665475955000750/nu/pattern/opencv/linux/x86_64/libopencv_java320.so: cannot enable executable stack as shared object requires: Invalid argument
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at nu.pattern.OpenCV$SharedLoader.<init>(OpenCV.java:204)
at nu.pattern.OpenCV$SharedLoader.<init>(OpenCV.java:185)
at nu.pattern.OpenCV$SharedLoader$Holder.<clinit>(OpenCV.java:225)
at nu.pattern.OpenCV$SharedLoader.getInstance(OpenCV.java:229)
at nu.pattern.OpenCV.loadShared(OpenCV.java:179)
at com.pdfextract.common.App.<clinit>(App.java:14)
I also have this at the top of my App.java (main class):
static {
nu.pattern.OpenCV.loadShared();
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
}
I have not downloaded and installed opencv, but I am under the impression that this should work without having to manually install and link the lib. What should I do?
Currently native OpenCV objects are freed (deleted) in finalize() method on GC sweep.
But in reality (during intensive use) there happens the situation when GC haven't finalized these objects (because there is still plenty of Java Heap), but OpenCV crashes due to exhaustion of native resources.
So please implement Closeable interface (with close() method) for each OpenCV class that have Java bindings.
Hi,
I need to get OpenCV working on a Raspberry Pi (via Docker), but it's really difficult to get this right with the native libraries. This is why I was looking into alternatives like OpenPNP. This works perfectly on my laptop, but when I try to run it on my Pi, it says;
java.lang.UnsupportedOperationException: Architecture "arm" is not supported.
I was looking into the past issues and pull request and came accross pull request #20 , which was merged into the develop branch, so I don't get why I'm getting this error?
Thanks!
Hi
I am facing below issue while running a sample code, just accessing VideoCapture instance.
java.lang.UnsatisfiedLinkError: org.opencv.videoio.VideoCapture.VideoCapture_2(I)J
I am working on Ubuntu and have open CV 3.4 installed properly.
I already set all class paths in environment variables as below :
OPENCV_HOME="/home/.../softwares/opencv-3.2.0/"
OPENCV_LIB="/home/.../softwares/opencv-3.2.0/build/lib"
OPENCV_JAR="/home/.../softwares/opencv-3.2.0/build/bin/opencv-320.jar"
I followed all the step for adding library in eclipse, whether it is by adding user library or by adding jar files. I followed for JNI.
I tried a lot.
Let me know what is issue or what i am missing .
Thanks
Arun
Hi
I use opencv 3.4.2 as a part of dl4j.
Now after my update I got this error:
Caused by: java.lang.UnsatisfiedLinkError: no opencv_imgproc342 in java.library.path
at org.bytedeco.javacpp.Loader.load(Loader.java:882)
at org.bytedeco.javacpp.helper.opencv_core$AbstractArray.<clinit>(opencv_core.java:109)
at org.datavec.image.loader.NativeImageLoader.streamToMat(NativeImageLoader.java:256)
at org.datavec.image.loader.NativeImageLoader.asMatrix(NativeImageLoader.java:227)
at org.datavec.image.loader.NativeImageLoader.asMatrix(NativeImageLoader.java:221)
Thanks
André
It seems that currently published Maven artifact for this project is built using JDK8 and thus doesn't work on JDK7 or OpenJDK.
It gives following error when project compiled with it tries to use OpenCV classes on JDK7:
OpenJDK Runtime Environment (rhel-2.6.8.0.el7_3-x86_64 u121-b00)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)
OpenJDK 64-Bit Server VM warning: You have loaded library /tmp/opencv_openpnp7480646247061802930/nu/pattern/opencv/linux/x86_64/libopencv_java320.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/opencv/core/Core : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at nu.pattern.OpenCV$LocalLoader.<init>(OpenCV.java:296)
at nu.pattern.OpenCV$LocalLoader.<init>(OpenCV.java:290)
at nu.pattern.OpenCV$LocalLoader$Holder.<clinit>(OpenCV.java:300)
at nu.pattern.OpenCV$LocalLoader.getInstance(OpenCV.java:304)
at nu.pattern.OpenCV.loadLocally(OpenCV.java:287)
The rest of the same app (other classes, not related to OpenCV bindings) work on that JDK just fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.