Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to access web camera in Java

I need to access web camera using Java. This is what I want to do

  1. Access web cam

  2. Now the user can see web cam working because his face is visible on screen (have heard some libs are there which doesn't show the video output of webcam)

  3. when user click save button, take a snapshot and save it

I have tried number of ways to do this, from a long time.

  1. JMF - Now it is dead
  2. FMJ - Now it is dead too
  3. VLCJ - too much because I am not creating a music/video player and it expect VLC to be installed
  4. Xuggler - too much and hard work
  5. JMyron - didn't work
  6. JavaFX - I thought it could do it, but seems like it can't

I am even satisfied if the library is just ONLY doing the above mentioned, because that's enough for me. But I expect it to be simple too. Really great if it is not using DLLs, because it is not platform independent if it does. Really appreciate if it can DETECT the camera, without manually passing the camera name and other info as have do in VLCJ (because there might be thousands of camera brands, so I can't create a list of thousand elements in it). And, I am creating a desktop application, not web app.

If you know a library like this, please be kind enough to let me know. Other libraries (which might not suit to all of my requirements, but suits to the basic requirement) also welcome. Please help

like image 984
PeakGen Avatar asked Jul 14 '12 20:07

PeakGen


People also ask

How to access webcam in Java?

Then, let's write a simple example to capture an image using the Webcam class: Webcam webcam = Webcam. getDefault(); webcam. open(); BufferedImage image = webcam.

What are the types of Web cameras?

There are two types of webcams: (1) basic webcams, made by Microsoft, Logitech, HP, etc., and (2) IP Network Webcams, also known as network cameras.

What is Web camera function?

A webcam is a digital video device commonly built into a computer. Its main function is to transmit pictures over the Internet. It is popularly used with instant messaging services and for recording images.


1 Answers

I think the project you are looking for is: https://github.com/sarxos/webcam-capture (I'm the author)

There is an example working exactly as you've described - after it's run, the window appear where, after you press "Start" button, you can see live image from webcam device and save it to file after you click on "Snapshot" (source code available, please note that FPS counter in the corner can be disabled):

snapshot

The project is portable (WinXP, Win7, Win8, Linux, Mac, Raspberry Pi) and does not require any additional software to be installed on the PC.

API is really nice and easy to learn. Example how to capture single image and save it to PNG file:

Webcam webcam = Webcam.getDefault(); webcam.open(); ImageIO.write(webcam.getImage(), "PNG", new File("test.png")); 
like image 167
Bartosz Firyn Avatar answered Sep 19 '22 12:09

Bartosz Firyn