jloyd / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Repost: OpenCVFrameGrabber.start() runtime exception #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a new Javacv project
2. copy and paste the following code,

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

import com.googlecode.javacv.OpenCVFrameGrabber;

public class Face {

    public Face() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @param args
     * @throws Exception 
     */
    public static void main(String[] args) throws Exception {

        OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
        grabber.start();

    }

}

3. Compile and run

What is the expected output? What do you see instead?
I expect no exceptions, but instead I see the following,

Exception in thread "main" java.lang.Exception: cvCreateCameraCapture() Error: 
Could not create camera capture.
    at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:98)
    at Face.main(Face.java:21)

What version of the product are you using? On what operating system?
I'm using the latest javacv, windows xp vm running on VMware, with java 1.6 and 
opencv 2.2

Please provide any additional information below.
I filed an issue earlier w/ the same problem (issue 57), I've switched to 
windows xp and opencv 2.2.

Original issue reported on code.google.com by jack.nan...@gmail.com on 20 Mar 2011 at 7:18

GoogleCodeExporter commented 9 years ago
Then OpenCV 2.2 cannot capture from your Webcam.. What else do you expect to 
hear from me?

Original comment by samuel.a...@gmail.com on 20 Mar 2011 at 7:20

GoogleCodeExporter commented 9 years ago
I am able to do this in c++ w/ OpenCV, so I'm just trying to find the missing 
link here w/ javacv.

Original comment by jack.nan...@gmail.com on 20 Mar 2011 at 7:26

GoogleCodeExporter commented 9 years ago
Well, it works just fine here.. If you figure out what is missing, let me know

Original comment by samuel.a...@gmail.com on 20 Mar 2011 at 7:30

GoogleCodeExporter commented 9 years ago
I got the same problem trying to run the example code. Here is the exception:

