bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.61k stars 1.59k forks source link

Cannot open local webcam on NetBeans JavaFX 8 Project #1618

Open Adi-18 opened 3 years ago

Adi-18 commented 3 years ago

I use new version 1.5.5 with example code JavaFxPlayVideo.java on JavaFX 8

For grabbing local webcam I use FrameGrabber grabber = new OpenCVFrameGrabber(1); because FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(1); is no more possible (yes 1 is correct).

In normal Java-Project I can run this example, but when I create it with NetBeans as a JavaFX project, I get an exception:

Exception in thread "Thread-5" java.lang.ExceptionInInitializerError at org.bytedeco.javacv.OpenCVFrameGrabber.(OpenCVFrameGrabber.java:95) at camtest.JavaFxPlayVideo.lambda$start$1(JavaFxPlayVideo.java:55) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) at java.lang.Class.createAnnotationData(Class.java:3521) at java.lang.Class.annotationData(Class.java:3510) at java.lang.Class.createAnnotationData(Class.java:3526) at java.lang.Class.annotationData(Class.java:3510) at java.lang.Class.createAnnotationData(Class.java:3526) at java.lang.Class.annotationData(Class.java:3510) at java.lang.Class.getAnnotation(Class.java:3415) at java.lang.reflect.AnnotatedElement.isAnnotationPresent(AnnotatedElement.java:258) at java.lang.Class.isAnnotationPresent(Class.java:3425) at org.bytedeco.javacpp.Loader.checkPlatform(Loader.java:994) at org.bytedeco.javacpp.Loader.load(Loader.java:1171) at org.bytedeco.javacpp.Loader.load(Loader.java:1148) at org.bytedeco.javacv.OpenCVFrameConverter.(OpenCVFrameConverter.java:43) ... 3 more

saudet commented 3 years ago

It looks like the main JAR file for JavaCPP is missing from the class path. Make sure all JAR files are in the class path.

Adi-18 commented 3 years ago

Thank you for the replay. I have already included JavaCPP. The problem is only, if I start demo as JavaFX-Project in my NetBeans 8.2. As "normal" project it works (also when I start code by context menu -> run file on that file).

image

saudet commented 3 years ago

If you're trying to use the javafx-maven-plugin, be aware that it's still not fully functional, see issue #1435. If you need to use that plugin, make sure it's set to use the class path, and not the module path.

/cc @johanvos

Adi-18 commented 3 years ago

I don't use javafx-maven-plugin. Its on Java 8 in Netbeans 8.2.

saudet commented 3 years ago

Sounds like a bug in JavaFX 8... Time to upgrade maybe? It's a 6-year-old release that is no longer supported.

Adi-18 commented 3 years ago

Since JavaFX is out of jdk and not easy to porting my project with many of unknowns, this is not an option at the moment

Same Problem while calling this: private static OpenCVFrameConverter.ToIplImage iplConv = new OpenCVFrameConverter.ToIplImage(); for converting to ImageView.

BTW: bevore I used FmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(1); and this worked perfectly for WebCam. Why this is no more possible?

saudet commented 3 years ago

BTW: bevore I used FmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(1); and this worked perfectly for WebCam. Why this is no more possible?

That never worked. FFmpeg needs a String, not an int.

Adi-18 commented 3 years ago

Yes, I know, that's why I have had to use the factory method FFmpegFrameGrabber.createDefault(int deviceNumber) -> http://bytedeco.org/javacv/apidocs/org/bytedeco/javacv/OpenCVFrameGrabber.html

saudet commented 3 years ago

What you're probably talking about is FrameGrabber.createDefault(1) and that probably returns you an OpenCVFrameGrabber, yes.