5

Anyone knows a Java library which can be used for the purpose of capturing high-resolution image snapshots from a webcam?

More precisely: - Detect the available webcams (laptops may have a built-in one and an external one attached trough an USB connection) - Choose a webcam to work with. - Detect available resolutions for IMAGE capture (ex: up to 1280x1024 for a web camera with 1.3 Mp sensor). They are generally much greater than the for VIDEO capture (ex: up to 640x480 for the same web camera). - Choose a resolution to work with. - On request (calling an API function), capture a snapshot from the selected camera with the selected resolution.

I've tried: - JMF: sucks, doesn't support automatic detection of attached web cameras. - FMJ: uses LTI-CIVIL for webcam support. - LTI-CIVIL: only supports VIDEO capture. The code is also very old (2007 if i remember correctly). Uses native libraries written in C++ for webcam access. DirectX for Windows and Video4Linux for (obviously, ) Linux. But looking over the C++ code, it becomes obvious that it's oriented towards video streaming which is not my purpose (as reflected in the description of what i need)

I would be thankful if anyone could point me to a Java library which fits the profile i need.

Thanks.

Michael
  • 51
  • 1
  • 2

4 Answers4

2

openCV is a popular C++ computer vision library. However, they have Java bindings as well. http://code.google.com/p/javacv/

OpenCV lets u access to image and video processing and capturing of image and video from multiple webcams as well.

Nick
  • 1,692
  • 3
  • 21
  • 35
1

This Java API should do the job: http://webcam-capture.sarxos.pl/ The following code takes a picture and saves it as a .png file in the project's workspace folder. Be sure to look through the creator's other examples on their website.

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.github.sarxos.webcam.Webcam;

public class TakePictureExample {

public static void main(String[] args) throws IOException {

    // get default webcam and open it
    Webcam webcam = Webcam.getDefault();
    webcam.open();

    // get image
    BufferedImage image = webcam.getImage();

    // save image to PNG file
    ImageIO.write(image, "PNG", new File("test.png"));
}
}
gwerven
  • 11
  • 2
0

The following open source project, webcamstudio http://code.google.com/p/webcamstudio/ has done a great job using Java for webcam support. Perhaps take some ideas from there.

Mohamed Mansour
  • 39,445
  • 10
  • 116
  • 90
0

You can use JMyron, the library is here and you can see how it works with this example

james_bond
  • 6,778
  • 3
  • 28
  • 34
  • 1
    Well, the example shows capturing a video stream (this i can do already with lti-civil). Will try openCV and if that fails too i'll try jMyron, thanks for the info. – Michael Jul 10 '11 at 16:27