ohmm
Class CvBase

java.lang.Object
  extended by ohmm.CvBase
Direct Known Subclasses:
CvDemo, CvKinect, CvUndistort

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

The default is only 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:

  1. Create a subclass that overrides the necessary functions. The main place you probably need to do this is the 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).
  2. Construct an instance of the subclass and configure any instance fields, e.g. set maxFPS, useServer, useConsole, etc.
  3. Call init(int, String[]) or init() and then mainLoop()
See CvDemo for an example.

Author:
Marsette Vona

Field Summary
 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 Summary
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.
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEF_USE_WINDOW

public static final boolean DEF_USE_WINDOW
Default for useWindow.

See Also:
Constant Field Values

DEF_USE_SERVER

public static final boolean DEF_USE_SERVER
Default for useServer.

See Also:
Constant Field Values

DEF_USE_CONSOLE

public static final boolean DEF_USE_CONSOLE
Default for useConsole.

See Also:
Constant Field Values

DEF_USE_CANVAS_FRAME

public static final boolean DEF_USE_CANVAS_FRAME
Default for useCanvasFrame. True unless the graphics environment is headless.


DEF_INPUT

public static final java.lang.String DEF_INPUT
Default input specification (use next available camera).

See Also:
Constant Field Values

DEF_CAM_W

public static final int DEF_CAM_W
Default width and height for camera input.

See Also:
Constant Field Values

DEF_CAM_H

public static final int DEF_CAM_H
Default width and height for camera input.

See Also:
Constant Field Values

DEF_MAX_FPS

public static final float DEF_MAX_FPS
Default maximum frames per second for processing and local display.

See Also:
Constant Field Values

DEF_MIN_DELAY_MS

public static final int DEF_MIN_DELAY_MS
Default minimum inter-frame delay in ms.

See Also:
Constant Field Values

DEF_APPNAME

public static final java.lang.String DEF_APPNAME
Default application name.

See Also:
Constant Field Values

DEF_SERVER_PORT

public static final int DEF_SERVER_PORT
Default serverPort.

See Also:
Constant Field Values

DEF_SERVER_FPS

public static final float DEF_SERVER_FPS
Default serverFPS.

See Also:
Constant Field Values

FMT

public static final java.text.DecimalFormat FMT
Number formatter.


CAP_PROPS

public static final int[] CAP_PROPS
OpenCV capture properties


CAP_PROP_NAMES

public static final java.lang.String[] CAP_PROP_NAMES
OpenCV capture property names


V4L2_CTRL_CLASS_USER

public static final int V4L2_CTRL_CLASS_USER
V4L2 control constants

See Also:
Constant Field Values

V4L2_CTRL_CLASS_MPEG

public static final int V4L2_CTRL_CLASS_MPEG
V4L2 control constants

See Also:
Constant Field Values

V4L2_CTRL_CLASS_CAMERA

public static final int V4L2_CTRL_CLASS_CAMERA
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_BASE

public static final int V4L2_CID_BASE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_USER_BASE

public static final int V4L2_CID_USER_BASE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_PRIVATE_BASE

public static final int V4L2_CID_PRIVATE_BASE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_USER_CLASS

public static final int V4L2_CID_USER_CLASS
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_BRIGHTNESS

public static final int V4L2_CID_BRIGHTNESS
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_CONTRAST

public static final int V4L2_CID_CONTRAST
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_SATURATION

public static final int V4L2_CID_SATURATION
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_HUE

public static final int V4L2_CID_HUE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_AUDIO_VOLUME

public static final int V4L2_CID_AUDIO_VOLUME
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_AUDIO_BALANCE

public static final int V4L2_CID_AUDIO_BALANCE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_AUDIO_BASS

public static final int V4L2_CID_AUDIO_BASS
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_AUDIO_TREBLE

public static final int V4L2_CID_AUDIO_TREBLE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_AUDIO_MUTE

public static final int V4L2_CID_AUDIO_MUTE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_AUDIO_LOUDNESS

public static final int V4L2_CID_AUDIO_LOUDNESS
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_BLACK_LEVEL

public static final int V4L2_CID_BLACK_LEVEL
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_AUTO_WHITE_BALANCE

public static final int V4L2_CID_AUTO_WHITE_BALANCE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_DO_WHITE_BALANCE

public static final int V4L2_CID_DO_WHITE_BALANCE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_RED_BALANCE

public static final int V4L2_CID_RED_BALANCE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_BLUE_BALANCE

public static final int V4L2_CID_BLUE_BALANCE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_GAMMA