(<unknown>:8737): GStreamer-CRITICAL **: gst_debug_add_log_function: assertion 
`func != NULL' failed
java.lang.Exception: cvCreateCameraCapture() Error: Could not create camera 
capture.
    at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:98)
    at graphics.CVprocessing.<init>(CVprocessing.java:15)
    at main.setupInterface(main.java:40)
    at main.main(main.java:29)

I use ubuntu 11.04 with eclipse. After placing the jars int the project and 
compiling the OpenCV libraries (from OpenCV svn) with all the options enabled I 
got the message. Anyway, it's an "assertion" so I doubt it is related with libs 
(because the JNA exceptions would have raised before)

Original comment by alvaroaccionmontes@gmail.com on 29 Apr 2011 at 1:13

GoogleCodeExporter commented 9 years ago
JavaCV now uses JavaCPP instead of JNA. You should try to upgrade to the latest 
version to see if it fixes your issue. (Also, make sure OpenCV 2.2 works from a 
program in C/C++. It's probably not JavaCV's fault...)

Original comment by samuel.a...@gmail.com on 29 Apr 2011 at 3:09

GoogleCodeExporter commented 9 years ago
It works from both C++ and python. 

I've tried to do what you suggested, but when I try to build the project it 
gives an error saying there is a header missing. (OpenCV_core.h I think it 
was). Well, if I arrive the solution I'll tell. Thanks. 

Original comment by alvaroaccionmontes@gmail.com on 29 Apr 2011 at 9:14

GoogleCodeExporter commented 9 years ago
In any case, seems to be a bug in gstreamer:
https://bugzilla.gnome.org/show_bug.cgi?id=640771
Try to upgrade to the latest prerelease and see if that fixes it. If it does 
not, let me know, thanks.

Original comment by samuel.a...@gmail.com on 30 Apr 2011 at 1:39

GoogleCodeExporter commented 9 years ago
I've switched to a proposed upgrade (latest package in Ubuntu 11.04) and the 
problem persists. Not sure if that upgraded the buggy lib since it was 
mentioned only the phonon back-end. I can try to debug the process if you want 
me to do it.

Original comment by alvaroaccionmontes@gmail.com on 30 Apr 2011 at 1:35

GoogleCodeExporter commented 9 years ago
If you cannot provide more details than that, then just wait for the next 
release of gstreamer and let me know if that one fails too, thanks

Original comment by samuel.a...@gmail.com on 30 Apr 2011 at 2:21

GoogleCodeExporter commented 9 years ago
Sorry for being so lazy, but I'm not a professional developer, only a mere 
first year student. After some debugging I can tell you that the program 
crashes immediately after a call to the method 
ClassLoader.findNative(ClassLoader,String): Line 1771

The next method called is opencv_highgui.cvCreateCameraCapture(int), that is 
the native method of the Opencv libs. So now the 

If you know how to debug the Java virtual machine itself I can give it a shoot.

I will try with the function of Gstreamer that OpenCV uses after locating it in 
the source to see if the problem is the same. 

And believe me, I'm not trying to make you lose your time. 

Original comment by alvaroaccionmontes@gmail.com on 30 Apr 2011 at 2:45

GoogleCodeExporter commented 9 years ago
I've tweaked the source of OpenCV to avoid calling any function of gstreamer 
from the native call you imlemented, and the exception that raises is this one:

java.lang.Exception: cvCreateCameraCapture() Error: Could not create camera 
capture.

So I think we can conclude that the problem is from gstreamer itself.

Thanks for your time.

Original comment by alvaroaccionmontes@gmail.com on 30 Apr 2011 at 3:15

GoogleCodeExporter commented 9 years ago
More info. V4L headers have been removed from kernel, so only V4Lv2 remains. 
This causes OpenCV to skip that interface and jump directly to gstreamer. You 
probably have both modules so there is no problem because V4L option engages 
(or because your gstreamer lib has not got this bug).

Original comment by alvaroaccionmontes@gmail.com on 30 Apr 2011 at 3:35

GoogleCodeExporter commented 9 years ago
Sorry, didn't mean to upset you, but some people /are/ lazy, so..

Anyway, gstreamer's fine. You say it works fine in C++ and Python, so it should 
work in Java. When you use OpenCV in C++ or Python, you do not use it within 
graphics.CVprocessing right? So what about using the same exact functions, in 
the same exact order? Does the exact same code in C++ or Python translated to 
Java still fail? And if so, what is this code? And please, no more than 10 
lines, thank you

Original comment by samuel.a...@gmail.com on 30 Apr 2011 at 3:45

GoogleCodeExporter commented 9 years ago
Let me explain better. I have a missing header for V4L, so I cannot use that 
module and the compiler skips to GStreamer. 
The libs I use with C++/ python are Ubuntu packages already compiled and 
tested, so the code works. And I cannot test Javacv with those because they're 
v2.1.
If you can provide me with an older version of Javacv already built (I couldn't 
manage to do it due to a similar issue) I'll try if the problem persists, but I 
bet it would work fine in case I try. Anyway, I'll disassemble my current libs 
in order to see if I my point was right.
Thanks for your hard work. Really.

Original comment by alvaroaccionmontes@gmail.com on 30 Apr 2011 at 4:27

GoogleCodeExporter commented 9 years ago
Here is the file with the asm code and the calls. As I supposed, it only uses 
V4L.

So it is not Javacv problem. See you arround :)

Original comment by alvaroaccionmontes@gmail.com on 30 Apr 2011 at 7:00

Attachments:

GoogleCodeExporter commented 9 years ago
JavaCV works with OpenCV 2.2 not 2.1. Please read the README.txt file before 
posting things like that next time, thank you

Original comment by samuel.a...@gmail.com on 1 May 2011 at 2:54

GoogleCodeExporter commented 9 years ago
Fixed in latest release:
 * New `videoInputLib` wrapper and corresponding `VideoInputFrameGrabber` to capture using DirectShow, useful under Windows 7 where OpenCV and FFmpeg can fail to capture using Video for Windows

Use VideoInputFrameGrabber instead of OpenCVFrameGrabber.

Original comment by samuel.a...@gmail.com on 11 May 2011 at 3:30