ohmm
Class CvBase

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

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

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

Nested Class Summary
protected  class CvBase.ExchangeHandler
          Http exchange handler for CvBase.ImageServer, see which.
protected  class CvBase.ImageServer
          HTTP multipart/x-mixed-replace image server.
 
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 float DEF_MAX_SERVER_FPS
          Default maximum frames per second for server.
static int DEF_MIN_DELAY_MS
          Default minimum inter-frame delay in ms.
static java.lang.String DEF_SERVER_FORMAT
          Default server ImageIO format name.
static java.lang.String DEF_SERVER_MIME_TYPE
          Default server image mime type.
static int DEF_SERVER_PORT
          Default CvBase.ImageServer TCP port.
 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.
static int HTTP_FORBIDDEN
          HTTP response codes
static int HTTP_NOT_FOUND
          HTTP response codes
static int HTTP_OK
          HTTP response codes
 double hue
          OpenCV capgure property override or NaN to use default
 float maxFPS
          Maximum frames per second.
 float maxServerFPS
          Maximum server framerate.
private static java.lang.String MIME_BOUNDARY
          MIME multipart boundary
 int minDelayMS
          Minimum inter-frame delay.
protected  com.googlecode.javacv.cpp.opencv_highgui.CvMouseCallback mouseCallback
          Mouse event callback object.
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).
protected  CvBase.ImageServer server
          The CvBase.ImageServer, if useServer.
static java.lang.String SERVER_HTML
          Server html file.
protected  boolean serverActive
          Whether the server is currently serving images.
 boolean serverDBG
          Debug next server frame.
 java.lang.String serverFormat
          Image format for the CvBase.ImageServer
protected  com.googlecode.javacv.cpp.opencv_core.IplImage serverImage
          Current server image, if any and if useServer
protected  boolean serverImagePending
          Whether a fresh serverImage is ready.
protected  char serverKey
          Last key char from serer iff useServer or 0 if none
protected  java.lang.Object serverLock
          Synchronization lock for server state.
 java.lang.String serverMimeType
          Image format for the CvBase.ImageServer
 int serverPort
          TCP port for the CvBase.ImageServer
protected  int streamIndex
          The OpenCV capture stream index.
private static java.lang.String svnid
           
 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 CvBase.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().
 int width
          Capture dimensions.
 
Constructor Summary
CvBase()
          Uses DEF_APPNAME.
CvBase(java.lang.String appname)
          Constructor initializes members.
 
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.
static double getCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap, int id)
          Wraps cvGetCaptureProperty(), catches RuntimeException.
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.
 java.lang.String mouseEventToString(int event, int x, int y, int flags)
          Make a human-readable string summarizing a mouse event.
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.
static int setCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap, int id, double value)
          Wraps cvSetCaptureProperty(), catches RuntimeException.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

svnid

private static final java.lang.String svnid
See Also:
Constant Field Values

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_MAX_SERVER_FPS

public static final float DEF_MAX_SERVER_FPS
Default maximum frames per second for server.

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 java.lang.String DEF_APPNAME
Default application name.


FMT

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


DEF_SERVER_PORT

public static final int DEF_SERVER_PORT
Default CvBase.ImageServer TCP port.

See Also:
Constant Field Values

DEF_SERVER_MIME_TYPE

public static final java.lang.String DEF_SERVER_MIME_TYPE
Default server image mime type.

See Also:
Constant Field Values

DEF_SERVER_FORMAT

public static final java.lang.String DEF_SERVER_FORMAT
Default server ImageIO format name.

See Also:
Constant Field Values

SERVER_HTML

public static final java.lang.String SERVER_HTML
Server html file.

See Also:
Constant Field Values

HTTP_OK

public static final int HTTP_OK
HTTP response codes

See Also:
Constant Field Values

HTTP_NOT_FOUND

public static final int HTTP_NOT_FOUND
HTTP response codes

See Also:
Constant Field Values

HTTP_FORBIDDEN

public static final int HTTP_FORBIDDEN
HTTP response codes

See Also:
Constant Field Values

MIME_BOUNDARY

private static final java.lang.String MIME_BOUNDARY
MIME multipart boundary

See Also:
Constant Field Values

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 CvBase.ImageServer on serverPort.


useConsole

public boolean useConsole
Whether to look for keypresses with ConsoleNonblocking.


serverPort

public int serverPort
TCP port for the CvBase.ImageServer


serverMimeType

public volatile java.lang.String serverMimeType
Image format for the CvBase.ImageServer


serverFormat

public volatile java.lang.String serverFormat
Image format for the CvBase.ImageServer


paused

public boolean paused
Whether processing is currently paused.


dbg

public boolean dbg
Whether debug is requested for next frame.


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


server

protected CvBase.ImageServer server
The CvBase.ImageServer, if useServer.


serverImage

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


serverLock

protected java.lang.Object serverLock
Synchronization lock for server state.


serverImagePending

protected volatile boolean serverImagePending
Whether a fresh serverImage is ready.


serverActive

protected volatile boolean serverActive
Whether the server is currently serving images.


maxServerFPS

public volatile float maxServerFPS
Maximum server framerate.


serverDBG

public volatile boolean serverDBG
Debug next server frame.


serverKey

protected volatile char serverKey
Last key char from serer 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)

Constructor initializes members.

Call init(int, String[]) and then mainLoop() to run the default application.


CvBase

public CvBase()
Uses DEF_APPNAME.

Method Detail

fmt

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


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

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

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.


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

mainLoop

public void mainLoop()

Main frame processing loop.

Default impl acquires a new frame from cap streamIndex or grabber, calls process(com.googlecode.javacv.cpp.opencv_core.IplImage), displays the result (if any), quits if doneProcessing(), otherwise delays for the remainder of the minimum frame time (inverse of maxFPS), handles user input, and then loops.


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 useServer, 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 static int setCaptureProperty(com.googlecode.javacv.cpp.opencv_highgui.CvCapture cap,
                                     int id,
                                     double value)

Wraps cvSetCaptureProperty(), catches RuntimeException.


getCaptureProperty

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

Wraps cvGetCaptureProperty(), catches RuntimeException.