public static final int V4L2_CID_GAMMA
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_WHITENESS

public static final int V4L2_CID_WHITENESS
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_EXPOSURE

public static final int V4L2_CID_EXPOSURE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_AUTOGAIN

public static final int V4L2_CID_AUTOGAIN
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_GAIN

public static final int V4L2_CID_GAIN
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_HFLIP

public static final int V4L2_CID_HFLIP
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_VFLIP

public static final int V4L2_CID_VFLIP
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_HCENTER_DEPRECATED

public static final int V4L2_CID_HCENTER_DEPRECATED
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_VCENTER_DEPRECATED

public static final int V4L2_CID_VCENTER_DEPRECATED
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_POWER_LINE_FREQUENCY

public static final int V4L2_CID_POWER_LINE_FREQUENCY
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_POWER_LINE_FREQUENCY_DISABLED

public static final int V4L2_CID_POWER_LINE_FREQUENCY_DISABLED
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_POWER_LINE_FREQUENCY_50HZ

public static final int V4L2_CID_POWER_LINE_FREQUENCY_50HZ
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_POWER_LINE_FREQUENCY_60HZ

public static final int V4L2_CID_POWER_LINE_FREQUENCY_60HZ
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_HUE_AUTO

public static final int V4L2_CID_HUE_AUTO
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_WHITE_BALANCE_TEMPERATURE

public static final int V4L2_CID_WHITE_BALANCE_TEMPERATURE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_SHARPNESS

public static final int V4L2_CID_SHARPNESS
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_BACKLIGHT_COMPENSATION

public static final int V4L2_CID_BACKLIGHT_COMPENSATION
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_LASTP1

public static final int V4L2_CID_LASTP1
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_CAMERA_CLASS_BASE

public static final int V4L2_CID_CAMERA_CLASS_BASE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_CAMERA_CLASS

public static final int V4L2_CID_CAMERA_CLASS
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_EXPOSURE_AUTO

public static final int V4L2_CID_EXPOSURE_AUTO
V4L2 control constants

See Also:
Constant Field Values

V4L2_EXPOSURE_AUTO

public static final int V4L2_EXPOSURE_AUTO
V4L2 control constants

See Also:
Constant Field Values

V4L2_EXPOSURE_MANUAL

public static final int V4L2_EXPOSURE_MANUAL
V4L2 control constants

See Also:
Constant Field Values

V4L2_EXPOSURE_SHUTTER_PRIORITY

public static final int V4L2_EXPOSURE_SHUTTER_PRIORITY
V4L2 control constants

See Also:
Constant Field Values

V4L2_EXPOSURE_APERTURE_PRIORITY

public static final int V4L2_EXPOSURE_APERTURE_PRIORITY
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_EXPOSURE_ABSOLUTE

public static final int V4L2_CID_EXPOSURE_ABSOLUTE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_EXPOSURE_AUTO_PRIORITY

public static final int V4L2_CID_EXPOSURE_AUTO_PRIORITY
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_PAN_RELATIVE

public static final int V4L2_CID_PAN_RELATIVE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_TILT_RELATIVE

public static final int V4L2_CID_TILT_RELATIVE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_PAN_RESET

public static final int V4L2_CID_PAN_RESET
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_TILT_RESET

public static final int V4L2_CID_TILT_RESET
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_PAN_ABSOLUTE

public static final int V4L2_CID_PAN_ABSOLUTE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_TILT_ABSOLUTE

public static final int V4L2_CID_TILT_ABSOLUTE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_FOCUS_ABSOLUTE

public static final int V4L2_CID_FOCUS_ABSOLUTE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_FOCUS_RELATIVE

public static final int V4L2_CID_FOCUS_RELATIVE
V4L2 control constants

See Also:
Constant Field Values

V4L2_CID_FOCUS_AUTO

public static final int V4L2_CID_FOCUS_AUTO
V4L2 control constants

See Also:
Constant Field Values

V4L2_AUTO_PROPS

public static final int[] V4L2_AUTO_PROPS
V4L2 auto camera properties


V4L2_AUTO_PROP_NAMES

public static final java.lang.String[] V4L2_AUTO_PROP_NAMES
V4L2 auto camera property names


V4L2_AUTO_PROP_OFF_VALS

public static final int[] V4L2_AUTO_PROP_OFF_VALS
V4L2 auto camera property off values


V4L2_AUTO_PROP_ON_VALS

public static final int[] V4L2_AUTO_PROP_ON_VALS
V4L2 auto camera property on values


