开发者

Capture high-resolution image snapshots from webcam, in Java

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 w开发者_运维问答ith. - 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.


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.


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"));
}
}


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