public class Webcam
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
protected |
Webcam(WebcamDevice device)
Webcam class.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
addDiscoveryListener(WebcamDiscoveryListener l)
Add new webcam discovery listener.
|
boolean |
addWebcamListener(WebcamListener l)
Add webcam listener.
|
boolean |
close()
Close the webcam.
|
protected void |
dispose()
Completely dispose capture device.
|
java.awt.Dimension[] |
getCustomViewSizes() |
static Webcam |
getDefault()
Will discover and return first webcam available in the system.
|
static Webcam |
getDefault(long timeout)
Will discover and return first webcam available in the system.
|
static Webcam |
getDefault(long timeout,
java.util.concurrent.TimeUnit tunit)
Will discover and return first webcam available in the system.
|
WebcamDevice |
getDevice()
Return underlying webcam device.
|
static WebcamDiscoveryListener[] |
getDiscoveryListeners() |
static WebcamDiscoveryService |
getDiscoveryService()
Return discovery service.
|
static WebcamDiscoveryService |
getDiscoveryServiceRef()
Return discovery service without creating it if not exists.
|
static WebcamDriver |
getDriver()
Return webcam driver.
|
double |
getFPS() |
java.awt.image.BufferedImage |
getImage()
Capture image from webcam and return it.
|
java.nio.ByteBuffer |
getImageBytes()
Get RAW image ByteBuffer.
|
void |
getImageBytes(java.nio.ByteBuffer target)
Get RAW image ByteBuffer.
|
WebcamImageTransformer |
getImageTransformer()
Return image transformer.
|
WebcamLock |
getLock()
Return webcam lock.
|
java.lang.String |
getName()
Get webcam name (device name).
|
java.awt.Dimension |
getViewSize()
Get current webcam resolution in pixels.
|
java.awt.Dimension[] |
getViewSizes()
Return list of supported view sizes.
|
static Webcam |
getWebcamByName(java.lang.String name)
Return webcam with given name or null if no device with given name has been found.
|
WebcamListener[] |
getWebcamListeners() |
int |
getWebcamListenersCount() |
static java.util.List<Webcam> |
getWebcams()
Get list of webcams to use.
|
static java.util.List<Webcam> |
getWebcams(long timeout)
Get list of webcams to use.
|
static java.util.List<Webcam> |
getWebcams(long timeout,
java.util.concurrent.TimeUnit tunit)
Get list of webcams to use.
|
static boolean |
isAutoOpenMode()
Is auto open mode enabled.
|
static boolean |
isHandleTermSignal()
Is TERM signal handler enabled.
|
boolean |
isImageNew() |
boolean |
isOpen()
Is webcam open?
|
protected void |
notifyWebcamImageAcquired(java.awt.image.BufferedImage image)
Asynchronously start new thread which will notify all webcam listeners about the new image
available.
|
boolean |
open()
Open the webcam in blocking (synchronous) mode.
|
boolean |
open(boolean async)
Open the webcam in either blocking (synchronous) or non-blocking (asynchronous) mode.
|
boolean |
open(boolean async,
WebcamUpdater.DelayCalculator delayCalculator)
Open the webcam in either blocking (synchronous) or non-blocking (asynchronous) mode.The
difference between those two modes lies in the image acquisition mechanism.
In blocking mode, when user calls getImage() method, device is being queried for new
image buffer and user have to wait for it to be available.In non-blocking mode, there is a special thread running in the background which constantly fetch new images and cache them internally for further use. |
static void |
registerDriver(java.lang.Class<? extends WebcamDriver> clazz)
Register new webcam video driver.
|
static void |
registerDriver(java.lang.String clazzName)
Register new webcam video driver.
|
static boolean |
removeDiscoveryListener(WebcamDiscoveryListener l)
Remove discovery listener
|
boolean |
removeWebcamListener(WebcamListener l)
Removes webcam listener.
|
static void |
resetDriver()
Reset webcam driver.
This method is not thread-safe! |
static void |
setAutoOpenMode(boolean on)
Switch all webcams to auto open mode.
|
void |
setCustomViewSizes(java.awt.Dimension... sizes)
Set custom resolution.
|
static void |
setDriver(java.lang.Class<? extends WebcamDriver> driverClass)
Set new video driver class to be used by webcam.
|
static void |
setDriver(WebcamDriver wd)
Set new video driver to be used by webcam.
This method is not thread-safe! |
static void |
setHandleTermSignal(boolean on)
CAUTION!!!
This is experimental feature to be used mostly in in development phase. |
void |
setImageTransformer(WebcamImageTransformer transformer)
Set image transformer.
|
void |
setParameters(java.util.Map<java.lang.String,?> parameters)
If the underlying device implements Configurable interface, specified parameters are passed
to it.
|
void |
setViewSize(java.awt.Dimension size)
Set new view size.
|
protected static void |
shutdown()
Shutdown webcam framework.
|
java.lang.String |
toString() |
protected java.awt.image.BufferedImage |
transform(java.awt.image.BufferedImage image)
TRansform image using image transformer.
|
protected Webcam(WebcamDevice device)
device
- - device to be used as webcamjava.lang.IllegalArgumentException
- when device argument is nullprotected void notifyWebcamImageAcquired(java.awt.image.BufferedImage image)
public boolean open()
WebcamException
- when something went wrong#open(boolean, DelayCalculator)
public boolean open(boolean async)
async
- true for non-blocking mode, false for blockingWebcamException
- when something went wrong#open(boolean, DelayCalculator)
public boolean open(boolean async, WebcamUpdater.DelayCalculator delayCalculator)
getImage()
method, device is being queried for new
image buffer and user have to wait for it to be available.isImageNew()
method to distinguish
if returned image is not the same as the previous one. async
- true for non-blocking mode, false for blockingdelayCalculator
- responsible for calculating delay between two image fetching in
non-blocking mode; It's ignored in blocking mode.WebcamException
- when something went wrongpublic boolean close()
public WebcamDevice getDevice()
WebcamDefaultDevice
is
returned when no external driver is used.protected void dispose()
protected java.awt.image.BufferedImage transform(java.awt.image.BufferedImage image)
image
- the image to be transformedpublic boolean isOpen()
public java.awt.Dimension getViewSize()
public java.awt.Dimension[] getViewSizes()
public void setCustomViewSizes(java.awt.Dimension... sizes)
sizes
- the array of custom resolutions to be supported by webcampublic java.awt.Dimension[] getCustomViewSizes()
public void setViewSize(java.awt.Dimension size)
size
- the new view size to be setsetCustomViewSizes(Dimension[])
,
getViewSizes()
public java.awt.image.BufferedImage getImage()
public boolean isImageNew()
public double getFPS()
public java.nio.ByteBuffer getImageBytes()
public void getImageBytes(java.nio.ByteBuffer target)
target
- the target ByteBuffer
object to copy data intopublic void setParameters(java.util.Map<java.lang.String,?> parameters)
parameters
- - Map of parameters changing device defaultsWebcamDevice.Configurable
public static java.util.List<Webcam> getWebcams() throws WebcamException
WebcamException
- when something is wronggetWebcams(long, TimeUnit)
public static java.util.List<Webcam> getWebcams(long timeout) throws java.util.concurrent.TimeoutException, WebcamException
timeout
- the time to wait for webcam devices to be discoveredjava.util.concurrent.TimeoutException
- when timeout occursWebcamException
- when something is wrongjava.lang.IllegalArgumentException
- when timeout is negativegetWebcams(long, TimeUnit)
public static java.util.List<Webcam> getWebcams(long timeout, java.util.concurrent.TimeUnit tunit) throws java.util.concurrent.TimeoutException, WebcamException
timeout
- the devices discovery timeouttunit
- the time unitjava.util.concurrent.TimeoutException
- when timeout has been exceededWebcamException
- when something is wrongjava.lang.IllegalArgumentException
- when timeout is negative or tunit nullpublic static Webcam getDefault() throws WebcamException
WebcamException
- if something is really wronggetWebcams()
public static Webcam getDefault(long timeout) throws java.util.concurrent.TimeoutException, WebcamException
timeout
- the webcam discovery timeout (1 minute by default)java.util.concurrent.TimeoutException
- when discovery timeout has been exceededWebcamException
- if something is really wrongjava.lang.IllegalArgumentException
- when timeout is negativegetWebcams(long)
public static Webcam getDefault(long timeout, java.util.concurrent.TimeUnit tunit) throws java.util.concurrent.TimeoutException, WebcamException
timeout
- the webcam discovery timeout (1 minute by default)tunit
- the time unitjava.util.concurrent.TimeoutException
- when discovery timeout has been exceededWebcamException
- if something is really wrongjava.lang.IllegalArgumentException
- when timeout is negative or tunit nullgetWebcams(long, TimeUnit)
public java.lang.String getName()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean addWebcamListener(WebcamListener l)
l
- the listener to be addedjava.lang.IllegalArgumentException
- when argument is nullpublic WebcamListener[] getWebcamListeners()
public int getWebcamListenersCount()
public boolean removeWebcamListener(WebcamListener l)
l
- the listener to be removedpublic static WebcamDriver getDriver()
public static void setDriver(WebcamDriver wd)
wd
- new webcam driver to be used (e.g. LtiCivil, JFM, FMJ, QTJ)java.lang.IllegalArgumentException
- when argument is nullpublic static void setDriver(java.lang.Class<? extends WebcamDriver> driverClass)
WebcamDriver
interface and should have public default constructor, so instance can be
created by reflection.driverClass
- new video driver class to usejava.lang.IllegalArgumentException
- when argument is nullpublic static void resetDriver()
public static void registerDriver(java.lang.Class<? extends WebcamDriver> clazz)
clazz
- webcam video driver classjava.lang.IllegalArgumentException
- when argument is nullpublic static void registerDriver(java.lang.String clazzName)
clazzName
- webcam video driver class namejava.lang.IllegalArgumentException
- when argument is nullpublic static void setHandleTermSignal(boolean on)
on
- signal handling will be enabled if true, disabled otherwisepublic static boolean isHandleTermSignal()
public static void setAutoOpenMode(boolean on)
on
- true to enable, false to disablepublic static boolean isAutoOpenMode()
public static boolean addDiscoveryListener(WebcamDiscoveryListener l)
l
- the listener to be addedjava.lang.IllegalArgumentException
- when argument is nullpublic static WebcamDiscoveryListener[] getDiscoveryListeners()
public static boolean removeDiscoveryListener(WebcamDiscoveryListener l)
l
- the listener to be removedpublic static WebcamDiscoveryService getDiscoveryService()
public static WebcamDiscoveryService getDiscoveryServiceRef()
public WebcamImageTransformer getImageTransformer()
public void setImageTransformer(WebcamImageTransformer transformer)
transformer
- the transformer to be setpublic WebcamLock getLock()
protected static void shutdown()
public static Webcam getWebcamByName(java.lang.String name)
name
- the webcam namejava.lang.IllegalArgumentException
- when name is nullCopyright © 2012-2018 Bartosz Firyn (SarXos). All Rights Reserved.