public class CvBase
extends java.lang.Object
Base class for JavaCV applications.
See CvDemo
for an example.
Reads input frames from either a camera or video file. Processes each frame (no operation by default) and displays the results in any combination of
useWindow
useCanvasFrame
serverPort
iff useServer
(see ImageServer
)useServer
; the other options work both
locally and over remote X window (use ssh -XC
) but consume a
lot of bandwidth in the latter case.
This class provides basic functions to pause/unpause the live input, emit debugging information for selected frames, and to save both raw capture and processed images.
You can use this class as a base for your own work:
process(com.googlecode.javacv.cpp.opencv_core.IplImage)
function. Also,
the various *Ext*() functions are hooks that mostly do nothing in the base
class, but are convenient places for you to insert your own code in a
subclass (but note that you can also override even non-Ext functions, if
needed).maxFPS
, useServer
, useConsole
, etc.init(int, String[])
or init()
and then mainLoop()
CvDemo
for an example.Modifier and Type | Field and Description |
---|---|
java.lang.String |
appname
Application name.
|
double |
brightness
OpenCV capgure property override or NaN to use default
|
protected com.googlecode.javacv.CanvasFrame |
canvasFrame
The JavaCV CanvasFrame, iff
useCanvasFrame . |
protected java.awt.event.KeyEvent |
canvasFrameKeyEvent
Last KeyEvent on
canvasFrame iff useCanvasFrame |
protected com.googlecode.javacv.cpp.opencv_highgui.CvCapture |
cap
The OpenCV capture object, if used.
|
static java.lang.String[] |
CAP_PROP_NAMES
OpenCV capture property names
|
static int[] |
CAP_PROPS
OpenCV capture properties
|
protected com.googlecode.javacv.cpp.opencv_core.IplImage |
capImage
Most recently captured image, if any (do not mutate or free).
|
boolean |
dbg
Whether debug is requested for next frame.
|
static java.lang.String |
DEF_APPNAME
Default application name.
|
static int |
DEF_CAM_H
Default width and height for camera input.
|
static int |
DEF_CAM_W
Default width and height for camera input.
|
static java.lang.String |
DEF_INPUT
Default input specification (use next available camera).
|
static float |
DEF_MAX_FPS
Default maximum frames per second for processing and local display.
|
static int |
DEF_MIN_DELAY_MS
Default minimum inter-frame delay in ms.
|
static float |
DEF_SERVER_FPS
Default
serverFPS . |
static int |
DEF_SERVER_PORT
Default
serverPort . |
static boolean |
DEF_USE_CANVAS_FRAME
Default for
useCanvasFrame . |
static boolean |
DEF_USE_CONSOLE
Default for
useConsole . |
static boolean |
DEF_USE_SERVER
Default for
useServer . |
static boolean |
DEF_USE_WINDOW
Default for
useWindow . |
boolean |
enableExit
Whether to call
System.exit() on fatal errors or user quit. |
double |
exposure
OpenCV capgure property override or NaN to use default
|
static java.text.DecimalFormat |
FMT
Number formatter.
|
protected double |
frameEndMS
Last frame end time.
|
protected int |
frameN
Most recent captured frame number.
|
double |
gain
OpenCV capgure property override or NaN to use default
|
protected com.googlecode.javacv.FrameGrabber |
grabber
The JavaCV frame grabber, if used.
|
int |
height
Capture dimensions.
|
double |
hue
OpenCV capgure property override or NaN to use default
|
float |
maxFPS
Maximum frames per second.
|
int |
minDelayMS
Minimum inter-frame delay.
|
protected com.googlecode.javacv.cpp.opencv_highgui.CvMouseCallback |
mouseCallback
Mouse event callback object.
|
java.io.PrintStream |
msgStream
Strems for messages and warnings, or null to disable.
|
protected double |
msPerTick
Milliseconds per OpenCV clock tick.
|
boolean |
paused
Whether processing is currently paused.
|
protected com.googlecode.javacv.cpp.opencv_core.IplImage |
procImage
Most recently processed image, if any (do not free).
|
double |
saturation
OpenCV capgure property override or NaN to use default
|
protected com.googlecode.javacv.cpp.opencv_core.IplImage |
saveImage
The file save image, if any (freed by destructor iff allocated).
|
ImageServer |
server
The
ImageServer , if useServer . |
float |
serverFPS
Default max server framerate.
|
protected com.googlecode.javacv.cpp.opencv_core.IplImage |
serverImage
Current server image, if any and if
useServer . |
protected char |
serverKey
Last key char from server iff
useServer or 0 if none. |
int |
serverPort
Server TCP listen port.
|
protected int |
streamIndex
The OpenCV capture stream index.
|
boolean |
useCanvasFrame
Whether to open and use a JavaCV CanvasFrame.
|
boolean |
useConsole
Whether to look for keypresses with
ConsoleNonblocking . |
boolean |
useServer
Whether to start an
ImageServer on serverPort . |
boolean |
useWindow
Whether to open and use an OpenCV window.
|
static java.lang.String[] |
V4L2_AUTO_PROP_NAMES
V4L2 auto camera property names
|
static int[] |
V4L2_AUTO_PROP_OFF_VALS
V4L2 auto camera property off values
|
static int[] |
V4L2_AUTO_PROP_ON_VALS
V4L2 auto camera property on values
|
static int[] |
V4L2_AUTO_PROPS
V4L2 auto camera properties
|
static int |
V4L2_CID_AUDIO_BALANCE
V4L2 control constants
|
static int |
V4L2_CID_AUDIO_BASS
V4L2 control constants
|
static int |
V4L2_CID_AUDIO_LOUDNESS
V4L2 control constants
|
static int |
V4L2_CID_AUDIO_MUTE
V4L2 control constants
|
static int |
V4L2_CID_AUDIO_TREBLE
V4L2 control constants
|
static int |
V4L2_CID_AUDIO_VOLUME
V4L2 control constants
|
static int |
V4L2_CID_AUTO_WHITE_BALANCE
V4L2 control constants
|
static int |
V4L2_CID_AUTOGAIN
V4L2 control constants
|
static int |
V4L2_CID_BACKLIGHT_COMPENSATION
V4L2 control constants
|
static int |
V4L2_CID_BASE
V4L2 control constants
|
static int |
V4L2_CID_BLACK_LEVEL
V4L2 control constants
|
static int |
V4L2_CID_BLUE_BALANCE
V4L2 control constants
|
static int |
V4L2_CID_BRIGHTNESS
V4L2 control constants
|
static int |
V4L2_CID_CAMERA_CLASS
V4L2 control constants
|
static int |
V4L2_CID_CAMERA_CLASS_BASE
V4L2 control constants
|
static int |
V4L2_CID_CONTRAST
V4L2 control constants
|
static int |
V4L2_CID_DO_WHITE_BALANCE
V4L2 control constants
|
static int |
V4L2_CID_EXPOSURE
V4L2 control constants
|
static int |
V4L2_CID_EXPOSURE_ABSOLUTE
V4L2 control constants
|
static int |
V4L2_CID_EXPOSURE_AUTO
V4L2 control constants
|
static int |
V4L2_CID_EXPOSURE_AUTO_PRIORITY
V4L2 control constants
|
static int |
V4L2_CID_FOCUS_ABSOLUTE
V4L2 control constants
|
static int |
V4L2_CID_FOCUS_AUTO
V4L2 control constants
|
static int |
V4L2_CID_FOCUS_RELATIVE
V4L2 control constants
|
static int |
V4L2_CID_GAIN
V4L2 control constants
|
static int |
V4L2_CID_GAMMA
V4L2 control constants
|
static int |
V4L2_CID_HCENTER_DEPRECATED
V4L2 control constants
|
static int |
V4L2_CID_HFLIP
V4L2 control constants
|
static int |
V4L2_CID_HUE
V4L2 control constants
|
static int |
V4L2_CID_HUE_AUTO
V4L2 control constants
|
static int |
V4L2_CID_LASTP1
V4L2 control constants
|
static int |
V4L2_CID_PAN_ABSOLUTE
V4L2 control constants
|
static int |
V4L2_CID_PAN_RELATIVE
V4L2 control constants
|
static int |
V4L2_CID_PAN_RESET
V4L2 control constants
|
static int |
V4L2_CID_POWER_LINE_FREQUENCY
V4L2 control constants
|
static int |
V4L2_CID_POWER_LINE_FREQUENCY_50HZ
V4L2 control constants
|
static int |
V4L2_CID_POWER_LINE_FREQUENCY_60HZ
V4L2 control constants
|
static int |
V4L2_CID_POWER_LINE_FREQUENCY_DISABLED
V4L2 control constants
|
static int |
V4L2_CID_PRIVATE_BASE
V4L2 control constants
|
static int |
V4L2_CID_RED_BALANCE
V4L2 control constants
|
static int |
V4L2_CID_SATURATION
V4L2 control constants
|
static int |
V4L2_CID_SHARPNESS
V4L2 control constants
|
static int |
V4L2_CID_TILT_ABSOLUTE
V4L2 control constants
|
static int |
V4L2_CID_TILT_RELATIVE
V4L2 control constants
|
static int |
V4L2_CID_TILT_RESET
V4L2 control constants
|
static int |
V4L2_CID_USER_BASE
V4L2 control constants
|
static int |
V4L2_CID_USER_CLASS
V4L2 control constants
|
static int |
V4L2_CID_VCENTER_DEPRECATED
V4L2 control constants
|
static int |
V4L2_CID_VFLIP
V4L2 control constants
|
static int |
V4L2_CID_WHITE_BALANCE_TEMPERATURE
V4L2 control constants
|
static int |
V4L2_CID_WHITENESS
V4L2 control constants
|
static int |
V4L2_CTRL_CLASS_CAMERA
V4L2 control constants
|
static int |
V4L2_CTRL_CLASS_MPEG
V4L2 control constants
|
static int |
V4L2_CTRL_CLASS_USER
V4L2 control constants
|
static int |
V4L2_EXPOSURE_APERTURE_PRIORITY
V4L2 control constants
|
static int |
V4L2_EXPOSURE_AUTO
V4L2 control constants
|
static int |
V4L2_EXPOSURE_MANUAL
V4L2 control constants
|
static int |
V4L2_EXPOSURE_SHUTTER_PRIORITY
V4L2 control constants
|
protected boolean |
v4l2Auto
Whether
v4l2EnableAuto() was called more recently than v4l2DisableAuto() . |
java.io.PrintStream |
warnStream
Strems for messages and warnings, or null to disable.
|
int |
width
Capture dimensions.
|
Constructor and Description |
---|
CvBase()
Uses defaults for all fields.
|
CvBase(boolean useWindow,
boolean useCanvasFrame,
boolean useConsole,
boolean useServer)
Uses
DEF_APPNAME . |
CvBase(java.lang.String appname)
Uses TBD.
|
CvBase(java.lang.String appname,
boolean useWindow,
boolean useCanvasFrame,
boolean useConsole,
boolean useServer)
Constructor initializes fields.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
camIndexOptional()
Whether the camera index is optional on the command line.
|
protected void |
cmdHelp()
Display command line help.
|
protected void |
cmdHelpExt()
Display extra command line help, for subclasses.
|
protected java.lang.String |
cmdHelpExtParams()
Extra command line parameters, for subclasses.
|
protected boolean |
doneProcessing()
Hook to check if
mainLoop() should end. |
void |
dumpCaptureProperties()
Dump all
CAP_PROPS |
void |
finalize()
Calls
release() . |
static java.lang.String |
fmt(double d)
Format a number for printing.
|
double |
getCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap,
int id)
Wraps cvGetCaptureProperty(), catches RuntimeException.
|
protected java.lang.String |
getDefAppname()
Gets the default appname, may be overridden.
|
protected java.lang.String |
getDefInput()
Gets the default input, may be overridden.
|
protected void |
guiHelp()
Display GUI help.
|
protected void |
guiHelpExt()
Display extra GUI help, for subclasses.
|
protected boolean |
handleKey(int code)
Handle keypresses.
|
protected boolean |
handleKeyExt(int code)
Keypresses not handled by the default implementation of handleKey() are
passed here.
|
protected void |
handleMouse(int event,
int x,
int y,
int flags)
Handle mouse events.
|
protected void |
handleMouse(java.awt.event.MouseEvent e)
forward an AWT mouse Event to
handleMouse(int, int, int, int) |
int |
init()
calls
init(int, String[]) with no args |
int |
init(int camIndex,
int w,
int h)
calls
init(int, String[]) with cam index and dimensions |
int |
init(int argc,
java.lang.String[] argv)
Initialize members based on command line arguments.
|
int |
init(java.lang.String fname)
calls
init(int, String[]) with video file name |
int |
initExt(int argc,
java.lang.String[] argv,
int ate)
Extra initialization, for subclasses.
|
void |
mainLoop()
Main frame processing loop.
|
protected com.googlecode.javacv.FrameGrabber |
makeGrabber(int cameraIndex,
int streamIndex)
Hook to allow a JavaCV FrameGrabber to replace the usual OpenCV capture
object.
|
protected ImageServer |
makeServer()
Hook to create the
ImageServer . |
java.lang.String |
mouseEventToString(int event,
int x,
int y,
int flags)
Make a human-readable string summarizing a mouse event.
|
protected void |
msg(java.lang.String m)
Display a message to
msgStream , if any. |
protected double |
nowMS()
Current time in milliseconds according to OpenCV clock.
|
protected com.googlecode.javacv.cpp.opencv_core.IplImage |
process(com.googlecode.javacv.cpp.opencv_core.IplImage frame)
Process the given frame.
|
void |
release()
Frees memory, closes windows, and releases resources.
|
(package private) boolean |
save(java.lang.String filename,
com.googlecode.javacv.cpp.opencv_core.IplImage image)
Save an image to file using the OpenCV API.
|
int |
setCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap,
int id,
double value)
Wraps cvSetCaptureProperty(), catches RuntimeException.
|
protected void |
updateServerImage()
Hook to update
serverImage |
void |
v4l2DisableAuto()
Try to disable all auto stuff for a V4L2 camera.
|
void |
v4l2EnableAuto()
Try to enable all auto stuff for a V4L2 camera.
|
float |
v4l2GetExposure()
Try to get the exposure time on a V4L2 camera.
|
void |
v4l2SetExposure(float ms)
Try to set the exposure time on a V4L2 camera.
|
int |
waitForKeypresss(int timeoutMS)
Wait for a keypress.
|
protected void |
warn(java.lang.String m)
Display a warning to
warnStream , if any. |
public static final boolean DEF_USE_WINDOW
useWindow
.public static final boolean DEF_USE_SERVER
useServer
.public static final boolean DEF_USE_CONSOLE
useConsole
.public static final boolean DEF_USE_CANVAS_FRAME
useCanvasFrame
.
True unless the graphics environment is headless.public static final java.lang.String DEF_INPUT
public static final int DEF_CAM_W
public static final int DEF_CAM_H
public static final float DEF_MAX_FPS
public static final int DEF_MIN_DELAY_MS
public static final java.lang.String DEF_APPNAME
public static final int DEF_SERVER_PORT
serverPort
.public static final float DEF_SERVER_FPS
serverFPS
.public static final java.text.DecimalFormat FMT
public static final int[] CAP_PROPS
public static final java.lang.String[] CAP_PROP_NAMES
public static final int V4L2_CTRL_CLASS_USER
public static final int V4L2_CTRL_CLASS_MPEG
public static final int V4L2_CTRL_CLASS_CAMERA
public static final int V4L2_CID_BASE
public static final int V4L2_CID_USER_BASE
public static final int V4L2_CID_PRIVATE_BASE
public static final int V4L2_CID_USER_CLASS
public static final int V4L2_CID_BRIGHTNESS
public static final int V4L2_CID_CONTRAST
public static final int V4L2_CID_SATURATION
public static final int V4L2_CID_HUE
public static final int V4L2_CID_AUDIO_VOLUME
public static final int V4L2_CID_AUDIO_BALANCE
public static final int V4L2_CID_AUDIO_BASS
public static final int V4L2_CID_AUDIO_TREBLE
public static final int V4L2_CID_AUDIO_MUTE
public static final int V4L2_CID_AUDIO_LOUDNESS
public static final int V4L2_CID_BLACK_LEVEL
public static final int V4L2_CID_AUTO_WHITE_BALANCE
public static final int V4L2_CID_DO_WHITE_BALANCE
public static final int V4L2_CID_RED_BALANCE
public static final int V4L2_CID_BLUE_BALANCE
public static final int V4L2_CID_GAMMA
public static final int V4L2_CID_WHITENESS
public static final int V4L2_CID_EXPOSURE
public static final int V4L2_CID_AUTOGAIN
public static final int V4L2_CID_GAIN
public static final int V4L2_CID_HFLIP
public static final int V4L2_CID_VFLIP
public static final int V4L2_CID_HCENTER_DEPRECATED
public static final int V4L2_CID_VCENTER_DEPRECATED
public static final int V4L2_CID_POWER_LINE_FREQUENCY
public static final int V4L2_CID_POWER_LINE_FREQUENCY_DISABLED
public static final int V4L2_CID_POWER_LINE_FREQUENCY_50HZ
public static final int V4L2_CID_POWER_LINE_FREQUENCY_60HZ
public static final int V4L2_CID_HUE_AUTO
public static final int V4L2_CID_WHITE_BALANCE_TEMPERATURE
public static final int V4L2_CID_SHARPNESS
public static final int V4L2_CID_BACKLIGHT_COMPENSATION
public static final int V4L2_CID_LASTP1
public static final int V4L2_CID_CAMERA_CLASS_BASE
public static final int V4L2_CID_CAMERA_CLASS
public static final int V4L2_CID_EXPOSURE_AUTO
public static final int V4L2_EXPOSURE_AUTO
public static final int V4L2_EXPOSURE_MANUAL
public static final int V4L2_EXPOSURE_SHUTTER_PRIORITY
public static final int V4L2_EXPOSURE_APERTURE_PRIORITY
public static final int V4L2_CID_EXPOSURE_ABSOLUTE
public static final int V4L2_CID_EXPOSURE_AUTO_PRIORITY
public static final int V4L2_CID_PAN_RELATIVE
public static final int V4L2_CID_TILT_RELATIVE
public static final int V4L2_CID_PAN_RESET
public static final int V4L2_CID_TILT_RESET
public static final int V4L2_CID_PAN_ABSOLUTE
public static final int V4L2_CID_TILT_ABSOLUTE
public static final int V4L2_CID_FOCUS_ABSOLUTE
public static final int V4L2_CID_FOCUS_RELATIVE
public static final int V4L2_CID_FOCUS_AUTO
public static final int[] V4L2_AUTO_PROPS
public static final java.lang.String[] V4L2_AUTO_PROP_NAMES
public static final int[] V4L2_AUTO_PROP_OFF_VALS
public static final int[] V4L2_AUTO_PROP_ON_VALS
protected boolean v4l2Auto
Whether v4l2EnableAuto()
was called more recently than v4l2DisableAuto()
.
public double brightness
public double saturation
public double hue
public double gain
public double exposure
public int width
public int height
public float maxFPS
public int minDelayMS
public java.lang.String appname
public boolean useWindow
public boolean useCanvasFrame
public boolean useServer
ImageServer
on serverPort
.public boolean useConsole
ConsoleNonblocking
.public boolean enableExit
System.exit()
on fatal errors or user quit.public boolean paused
public boolean dbg
public ImageServer server
ImageServer
, if useServer
.public int serverPort
public float serverFPS
public java.io.PrintStream msgStream
public java.io.PrintStream warnStream
protected com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap
protected com.googlecode.javacv.FrameGrabber grabber
protected int streamIndex
protected com.googlecode.javacv.cpp.opencv_core.IplImage saveImage
protected com.googlecode.javacv.cpp.opencv_core.IplImage capImage
protected com.googlecode.javacv.cpp.opencv_core.IplImage procImage
protected com.googlecode.javacv.cpp.opencv_core.IplImage serverImage
useServer
.protected volatile char serverKey
useServer
or 0 if none.protected int frameN
protected double msPerTick
protected double frameEndMS
protected com.googlecode.javacv.cpp.opencv_highgui.CvMouseCallback mouseCallback
protected com.googlecode.javacv.CanvasFrame canvasFrame
useCanvasFrame
.protected volatile java.awt.event.KeyEvent canvasFrameKeyEvent
canvasFrame
iff useCanvasFrame
public CvBase(java.lang.String appname, boolean useWindow, boolean useCanvasFrame, boolean useConsole, boolean useServer)
Constructor initializes fields.
Call init(int, String[])
and then mainLoop()
to run the
default application.
public CvBase(boolean useWindow, boolean useCanvasFrame, boolean useConsole, boolean useServer)
DEF_APPNAME
.public CvBase(java.lang.String appname)
public CvBase()
public static final java.lang.String fmt(double d)
public void finalize()
release()
.finalize
in class java.lang.Object
public void release()
public int init(int argc, java.lang.String[] argv)
Initialize members based on command line arguments.
In particular, this constructs cap
or grabber
(see
makeGrabber(int, int)
) and opens the main window (named appname
).
java.lang.IllegalArgumentException
- if there was an error initializing the
inputpublic int init()
init(int, String[])
with no argspublic int init(java.lang.String fname)
init(int, String[])
with video file namepublic int init(int camIndex, int w, int h)
init(int, String[])
with cam index and dimensionspublic int initExt(int argc, java.lang.String[] argv, int ate)
Extra initialization, for subclasses.
ate
- the number of command line arguments already eaten by init(int, String[])
protected ImageServer makeServer() throws java.io.IOException
Hook to create the ImageServer
.
Called from init(int, java.lang.String[])
to set server
iff useServer
(and note that field will be overridden if "imserver" or "noimserver"
command line args are given).
Default impl makes an ImageServer
, using serverPort
and serverFPS
, hooks up its ImageServer.msgStream
to
msgStream
and ImageServer.warnStream
to warnStream
, overrides ImageServer.updateImage(java.awt.image.BufferedImage)
to read from
serverImage
, and connects ImageServer.handleKey(ohmm.ImageServer.ExchangeState)
to handleKey(int)
(via serverKey
) and ImageServer.handleMouse(ohmm.ImageServer.ExchangeState)
to handleMouse(int, int, int, int)
.
java.io.IOException
protected com.googlecode.javacv.FrameGrabber makeGrabber(int cameraIndex, int streamIndex)
Hook to allow a JavaCV FrameGrabber to replace the usual OpenCV capture object.
cameraIndex
- the OpenCV camera indexstreamIndex
- the OpenCV stream indexDefault impl only takes action if cameraIndex is in the range 950-999, which is the upper half of the range reserved for CV_CAP_OPENNI=900. In that case we try to use OpenKinectFrameGrabber, which uses libfreenect, if possible, instead of OpenCV which uses OpenNI. This only works if streamIndex is CV_CAP_OPENNI_DEPTH_MAP=0 or CV_CAP_OPENNI_BGR_IMAGE=5.
The stream index sets the default capture image type (the OpenKinectFrameGrabber "format" which can be either "depth" or "video"); the other image type an then be acquired by calling ((OpenKinectFrameGrabber) grabber).grabDepth() or ((OpenKinectFrameGrabber) grabber).grabVideo() specifically, or by changing the grabber format.
protected double nowMS()
protected void cmdHelp()
protected boolean camIndexOptional()
protected void cmdHelpExt()
protected java.lang.String cmdHelpExtParams()
protected void guiHelp()
protected void guiHelpExt()
public void dumpCaptureProperties()
CAP_PROPS
protected com.googlecode.javacv.cpp.opencv_core.IplImage process(com.googlecode.javacv.cpp.opencv_core.IplImage frame)
Process the given frame.
Default impl is identity.
Note that the passed image may not be mutated. So to do any significant processing, you will need to allocate your own return image. It is typically best to do this once for the first frame, store the results in subclass instance variables, and then deallocate any allocated space in the subclass destructor.
All frames are guaranteed to have the same dimensions and pixel format.
This will be called for every iteration of mainLoop()
, even while
paused. You may use the various instance fields (frameN
, capImage
, paused
, dbg
, etc) to determine what
operations to perform. Of course, when writing a subclass, you may also
add your own fields.
protected boolean doneProcessing()
Hook to check if mainLoop()
should end.
Default impl returns false.
protected boolean handleKey(int code)
Handle keypresses.
protected boolean handleKeyExt(int code)
Keypresses not handled by the default implementation of handleKey() are passed here.
Default impl just prints the keycode.
Overriding this is one way that subclasses can handle extra keypresses.
protected void handleMouse(int event, int x, int y, int flags)
Handle mouse events.
event
- one of the CV_EVENT_* constants (see opencv_highgui.java in
the JavaCV sources for a list)x
- the x pixel coordinate of the mouse eventy
- the y pixel coordinate of the mouse eventflags
- bitmask of the CV_EVENT_FLAG_* constants (see
opencv_highgui.java in the JavaCV sources for a list)
Default impl prints a message using mouseEventToString(int, int, int, int)
except
for CV_EVENT_MOUSEMOVE.
Overriding this is one way that subclasses can handle mouse events.
protected void handleMouse(java.awt.event.MouseEvent e)
handleMouse(int, int, int, int)
public java.lang.String mouseEventToString(int event, int x, int y, int flags)
Make a human-readable string summarizing a mouse event.
boolean save(java.lang.String filename, com.googlecode.javacv.cpp.opencv_core.IplImage image)
Save an image to file using the OpenCV API.
public void mainLoop()
Main frame processing loop.
Default impl does the following in an infinite loop:
doneProcessing()
cap
:streamIndex
or JavaCV grabber
if the former is nullprocess(com.googlecode.javacv.cpp.opencv_core.IplImage)
useWindow
and the user closed the OpenCV window or if
useCanvasFrame
and the user closed the JavaCV canvas frameprocess(com.googlecode.javacv.cpp.opencv_core.IplImage)
, if not null, inuseWindow
CanvasFrame
iff useCanvasFrame
updateServerImage()
hookdoneProcessing()
maxFPS
), handling user keypresses via handleKey(int)
Thread.interrupted()
protected void updateServerImage()
Hook to update serverImage
Default impl does nothing if server
or procImage
is
null. Otherwise it synchronizes on server
, (re-)allocates serverImage
to match procImage
iff necessary, and then copies
procImage
to serverImage
.
public int waitForKeypresss(int timeoutMS) throws java.lang.InterruptedException
Wait for a keypress.
timeoutMS
- maximum time to wait or 0 to wait forever
Returns when the first keypress is detected in the OpenCV window iff
useWindow
, any canvasFrame
iff useCanvasFrame
,
any client connected to the server
iff that field is non-null, or
the console if useConsole
.
java.lang.InterruptedException
public void v4l2DisableAuto()
Try to disable all auto stuff for a V4L2 camera.
Call e.g. from initExt(int, java.lang.String[], int)
.
public void v4l2EnableAuto()
Try to enable all auto stuff for a V4L2 camera.
Call e.g. from initExt(int, java.lang.String[], int)
.
public void v4l2SetExposure(float ms)
Try to set the exposure time on a V4L2 camera.
ms
- the new exposure time in milliseconds (0.1ms resolution) if
positive, else set auto exposurepublic float v4l2GetExposure()
Try to get the exposure time on a V4L2 camera.
public int setCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap, int id, double value)
Wraps cvSetCaptureProperty(), catches RuntimeException.
public double getCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap, int id)
Wraps cvGetCaptureProperty(), catches RuntimeException.
protected void msg(java.lang.String m)
msgStream
, if any.protected void warn(java.lang.String m)
warnStream
, if any.protected java.lang.String getDefAppname()
protected java.lang.String getDefInput()