public class CameraHelper extends HelperBase implements com.github.sarxos.webcam.WebcamListener
Note that you can use the Ptolemy II ImageDisplay actor to display image sequences captured using this module, but this does not work well when executed within Eclipse. In Eclipse, the Swing event thread blocks "waiting for: OGLRenderQueue$QueueFluher", and spends most of its time blocked rather than rendering. Hence, we do not get smooth video. Perhaps this is an Eclipse bug?
See the documentation for the JavaScript cameras module to see how to use this.
If invoking the constructor generates a message like:
Caused by: java.lang.RuntimeException: Library 'OpenIMAJGrabber' was not loaded successfully from file '/tmp/BridJExtractedLibraries5717506824090765864/OpenIMAJGrabber.so'
Then under Red Hat Linux, install lib4l for 64-bit JVMs, run:
sudo yum install libstdc++.x86_64
The way to diagnose these problems under Linux is to unjar the webcam-capture jar and run ldd:
cd /tmp jar -xf $PTII/lib/webcam-capture-0.3.12.jar ldd ./com/github/sarxos/webcam/ds/buildin/lib/linux_x64/OpenIMAJGrabber.so
Note that the webcam-capture jar contains both 32-bit and 64-bit shared libraries, be sure to run the ldd command on the version appropriate for your JVM.
Then look for libraries that are listed as "not found", then as root use
yum search xxx
to find them and then install them.
For example, if libv4l2.so.0 is not found, then run
yum search v4l2
and if v4l2 is not installed, then
yum install libv4l.x86_64
.
HelperBase.DATA_TYPE
_actor, _currentObj
Constructor and Description |
---|
CameraHelper(java.lang.Object actor,
jdk.nashorn.api.scripting.ScriptObjectMirror currentObj)
Create the system default camera.
|
CameraHelper(java.lang.Object actor,
jdk.nashorn.api.scripting.ScriptObjectMirror currentObj,
java.lang.String name)
Create a camera with the specified name.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
cameras()
Return an array of camera names that are available on this host.
|
void |
close()
Close the camera.
|
static java.lang.String |
defaultCamera()
Return the system default camera name.
|
java.lang.String |
getViewSize()
Return the current view size for this camera,
given as a JSON formatted string with fields "width"
and "height", for example '{"width":176, "height":144}'.
|
void |
open()
Open the camera.
|
void |
setViewSize(java.util.Map spec)
Set the current view size for this camera, representing the desired size
as a Map with integer valued fields "width" and "height".
|
AWTImageToken |
snapshot()
Return the most recent image obtained by the camera, or null
if no image has been obtained.
|
java.lang.String[] |
viewSizes()
Return an array of view sizes supported by this camera,
each given as a string of the form "width=176,height=144", for example.
|
void |
webcamClosed(com.github.sarxos.webcam.WebcamEvent event)
Notify this object that its camera has been closed.
|
void |
webcamDisposed(com.github.sarxos.webcam.WebcamEvent event)
Notify this object that its camera has been disposed.
|
void |
webcamImageObtained(com.github.sarxos.webcam.WebcamEvent event)
Notify this object that a new image has been obtained.
|
void |
webcamOpen(com.github.sarxos.webcam.WebcamEvent event)
Notify this object that its camera has been opened.
|
_appendNumericToBuffer, _appendToBuffer, _error, _error, _error, _error, _extractFromBuffer, _issueResponse, _removeDuplicates, _sizeOfType, _toJavaBytes, _toJSArray, getHelping
public CameraHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror currentObj) throws java.io.IOException
actor
- The actor associated with this camera.currentObj
- The JavaScript object that this is helping.java.io.IOException
- If there is no such camera.public CameraHelper(java.lang.Object actor, jdk.nashorn.api.scripting.ScriptObjectMirror currentObj, java.lang.String name) throws java.io.IOException
cameras()
,
or else a exception will be thrown. If cameras()
returns no cameras, then the dummy camera is used.name
- The name of the camera.actor
- The actor associated with this camera.currentObj
- The JavaScript object that this is helping.java.io.IOException
- If the camera does not exist.public static java.lang.String[] cameras()
public void close()
public static java.lang.String defaultCamera()
public java.lang.String getViewSize()
setViewSize(Map)
public void open()
public void setViewSize(java.util.Map spec) throws IllegalActionException
spec
- A map with integer valued fields "width" and "height".IllegalActionException
- If either field is absent.getViewSize()
public AWTImageToken snapshot()
public java.lang.String[] viewSizes()
public void webcamClosed(com.github.sarxos.webcam.WebcamEvent event)
webcamClosed
in interface com.github.sarxos.webcam.WebcamListener
event
- The event that closed the camera.public void webcamDisposed(com.github.sarxos.webcam.WebcamEvent event)
webcamDisposed
in interface com.github.sarxos.webcam.WebcamListener
event
- The event that disposed the camera.public void webcamImageObtained(com.github.sarxos.webcam.WebcamEvent event)
webcamImageObtained
in interface com.github.sarxos.webcam.WebcamListener
event
- The event of obtaining the image.public void webcamOpen(com.github.sarxos.webcam.WebcamEvent event)
webcamOpen
in interface com.github.sarxos.webcam.WebcamListener
event
- The event that opened the camera.