views:

420

answers:

3

I am implementing a simple eye tracker, which requires fast screenshoting of what is happening on the screen simultaneously with capturing the video from webcam.

The thing is that the way of doing it with Robot, mentioned here: http://stackoverflow.com/questions/2475303/java-library-for-capturing-active-window-screenshot is extremely slow.

By the way, retrieving the video from a webcam works much faster and returns the byte array, which is very fast to be processed.

Does anybody know a faster solution? C++ libraries, which can be linked to Java for doing this may help as well.

Thank you!

UPDATE: Decided to switch to OpenCV, now looking for the way to make screenshot with it :)

A: 

May be you can make use of JMF.. Checkout the Screen Grabber code @ Oracle's site. I think it will help you solve your problem.

Abdel Olakara
As from the source code, it seems to use the Robot as well:http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/screengrabber/LiveStream.javaOr am I wrong?
lyuba
+4  A: 

The robot.createScreenCapture(captureSize); call takes about 20ms for me.

Stephen Denne
I think the speed would be dependent on the framerate/drivers of the webcam in question.
graham.reeds
I haven't much experience working with data from webcams, but I thought they would supply much lower resolution, and pre-compressed streams.
Stephen Denne
You're right: I have the regular Logitek C300 webcam, so it returns 480*640 images. I use the Video for Linux lib to process video, it's written on C and runs perfectly fast. Ones I try to catch the screenshot with the same speed in real-time - it immediately slows down the process.I capture it like BufferedImage screenshot = robot.createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));May it happen because of the BurrefedImage? Is there any way to the the bit array from Robot?
lyuba
What I should add is that the most important thing in eye tracker is to catch the screenshot almost at the same moment as each webcam shot. 20ms may be actually too long. That would be also great to capture screen in the normal size, not just 480*640.
lyuba
Looking at the source of `createScreenCapture` shows that a RobotPeer is asked for the byte array, which is then wrapped in an appropriate BufferedImage. It also includes sync and restoreLocalAcceleration calls. However RobotPeer is not able to be used directly.
Stephen Denne
A: 

u should definitely give a shot to OpenCV

Elijah
Is there any way to link OpenCV to Java? I've heard about OpenCV, but right now I want to try Java for this task, and will switch to C++ only if it will be really needed.
lyuba
Here is the way to do it: http://ubaa.net/shared/processing/opencv/However I decided to try C++, thank you for the inspiration!
lyuba
oh thanx for the java api, i was actually looking for it too!
Elijah
Here is even a better API: http://code.google.com/p/javacv/
lyuba