• Stars
    star
    2,256
  • Rank 20,407 (Top 0.5 %)
  • Language
    Java
  • License
    MIT License
  • Created over 12 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The goal of this project is to allow integrated or USB-connected webcams to be accessed directly from Java. Using provided libraries users are able to read camera images and detect motion. Main project consist of several sub projects - the root one, which contains required classes, build-in webcam driver compatible with Windows, Linux and Mac OS, which can stream images as fast as your camera can serve them (up to 50 FPS). Main project can be used standalone, but user is able to replace build-in driver with different one - such as OpenIMAJ, GStreamer, V4L4j, JMF, LTI-CIVIL, FMJ, etc.

Webcam Capture API

This library allows you to use your build-in or external webcam directly from Java. It's designed to abstract commonly used camera features and support various capturing frameworks.

Maven Central Build Status Coverage Status

Rationale

Assume a situation when your code depends on some capturing framework, but suddenly you have to drop it and use a different, maybe newer one (e.g. replace archaic JMF with newest GStreamer). By doing this you will have to rewrite significant piece of your code because these frameworks are completely different and not compatible at all. This is where Webcam Capture API comes to save the world - it was created to remove the burden of such situations so you do not have to rewrite your code ever again, but instead you can simply switch the driver class to different one.

Features

  • Simple, thread-safe and non-blocking API,
  • No additional software required,
  • Supports multiple platforms (Windows, Linux, Mac OS, etc) and various architectures (32-bit, 64-bit, ARM),
  • Get images from build-in or USB-connected PC webcams,
  • Get images from IP / network cameras (as MJPEG or JPEG),
  • Offers ready to use motion detector,
  • All required JARs Available in Maven Central,
  • Offers possibility to expose images as MJPEG stream,
  • It is available as Maven dependency or standalone ZIP binary (with all dependencies included),
  • Swing component to display video feed from camera,
  • Swing component to choose camera (drop down),
  • Multiple capturing frameworks are supported:

The latest stable version is: 0.3.12

The latest development version is: 0.3.13-SNAPSHOT

Raspberry PI

(and other ARM devices)

The latest version (0.3.10) does not work on ARM just out of the box. To make it working you need to replace version 0.6.2 of BridJ JAR by the 0.6.3-SNAPSHOT or newer bridj-0.7-20140918. Moreover, lately Jonathon Hare from OpenIMAJ team, found a problem described in bridj #525 which causes problems on armhf architecture.

Maven

The latest stable version is available in Maven Central:

<dependency>
  <groupId>com.github.sarxos</groupId>
  <artifactId>webcam-capture</artifactId>
  <version>0.3.12</version>
</dependency>

Snapshot version:

<repository>
	<id>Sonatype OSS Snapshot Repository</id>
	<url>http://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<dependency>
	<groupId>com.github.sarxos</groupId>
	<artifactId>webcam-capture</artifactId>
	<version>0.3.13-SNAPSHOT</version>
</dependency>

Download

The newest stable version can be downloaded as separated ZIP binary. This ZIP file contains Webcam Capture API itself and all required dependencies (in libs directory). Click on the below link to download it:

webcam-capture-0.3.12-dist.zip

The latest development version JAR (aka SNAPSHOT) can be downloaded here.

Contribution

If you have strong will, spare time, knowledge or even some small amount of money you would like to spent for good purpose you can help developing this awesome Webcam Capture API and make it even better! Several kinds of contributions are very welcome:

Star Project

If you think this project is great, you would like to help, but you don't know how - you can become project's stargazer. By starring you're making project more popular. Visit this link if you would like to learn more about how notifications and stars works on Github.

Report Bug or Feature

If you've found a bug or you've came-up with some fantastic feature which can make Webcam Capture a better API to use, don't hesitate to create new issue where you can describe in details what the problem is, or what would you like to improve.

Perform Tests

