IplImage img = IplImage.create(cvSize(width, height), depth, channels)
width
- number of pixel columnsheight
- number of pixel rowsdepth
- number of bits per channel, typically IPL_DEPTH_8U
to use one unsigned 8 bit integer per channel (i.e. one byte), but there are a number of available formats. For example use IPL_DEPTH_32F
for one 32-bit floating point number per channel.channels
- number of channels per pixel, typically 3 for color images (RGB, HSV, etc) or 1 for grayscale or binary imagesimg.width()
, img.height()
, img.channels()
, img.depth()
- get image propertiesimg.release()
- must explicitly free native memoryCvScalar rgb = cvGet2D(img, y, x)
, CvScalar hsv = cvGet2D(hsvImg, y, x)
rgb.getVal(0)
(or rgb.blue()
) is the blue componentrgb.getVal(1)
(or rgb.green()
) is the green componentrgb.getVal(2)
(or rgb.red()
) is the red componenthsv.getVal(0)
is the hue componenthsv.getVal(1)
is the saturation componenthsv.getVal(2)
is the value componentcvSmooth(src, dst, smoothtype, size1, size2, sigma1, sigma2)
src
,dst
- source and destination images, same size/depth/channelssmoothtype
- the smoothing algorithm to use, the default CV_GAUSSIAN
is most common; other options include CV_BLUR
, CV_MEDIAN
, and moresize1
,size2
- convolution kernel width and height. size1
(width) must be a positive odd number (default 3). size2
(height) is ignored for some algorithms like median filter, which must have a square kerner. size2=0
, the default, implies use a square kernel given by size1
. Otherwise must size2
(height) must be a positive odd number.sigma1
,sigma2
- standard deviation for Gaussian filter. sigma1=0
, the default, implies the standard deviation from the kernel size. sigma2
appears to be ignored (set it to 0).cvCopyMakeBorder()
- default is typically replicatecvCvtColor(src, dst, code)
src
,dst
- source and destination images, same size and depth, may differ in channels depending on requested conversioncode
- conversion algorithm to apply. Many possibilities, but common ones are CV_BGR2RGB
, CV_BGR2HSV
, CV_BGR2HSVFULL
, CV_BGR2GRAY
.CV_BGR2HSV_FULL
is similar to CV_BGR2HSV
, but use the mapping
CV_BGR2HSV
.cvInRangeS(src, lower, upper, dst)
- threshold to a binary image
src
- source imagelower
- CvScalar
minimum pixel component values to convert to a oneupper
- CvScalar
maximum pixel component values to convert to a onedst
- destination binary image, one channel 8-bitcvOr(src1, src2, dst, mask)
- bitwise OR operation
src1
,src2
,dst
- source and destination images, same size/depth/channelsmask
- one channel 8-bit binary mask for the operation, or null to process all pixelscvErode(src, dst, element, iterations)
,cvDilate(src, dst, element, iterations)
src
,dst
- source and destination imageselement
- convolution mask specifying which neighborhood pixels to considder (specify null
to get the default
iterations
- how many times to repeat the operationcvFindContours(image, storage, first_contour, header_size, mode, method)
//setup
CvMemStorage storage = CvMemStorage.create();
CvSeq contour = CvSeq();
IplImage bimg = null;
CvScalar min = cvScalar(MIN0, MIN1, MIN2, 0);
CvScalar max = cvScalar(MAX0, MAX1, MAX2, 0);
protected IplImage process(IplImage frame) {
if (bimg == null) //allocate binary image on first call
bimg = IplImage.create(cvSize(frame.width(), frame.height()), IPL_DEPTH_8U, 1);
cvInRangeS(frame, min, max, bimg); //convert to binary image
cvFindContours(bimg, storage, contour, Loader.sizeof(CvContour.class),
CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
for (CvSeq c = contour; !c.isNull(); c = c.h_next()) {
if (c.elem_size() > 0) {
CvRect r = cvBoundingRect(c, 0);
//do things here with r and/or c
}
}
cvClearMemStorage(storage);
return bimg; //or whatever image you want to be displayed for debug
}
protected void release() { //cleanup
//important to explicitly null and check for non-null to avoid double releasing even
//if this is called more than once, which it may be since CvBase.finalize() calls release()
if (storage != null) { storage.release(); storage = null; }
if (bimg != null) { bimg.release(); bimg = null; }
super.release();
}
cvCanny(image, edges, threshold1, threshold2, aperture_size)
cvHoughLines2(image, line_storage, method, rho, theta, threshold, param1, param2)
cvHoughCircles(image, circle_storage, method, dp, min_dist, param1, param2, min_radius, max_radius)