v4l2Auto

protected boolean v4l2Auto

Whether v4l2EnableAuto() was called more recently than v4l2DisableAuto().


brightness

public double brightness
OpenCV capgure property override or NaN to use default


saturation

public double saturation
OpenCV capgure property override or NaN to use default


hue

public double hue
OpenCV capgure property override or NaN to use default


gain

public double gain
OpenCV capgure property override or NaN to use default


exposure

public double exposure
OpenCV capgure property override or NaN to use default


width

public int width
Capture dimensions.


height

public int height
Capture dimensions.


maxFPS

public float maxFPS
Maximum frames per second.


minDelayMS

public int minDelayMS
Minimum inter-frame delay.


appname

public java.lang.String appname
Application name.


useWindow

public boolean useWindow
Whether to open and use an OpenCV window.


useCanvasFrame

public boolean useCanvasFrame
Whether to open and use a JavaCV CanvasFrame.


useServer

public boolean useServer
Whether to start an ImageServer on serverPort.


useConsole

public boolean useConsole
Whether to look for keypresses with ConsoleNonblocking.


enableExit

public boolean enableExit
Whether to call System.exit() on fatal errors or user quit.


paused

public boolean paused
Whether processing is currently paused.


dbg

public boolean dbg
Whether debug is requested for next frame.


server

public ImageServer server
The ImageServer, if useServer.


serverPort

public int serverPort
Server TCP listen port.


serverFPS

public float serverFPS
Default max server framerate.


msgStream

public java.io.PrintStream msgStream
Strems for messages and warnings, or null to disable.


warnStream

public java.io.PrintStream warnStream
Strems for messages and warnings, or null to disable.


cap

protected com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap
The OpenCV capture object, if used.


grabber

protected com.googlecode.javacv.FrameGrabber grabber
The JavaCV frame grabber, if used.


streamIndex

protected int streamIndex
The OpenCV capture stream index.


saveImage

protected com.googlecode.javacv.cpp.opencv_core.IplImage saveImage
The file save image, if any (freed by destructor iff allocated).


capImage

protected com.googlecode.javacv.cpp.opencv_core.IplImage capImage
Most recently captured image, if any (do not mutate or free).


procImage

protected com.googlecode.javacv.cpp.opencv_core.IplImage procImage
Most recently processed image, if any (do not free).


serverImage

protected com.googlecode.javacv.cpp.opencv_core.IplImage serverImage
Current server image, if any and if useServer.


serverKey

protected volatile char serverKey
Last key char from server iff useServer or 0 if none.


frameN

protected int frameN
Most recent captured frame number.


msPerTick

protected double msPerTick
Milliseconds per OpenCV clock tick.


frameEndMS

protected double frameEndMS
Last frame end time.


mouseCallback

protected com.googlecode.javacv.cpp.opencv_highgui.CvMouseCallback mouseCallback
Mouse event callback object.


canvasFrame

protected com.googlecode.javacv.CanvasFrame canvasFrame
The JavaCV CanvasFrame, iff useCanvasFrame.


canvasFrameKeyEvent

protected volatile java.awt.event.KeyEvent canvasFrameKeyEvent
Last KeyEvent on canvasFrame iff useCanvasFrame

Constructor Detail

CvBase

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.


CvBase

public CvBase(boolean useWindow,
              boolean useCanvasFrame,
              boolean useConsole,
              boolean useServer)
Uses DEF_APPNAME.


CvBase

public CvBase(java.lang.String appname)
Uses TBD.


CvBase

public CvBase()
Uses defaults for all fields.

Method Detail

fmt

public static final java.lang.String fmt(double d)
Format a number for printing.


finalize

public void finalize()
Calls release().

Overrides:
finalize in class java.lang.Object

release

public void release()
Frees memory, closes windows, and releases resources.


init

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).

Returns:
the number of arguments eaten
Throws:
java.lang.IllegalArgumentException - if there was an error initializing the input

init

public int init()
calls init(int, String[]) with no args


init

public int init(java.lang.String fname)
calls init(int, String[]) with video file name


init

public int init(int camIndex,
                int w,
                int h)
calls init(int, String[]) with cam index and dimensions


initExt

public int initExt(int argc,
                   java.lang.String[] argv,
                   int ate)

Extra initialization, for subclasses.

Parameters:
ate - the number of command line arguments already eaten by init(int, String[])
Returns:
the total number of arguments eaten

makeServer

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).

Throws:
java.io.IOException

makeGrabber