Since Webcam Capture use some part of native code, it's very hard to cover all supported operating systems. I'm always testing it on 64-bit Ubuntu Linux, Windows XP and Vista (both 32-bit), but I have no possibility to test on Raspberry Pi, Mac OS and 32-bit Linux. Please help and test on those systems if you have such possibility.

Write Code

If you know Java or C++ you can help developing Webcam Capture by forking repository and sending pull requests. Please visit this link if you don't know how to contribute to other's code at Github.

Donate

People have expressed a wish to donate a little money. Donating won't get you anything special, other than a warm feeling inside, and possibly urge me to produce more freely available material for Webcam Capture project. You can donate via PayPal, just click donate button available below - it will redirect you to the secured PayPal page where you can provide donation amount (there is no minimal value).

Donate via PayPal

Hello World

Code below will capture image from your default webcam and save it in hello-world.png file:

Webcam webcam = Webcam.getDefault();
webcam.open();
ImageIO.write(webcam.getImage(), "PNG", new File("hello-world.png"));

More Examples!

Below are the very pretty basic examples demonstrating of how Webcam Capture API can be used in the Java code. All can be found in the project source code. Please note that some of those examples may use the newest API which has not yet been released to maven Central. In such a case please make sure you are using the newest Webcam Capture API SNAPSHOT.

And here are some more advanced examples, few with quite fancy GUI.

YouTube Tutorials

Video series by Genuine Coder for Webcam Capture beginners:

Capture Drivers

Webcam Capture API defines WebcamDriver interface which has been already implemented in several capturing drivers build on top of well-known frameworks used to work with multimedia and cameras. Complete list can be found below.

By default (if other driver is not specified) library uses default driver which consists of small, refined part of awesome OpenIMAJ framework wrapped in thread-safe container. However, there are more ready-to-use drivers which can be used as a replacement or addition to the default one. By utilizing those drivers Webcam Capture can be extended with various new features (e.g. IP camera support).

List of additional capture drivers includes:

Driver Name Stable Central Description
ipcam yes yes Driver for IP / network camera
fswebcam yes yes Driver for FSWebcam CLI tool
gstreamer yes yes Driver for GStreamer framework
openimaj yes yes Driver for OpenIMAJ framework
v4l4j yes no Driver for V4L4j library
jmf yes yes Driver for JMF / FMJ frameworks
lti-civil yes yes Driver for LTI-CIVIL library
vlcj yes yes Driver for vlcj library
javacv yes yes Driver for JavaCV library
ffmpeg-cli poc no Driver for FFmpeg CLI tool
raspicam poc no Driver for Raspicam CLI PIcam tool
  • Central = available in Maven Central Repository
  • poc = Proof of Concept

Default Driver

If no other driver is specified, the default driver will be used. It consists of small, refined part of awesome OpenIMAJ framework wrapped in thread-safe container.

IP Camera Driver

This capture driver gives possibility to access IP camera devices and handle images in form of JPEG pictures or MJPEG streams.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-ipcam</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use:

Webcam.setDriver(new IpCamDriver());

More details and binaries download can be found on dedicated webcam-capture-driver-ipcam page.

Fswebcam Driver

This capture driver gives possibility to use CLI tool called fswebcam (written by Philip Heron) to access UVC devices connected to the computer. It works only on *nix and requires tool to be installed on the environment where driver is used.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-fswebcam</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use:

Webcam.setDriver(new FsWebcamDriver());

More details on how to use, how to install fswebcam and where binaries can be downloaed, can be found on dedicated webcam-capture-driver-fswebcam page.

GStreamer Driver

This capture driver gives possibility to use GStreamer to access UVC camera devices connected to computer. It works on Windows and Linux only.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-gstreamer</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use:

Webcam.setDriver(new GStreamerDriver());

More details on how to use, how to install GStreamer and where binaries can be downloaded, can be found on dedicated webcam-capture-driver-gstreamer page.

