|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object hypermedia.video.OpenCV
public class OpenCV
The main object for all computer vision processes.
To use OpenCV library in a PApplet directly in pure Java, start with this small integration sample
for more details about Processing see the home page
import processing.core.*; import hypermedia.video.OpenCV; public class OpenCV_PApplet extends PApplet { OpenCV cv = null; // OpenCV object // Initialise Objects public void setup() { size( 640, 480 ); // set frame size cv = new OpenCV( this ); // link OpenCV process to this PApplet cv.capture( width, height ); // start video stream } // Display the input camera stream in frame public void draw() { cv.read(); image( cv.image(), 0, 0 ); } // Call the PApplet main method public static void main( String[] args ) { PApplet.main( new String[]{"OpenCV_PApplet"} ); } }
Field Summary | |
---|---|
static int |
BILATERAL
|
static int |
BLUR
Blur method |
static int |
BUFFER
|
static java.lang.String |
CASCADE_FRONTALFACE_ALT
|
static java.lang.String |
CASCADE_FRONTALFACE_ALT_TREE
Standard Haar classifier cascade file used for object detection |
static java.lang.String |
CASCADE_FRONTALFACE_ALT2
|
static java.lang.String |
CASCADE_FRONTALFACE_DEFAULT
|
static java.lang.String |
CASCADE_FULLBODY
|
static java.lang.String |
CASCADE_LOWERBODY
|
static java.lang.String |
CASCADE_PROFILEFACE
|
static java.lang.String |
CASCADE_UPPERBODY
|
static int |
FLIP_BOTH
|
static int |
FLIP_HORIZONTAL
|
static int |
FLIP_VERTICAL
Flip mode |
static int |
GAUSSIAN
|
static int |
GRAY
|
static int |
HAAR_DO_CANNY_PRUNING
Haar classifier flag |
static int |
HAAR_DO_ROUGH_SEARCH
|
static int |
HAAR_FIND_BIGGEST_OBJECT
|
static int |
HAAR_SCALE_IMAGE
|
int |
height
OpenCV image/buffer height |
static int |
INTER_AREA
|
static int |
INTER_CUBIC
|
static int |
INTER_LINEAR
|
static int |
INTER_NN
Interpolation method |
static int |
MAX_VERTICES
The maximum number of contour points available to blob detection (by default) |
static int |
MEDIAN
|
static int |
MEMORY
|
static int |
MOVIE_FRAMES
|
static int |
MOVIE_MILLISECONDS
Movie info selector (not yet implemented) |
static int |
MOVIE_RATIO
|
static int |
RGB
Colorspace of image |
static int |
SOURCE
Type of Image |
static int |
THRESH_BINARY
Thresholding method |
static int |
THRESH_BINARY_INV
|
static int |
THRESH_OTSU
|
static int |
THRESH_TOZERO
|
static int |
THRESH_TOZERO_INV
|
static int |
THRESH_TRUNC
|
int |
width
OpenCV image/buffer width |
Constructor Summary | |
---|---|
OpenCV()
Create a new OpenCV instance. |
|
OpenCV(processing.core.PApplet parent)
Create a new OpenCV instance. |
Method Summary | |
---|---|
void |
absDiff()
Calculate the absolute difference between the image in memory and the current image. |
java.lang.String |
absolutePath(java.lang.String file)
Prepend the absolute path for the given file name. |
void |
allocate(int width,
int height)
Allocate required buffer with the given size. |
float |
arcLength(int index)
Deprecated. |
float |
area(int index)
Deprecated. |
int |
blobCount()
Deprecated. |
Blob[] |
blobs(int minArea,
int maxArea,
int maxBlobs,
boolean findHoles)
Blob and contour detection. |
Blob[] |
blobs(int minArea,
int maxArea,
int maxBlobs,
boolean findHoles,
int maxVertices)
Blob and contour detection. |
void |
blur(int type,
int param1)
Smooth the image in one of several ways. |
void |
blur(int type,
int param1,
int param2,
float param3,
float param4)
Smooth the image in one of several ways. |
void |
brightness(int value)
Adjust the image brightness with the specified value (in range of -128 to 128). |
void |
capture(int width,
int height)
Allocate and initialize resources for reading a video stream from the default camera. |
void |
capture(int width,
int height,
int index)
Allocate and initialize resources for reading a video stream from the specified camera. |
void |
cascade(java.lang.String file)
Load into memory the descriptor file for a trained cascade classifier. |
java.awt.Point |
centroid(int index)
Deprecated. |
void |
contrast(int value)
Adjust the image contrast with the specified value (in range of -128 to 128). |
void |
convert(int type)
Convert the current image from one colorspace to another. |
void |
copy(int[] pixels,
int step,
int sx,
int sy,
int swidth,
int sheight,
int dx,
int dy,
int dwidth,
int dheight)
Copies a region of pixels from an image to the current buffer at the specified position and with the given dimensions. |
void |
copy(processing.core.PImage image)
Copy an image into the current OpenCV buffer. |
void |
copy(processing.core.PImage image,
int sx,
int sy,
int swidth,
int sheight,
int dx,
int dy,
int dwidth,
int dheight)
Copy the image (or a part of it) into the current OpenCV buffer (or a part of it). |
void |
copy(java.lang.String file)
Copy the specified image file into the current OpenCV buffer. |
void |
copy(java.lang.String file,
int sx,
int sy,
int swidth,
int sheight,
int dx,
int dy,
int dwidth,
int dheight)
Copy the specified image file (or a part of it) into the current OpenCV buffer (or a part of it). |
java.awt.Rectangle[] |
detect()
|
java.awt.Rectangle[] |
detect(float scale,
int min_neighbors,
int flags,
int min_width,
int min_height)
Detect object(s) in the current image depending on the current cascade description. |
void |
dispose()
Forget all OpenCV resources. |
void |
findContours(int minArea,
int maxArea,
int maxBlobs,
boolean findHoles)
Deprecated. |
void |
findContours(int minArea,
int maxArea,
int maxBlobs,
boolean findHoles,
int maxVertices)
Deprecated. |
void |
flip(int mode)
Flip the current image around vertical, horizontal or both axes. |
processing.core.PImage |
image()
Return the current OpenCV image. |
processing.core.PImage |
image(int type)
Return the specified OpenCV image |
void |
interpolation(int method)
Set global interpolation method. |
void |
invert()
Invert image. |
boolean |
isHole(int index)
Deprecated. |
void |
jump(float ratio)
Jump to a specified movie frame. |
void |
jump(float value,
int type)
Jump to a specified movie frame. |
void |
jump(int millis)
Jump to a specified movie frame. |
void |
loadImage(java.lang.String file)
Load an image from the specified file. |
void |
loadImage(java.lang.String file,
int width,
int height)
Load an image from the specified file with the given size dependin of the current scale interpolation method. |
void |
movie(java.lang.String filename)
Allocate and initialize resources for reading a video file from the specified file name. |
void |
movie(java.lang.String filename,
int width,
int height)
Allocate and initialize resources for reading a video file from the specified file name, with the given frames dimensions. |
int[] |
pixels()
|
int[] |
pixels(int type)
Retrieve cuurent (or specified) image data. |
int |
pointCount(int index)
Deprecated. |
java.awt.Point[] |
points(int index)
Deprecated. |
void |
read()
Grab a new frame from the input camera or a movie file. |
java.awt.Rectangle |
rectangle(int index)
Deprecated. |
void |
remember()
Place the image source in memory. |
void |
remember(int type)
Place the specified image in memory. |
void |
remember(int type,
int mode)
Place the specified image in memory and flip the stored image around the given axis. |
void |
restore()
Revert to the original image. |
void |
restore(int type)
Restore the current image data from the original image with the given color space. |
void |
ROI(int x,
int y,
int width,
int height)
Set image region of interest to the given rectangle. |
void |
ROI(java.awt.Rectangle rect)
Set image region of interest to the given rectangle. |
void |
stop()
Stop OpenCV process. |
void |
threshold(float value)
Applies fixed-level threshold to the current image using the THRESH_BINARY thresholding type and 255 as the maximum value. |
void |
threshold(float value,
float max,
int type)
Apply fixed-level threshold to the current image. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SOURCE
image(int)
,
remember(int)
,
Constant Field Valuespublic static final int BUFFER
public static final int MEMORY
public static final int RGB
convert(int)
,
Constant Field Valuespublic static final int GRAY
public static final int THRESH_BINARY
threshold( float )
,
threshold( float, float, int )
,
Constant Field Valuespublic static final int THRESH_BINARY_INV
public static final int THRESH_TRUNC
public static final int THRESH_TOZERO
public static final int THRESH_TOZERO_INV
public static final int THRESH_OTSU
public static final int FLIP_VERTICAL
flip( int )
,
remember( int, int )
,
Constant Field Valuespublic static final int FLIP_HORIZONTAL
public static final int FLIP_BOTH
public static final int INTER_NN
interpolation( int )
,
Constant Field Valuespublic static final int INTER_LINEAR
public static final int INTER_CUBIC
public static final int INTER_AREA
public static final int MAX_VERTICES
blobs( int, int, int, boolean )
,
blobs( int, int, int, boolean, int )
,
Constant Field Valuespublic static final int BLUR
blur(int, int)
,
blur(int, int, int, float, float)
,
Constant Field Valuespublic static final int GAUSSIAN
public static final int MEDIAN
public static final int BILATERAL
public static final int MOVIE_MILLISECONDS
jump(float, int)
,
Constant Field Valuespublic static final int MOVIE_FRAMES
public static final int MOVIE_RATIO
public static final int HAAR_DO_CANNY_PRUNING
detect(float, int, int, int, int)
,
Constant Field Valuespublic static final int HAAR_SCALE_IMAGE
public static final int HAAR_FIND_BIGGEST_OBJECT
public static final int HAAR_DO_ROUGH_SEARCH
public static final java.lang.String CASCADE_FRONTALFACE_ALT_TREE
cascade(String)
,
Constant Field Valuespublic static final java.lang.String CASCADE_FRONTALFACE_ALT
public static final java.lang.String CASCADE_FRONTALFACE_ALT2
public static final java.lang.String CASCADE_FRONTALFACE_DEFAULT
public static final java.lang.String CASCADE_PROFILEFACE
public static final java.lang.String CASCADE_FULLBODY
public static final java.lang.String CASCADE_LOWERBODY
public static final java.lang.String CASCADE_UPPERBODY
public int width
height
public int height
width
Constructor Detail |
---|
public OpenCV()
public OpenCV(processing.core.PApplet parent)
Method Detail |
---|
public void dispose()
stop()
public void allocate(int width, int height)
This method allows you to create your own (blank) image buffer to work on.
Except for creating an empty buffer, this method should not be directly used.
capture()
, movie()
and loadImage()
methods will
automatically re-allocate the current buffer.
capture( int, int )
,
movie( String )
,
loadImage( String )
,
copy(PImage)
,
copy(String)
,
copy(PImage, int, int, int, int, int, int, int, int)
,
copy(String, int, int, int, int, int, int, int, int)
,
copy(int[], int, int, int, int, int, int, int, int, int)
public void stop()
public void remember()
absDiff()
to compare two images (for background extraction, for example).
remember( int, int )
,
remember( int )
,
absDiff()
public void remember(int type)
absDiff()
to compare two images (for background extraction, for example).
type
- which image to be stored: SOURCE or BUFFERremember( int, int )
,
remember()
,
absDiff()
public void remember(int type, int mode)
absDiff()
to compare two images (for background extraction, for example).
type
- which image to be stored: SOURCE or BUFFERmode
- the used axis: FLIP_HORIZONTAL, FLIP_VERTICAL or FLIP_BOTHremember( int, int )
,
flip( int )
,
absDiff()
public void convert(int type)
type
- the target color space : RGB, GRAYpublic void absDiff()
remember()
,
remember( int )
,
remember( int, int )
public void flip(int mode)
mode
- the used axis, FLIP_HORIZONTAL, FLIP_VERTICAL or FLIP_BOTHpublic void threshold(float value, float max, int type)
This method applies fixed-level thresholding to single-channel array. It is typically used to get bi-level (binary) image out of grayscale image or for removing a noise (filtering out pixels with too small or too large values).
About types of thresholding
value
- threshold valuemax
- the maximum value to use with THRESH_BINARY and THRESH_BINARY_INV thresholding types.type
- Types of thresholdingthreshold( float )
public void threshold(float value)
value
- threshold valuethreshold( float, float, int )
public void brightness(int value)
value
- the new brightness valuecontrast( int )
public void contrast(int value)
value
- the new contrast valuebrightness( int )
public void invert()
public void blur(int type, int param1)
param1
- The first parameter of smoothing operation. It should be odd (1, 3, 5, …),
so that a pixel neighborhood used for smoothing operation is symmetrical
relative to the pixel.blur( int, int, int, float, float )
public void blur(int type, int param1, int param2, float param3, float param4)
param1
- The first parameter of smoothing operation. It should be odd (1, 3, 5, …),
so that a pixel neighborhood used for smoothing operation is symmetrical
relative to the pixel.param2
- The second parameter of smoothing operation. In case of simple
scaled/non-scaled and Gaussian blur if param2 is zero, it is set to param1.
When not 0, it should be odd too.param3
- In case of Gaussian kernel this parameter may specify Gaussian sigma
(standard deviation). If it is zero, it is calculated from the kernel size:
sigma = (n/2 - 1)*0.3 + 0.8, where n=param1 for horizontal kernel,
n=param2 for vertical kernel. With the standard sigma for small kernels
(3×3 to 7×7) the performance is better. If param3 is not zero, while param1
and param2 are zeros, the kernel size is calculated from the sigma
(to provide accurate enough operation).param4
- In case of non-square Gaussian kernel the parameter may be used to specify a
different (from param3) sigma in the vertical direction.blur( int, int )
public void interpolation(int method)
INTER_LINEAR
.
Used by all methods (ex. copy()
, loadImage()
, …) that resize the image.
method
- INTER_NN, INTER_LINEAR, INTER_CUBIC or INTER_AREApublic void copy(processing.core.PImage image)
image
- the image to copy into bufferallocate(int,int)
,
interpolation( int )
,
copy( String )
,
copy( PImage, int, int, int, int, int, int, int, int )
,
copy( String, int, int, int, int, int, int, int, int )
,
copy( int[], int, int, int, int, int, int, int, int, int )
public void copy(java.lang.String file)
file
- the filepath of the image to copy into bufferallocate(int,int)
,
interpolation( int )
,
copy( PImage )
,
copy( PImage, int, int, int, int, int, int, int, int )
,
copy( int[], int, int, int, int, int, int, int, int, int )
public void copy(processing.core.PImage image, int sx, int sy, int swidth, int sheight, int dx, int dy, int dwidth, int dheight)
image
- the filepath of the image to copy into bufferallocate(int,int)
,
interpolation( int )
,
copy( PImage )
,
copy( String )
,
copy( String, int, int, int, int, int, int, int, int )
,
copy( int[], int, int, int, int, int, int, int, int, int )
,
copy( int[], int, int, int, int, int, int, int, int, int )
public void copy(java.lang.String file, int sx, int sy, int swidth, int sheight, int dx, int dy, int dwidth, int dheight)
image
- the filepath of the image to copy into bufferallocate(int,int)
,
interpolation( int )
,
copy( PImage )
,
copy( PImage, int, int, int, int, int, int, int, int )
,
copy( int[], int, int, int, int, int, int, int, int, int )
,
copy( int[], int, int, int, int, int, int, int, int, int )
public void copy(int[] pixels, int step, int sx, int sy, int swidth, int sheight, int dx, int dy, int dwidth, int dheight)
pixels
- the image datastep
- the width of one horizontal line of pixelssx
- the source x coordinatesy
- the source y coordinateswidth
- the source widthsheight
- the source heightdx
- the destination x coordinatedy
- the destination y coordinatedwidth
- the destination widthdheight
- the destination heightallocate(int,int)
,
interpolation( int )
,
copy( PImage )
public void restore()
blobs( int, int, int, boolean, int )
,
blobs( int, int, int, boolean )
public void restore(int type)
type
- the target color space : RGB or GRAYblobs( int, int, int, boolean, int )
,
blobs( int, int, int, boolean )
public int[] pixels(int type)
type
- the type of the image: SOURCE, BUFFER, MEMORYpublic int[] pixels()
public void loadImage(java.lang.String file)
Currently the following file formats are supported:
note : this method automatically updates previous memory allocation
Currently there is an impressive OpenCV-caused memory leak on Macintosh computers when recalling this method successively. To fix this bug, load the image file from Processing and pass the pixels over usingcopy()
.
file
- String : the name of file to be loadedloadImage( String, int, int )
public void loadImage(java.lang.String file, int width, int height)
Currently the following file formats are supported:
note : this method automatically updates previous memory allocation
file
- the name of file to be loadedwidth
- the destination image (buffer) width sizeheight
- the destination image (buffer) height sizeinterpolation( int )
,
loadImage( String )
public processing.core.PImage image()
image(int)
public processing.core.PImage image(int type)
type
- the type of the image: SOURCE, BUFFER, MEMORY
image()
public Blob[] blobs(int minArea, int maxArea, int maxBlobs, boolean findHoles)
This function looks for contours within the image, returning a list of Blob
objects.
When searching for blobs, you must define the minimum and maximum size in pixels. This can be calculated by any number of means; for example, if you want to limit blobs to no larger than half the Region Of Interest, pass (width * height) / 2
for the maxArea
. Blobs are then ordered from largest to smallest.
Blob
objects contain all the relevant information about each contour (area, length, centroid, isHole, …)
minArea
- the minimum area to search for (total pixels)maxArea
- the maximum area to search for (total pixels)maxBlobs
- the maximim number of blobs to returnfindHoles
- accept blobs fully inside of other blobs
blobs( int, int, int, boolean, int )
,
Blob
,
restore()
,
restore( int )
,
MAX_VERTICES
public Blob[] blobs(int minArea, int maxArea, int maxBlobs, boolean findHoles, int maxVertices)
This function looks for contours within the image, returning a list of Blob
objects.
When searching for blobs, you must define the minimum and maximum size in pixels. This can be calculated by any number of means; for example, if you want to limit blobs to no larger than half the Region Of Interest, pass (width * height) / 2
for the maxArea
. Blobs are then ordered from largest to smallest.
Blob
objects contain all the relevant information about each contour (area, length, centroid, isHole, …)
The optional maxVertices
parameter, allows you to increase the overall number of points defining the contour of the blob. Use this parameter if for some reason your blob shapes are incomplete.
minArea
- the minimum area to search for (total pixels)maxArea
- the maximum area to search for (total pixels)maxBlobs
- the maximim number of blobs to returnfindHoles
- accept blobs fully inside of other blobsmaxVertices
- the maximum number of points used to define the contour
blobs( int, int, int, boolean )
,
Blob
,
restore()
,
restore( int )
,
MAX_VERTICES
public void findContours(int minArea, int maxArea, int maxBlobs, boolean findHoles)
minArea
- the minimum area to searchedmaxArea
- the maximum area to searchedpublic void findContours(int minArea, int maxArea, int maxBlobs, boolean findHoles, int maxVertices)
public int blobCount()
public float area(int index)
public float arcLength(int index)
public java.awt.Point centroid(int index)
public java.awt.Rectangle rectangle(int index)
public int pointCount(int index)
public java.awt.Point[] points(int index)
public boolean isHole(int index)
public void capture(int width, int height)
width
- the width of the video stream imageheight
- the height of the video stream imagecapture( int, int, int )
,
movie( String )
public void capture(int width, int height, int index)
width
- the width of the video stream imageheight
- the height of the video stream imageindex
- the index of the camera to be usedcapture( int, int )
,
movie( String )
public void movie(java.lang.String filename)
Supported codecs and file formats depends on the backend video library :
For more information about video on OpenCV or about reading your video files on all platforms, see VideoCodecs
filename
- the filepath of the movie filemovie( String, int, int )
,
capture( int, int )
,
capture( int, int, int )
,
jump( int )
,
jump( float )
,
jump( float, int )
public void movie(java.lang.String filename, int width, int height)
Supported codecs and file formats depends on the backend video library :
For more information about video on OpenCV or about reading your video files on all platforms, see VideoCodecs
filename
- the filepath of the movie filewidth
- the width of the movie imageheight
- the height of the movie imagemovie( String )
,
jump( int )
,
jump( float )
,
jump( float, int )
public void read()
public void jump(int millis)
millis
- the time in milliseconds of the desired framemovie( String )
,
movie( String, int, int )
,
jump( float )
,
jump( float, int )
public void jump(float ratio)
ratio
- the time expressed as a ratio (0.0 - 1.0) of the desired framejump( int )
,
jump( float, int )
,
movie( String )
,
movie( String, int, int )
public void jump(float value, int type)
value
- the time (according to type) of the desired frametype
- use: MOVIE_MILLISECONDS, MOVIE_FRAMES or MOVIE_RATIOjump( float )
,
jump( int )
,
movie( String )
,
movie( String, int, int )
public void ROI(java.awt.Rectangle rect)
ROI(null);
rect
- the new region of interest or null
to resetpublic void ROI(int x, int y, int width, int height)
ROI(null);
x
- the region x-coordinatey
- the region y-coordinatewidth
- the region widthheight
- the region heightpublic java.lang.String absolutePath(java.lang.String file)
This method try to return a full path to an item in the sketch/program folder, in the data folder for Processing user, the system OpenCV's resources folder ('data' or 'resources'), in any resources folder for Java user. The search order is the 'data' folder, the current user directory, any resources folder.
file
- the filename to be search
public void cascade(java.lang.String file)
detect()
).
While you may use your own cascade description files, this library links as well to a standard family of detection cascades (CASCADE_FRONTALFACE_DEFAULT
, CASCADE_FULLBODY
, …). These are installed automatically in the Windows installer and most Linux packages. For those using Macs, we have included these files in our opencv-framework-*.*.dmg
installer. If you use a different Mac installer, you will have to import these files on your own.
It is recommended that you avoid loading the file at each cycle.
Available detection cascade flags :
file
- The filepath, or standard cascade flag (see above) of the Haar classifier cascade file to be used for object detectiondetect()
,
detect( float, int, int, int, int )
public java.awt.Rectangle[] detect(float scale, int min_neighbors, int flags, int min_width, int min_height)
This method finds rectangular regions in the current image that are likely to contain objects the cascade has been trained to recognize. It returns found regions as a sequence of rectangles.
The default parameters (scale=1.1, min_neighbors=3, flags=0) are tuned for accurate
(but slow) object detection. For a faster operation on real-time images, the more preferable
settings are: scale=1.2, min_neighbors=2, flags=HAAR_DO_CANNY_PRUNING,
min_size=
Mode of operation flags:
Note, that in single-object mode HAAR_DO_CANNY_PRUNING does not improve performance much and can even slow down the processing.
scale
- The factor by which the search window is scaled between the subsequent scans, for example, 1.1 means increasing window by 10%.min_neighbors
- Minimum number (minus 1) of neighbor rectangles that makes up an object. All the groups of a smaller number of rectangles than min_neighbors-1 are rejected. If min_neighbors is 0, the function does not any grouping at all and returns all the detected candidate rectangles, which may be useful if the user wants to apply a customized grouping procedure.flags
- Mode of operation. It can be a combination of zero or more of the above flags.min_width
- Minimum window size. By default, it is set to the size of samples the classifier has been trained on (~20×20 for face detection).min_height
- Minimum window size. By default, it is set to the size of samples the classifier has been trained on (~20×20 for face detection).cascade( String )
public java.awt.Rectangle[] detect()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |