Skip to content
scs edited this page Jul 14, 2012 · 2 revisions

Table of Contents

Overview

The LeanCV library is a set of vision algorithms with a simple and consistent API. It contains functions for Debayering, Image conversions and Filters and more...
LeanCV uses the same primitives as OpenCV. That makes it easy to use OpenCV and LeanCV in one project.

Credits

Contributed by Beat Küng

Dependencies

  • Oscar v2.1 or greater (only the headers are used)

Usage

See Oscar Code Collection for general information how to use an OSC-CC module. Use #include <leancv.h> to include LeanCV into an application.
Important: Include leancv.h before stl headers (e.g. iostream).

API

All Functions use the image datatype IplImage, which is from OpenCV. They all begin with the prefix lcv.

Supported Image Formats/Image Conditions

  • depth: IPL_DEPTH_8U or IPL_DEPTH_16FRACT.
  • width: Must be a multiple of LCV_WIDTH_ALIGN = 4.
  • channels: Either 1 (gray) or 3 (BGR color format).

Image Allocation & Deallocation

See Supported Image Formats for more information about valid arguments.

   lcvCreateImage

Allocate image header and image data.

Arguments:

  • struct CvSize size: image size.
  • int depth: image depth
  • int channels: Image Channel count.
Return value:
  • IplImage*: Created Image.
Example:
 IplImage* img=lcvCreateImage(cvSize(OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT), IPL_DEPTH_8U, 1);

   lcvCreateImageHeader

Allocate Image Header only. Set img->imageData pointer to the image data after calling the function. Note that the imageData pointer must be aligned. See lcvAlignImage.

Arguments:

  • struct CvSize size: image size.
  • int depth: image depth
  • int channels: Image Channel count.
Return value:
  • IplImage*: Created Header.
Example:
 IplImage* img=lcvCreateImageHeader(cvSize(OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT), IPL_DEPTH_8U, 1);
 img->imageData=(char*)pic;

   lcvAlignImage

Align an image pointer to the next multiple of LCV_IMG_ALIGN. Effective image size must be LCV_IMG_ALIGN larger than needed.

Arguments:

  • char* img: pointer to be aligned
Return value:
  • char*: aligned pointer.
Example:
 uint8 pic[OSC_CAM_MAX_IMAGE_HEIGHT*OSC_CAM_MAX_IMAGE_WIDTH  + LCV_IMG_ALIGN];
 IplImage* img=lcvCreateImageHeader(cvSize(OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT), IPL_DEPTH_8U, 1);
 img->imageData=lcvAlignImage((char*)pic);

   lcvReleaseImage

Deallocate image header and data.

Arguments:

  • IplImage** image: Address of the image pointer.
Return value:
  • void
Example:
 [...]
 
 lcvReleaseImage(&img);

   lcvReleaseImageHeader

Deallocate image header only.

Arguments:

  • IplImage** image: Address of the image pointer.
Return value:
  • void

Debayering

Convert a raw image, captured with a color sensor to another format.

   lcvDebayer

Debayer a captured image to BGR color format. Input channel count is 1 and the output image must have 3 channels. Input and output image must have the same size. Arguments:

  • IplImage* raw_img: the captured image. Must have 1 channel.
  • enum EnBayerOrder order: Bayer order.
  • IplImage* output: the debayered output image. Must have 3 channels.
Return value:
  • void

   lcvDebayerGray

Debayer a captured image to half size with color format gray. Both images must have 1 channels and the output image must have half the width and height from the raw image. Arguments:

  • IplImage* raw_img: the captured image. Must have 1 channel.
  • enum EnBayerOrder order: Bayer order.
  • IplImage* output: the debayered output image. Must have 1 channels.
Return value:
  • void

Image Formats

   lcvBmpWrite

Write an image to a BMP image file. Arguments:

  • IplImage* img: pointer to an image
  • char* file_name: file name string.
Return value:
  • OSC_ERR: 0 on success. Appropriate error code otherwise.

   lcvBmpHeader

get a pointer to a BMP image header.
Note: Release created image with lcvReleaseImage after usage! Arguments:

  • IplImage* img: pointer to an image
  • char** header_out: this pointer will be set to the header.
Return value:
  • int: header size on success. < 0 on error.

   lcvBmpRead

Read a BMP image file to an IplImage structure. Arguments:

  • char* file_name: BMP image file name.
Return value:
  • IplImage*: Created Image on success, NULL on error.

   lcvImgReverseRowOrder

Reverse image rows. Used by lcvBmpRead, because BMP stores the image upside down. Arguments:

  • IplImage* img: pointer to the image.
Return value:
  • void

Image Scaling & Conversion

   lcvConvertImage

Convert one image type to another. Currently conversions between image depth IPL_DEPTH_16FRACT and IPL_DEPTH_8U is supported. Arguments:

  • IplImage* img_in: pointer to the input image.
  • IplImage* img_out: pointer to the resulting image.
Return value:
  • void

   lcvConvertImageBinary

Converts a grayscale image to a binary image. Input image can be the same as output image. Image depth can be either IPL_DEPTH_16FRACT or IPL_DEPTH_8U. The resulting image contains only 0 and 1. Arguments:

  • IplImage* img_in: pointer to the input image.
  • IplImage* img_out: pointer to the resulting image.
  • int threshold: if input pixel is greater than threshold, the result will be 1 and 0 if pixel is smaller than the threshold value.
Return value:
  • void

Filters & Object detection

   lcvLabelBinary

This function labels the binary image by checking for connected components based on run-length encoding. This function outputs a representation of the binary image based on connected sets of runs. The sets of runs are refered to as 'objects' (=regions of foreground pixels). Arguments:

  • IplImage* img_in: pointer to the input image. One channel, binary and depth must be IPL_DEPTH_8U
  • LCV_REGIONS regions: pointer to a regions data struction. result will be stored here
Return value:
  • void

   lcvGetRegionProperties

Extract Properties of the Regions (=labeled binary Image), calculated with the function lcvLabelBinary. Arguments:

  • LCV_REGIONS regions: pointer to a regions data struction
Return value:
  • void

Drawing

   lcvDrawCentroidMarkers

This function draws the centroids of the Regions as small crosses. Arguments:

  • IplImage* img_in: pointer to the input image.
  • LCV_REGIONS regions: pointer to a regions data struction.
  • const char* color: the drawing color. size must be img_in->nChannels * image depth/8
Return value:
  • void

   lcvDrawBoundingBox

This function draws the bounding boxes of the Regions as rectangles. Arguments:

  • IplImage* img_in: pointer to the input image.
  • LCV_REGIONS regions: pointer to a regions data struction.
  • const char* color: the drawing color. size must be img_in->nChannels * image depth/8
Return value:
  • void
Clone this wiki locally