OpenIMAJ Driver

This capture driver gives possibility to use OpenIMAJ to access UVC camera devices connected to the computer.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-openimaj</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use:

Webcam.setDriver(new OpenImajDriver());

More details on how to use it and where binaries can be downloaded, can be found on dedicated webcam-capture-driver-openimaj page.

V4L4j Driver

This is capture driver which uses V4L4j project to access UVC camera devices. It works on Linux only and it seems like it is most suitable for use on Raspberry Pi.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-v4l4j</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use:

Webcam.setDriver(new V4l4jDriver());

More details on how to use it and where necessary binaries can be downloaded, can be found on dedicated webcam-capture-driver-v4l4j page.

JMF Driver

This is capture driver which uses JMF (Java Media Framework) to access UVC webcam devices. The JMF needs to be installed and configured on the PC before this driver can be used. It can also be used alternatively with the FMJ project.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-jmf</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use:

Webcam.setDriver(new JmfDriver());

More details on how to use it, install, and where necessary binaries can be downloaded, can be found on dedicated webcam-capture-driver-jmf page.

LTI-CIVIL Driver

This is capture driver designed to leverage capabilities of LTI-CIVIL project (by Larson Technologies Inc.) and use it to access wide range of UVC devices. It works on 32-bit architectures only.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-lti-civil</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use it:

Webcam.setDriver(new LtiCivilDriver());

More details on how to use it, and where necessary binaries can be downloaded, can be found on dedicated webcam-capture-driver-lti-civil page.

VLCj Driver

This is capture driver which uses VLCj library from Caprica Software Limited to gain access to the UVC camera device.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-vlcj</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use it:

Webcam.setDriver(new VlcjDriver());

More details on how to use it, how to install, and where necessary binaries can be downloaded, can be found on dedicated webcam-capture-driver-vlcj page.

JavaCV Driver

This is capture driver which uses JavaCV binding for OpenCV to gain access to the UVC camera device.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-opencv</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

or if you are using webcam-capture < 0.3.12:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-javacv</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

If you only target specific platforms take a look at Reducing the Number of Dependencies.

How to use it:

Webcam.setDriver(new JavaCvDriver());

More details on how to use it, how to install, and where necessary binaries can be downloaded, can be found on dedicated webcam-capture-driver-javacv page.

FFmpeg CLI Driver

This is capture driver which uses ffmpeg CLI tool from FFmpeg to access UVC camera device.

Maven dependency:

<dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture-driver-ffmpeg-cli</artifactId>
    <version>{webcam-capture-version-here}</version>
</dependency>

How to use it:

Webcam.setDriver(new FFmpegCliDriver());

More details on how to use it, how to install, and where necessary binaries can be downloaded, can be found on dedicated webcam-capture-driver-ffmpeg-cli page.

History

I initially started working on Webcam Capture as a simple proof-of-concept after I read Andrew Davison's fantastic book entitled Killer Game Programming (which is also available online). Thank you Andrew! Later I found that there is a complete mess in Java APIs allowing you to capture images from webcams. Once you choose specific API you cannot change it without modifying large parts of the code. I decided to change this situation and write general purpose wrapper for various different APIs (like JMF, OpenCV, OpenIMAJ, LTI-CIVIL, VLC). In such a way, Webcam Capture as we know it today, was brought to life. Today you can change underlying frameworks just by replacing webcam driver (one line code change). If there is no driver for particular framework, it's very easy to write it yourself.

License

