EngnzWaks / javacv

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

could not create camera capture #239

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Linux Mint Release 12, Kernel 3.0.0-12 (Netbeans)
2.Code:

package javaapplication1;

import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;

public class JavaApplication1 {

    public static void DoSomething() {
        try {
            OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(-1);
            grabber.start();
            //do other stuff
        } 
        catch (Exception e) {
            String exp = e.toString();
            System.out.println(e.toString());
        }
    }

    public static void main(String[] args) {
        DoSomething();

    }
}

3.Exception thrown: "com.googlecode.javacv.FrameGrabber$Exception: 
cvCreateCameraCapture() Error: Could not create camera capture."

What is the expected output? What do you see instead?

Expect: Successful completion of try block
Entered Catch block upon 
grabber.start()(throws:com.googlecode.javacv.FrameGrabber$Exception: 
cvCreateCameraCapture() Error: Could not create camera capture.)

What version of the product are you using? On what operating system?

javacv-0.2-bin.zip on Linux Mint Release 12 32 bit, Kernel 3.0.0-12 (Netbeans)
Opencv version is OpenCV-2.4.2

Please provide any additional information below.

Single usb webcam is Logitech 9000

I can create IplImage from a loaded image (indicating that my included jars are 
there).

The following c++ code works

void GrabImage() {
    CvCapture *pCapturedImage = cvCreateCameraCapture(-1);
    IplImage *pRGBImg = cvQueryFrame(pCapturedImage);
    cvReleaseCapture(&pCapturedImage);
    //do other stuff
}

Have tried OpenCVFrameGrabber(0, 1, 2, 3), 

Dependencies are update to current Precise packages.

PS: I am certain I am doing something stupid.

Original issue reported on code.google.com by trapperj...@haunted-river.net on 30 Aug 2012 at 4:57

GoogleCodeExporter commented 8 years ago
So, if `cvCreateCameraCapture(-1)` works in C++, does it work in Java too, or 
not?

Original comment by samuel.a...@gmail.com on 31 Aug 2012 at 1:20

GoogleCodeExporter commented 8 years ago
In the following method the try block will complete:

    public static void tryThis() {
        try {
            CvCapture capture = cvCreateCameraCapture(-1);
            IplImage iplImage = cvQueryFrame(capture);
            cvSaveImage("tryThisJ.jpg", iplImage);
        } catch (Exception e) {
            String exp = e.toString();
            System.out.println(e.toString());
        }
    }

But, the IplImage (iplImage) is null. 

With a c++ implementation:

void tryThisC() {
    try {
        CvCapture *capture = cvCreateCameraCapture(-1);
        IplImage *iplImage = cvQueryFrame(capture);
        cvSaveImage("trythisC.jpg", iplImage);
        cvReleaseCapture(&capture);
        cvReleaseImage(&iplImage);
    } catch (Exception e) {
        cout << e.err;
    }
}

the error "VIDIOC_QUERYMENU: Invalid argument" appears in the output console, 
but the try block completes, creating an image that is a valid capture from the 
webcam. Note that, with the webcam unplugged, the c++ method will behave 
exactly like the java implementation... completing the try block and collecting 
a null image. 

Original comment by trapperj...@haunted-river.net on 31 Aug 2012 at 1:56

GoogleCodeExporter commented 8 years ago
You are obviously using two different versions of OpenCV. If you use the same 
version for C++ and Java, they will behave the same.

Original comment by samuel.a...@gmail.com on 31 Aug 2012 at 2:13

GoogleCodeExporter commented 8 years ago
Sorry I'm so dunderheaded, but there is only one opencv on this machine (at 
/usr/local/include/opencv).

I'm guessing that I have to rebuild javacv from source on my machine, but this 
is a huge guess at my skill level.

Original comment by trapperj...@haunted-river.net on 31 Aug 2012 at 5:30

GoogleCodeExporter commented 8 years ago
No need to rebuild. You should simply make sure to uninstall any old version of 
OpenCV. When you execute your C++ code, it's probably using the old version, 
which works better for some reason. You can try to recompile JavaCV against 
that old version of OpenCV if it works better for you, yes, I suppose...

Original comment by samuel.a...@gmail.com on 1 Sep 2012 at 1:28

GoogleCodeExporter commented 8 years ago
BTW, if you are certain you do not have any other versions of OpenCV on your 
machine, how did you confirm that fact?

Original comment by samuel.a...@gmail.com on 1 Sep 2012 at 4:28

GoogleCodeExporter commented 8 years ago
OK, I fixed it by:

1) Created a new partition and installed Mint Maya (32 bit)
2) Followed the instructions at "A Comprehensive Guide to Installing and 
Configuring OpenCV 2.4.1 on Ubuntu" (hxxp:// 
http://www.ozbotz.org/opencv-installation/)

I'm sorry I was zoned out about the "other versions" notion. I originally came 
to that conclusion, erroneously, by checking whether is showed as installed in 
my synaptic package manager (it wasn't). Later, I noticed that my java programs 
were using a library from an earlier version. How it got there, I don't know.

Anyway, it's fixed. Many thanks to the team for this resource.

Original comment by trapperj...@haunted-river.net on 2 Sep 2012 at 7:10