protected com.googlecode.javacv.FrameGrabber makeGrabber(int cameraIndex,
                                                         int streamIndex)

Hook to allow a JavaCV FrameGrabber to replace the usual OpenCV capture object.

Parameters:
cameraIndex - the OpenCV camera index
streamIndex - the OpenCV stream index
Returns:
non-null to use a FrameGrabber

Default 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.


nowMS

protected double nowMS()
Current time in milliseconds according to OpenCV clock.


cmdHelp

protected void cmdHelp()
Display command line help.


camIndexOptional

protected boolean camIndexOptional()
Whether the camera index is optional on the command line.


cmdHelpExt

protected void cmdHelpExt()
Display extra command line help, for subclasses.


cmdHelpExtParams

protected java.lang.String cmdHelpExtParams()
Extra command line parameters, for subclasses.


guiHelp

protected void guiHelp()
Display GUI help.


guiHelpExt

protected void guiHelpExt()
Display extra GUI help, for subclasses.


dumpCaptureProperties

public void dumpCaptureProperties()
Dump all CAP_PROPS


process

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.

Returns:
the processed image, null will cause image display to be skipped for this frame

doneProcessing

protected boolean doneProcessing()

Hook to check if mainLoop() should end.

Returns:
true iff main loop should end

Default impl returns false.


handleKey

protected boolean handleKey(int code)

Handle keypresses.

Returns:
true to continue processing frames, false to end program

handleKeyExt

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.


handleMouse

protected void handleMouse(int event,
                           int x,
                           int y,
                           int flags)

Handle mouse events.

Parameters:
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 event
y - the y pixel coordinate of the mouse event
flags - 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.


handleMouse

protected void handleMouse(java.awt.event.MouseEvent e)
forward an AWT mouse Event to handleMouse(int, int, int, int)


mouseEventToString

public java.lang.String mouseEventToString(int event,
                                           int x,
                                           int y,
                                           int flags)

Make a human-readable string summarizing a mouse event.

See handleMouse(int, int, int, int).


save

boolean save(java.lang.String filename,
             com.googlecode.javacv.cpp.opencv_core.IplImage image)

Save an image to file using the OpenCV API.

Returns:
true on success.

mainLoop

public void mainLoop()

Main frame processing loop.

Default impl does the following in an infinite loop:

  1. quit if doneProcessing()
  2. acquire a new frame from OpenCV capture device cap:streamIndex or JavaCV grabber if the former is null
  3. call process(com.googlecode.javacv.cpp.opencv_core.IplImage)
  4. quit if useWindow and the user closed the OpenCV window or if useCanvasFrame and the user closed the JavaCV canvas frame
  5. displays the image returned from process(com.googlecode.javacv.cpp.opencv_core.IplImage), if not null, in
  6. quit if doneProcessing()
  7. delay for the remainder of the minimum frame time (inverse of maxFPS), handling user keypresses via handleKey(int)
  8. quit if Thread.interrupted()


updateServerImage

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.


waitForKeypresss

public int waitForKeypresss(int timeoutMS)
                     throws java.lang.InterruptedException

Wait for a keypress.

Parameters:
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.Throws:

java.lang.InterruptedException

v4l2DisableAuto

public void v4l2DisableAuto()

Try to disable all auto stuff for a V4L2 camera.

Call e.g. from initExt(int, java.lang.String[], int).


v4l2EnableAuto

public void v4l2EnableAuto()

Try to enable all auto stuff for a V4L2 camera.

Call e.g. from initExt(int, java.lang.String[], int).


v4l2SetExposure

public void v4l2SetExposure(float ms)

Try to set the exposure time on a V4L2 camera.

Parameters:
ms - the new exposure time in milliseconds (0.1ms resolution) if positive, else set auto exposure

v4l2GetExposure

public float v4l2GetExposure()

Try to get the exposure time on a V4L2 camera.

Returns:
the exposure time in milliseconds (0.1ms resolution) or -1 if it cannot be determined

setCaptureProperty

public int setCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap,
                              int id,
                              double value)

Wraps cvSetCaptureProperty(), catches RuntimeException.


getCaptureProperty

public double getCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap,
                                 int id)

Wraps cvGetCaptureProperty(), catches RuntimeException.


msg

protected void msg(java.lang.String m)
Display a message to msgStream, if any.


warn

protected void warn(java.lang.String m)
Display a warning to warnStream, if any.


getDefAppname

protected java.lang.String getDefAppname()
Gets the default appname, may be overridden.


getDefInput

protected java.lang.String getDefInput()
Gets the default input, may be overridden.