Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX 10.10: OpenCVFrameGrabber freezes the application #92

Closed
Golui opened this issue Feb 6, 2015 · 12 comments
Closed

OSX 10.10: OpenCVFrameGrabber freezes the application #92

Golui opened this issue Feb 6, 2015 · 12 comments

Comments

@Golui
Copy link

Golui commented Feb 6, 2015

I wanted to play around with JavaCV and I tried to compile some sample code. After linking the native binaries, it did compile, however, it didn't work. After doing some research, I pinned down the problem might be the OpenCVFrameGrabber class.

To reproduce compile the following code:

public class Test 
{
    public static void main(String[] args) throws Exception 
    {
        OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
        grabber.start();

        IplImage frame = grabber.grab();
        IplImage image = null;
        IplImage prevImage = null;
        IplImage diff = null;

        System.out.println("Before");
        CanvasFrame canvasFrame = new CanvasFrame("Test");
        System.out.println("After");
        canvasFrame.setCanvasSize(frame.width(), frame.height());

        grabber.stop();
        canvasFrame.dispose();
    }
}

The webcam will turn on and the app will freeze, with the console output 'Before'.

I've been unable to reproduce this issue on the python bindings, so I believe this is a JavaCV issue. Also, it runs fine on Windows.

I'm using JavaCV 0.10 with OpenCV 2.4.10 and Java 8. OS is OSX 10.10 Yosemite.

@saudet
Copy link
Member

saudet commented Feb 7, 2015

Does the same thing happen if you use the new C++ API of OpenCV directly?

@Golui
Copy link
Author

Golui commented Feb 7, 2015

No. Neither using the native C++ API (version 2.4.10) nor the Python bindings.

@saudet
Copy link
Member

saudet commented Feb 7, 2015

Are you saying there is no problem if you use the following VideoCapture class in Java?
http://bytedeco.org/javacpp-presets/opencv/apidocs/org/bytedeco/javacpp/opencv_highgui.VideoCapture.html

@Golui
Copy link
Author

Golui commented Feb 7, 2015

I have not tried this. I'm new to opencv in general, can you please give me a sample program?

@saudet
Copy link
Member

saudet commented Feb 7, 2015

Just do it the same way you would do it from C++ or Python.

@Golui
Copy link
Author

Golui commented Feb 7, 2015

Using the VideoCapture I am able to display the frames, so I suppose it works.

However, the FrameGrabber still hangs. I also forgot to mention that the code I was testing it with was a stripped down version of the MotionDetection sample.

@saudet
Copy link
Member

saudet commented Feb 7, 2015

So, maybe it's only the old C API of OpenCV that doesn't work well anymore. What happens when if you call the following?

CvCapture capture = cvCreateCameraCapture(0);
IplImage image = cvQueryFrame(capture);

@Golui
Copy link
Author

Golui commented Feb 7, 2015

It does work, however, the canvas is blank about every second frame.

@saudet
Copy link
Member

saudet commented Feb 7, 2015

Right, so it works with VideoCapture. I'll be sure to use that, but first I need to redesign FrameGrabber so it doesn't rely on IplImage or Mat, to remove the dependency on OpenCV for users of FFmpeg only. But I haven't figured out yet what we should use. Any ideas?

@Golui
Copy link
Author

Golui commented Feb 7, 2015

Don't ask me. I'm new to this.

@saudet
Copy link
Member

saudet commented Apr 11, 2015

Does this still happen with JavaCV 0.11 and OpenCV 2.4.11?

@saudet
Copy link
Member

saudet commented Jul 4, 2015

OpenCV still doesn't support AVFoundation, but FFmpeg does, so I would say the fix to this issue is simply to use FFmpegFrameGrabber with the AVFoundation device: bytedeco/javacpp-presets#39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants