OpenCV
From flowdesigner
Contents |
Description
The plugin OpenCV enable to manage image and video in Flowdesigner. You could perform different operations of treatment of images. After the installation, you could find a new menu in Flowdesigner called FDOpenCV where there is different sub menu.
Required softwares
- Flowdesigner v0.9.1
- OpenCV v1.0
Installation
You could download the OpenCV plugin with this command :
svn co https://flowdesigner.svn.sourceforge.net/svnroot/flowdesigner/trunk/FDOpenCV FDOpenCV
Then, you could install it with this command :
./autogen.sh make make install
Image
This sub menu contains many function to manage an image.
CvLoadImage
This block loads an image from the specified file. It returns on output the image associate. The following file formats are supported:
- Windows bitmaps - BMP, DIB
- JPEG files - JPEG, JPG, JPE
- Portable Network Graphics - PNG
- Portable image format - PBM, PGM, PPM
- Sun rasters - SR, RAS
- TIFF files - TIFF, TIF
ISCOLOR: Specifies colorness of the loaded image:
- if >0, the loaded image is forced to be color 3-channel image;
- if 0, the loaded image is forced to be grayscale;
- if <0, the loaded image will be loaded as is (with number of channels depends on the file).
CvSaveImage
This block saves the image in input, to the specified file. The image format is chosen depending on the filename extension, see CvLoadImage.
CvShowImage
This block display the image in input, in a window.
- WNDOW_TITLE: Name of the widow. Don't forget to use different name to create new windows!
- FLAGS: If it is set to 1, window size is automatically adjusted to fit the displayed image, while user can not change the window size manually.
CvCreateImage
Create a black image (all the pixel are initialized to 0) with specified:
- Size: you could specified its width and height
- Bit depth of image elements: can be one of:
- IPL_DEPTH_8U - unsigned 8-bit integers
- IPL_DEPTH_8S - signed 8-bit integers
- IPL_DEPTH_16U - unsigned 16-bit integers
- IPL_DEPTH_16S - signed 16-bit integers
- IPL_DEPTH_32S - signed 32-bit integers
- IPL_DEPTH_32F - single precision floating-point numbers
- IPL_DEPTH_64F - double precision floating-point numbers
- Channels: number of channels per element (pixel). Can be 1, 2, 3 or 4.
Draw
This sub menu contains many function to draw some figures on an image
CvLine
This block draws the line segment between two points in the image. For non-antialiased lines with integer coordinates the 8-connected or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased lines are drawn using Gaussian filtering. LINE_TYPE :
- 8 - 8-connected line.
- 4 - 4-connected line.
- CV_AA - antialiased line.
The color, in input, specified for the line is in RGB.
Example with a black image of size 400x400, line [(50,50);(350,350)] and LINE_TYPE=8 :
CvRectangle
This block draws simple, thick or filled rectangle two opposite corners.
- THICKNESS: Thickness of lines that make up the rectangle. Negative values make the function to draw a filled rectangle.
- LINE_TYPE: Type of the line, see CvLine description
- SHIFT: Number of fractional bits in the point coordinates.
The color, in input, specified for the rectangle is in RGB.
Example where the small rectangle is filled and the big no :
Arithmetic, Logic and Comparison
This sub menu contains many function to perform some arithmetic, logic and comparison operation between some images.
CvAdd
This block adds one array to another one:
dst(I)=src1(I)+src2(I)
The images must have the same type and the same size.
CvComp
This block compares the corresponding elements of two images. Both image must have a single channel. The flag CMP_OP specifying the relation between the elements to be checked:
- CV_CMP_EQ - src1(I) "equal to" src2(I)
- CV_CMP_GT - src1(I) "greater than" src2(I)
- CV_CMP_GE - src1(I) "greater or equal" src2(I)
- CV_CMP_LT - src1(I) "less than" src2(I)
- CV_CMP_LE - src1(I) "less or equal" src2(I)
- CV_CMP_NE - src1(I) "not equal to" src2(I)
dst(I)=src1(I) op src2(I),
where op is '=', '>', '>=', '<', '<=' or '!='. dst(I) is set to 0xff (all '1'-bits) if the particular relation between the elements is true and 0 otherwise. All the images must have the same type, except the destination, and the same size.
CvAvg
This block calculates the average value of the image, independently for each channel.
Color
This sub menu contains different function to manage color in an image.
CvCreateColor
This block creates a color in 3 channels like : HSV or RGB.
CvGray
Convert an image in color to gray
Example :
CvFindColorHSV
This block finds color in the HSV color space. You put in input 2 colors which specified the limit for each channel. For the hue, if the min limit is superior to the max limit, the detection is perform to the extremity (notably useful to detect red color). The result image is on 1 channel. Each pixel of this image is set to 0 if the color corresponds and 0xff (all '1'-bits) otherwise.
Example to detect red color :
Color min : H=340; S=80; V=100 Color max : H=20; S=255; V=255
CvFindColorRGB
This block finds color in the RGB color space. You put in input the color you want to detect then you must specified in parameter the sensibility around this color. The result image is on 1 channel. Each pixel of this image is set to 0 if the color corresponds and 0xff (all '1'-bits) otherwise.
Example to detect red color :
Color : R=211 ; G=41 ; B=15 Sensibility : R=80 ; G=80 ; B=80
Structuring Element
CvCreateStructuringElement
This block enable to create a structuring element which is used by some morphological operations. It takes many parameters :
- COLS: Number of columns in the structuring element.
- ROWS: Number of rows in the structuring element.
- ANCHOR_x: Relative horizontal offset of the anchor point.
- ANCHOR_y: Relative vertical offset of the anchor point.
- SHAPE: Shape of the structuring element; may have the following values:
- CV_SHAPE_RECT - a rectangular element.
- CV_SHAPE_CROSS - a cross-shaped element.
- CV_SHAPE_ELLIPSE - an elliptic element.
Morphological Operations
This sub menu contains many functions to perform morphological operation on an image.
CvErode
This block erodes the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the minimum is taken. Erosion can be applied several (iterations) times. For color images, each channel is processed independently.
Example with a 3x3 rectangular element and 1 iteration:
CvDilate
This block dilates the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the maximum is taken. Dilatation can be applied several (iterations) times. For color images, each channel is processed independently.
Example with a 3x3 rectangular element and 1 iteration:
CvCanny
This block finds the edges on the input image and marks them in the output image using the Canny algorithm. The smallest of THRESHOLD1 and THRESHOLD2 is used for edge linking, the largest to find initial segments of strong edges. aperture_size APERTURE_SIZE is the aperture parameter for Sobel operator. If the input image is in color (3 channels), it's convert automatically the image in gray (1 channel).
Example with THRESHOLD1=50, THRESHOLD2=200, APERTURE_SIZE=3:
CvSmooth
This block smooths the image in one of several ways (SMOOTH_TYPE) :
- CV_BLUR_NO_SCALE (simple blur with no scaling) - summation over a pixel param1×param2 neighborhood. If the neighborhood size may vary, one may precompute integral image with cvIntegral function.
- CV_BLUR (simple blur) - summation over a pixel param1×param2 neighborhood with subsequent scaling by 1/(param1•param2).
- CV_GAUSSIAN (gaussian blur) - convolving image with param1×param2 Gaussian kernel.
- CV_MEDIAN (median blur) - finding median of param1×param1 neighborhood (i.e. the neighborhood is square).
- CV_BILATERAL (bilateral filter) - applying bilateral 3x3 filtering with color sigma=param1 and space sigma=param2.
Example with SMOOTH_TYPE=CV_GAUSSIAN, PARAM1=5, PARAM2=5
CvMorphology
This block can perform advanced morphological transformations using erosion and dilation as basic operations. Type of morphological operation (OPERATION) :
- CV_MOP_OPEN - opening
dst=open(src,element)=dilate(erode(src,element),element)
- CV_MOP_CLOSE - closing
dst=close(src,element)=erode(dilate(src,element),element)
- CV_MOP_GRADIENT - morphological gradient
dst=morph_grad(src,element)=dilate(src,element)-erode(src,element)
- CV_MOP_TOPHAT - "top hat"
dst=tophat(src,element)=src-open(src,element)
- CV_MOP_BLACKHAT - "black hat"
dst=blackhat(src,element)=close(src,element)-src
Example with a 3x3 rectangular element, 1 iteration and OPERATION=CV_MOP_GRADIENT
CvSobel
This block calculates first, second, third or mixed image derivatives using extended Sobel operator. If the input image is in color (3 channels), it's convert automatically the image in gray (1 channel).
Example with XORDER=1, YORDER=0, APERTURE_SIZE=3 (calculate first x image derivative):
CvThreshold
This block applies fixed-level thresholding to single-channel image. The function is typically used to get bi-level (binary) image out of grayscale image or for removing a noise. If the input image is in color (3 channels), it's convert automatically the image in gray (1 channel). There are several types of thresholding the block supports that are determined by THRESHOLD_TYPE:
- CV_THRESH_BINARY:
dst(x,y) = MAX_VALUE, if src(x,y)>THRESHOLD
0, otherwise
- CV_THRESH_BINARY_INV:
dst(x,y) = 0, if src(x,y)>THRESHOLD
MAX_VALUE, otherwise
- CV_THRESH_TRUNC:
dst(x,y) = THRESHOLD, if src(x,y)>THRESHOLD
src(x,y), otherwise
- CV_THRESH_TOZERO:
dst(x,y) = src(x,y), if src(x,y)>THRESHOLD
0, otherwise
- CV_THRESH_TOZERO_INV:
dst(x,y) = 0, if src(x,y)>THRESHOLD
src(x,y), otherwise
Example : MAX_VALUE = 70
Contours
This sub menu contains many function to manage the contours in an image.
CvFindContours
This block retrieves contours from the binary image and returns in output the number of retrieved contours and the first most outer contour. Other contours may be reached from this by using the blocks : CvNextContour, CvNextHierarchy, CvPrevContour, CvPrevHierarchy (see below).
- MODE: Retrieval mode.
- CV_RETR_EXTERNAL - retrive only the extreme outer contours
- CV_RETR_LIST - retrieve all the contours and puts them in the list
- CV_RETR_CCOMP - retrieve all the contours and organizes them into two-level hierarchy: top level are external boundaries of the components, second level are bounda boundaries of the holes
- CV_RETR_TREE - retrieve all the contours and reconstructs the full hierarchy of nested contours
- METHOD: Approximation method (for all the modes, except CV_LINK_RUNS, which uses built-in approximation).
- CV_CHAIN_CODE - output contours in the Freeman chain code. All other methods output polygons (sequences of vertices).
- CV_CHAIN_APPROX_NONE - translate all the points from the chain code into points;
- CV_CHAIN_APPROX_SIMPLE - compress horizontal, vertical, and diagonal segments, that is, the function leaves only their ending points;
- CV_CHAIN_APPROX_TC89_L1,CV_CHAIN_APPROX_TC89_KCOS - apply one of the flavors of Teh-Chin chain approximation algorithm.
- CV_LINK_RUNS - use completely different contour retrieval algorithm via linking of horizontal segments of 1?s. Only CV_RETR_LIST retrieval mode can be used with this method.
CvDrawContours
This block draws contour outlines or interiors in the image. You could choice in input the color of the contours and the holes. You could specified in parameter:
- MAX_LEVEL: Maximal level for drawn contours. If 0, only contour is drawn. If 1, the contour and all contours after it on the same level are drawn. If 2, all contours after and all contours one level below the contours are drawn, etc. If the value is negative, the function does not draw the contours following after contour but draws child contours of contour up to abs(max_level)-1 level.
- THICKNESS: Thickness of lines the contours are drawn with. If it is negative, the contour interiors are drawn.
- LINE_TYPE: Type of the contour segments, see CvLine description.
Example : All the contours (green) and holes (blue) are drawn
CvContourArea
This block calculates area of the whole contour or contour section. In the latter case the total area bounded by the contour arc and the chord connecting the 2 selected points is calculated.
CvNextContours
This block reaches the next contours on the same hierarchical level. If the next contour doesn't exit, it returns the first contour and the output BOOL = false. If the input BOOL = true, then it returns the same contour. It returns also the number of elements in the contour returned.
CvPrevContours
This block reaches the previous contours on the same hierarchical level. If the previous contour doesn't exit, it returns the first contour and the output BOOL = false. If the input BOOL = true, then it returns the same contour. It returns also the number of elements in the contour returned.
CvNextHierarchy
This block reaches the next contours in the vertical direction, that is, parent. If the next hierarchy doesn't exit, it returns the first contour and the output BOOL = false. It returns also the number of elements in the contour returned.
CvPrevHierarchy
This block reaches the previous contours in the vertical direction, that is, its first child. If the next hierarchy doesn't exit, it returns the first contour and the output BOOL = false. It returns also the number of elements in the contour returned.
CvSelectContour
This block reaches the contour indicate by the index. It makes the search of the next contour as many time as the value of the index, so you can't access to the hierarchy with this function. It returns also the number of elements in the contour returned. It could be notably useful when you don't have hierarchy in your contours : for example when you choice to find your contours with : CV_RETR_EXTERNAL or CV_RETR_LIST.
video
CvLoadVideo
This block initialized the reading of the video stream from the specified file. Which codecs and file formats are supported depends on the back end library. On Windows HighGui uses Video for Windows (VfW), on Linux this is ffmpeg, on Mac OS X the back end is QuickTime.
CvWebcam
This block initialized the reading of video stream from the camera. Currently two camera interfaces can be used on Windows: Video for Windows (VFW) and Matrox Imaging Library (MIL); and two on Linux: V4L and FireWire (IEEE1394).
- INDEX: Index of the camera to be used. If there is only one camera or it does not matter what camera to use -1 may be passed.
CvQueryFrame
This block grabs a frame from camera or video file, decompresses and returns it.
CvOpticalFlow
This block calculates optical flow for two images. It computes flow for every pixel of the first input image. It returns on outputs:
- VELX: Horizontal component of the optical flow of the same size as input images, 32-bit floating-point, single-channel.
- VELY: Vertical component of the optical flow of the same size as input images, 32-bit floating-point, single-channel.