Copyright (C) 2012 - 2017 Bartosz Firyn (https://github.com/sarxos) and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sarxos

More Repositories

1

secure-tokens

Small set of tools allowing you to create secure encrypted tokens, which can be later exchanged with 3rd party systems or stored as a license files. The goal of this project is to play with JCA and learn its API.
Java
81
star
2

win-registry

100% pure Java Windows registry utility
Java
57
star
3

sikuli-ocr

Sikuli-based OCR engine
Java
43
star
4

v4l4j

This is mavenized and customized fork of original V4L4J by Gilles Gigan. It contains only Java source code (no natives) and *.so objects precompiled for several architectures.
Java
13
star
5

l2fprod-common

Property sheet (aka Java Bean Property Editor) Swing component from L2FProd with redesigned and partially rewritten API. Original L2FProd project has not been updated for years and the code here is new, customized and reworked code with partially backward-uncompatible API. It works fine, but please use on your own risk. Plan to release to Maven Central as OSGi bundle.
Java
12
star
6

equinox-launcher

Simple proof-of-concept of how to embed Equinox OSGi runtime in Java program.
Java
11
star
7

fixml-converter

[DEPRECATED] XStream based converter between FIX and FIXML messages
Java
8
star
8

medusa-system

Medusa Trading System
Java
7
star
9

spycam

Change your webcam into spycam
Java
3
star
10

exchange-rates-api

Java API to access forex exchange rates via Yahoo YQL with fallback to OpenExchangeRates JSON
Java
3
star
11

vita-image-gallery

Simple file-based images gallery with AJAX support for getting categories and images
PHP
2
star
12

alior-api

[DEPRECATED] API do systemu internetowego Alior Banku
Java
2
star
13

1-wire-network

Java event-driven implementation of 1-Wire service.
Java
2
star
14

fasm-compiler-plugin

Maven plugin to compile flat assembler (FASM) asm files.
Assembly
2
star
15

sikulix-maven-plugin

Sikuli X plugin for Maven
Java
1
star
16

kinomaniak-loader

Greasemonkey script loading movies from kinomaniak.tv
JavaScript
1
star
17

lighthouse

Identifying the position of the lighthouse on the basis of its characteristics of light.
Java
1
star
18

filmweb-adv-avoid

Greasemonkey script removing filmweb.pl welcome advertisement
JavaScript
1
star
19

weather-sat-gen

Download satellite weather images and create movie
Java
1
star
20

uhuru-cloud-test

Just a simple POC for JAX-WS service deployed in Uhuru AppCloud Tomcat instance, build with Maven and Eclipse WTP.
Java
1
star
21

smesx

SmesX v2.2 protocol implementation with Apache HTTP Client component and JAXB
Java
1
star
22

ryzom-network-client

This is Java client for LV-20 Ryzom Network, crafted by the Matis engineers after studies performed on very ancient amber cubes found at the Megacorp SAT01-B satellite crash site near Sandy Workshop of Aeden Aqueous.
Java
1
star
23

simple-servant

Minimalistic and simple HTTP service written in C#
C#
1
star
24

gadacz-server

Server for the Gadacz application. I've just played with socket connections and created Gadacz communicator server (J2SE) and mobile client (J2ME, MIDP1.0) for it, both as POC in only one day. Mobile client you can find in separate repo.
Java
1
star
25

sx-swing

Swing utilities and other stuff
Java
1
star
26

sx-mobile-tuner

Mobile guitar tuner (J2ME, MIDP2.0). Unfortunately, it can only tune in the key of E. Application language is PL only.
Java
1
star
27

gadacz-client-mobile

Mobile client (J2ME, MIDP2.0) for Gadacz application. There can be unlimited number of Gadacz clients connected (but please note that each client uses one thread on the server side, so its number is not fully unlimited - there can be so many clients connected as number of free threads, and this strongly depends on the memory allocation possibility)
Java
1
star
28

bossa-api-connector

[DEPRECATED] Connector for BossaAPI delivered in NOL3 from BOÅš. This project has been deprecated, I don't know if I will maintain it in the future. I simply don't use NOL3 any more.
Java
1
star
29

net-calculus

One of the projects I've made for the programing lecture. Simple POC of distributed computing. It design allows to execute different mathematical operations on the different machines (only sum and multiplication is supported as I remember).
Java
1
star