]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
imported from a new release
authorneurosurg <neurosurg@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Sat, 19 Oct 2002 19:32:05 +0000 (19:32 +0000)
committerneurosurg <neurosurg@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Sat, 19 Oct 2002 19:32:05 +0000 (19:32 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@18 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/include/opencv/cv.h
opencv/include/opencv/cv.hpp
opencv/include/opencv/cvcompat.h
opencv/include/opencv/cvtypes.h
opencv/src/cv/Makefile.am
opencv/src/cv/cvthresh.cpp
opencv/src/cv/cvundistort.cpp
opencv/src/cv/cvutils.cpp

index 72c4ccc5fc0d18b4973e957a162a64930cf4bc6d..3e766d85b393ee251c79f53ac3a4b7baf17a2489 100644 (file)
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-//  By downloading, copying, installing or using the software you agree to this license.
-//  If you do not agree to this license, do not download, install,
-//  copy or use the software.
-//
-//
-//                        Intel License Agreement
-//                For Open Source Computer Vision Library
-//
-// Copyright( C) 2000, Intel Corporation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-//   * Redistribution's of source code must retain the above copyright notice,
-//     this list of conditions and the following disclaimer.
-//
-//   * Redistribution's in binary form must reproduce the above copyright notice,
-//     this list of conditions and the following disclaimer in the documentation
-//     and/or other materials provided with the distribution.
-//
-//   * The name of Intel Corporation may not be used to endorse or promote products
-//     derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-//(including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort(including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-#ifndef _CV_H_
-#define _CV_H_
-
-#ifndef _INC_WINDOWS
-    #define CV_PRETEND_WINDOWS
-    #define _INC_WINDOWS
-    typedef struct tagBITMAPINFOHEADER BITMAPINFOHEADER;
-    typedef int BOOL;
-#endif
-#include "ipl.h"
-#ifdef CV_PRETEND_WINDOWS
-    #undef _INC_WINDOWS
-#endif
-#include "cvpixelaccess.h"
-#include "cvtypes.h"
-#include "cverror.h"
-
-/****************************************************************************************\
-*                                    Function definition                                 *
-\****************************************************************************************/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateImageHeader
-//    Purpose: allocates IplImage structure, initializes and returns it
-//    Context:
-//    Parameters:
-//      size - image size(width and height)
-//      depth- image depth
-//      channels - number of channels.
-//    Returns:
-//      created image header
-//    Notes:
-//      this call is short form of
-//         iplCreateImageHeader( channels, 0, depth, channels == 1 ? "GRAY" :
-//                               channels == 3 || channels == 4 ? "RGB" : "",
-//                               channels == 1 ? "GRAY" : channels == 3 ? "BGR" :
-//                               channels == 4 ? "BGRA" : "",
-//                               IPL_DATA_ORDER_PIXEL, IPL_ORIGIN_TL, 4,
-//                               size.width, size.height,
-//                               0,0,0,0);
-//F*/
-OPENCVAPI  IplImage*  cvCreateImageHeader( CvSize size, int depth, int channels );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvInitImageHeader
-//    Purpose: initializes image header structure without memory allocation
-//    Context:
-//    Parameters:
-//      image - image header. User allocates it manually(e.g. on the stack)
-//      size  - width and height of the image
-//      depth - image depth
-//      channels - number of channels
-//      origin - IPL_ORIGIN_TL or IPL_ORIGIN_BL.
-//      align - alignment for raster lines
-//      clear - if 1, header is cleared before it is initialized.
-//    Returns:
-//      initialized header
-//F*/
-OPENCVAPI IplImage* cvInitImageHeader( IplImage* image, CvSize size, int depth,
-                                       int channels, int origin CV_DEFAULT(0),
-                                       int align CV_DEFAULT(4), int clear CV_DEFAULT(1));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateImage
-//    Purpose: creates image header and allocates data
-//    Context:
-//    Parameters:
-//      size - image size(width and height)
-//      depth- image depth
-//      channels - number of channels.
-//    Returns:
-//      created image
-//    Notes:
-//      this call is short form of
-//         header = cvCreateImageHeader(size,depth,channels);
-//         cvCreateData(header);
-//F*/
-OPENCVAPI  IplImage*  cvCreateImage( CvSize size, int depth, int channels );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvReleaseImageHeader
-//    Purpose: releases header
-//    Context:
-//    Parameters:
-//        image - released image header
-//    Returns:
-//      this call is short form of
-//         if( image )
-//         {
-//              iplDeallocate( *image, IPL_IMAGE_HEADER | IPL_IMAGE_ROI );
-//              *image = 0;
-//         }
-//F*/
-OPENCVAPI  void  cvReleaseImageHeader( IplImage** image );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvReleaseImage
-//    Purpose: releases header and image data
-//    Context:
-//    Parameters:
-//      image - released image
-//    Returns:
-//      this call is short form of
-//         if( image && *image )
-//         {
-//              iplDeallocate( *image, IPL_IMAGE_ALL );
-//              *image = 0;
-//         }
-//F*/
-OPENCVAPI  void  cvReleaseImage( IplImage** image );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCloneImage
-//    Purpose: creates a whole copy of the image
-//    Context:
-//    Parameters:
-//      image - source image
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI IplImage* cvCloneImage( const IplImage* image );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSetImageCOI
-//    Purpose: set channel of interest to given value.
-//    Context:
-//    Parameters:
-//      image - image header
-//      coi   - channel of interest
-//    Returns:
-//    Notes:
-//      If roi is NULL and coi != 0, roi is allocated.
-//F*/
-OPENCVAPI  void  cvSetImageCOI( IplImage* image, int coi );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetImageCOI
-//    Purpose: retrieves channel of interest
-//    Context:
-//    Parameters:
-//      image - image header
-//    Returns:
-//      COI
-//F*/
-OPENCVAPI  int  cvGetImageCOI( IplImage* image );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSetImageROI
-//    Purpose: set image ROI to given rectangle
-//    Context:
-//    Parameters:
-//      image - image header
-//      rect  - ROI rectangle
-//    Returns:
-//    Notes:
-//       If roi is NULL and rect is not equal to a whole image, roi is allocated.
-//F*/
-OPENCVAPI  void  cvSetImageROI( IplImage* image, CvRect rect );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvResetImageROI
-//    Purpose: deletes image ROI
-//    Context:
-//    Parameters:
-//      image - image header
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvResetImageROI( IplImage* image );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetImageROI
-//    Purpose: return region of interest (ROI) for given image or
-//             (0,0,image->width,image->height) if ROI is not set
-//    Context:
-//    Parameters:
-//      image - image header
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  CvRect cvGetImageROI( const IplImage* image );
-
-
-#define CV_AUTOSTEP  0x7fffffff
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateMatHeader
-//    Purpose: allocates CvMat structure, initializes and returns it
-//    Context:
-//    Parameters:
-//      rows - number of matrix rows
-//      cols - number of matrix columns
-//      type - matrix type
-//      step - matrix step (or stride) - an optional parameter.
-//    Returns:
-//      created matrix header
-//F*/
-OPENCVAPI  CvMat*  cvCreateMatHeader( int rows, int cols, int type );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvInitMatHeader
-//    Purpose: initializes matrix header structure without memory allocation
-//    Context:
-//    Parameters:
-//      mat   - matrix header. User allocates it manually(e.g. on the stack)
-//      rows  - number of matrix rows
-//      cols  - number of matrix columns
-//      type  - matrix type
-//      step  - matrix step (optional)
-//    Returns:
-//      initalized matrix header
-//F*/
-OPENCVAPI CvMat* cvInitMatHeader( CvMat* mat, int rows, int cols,
-                                  int type, void* data CV_DEFAULT(0),
-                                  int step CV_DEFAULT(CV_AUTOSTEP) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateMat
-//    Purpose: creates matrix header and allocates data
-//    Context:
-//    Parameters:
-//      rows  - number of matrix rows
-//      cols  - number of matrix columns
-//      type  - matrix type
-//      step  - matrix step (optional)
-//    Returns:
-//      created matrix
-//F*/
-OPENCVAPI  CvMat*  cvCreateMat( int rows, int cols, int type );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvReleaseMatHeader
-//    Purpose: releases matrix header
-//    Context:
-//    Parameters:
-//        mat - released matrix header
-//    Returns:
-//      nothing
-//F*/
-OPENCVAPI  void  cvReleaseMatHeader( CvMat** mat );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvReleaseMat
-//    Purpose: releases matrix header and underlying data
-//    Context:
-//    Parameters:
-//      matrix - released matrix
-//    Returns:
-//      nothing
-//    Notes:
-//F*/
-OPENCVAPI  void  cvReleaseMat( CvMat** mat );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCloneMat
-//    Purpose: creates a whole copy of the matrix
-//    Context:
-//    Parameters:
-//      mat - the cloned matrix
-//    Returns:
-//F*/
-OPENCVAPI CvMat* cvCloneMat( const CvMat* mat );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetSubArr
-//    Purpose: returns sub-matrix w.o copying data
-//    Context:
-//    Parameters:
-//      arr - the original matrix (or IplImage)
-//      submat - pointer to sub-matrix stucture
-//      rect - extracted rectange
-//    Returns:
-//      filled header of submatrix (i.e., &submat)
-//F*/
-OPENCVAPI CvMat* cvGetSubArr( const CvArr* arr, CvMat* submat, CvRect rect );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetRow
-//    Purpose: The function is analogous to the previous, but returns a single row
-//    Context:
-//    Parameters:
-//      arr - an original matrix (or IplImage)
-//      submat - pointer to sub-matrix stucture
-//      row - index of the row
-//    Returns:
-//      filled header of sub-matrix (i.e., &submat)
-//F*/
-OPENCVAPI CvMat* cvGetRow( const CvArr* arr, CvMat* submat, int row );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetCol
-//    Purpose: The function is analogous to the previous, but returns a single column
-//    Context:
-//    Parameters:
-//      arr - an original matrix (or IplImage)
-//      submat - pointer to sub-matrix stucture
-//      column - index of the column
-//    Returns:
-//      filled header of sub-matrix (i.e., &submat)
-//F*/
-OPENCVAPI CvMat* cvGetCol( const CvArr* arr, CvMat* submat, int column );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetCol
-//    Purpose: The function is analogous to the previous, but returns a single diagonal
-//    Context:
-//    Parameters:
-//      arr - an original matrix (or IplImage)
-//      submat - pointer to sub-matrix stucture
-//      diag - index of the diagonal ( 0 corresponds to the main diagonal,
-//                positive number - to some upper diagonal, negative number - to
-//                some lower diagonal ), as shown below:
-//             0  1  2  3  4
-//            -1  0  1  2  3
-//            -2 -1  0  1  2
-//            -3 -2 -1  0  1
-//            -4 -3 -2 -1  0
-//            -5 -4 -3 -2 -1
-//
-//    Returns:
-//      filled header of sub-matrix (i.e., &submat)
-//F*/
-OPENCVAPI CvMat* cvGetDiag( const CvArr* arr, CvMat* submat,
-                            int diag CV_DEFAULT(0));
-
-
-/* ptr = &arr(idx) */
-OPENCVAPI uchar* cvGetPtrAt( const CvArr* arr, int y, int x CV_DEFAULT(0));
-
-/* value = arr(idx) */
-OPENCVAPI CvScalar cvGetAt( const CvArr* arr, int y, int x CV_DEFAULT(0)); 
-
-/* arr(idx) = value */
-OPENCVAPI void cvSetAt( CvArr* arr, CvScalar value,
-                        int y, int x CV_DEFAULT(0)); 
-
-
-/* Converts CvArr (IplImage or CvMat) to CvMat */
-OPENCVAPI CvMat* cvGetMat( const CvArr* src, CvMat* header, int* coi CV_DEFAULT(0));
-
-/* Converts CvArr (IplImage or CvMat) to IplImage */
-OPENCVAPI IplImage* cvGetImage( const CvArr* array, IplImage* img );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvReshape
-//    Purpose: reshapes the matrix
-//    Context:
-//    Parameters:
-//      array  - image or matrix
-//      header - the output matrix header (may be the same as input)
-//      new_cn - the new channel number. The original array width multiplied by the
-//               original number of channels should be divisible
-//               by the new number of channels.
-//      new_rows - the new number of rows in the matrix. 0 means do not change it if
-//               it is not neccessary. Number of rows can be changed only if the matrix
-//               continuous.
-//    Returns:
-//    Notes:
-//      All the output parameters are optional
-//F*/
-OPENCVAPI CvMat* cvReshape( const CvArr* array, CvMat* header,
-                            int new_cn, int new_rows CV_DEFAULT(0));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateData
-//    Purpose: allocates image or matrix data
-//    Context:
-//    Parameters:
-//        array - image or matrix header
-//F*/
-OPENCVAPI  void  cvCreateData( CvArr* array );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvReleaseData
-//    Purpose: releases image data
-//    Context:
-//    Parameters:
-//      array - image or matrix header
-//F*/
-OPENCVAPI  void  cvReleaseData( CvArr* array );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSetData
-//    Purpose: sets pointer to data and step parameter to given values
-//    Context:
-//    Parameters:
-//      array - image or matrix header
-//      data  - user data
-//      step  - full width or data (distance between successive rows)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvSetData( CvArr* array, void* data, int step );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetRawData
-//    Purpose: fills output variables with image parameters
-//    Context:
-//    Parameters:
-//      array - image or matrix
-//      data  - pointer to top-left corner of ROI
-//      step  - is set to <widthStep> field in case of IplImage or
-//              to <step> field in case of CvMat
-//      roi_size - width and height of ROI
-//    Returns:
-//    Notes:
-//      All the output parameters are optional
-//F*/
-OPENCVAPI void cvGetRawData( const CvArr* array, uchar** data,
-                             int* step, CvSize* roi_size );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetSize
-//    Purpose: returns size of matrix or image ROI.
-//             in case of matrix size.width == number_of_columns,
-//                               size.height == number_of_rows.
-//    Context:
-//    Parameters:
-//      arr - image or matrix
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  CvSize cvGetSize( const CvArr* arr );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCopy
-//    Purpose: copies image ROI or matrix
-//    Context:
-//    Parameters:
-//      src - source array
-//      dst - destination array
-//      mask - optional mask
-//F*/
-OPENCVAPI  void  cvCopy( const CvArr* src, CvArr* dst,
-                         const CvArr* mask CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSet
-//    Purpose: sets image ROI or matrix to given value
-//    Context:
-//    Parameters:
-//      arr - array
-//      scalar - value to set to
-//      mask - optional mask
-//F*/
-OPENCVAPI  void  cvSet( CvArr* arr, CvScalar scalar,
-                        const CvArr* mask CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvLUT
-//    Purpose: Performs lookup-table transform: dst(x,y) = lut[src(x,y)]
-//    Parameters:
-//      srcarr - the source array: 8u or 8s type
-//      dstarr - the destination array of arbitrary type,
-//      lutarr - the LUT array. The same type as the destination array,
-//               contains 256 entries.
-//    Note:
-//      if the source array has 8s type, the modified formula is used:
-//      dst(x,y) = lut[src(x,y) + 128]
-//F*/
-OPENCVAPI  void cvLUT( const CvArr* srcarr, CvArr* dstarr, const CvArr* lutarr );
-
-
-/****************************************************************************************\
-*                                     Pyramids                                           *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvPyrUp
-//    Purpose: performs factor-2 upsampling of the image with subsequent
-//             Gaussian smoothing.
-//    Context:
-//    Parameters:
-//      src - source image
-//      dst - destination image(must have twice larger width and height than source image)
-//      filter - filter applied. Only IPL_GAUSSIAN_5x5 is allowed.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvPyrUp( const CvArr* src, CvArr* dst,
-                          int filter CV_DEFAULT(IPL_GAUSSIAN_5x5) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvPyrDown
-//    Purpose: performs factor-2 downsampling of the image
-//             with prior Gaussian smoothing
-//    Context:
-//    Parameters:
-//        src - source image
-//        dst - destination image(must have twice smaller width and height than
-//                                 source image)
-//        filter - filter applied. Only IPL_GAUSSIAN_5x5 is allowed.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvPyrDown( const CvArr* src, CvArr* dst,
-                            int filter CV_DEFAULT(IPL_GAUSSIAN_5x5) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvPyrSegmentation
-//    Purpose: segments image using iterative multi-scale algorithm 
-//    Context:
-//    Parameters:
-//      src - source image
-//      dst - destination image
-//      storage - pointer to the memory storage
-//      comp - pointer to the output sequence of the connected components
-//      level - number of level to the pyramid costruction
-//      threshold1 - the first segmentation threshold
-//      threshold2 - the second segmentation threshold
-//    Notes:
-//      Source and destination image must be equal types and planes
-//F*/
-OPENCVAPI void cvPyrSegmentation( IplImage* src,
-                               IplImage* dst,
-                               CvMemStorage *storage,
-                               CvSeq **comp,
-                               int level, double threshold1,
-                               double threshold2 );
-
-
-/****************************************************************************************\
-*                              Derivative calculation                                    *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSobel
-//    Purpose: calculates an image derivative d^(xorder+yorder)I/((dx)^xorder)*(dy^yoder))
-//             by convolving the image with extended Sobel operators.
-//             No scaling is performed.
-//
-//             |-1 -2 -1|     |-1 0 1|
-//             | 0  0  0| and |-2 0 2| are partial cases of it.
-//             | 1  2  1|     |-1 0 1|
-//
-//             First one corresponds to xorder = 0, yorder = 1, apertureSize = 3,
-//             And the second corresponds to xorder = 1, yorder = 0, apertureSize = 3.
-//    Context:
-//    Parameters:
-//      src    - source image
-//      dst    - destination derivative image
-//      xorder - order of x derivative
-//      yorder - order of y derivative
-//      apertureSize - size of colvolution operator. Must be odd: 3, 5, ... or
-//                                        | -3  0  3 |    | -3 -10 -3 |
-//                     CV_SCHARR (-1) for | -10 0 10 | or |  0   0  0 | kernels.
-//                                        | -3  0  3 |    |  3  10  3 |
-//    Returns:
-//    Notes:
-//      The function uses replicatation border mode.
-//      In case of yorder is odd, the image origin is taken into account.
-//      (for matrices the top-left origin is assumed)
-//F*/
-#define CV_SCHARR -1
-
-OPENCVAPI void cvSobel( const CvArr* src, CvArr* dst,
-                        int xorder, int yorder,
-                        int apertureSize CV_DEFAULT(3));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvLaplace
-//    Purpose:  Calculates Laplacian of the image: deltaI = d^2(I)/dx^2 + d^2(I)/dy^2.
-//              Sobel operator is used for calculating derivatives.
-//    Context:
-//    Parameters:
-//      src - source image
-//      dst - destination image
-//      apertureSize - size of applied aperture
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI void cvLaplace( const CvArr* src, CvArr* dst,
-                          int apertureSize CV_DEFAULT(3) );
-
-/****************************************************************************************\
-*                                    Morphology                                          *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvCreateStructuringElementEx
-//    Purpose:
-//      Allocates and fills IplConvKernel structure
-//      which can be used as a structuring element in following morphological operations
-//    Context:
-//    Parameters:
-//        cols   - number of columns in the kernel
-//        rows   - number of rows in the kernel
-//        anchorX - x-coordinate of anchor point(0..cols-1)
-//        anchorY - y-coordinate of anchor point(0..rows-1)
-//        shape   - shape of the structuring element
-//              CV_SHAPE_RECT - rectangular element
-//              CV_SHAPE_CROSS - cross-shaped element
-//              CV_SHAPE_ELLIPSE - elliptic element
-//              CV_SHAPE_CUSTOM - arbitrary element.
-//              <values> array determines mask
-//        values  - mask array. non-zero pixels determine shape of the element
-//    Returns:
-//        structuring element
-//F*/
-typedef enum CvElementShape
-{
-    CV_SHAPE_RECT    = 0,
-    CV_SHAPE_CROSS   = 1,
-    CV_SHAPE_ELLIPSE = 2,
-    CV_SHAPE_CUSTOM  = 100
-}
-CvElementShape;
-
-OPENCVAPI  IplConvKernel*  cvCreateStructuringElementEx( int  cols,    int rows,
-                                                         int  anchorX, int anchorY,
-                                                         CvElementShape shape,
-                                                         int* values CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvReleaseStructuringElement
-//    Purpose:
-//      Releases structuring element and clears pointer
-//    Context:
-//    Parameters:
-//        element - double pointer to structuring element
-//    Returns:
-//F*/
-OPENCVAPI  void  cvReleaseStructuringElement( IplConvKernel** element );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvErode
-//    Purpose:
-//      Applies minimum filter to the source image. Structuring element specifies
-//      a shape of a pixel neigborhood, over which the minimum is calculated
-//    Context:
-//    Parameters:
-//        src    - source image
-//        dst    - destination image, may be the same as source one.
-//        element - structuring element.
-//                  If the pointer is 0, 3x3 rectangular element is used.
-//        iterations - how many times the erosion needs to be applied
-//    Returns:
-//F*/
-OPENCVAPI  void  cvErode( const CvArr* src, CvArr* dst,
-                          IplConvKernel* element CV_DEFAULT(0),
-                          int iterations CV_DEFAULT(1) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvDilate
-//    Purpose:
-//      Applies maximum filter to the source image. Structuring element specifies
-//      a shape of a pixel neigborhood, over which the maximum is calculated
-//    Context:
-//    Parameters:
-//        src    - source image
-//        dst    - destination image, may be the same as source one.
-//        element - structuring element.
-//                  If the pointer is 0, 3x3 rectangular element is used.
-//        iterations - how many times the dilation needs to be applied
-//    Returns:
-//F*/
-OPENCVAPI  void  cvDilate( const CvArr* src, CvArr* dst,
-                           IplConvKernel* element CV_DEFAULT(0),
-                           int iterations CV_DEFAULT(1) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvMorphologyEx
-//    Purpose:
-//      Applies one of the extended morphological operations that are based on
-//      erosion and dilation.
-//    Context:
-//    Parameters:
-//        src    - source image
-//        dst    - destination image, may be the same as source one.
-//        temp   - temporary image. The parameter must be non-zero
-//                 if operation is CV_MOP_TOPHAT or CV_MOP_BLACKHAT and src == dst, or
-//                 if operation is CV_MOP_GRADIENT
-//        element - structuring element.
-//                  If the pointer is 0, 3x3 rectangular element is used.
-//        operation - one of the following:
-//               (let's nB = "<element>, applied <iterations> times")
-//                CV_MOP_OPEN:   dst = dilate(erode(src,nB),nB);
-//                CV_MOP_CLOSE:  dst = erode(dilate(src,nB),nB);
-//                CV_MOP_GRADIENT: dst = dilate(src,nB)-erode(src,nB)
-//                CV_MOP_TOPHAT:   dst = src - erode(src,nB)
-//                CV_MOP_BLACKHAT: dst = dilate(src,nB) - src
-//        iterations - how many times the erosion/dilation needs to be applied
-//    Returns:
-//F*/
-typedef enum CvMorphOp
-{
-    CV_MOP_OPEN = 2,
-    CV_MOP_CLOSE = 3,
-    CV_MOP_GRADIENT = 4,
-    CV_MOP_TOPHAT = 5,
-    CV_MOP_BLACKHAT = 6
-} CvMorphOp;
-
-OPENCVAPI  void  cvMorphologyEx( const CvArr* src, CvArr* dst,
-                                 CvArr* temp, IplConvKernel* element,
-                                 CvMorphOp operation, int iterations CV_DEFAULT(1) );
-
-/****************************************************************************************\
-*                                  Image Statistics                                      *
-\****************************************************************************************/
-
-/****************************************************************************************\
-*      Image statistics functions support the next image formats:                        *
-*         single-channel: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_32F                      *
-*         three-channel: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_32F (COI must be != 0)    *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvSum
-//    Purpose:
-//      Sums all the elements in the image ROI or in the matrix
-//    Context:
-//    Parameters:
-//        array - image or matrix.
-//    Returns:
-//        sum of every channel.
-//    Note:
-//        In case of COI is set the sum over the selected channel is saved
-//        if the 0-th element of the returned CvScalar structure.
-//F*/
-OPENCVAPI  CvScalar  cvSum( const CvArr* array );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvCountNonZero
-//    Purpose:
-//        Counts all the non-zero elements in the image ROI or in the matrix
-//    Context:
-//    Parameters:
-//        array - image or matrix.
-//    Returns:
-//        count of non-zero pixels
-//    Note:
-//        For multi-channel images COI must be set.
-//F*/
-OPENCVAPI  int  cvCountNonZero( const CvArr* array );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvAvg
-//    Purpose:
-//      Calculates average value of the image region or the matrix.
-//    Context:
-//    Parameters:
-//        array - input image or matrix.
-//        mask - optional parameter: 8uC1 or 8sC1 array that specifies
-//               the processed region of the input array
-//    Returns:
-//        average value for every channel. In case of COI is set, average value
-//        of the selected COI is stored into 0-th element
-//        of the returned CvScalar structure
-//F*/
-OPENCVAPI  CvScalar  cvAvg( const CvArr* array, const CvArr* mask CV_DEFAULT(0) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvAvgSdv
-//    Purpose:
-//      Calculates mean and standard deviation of pixels in the image region
-//    Context:
-//    Parameters:
-//        img - input image.
-//        mean - mean value
-//        std_dev - standard deviation
-//        mask - mask(byte-depth, single channel)
-//    Returns:
-//
-//F*/
-OPENCVAPI  void  cvAvgSdv( const CvArr* array, CvScalar* mean, CvScalar* std_dev,
-                           const CvArr* mask CV_DEFAULT(0) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvMinMaxLoc
-//    Purpose:
-//      Finds minimum and maximum pixel values in the image region
-//      and determines their locations.
-//    Context:
-//    Parameters:
-//        img - input image.
-//        minVal - minimum value
-//        maxVal - maximum value
-//        minLoc - location of the minimum
-//        maxLoc - location of the maximum
-//        mask - mask(byte-depth, single channel)
-//    Returns:
-//    Note:
-//      If there are several global minimums and/or maximums,
-//      function returns the most top-left extremums.
-//F*/
-OPENCVAPI  void  cvMinMaxLoc( const CvArr* array, double* min_val, double* max_val,
-                              CvPoint* min_loc CV_DEFAULT(0),
-                              CvPoint* max_loc CV_DEFAULT(0),
-                              const CvArr* mask CV_DEFAULT(0) );
-
-
-/****************************************************************************************\
-*                                         Moments                                        *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvMoments
-//    Purpose:
-//      Calculates moments(up to third order) of the image ROI.
-//      It fills moments state and after that, it is possible to
-//      return concrete moments using
-//        cvGetSpatialMoment, cvGetCentralMoment or
-//        cvGetNormalizedCentralMoment
-//    Context:
-//    Parameters:
-//        img - input image
-//        moments - output moments state.
-//        binary - if non zero, function treats non-zero pixels as 1s.
-//    Returns:
-//F*/
-typedef struct CvMoments
-{
-    /* spatial moments */
-    double  m00, m10, m01, m20, m11, m02, m30, m21, m12, m03;
-    /* central moments */
-    double  mu20, mu11, mu02, mu30, mu21, mu12, mu03;
-    /* m00 != 0 ? 1/sqrt(m00) : 0 */
-    double  inv_sqrt_m00;
-} CvMoments;
-
-OPENCVAPI void cvMoments( const CvArr* array, CvMoments* moments, int binary CV_DEFAULT( 0 ));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvGetSpatialMoment, cvGetCentralMoment, cvGetCentralNormalizedMoment
-//    Purpose:
-//      Returns different moments(up to third order) from moments state.
-//        for raster image, these moments are defined as:
-//        mij = spatial_moment(i,j) = sum(y=0,H-1) sum(x=0,W-1) [I(x,y) *(x^i) *(y^j)]
-//       (where I(x,y) means pixel value at point(x,y). x^y means x power y).
-//
-//        muij = central_moment(i,j) = sum(y=0,H-1) sum(x=0,W-1)
-//                                     [I(x,y) *(x-mean_x)^i) *((y-mean_y)^j)]
-//       (where mean_x = m10/m00, mean_y = m01/m00.
-//         it's easy to see that mu00 = m00, mu10 = mu01 = 0)
-//
-//        nu_ij = central_normalized_moment(i,j) = muij/(m00^((i+j)/2+1))
-//    Context:
-//    Parameters:
-//        moments - moment state( filled by cvMoments or cvContourMoments )
-//        x_order - x order of the moment
-//        y_order - y order of the moment.
-//        The following condition has to be satifsied:
-//          0 <= x_order + y_order <= 3
-//    Returns:
-//        Required moment
-//F*/
-OPENCVAPI  double  cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order );
-OPENCVAPI  double  cvGetCentralMoment( CvMoments* moments, int x_order, int y_order );
-OPENCVAPI  double  cvGetNormalizedCentralMoment( CvMoments* moments,
-                                              int x_order, int y_order );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvGetHuMoments
-//    Purpose:
-//      Calculates seven Hu invariants from normalized moments
-//    Context:
-//    Parameters:
-//        moments - moments state.
-//        hu_moments - Hu moments
-//    Returns:
-//F*/
-typedef struct CvHuMoments
-{
-    double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /* Hu invariants */
-} CvHuMoments;
-
-OPENCVAPI void cvGetHuMoments( CvMoments*  moments, CvHuMoments*  hu_moments );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvNorm, cvNormMask
-//    Purpose:
-//      Calculates different types of norm for single or a pair of images
-//    Context:
-//    Parameters:
-//        imgA - first input image
-//        imgB - second input image
-//        mask - determine pixels that are considered in norm calculation
-//        norm_type - type of the norm.
-//                                imgB == 0           imgB != 0
-//         ---------------------------------------------------------------------------
-//          CV_C:               ||imgA||_inf      ||imgA - imgB||_inf
-//          CV_L1:              ||imgA||_L1       ||imgA - imgB||_L1
-//          CV_L2:              ||imgA||_L2       ||imgA - imgB||_L2
-//         ---------------------------------------------------------------------------
-//          CV_RELATIVE_C:       forbidden       ||imgA - imgB||_inf/||imgB||_inf
-//          CV_RELATIVE_L1:      forbidden       ||imgA - imgB||_L1/||imgB||_L1
-//          CV_RELATIVE_L2:      forbidden       ||imgA - imgB||_L2/||imgB||_L2
-//    Returns:
-//      required norm
-//F*/
-#define CV_C            1
-#define CV_L1           2
-#define CV_L2           4
-#define CV_NORM_MASK    7
-#define CV_RELATIVE     8
-#define CV_DIFF         16
-
-#define CV_DIFF_C       (CV_DIFF | CV_C)
-#define CV_DIFF_L1      (CV_DIFF | CV_L1)
-#define CV_DIFF_L2      (CV_DIFF | CV_L2)
-#define CV_RELATIVE_C   (CV_RELATIVE | CV_C)
-#define CV_RELATIVE_L1  (CV_RELATIVE | CV_L1)
-#define CV_RELATIVE_L2  (CV_RELATIVE | CV_L2)
-
-OPENCVAPI  double  cvNorm( const CvArr* imgA, const CvArr* imgB, int normType,
-                           const CvArr* mask CV_DEFAULT(0) );
-
-/****************************************************************************************\
-*                                     Drawing                                            *
-\****************************************************************************************/
-
-/****************************************************************************************\
-*       Drawing functions work with the following formats:                               *
-*           single channel: IPL_DEPTH_8U, IPL_DEPTH_8S                                   *
-*           three channels: IPL_DEPTH_8U, IPL_DEPTH_8S, coi must be == 0                 *
-*       All the functions include parameter color that means rgb value for three-channel *
-*       images(and may be constructed with CV_RGB macro) and brightness                 *
-*      (least-significant byte of color) for grayscale images.                          *
-*       If drawn figure is partially or completely outside the image, it is clipped.     *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvLine
-//    Purpose:
-//      Draws line on the image ROI between two points
-//    Context:
-//    Parameters:
-//        img  - image where the line is drawn.
-//        pt1  - starting point
-//        pt2  - ending point
-//        color - line color(or brightness)
-//        thickness - line thickness. 1 means simple line.
-//                    if line is thick, function draws the line with round endings.
-//        connectivity - line connectivity (4 or 8)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvLine( CvArr* array, CvPoint pt1, CvPoint pt2,
-                         double color, int thickness CV_DEFAULT(1),
-                         int connectivity CV_DEFAULT(8) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvLineAA
-//    Purpose:
-//      Draws thin antialiazed line on the image ROI between two points
-//    Context:
-//    Parameters:
-//        img  - image where the line is drawn.
-//        pt1  - starting point
-//        pt2  - ending point
-//        scale - number of fractional bits in point coordinates.
-//                That is, line can be drawn with sub-pixel accuracy
-//        color - line color(or brightness)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvLineAA( CvArr* array, CvPoint pt1, CvPoint pt2,
-                           double color, int scale CV_DEFAULT(0));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvRectangle
-//    Purpose:
-//      Draws rectangle on the image ROI
-//    Context:
-//    Parameters:
-//        img  - image where the rectangle is drawn.
-//        pt1  - one of the rectangle corners
-//        pt2  - opposite corner of the rectangle
-//        thickness - thickness of the lines that made up rectangle.
-//        color - line color(or brightness)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvRectangle( CvArr* array, CvPoint pt1, CvPoint pt2,
-                              double color, int thickness CV_DEFAULT(1));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvCircle
-//    Purpose:
-//      Draws circle on the image ROI
-//    Context:
-//    Parameters:
-//        img  - image.
-//        center - circle center
-//        radius - circle radius(must be >= 0)
-//        color - circle color(or brightness)
-//        thickenss - thickness of drawn circle. <0 means filled circle.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvCircle( CvArr* array, CvPoint center, int radius,
-                           double color, int thickness CV_DEFAULT(1));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvCircleAA
-//    Purpose:
-//      Draws circle on the image ROI
-//    Context:
-//    Parameters:
-//        img  - image.
-//        center - circle center
-//        radius - circle radius(must be >= 0)
-//        color - circle color(or brightness)
-//        scale - number of fractional bits in point coordinates.
-//                That is, circle can be drawn with sub-pixel accuracy
-//    Returns:
-//F*/
-OPENCVAPI  void  cvCircleAA( CvArr* array, CvPoint center, int radius,
-                             double color, int scale CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvEllipse
-//    Purpose:
-//      Draws elliptic arc
-//    Context:
-//    Parameters:
-//        img  - image.
-//        center - ellipse center
-//        axes - half axes of the ellipse
-//        angle - ellipse angle
-//        startAngle - starting angle of elliptic arc
-//        endAngle - ending angle of elliptic arc
-//        thickness - arc thickness
-//        color - ellipse color(or brightness)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvEllipse( CvArr* array, CvPoint center, CvSize axes,
-                            double angle, double startAngle, double endAngle,
-                            double color, int thickness CV_DEFAULT(1));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvEllipseAA
-//    Purpose:
-//      Draws antialiazed elliptic arc
-//    Context:
-//    Parameters:
-//        img  - image.
-//        center - ellipse center
-//        axes - half axes of the ellipse
-//        angle - ellipse angle
-//        startAngle - starting angle of elliptic arc
-//        endAngle - ending angle of elliptic arc
-//        scale - number of fractioanl bits in center coordinates and axes sizes.
-//        color - ellipse color(or brightness)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvEllipseAA( CvArr* array, CvPoint center, CvSize axes,
-                              double angle, double startAngle,
-                              double endAngle, double color,
-                              int scale CV_DEFAULT(0) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvFillConvexPoly
-//    Purpose:
-//      Fills convex polygon
-//    Context:
-//    Parameters:
-//        img  - image.
-//        pts  - array of polygon vertices
-//        ntps - number of vertices in the polygon
-//        color - polygon color(or brightness)
-//    Returns:
-//    Notes:
-//        fucntion automatically closes the contour -
-//        adds edge between first and last vertices.
-//        function doesn't check that input polygon is convex.
-//F*/
-OPENCVAPI  void  cvFillConvexPoly( CvArr* array, CvPoint* pts, int npts, double color );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvFillPoly
-//    Purpose:
-//      Fills arbitrary regions, bounded by several polygonal contours.
-//    Context:
-//    Parameters:
-//        img  - image.
-//        contours - number of contours
-//        pts  - array of pointers to polygonal contours
-//        ntps - array of vertices counters for the contours
-//        color - polygons color(or brightness)
-//    Returns:
-//    Notes:
-//        function automatically closes each polygonal contour.
-//        If some contours are overlapped, they are added modulo 2.
-//        That is, pixel is filled, if it belongs to odd number of polygonal contours.
-//F*/
-OPENCVAPI  void  cvFillPoly( CvArr* array, CvPoint** pts,
-                             int* npts, int contours, double color );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvPolyLine
-//    Purpose:
-//      Draws polygons outline with simple or thick lines.
-//    Context:
-//    Parameters:
-//        img  - image.
-//        contours - number of contours
-//        pts  - array of pointers to polygonal contours
-//        ntps - array of vertices counters for the contours
-//        closed - if non-zero, function closes each contour.
-//        thickness - line thickness
-//        color - polygons color(or brightness)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvPolyLine( CvArr* array, CvPoint** pts, int* npts, int contours,
-                             int closed, double color,
-                             int thickness CV_DEFAULT(1),
-                             int connectivity CV_DEFAULT(8));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvPolyLineAA
-//    Purpose:
-//      Draws polygons outline with antialiazes lines.
-//    Context:
-//    Parameters:
-//        img  - image.
-//        contours - number of contours
-//        pts  - array of pointers to polygonal contours
-//        ntps - array of vertices counters for the contours
-//        closed - if non-zero, function closes each contour.
-//        scale - number of fractioanl bits in vertex coordinates
-//        color - polygons color(or brightness)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvPolyLineAA( CvArr* array, CvPoint** pts, int* npts, int contours,
-                               int closed, double color, int scale CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvInitFont
-//    Purpose:
-//      Initializes font to use it in following text rendering operations
-//    Context:
-//    Parameters:
-//        font - pointer to initialized font structure.
-//        font_face - font family. There is a single font,
-//                    supported now - CV_FONT_VECTOR0.
-//        hscale - multiplier for horizontal letter sizes.
-//                 If 1 then the original size is used,
-//                 if 2 - twice wider, if 0.5 - twice thinner etc.
-//        vscale - multiplier for vertical letter sizes.
-//                 If 1 then the original size is used,
-//                 if 2 - twice longer, if 0.5 - twice shorter etc.
-//        italic_scale - tangent of letter slope, 0 means no slope,
-//                       1 - 45 degree slope
-//        thickness - letter thickness
-//    Returns:
-//F*/
-typedef enum CvFontFace
-{
-    CV_FONT_VECTOR0 = 0
-} CvFontFace;
-
-typedef struct CvFont
-{
-    const int*  data; /* font data and metrics */
-    CvSize      size; /* horizontal and vertical scale factors,
-                         (8:8) fix-point numbers */
-    int         italic_scale; /* slope coefficient: 0 - normal, >0 - italic */
-    int         thickness; /* letters thickness */
-    int         dx; /* horizontal interval between letters */
-} CvFont;
-
-OPENCVAPI  void  cvInitFont( CvFont* font, CvFontFace font_face,
-                             double hscale, double vscale,
-                             double italic_scale CV_DEFAULT(0),
-                             int thickness CV_DEFAULT(1) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvPutText
-//    Purpose:
-//      Draws text string on the image with given font
-//    Context:
-//    Parameters:
-//        img  - image.
-//        text - text string
-//        org  - left-bottom corner of output text string
-//        font - text font
-//        color - polygons color(or brightness)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvPutText( CvArr* array, const char* text, CvPoint org,
-                            CvFont* font, double color );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvGetTextSize
-//    Purpose:
-//      Calculates bounding rectangle for given text string and font.
-//    Context:
-//    Parameters:
-//        text - text string
-//        font - font to draw the string with
-//        text_size - output parameter. width and height of bounding box
-//                   (not including part of the text below base line)
-//        ymin - output parameter. negative value or zero - minus height of
-//               text part below base line
-//    Returns:
-//F*/
-OPENCVAPI  void  cvGetTextSize( const char* text_string, CvFont* font,
-                                CvSize* text_size, int* ymin );
-
-
-/****************************************************************************************\
-*                                 Color Transforms                                       *
-\****************************************************************************************/
-
-#define  CV_BGR2BGRA    0
-#define  CV_RGB2RGBA    CV_BGR2BGRA
-
-#define  CV_BGRA2BGR    1
-#define  CV_RGBA2RGB    CV_BGRA2BGR
-
-#define  CV_BGR2RGBA    2
-#define  CV_RGB2BGRA    CV_BGR2RGBA
-
-#define  CV_RGBA2BGR    3
-#define  CV_BGRA2RGB    CV_RGBA2BGR
-
-#define  CV_BGR2GRAY    4
-#define  CV_RGB2GRAY    5
-
-#define  CV_GRAY2BGR    6
-#define  CV_GRAY2RGB    CV_GRAY2BGR
-
-#define  CV_BGR2BGR565  7
-#define  CV_RGB2BGR565  8
-#define  CV_BGR5652BGR  9
-#define  CV_BGR5652RGB  10
-
-#define  CV_BGR2RGB     11
-#define  CV_RGB2BGR     CV_BGR2RGB
-
-#define  CV_BGR2XYZ     12
-#define  CV_RGB2XYZ     13
-#define  CV_XYZ2BGR     14
-#define  CV_XYZ2RGB     15
-
-#define  CV_BGR2YCrCb   16
-#define  CV_RGB2YCrCb   17
-#define  CV_YCrCb2BGR   18
-#define  CV_YCrCb2RGB   19
-
-#define  CV_BGR2HSV     20
-#define  CV_RGB2HSV     21
-
-#define  CV_BGR2Lab     22
-#define  CV_RGB2Lab     23
-
-#define  CV_GRAY2BGR565 24
-#define  CV_GRAY2BGRA   25
-#define  CV_GRAY2RGBA   CV_GRAY2BGRA
-
-#define  CV_BGR5652GRAY 26
-#define  CV_BGRA2GRAY   27
-#define  CV_RGBA2GRAY   28
-
-#define  CV_BGRA2BGR565 29
-#define  CV_RGBA2BGR565 30
-
-#define  CV_COLORCVT_MAX  32
-
-OPENCVAPI  void  cvCvtColor( const CvArr* src, CvArr* dst, int colorCvtCode );
-
-
-/****************************************************************************************\
-*                                 Geometrical Transforms                                 *
-\****************************************************************************************/
-
-#define  CV_INTER_NN        0
-#define  CV_INTER_LINEAR    1
-/*#define  CV_INTER_CUBIC     2*/
-
-OPENCVAPI  void  cvResize( const CvArr* src, CvArr* dst,
-                           int method CV_DEFAULT( CV_INTER_LINEAR ));
-
-/****************************************************************************************\
-*                                       Utilities                                        *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvInitLineIterator
-//    Purpose:
-//      Initializes iterator that gets all the pixels, lying on the raster line between
-//      two given points
-//    Context:
-//    Parameters:
-//        img  - image.
-//        pt1  - starting point
-//        pt2  - ending point. Both points must be inside the image
-//        lineIterator - pointer to initialized iterator state
-//    Returns:
-//        number of pixels between pt1 and pt2.
-//        It is equal to max( abs(pt1.x - pt2.x), abs(pt1.y - pt2.y))
-//F*/
-typedef struct CvLineIterator
-{
-    uchar* ptr;
-    int  err;
-    int  plus_delta;
-    int  minus_delta;
-    int  plus_step;
-    int  minus_step;
-} CvLineIterator;
-
-OPENCVAPI  int  cvInitLineIterator( const CvArr* array, CvPoint pt1, CvPoint pt2,
-                                    CvLineIterator* lineIterator,
-                                    int connectivity CV_DEFAULT(8));
-
-/* Move to the next line point */
-#define CV_NEXT_LINE_POINT( iterator )                                          \
-{                                                                               \
-    int mask =  (iterator).err < 0 ? -1 : 0;                                    \
-    (iterator).err += (iterator).minus_delta + ((iterator).plus_delta & mask);  \
-    (iterator).ptr += (iterator).minus_step + ((iterator).plus_step & mask);    \
-}
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvSampleLine
-//    Purpose:
-//      Fetch all the pixel, lying on the raster line between two given points and
-//      writes them to the buffer
-//    Context:
-//    Parameters:
-//        img  - image.
-//        pt1  - starting point
-//        pt2  - ending point. Both points must be inside the image
-//        buffer - pointer to destination buffer.
-//    Returns:
-//        number of pixels stored.
-//        It is equal to max( abs(pt1.x - pt2.x), abs(pt1.y - pt2.y))
-//F*/
-OPENCVAPI  int  cvSampleLine( const CvArr* array, CvPoint pt1, CvPoint pt2, void* buffer,
-                              int connectivity CV_DEFAULT(8));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvGetRectSubPix
-//    Purpose:
-//      Retrieves rectangle from the image with sub-pixel accuracy
-//    Context:
-//    Parameters:
-//        src  - source image.
-//        dst  - destination image.
-//        center - center point of the extracted rectangle.
-//                 Size of extracted rectangle is equal to
-//                 desination image ROI size.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvGetQuandrangleSubPix
-//    Purpose:
-//      Retrieves rectangle from the image with sub-pixel accuracy
-//    Context:
-//    Parameters:
-//        src  - source image.
-//        dst  - destination image.
-//        matrix - transformation matrix (2 rows x 3 columns).
-//                 ( a11  a12 | b1 )      dst([x,y]') = src(A[x y]' + b)
-//                 ( a21  a22 | b2 )      (bilinear interpolation is used)
-//        fillOutliers - fill outlier pixels with some constant value or take them from
-//                       the nearest boundary
-//        fillValue - constant value to fill with
-//    Returns:
-//F*/
-OPENCVAPI  void  cvGetQuadrangleSubPix( const CvArr* src, CvArr* dstarr,
-                                        const CvArr* matrixarr,
-                                        int fillOutliers CV_DEFAULT(0),
-                                        CvScalar fillvalue CV_DEFAULT(cvScalarAll(0)));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvCvtPixToPlane
-//    Purpose:
-//      Splits source image into several separate planes
-//    Context:
-//    Parameters:
-//        src  - source image. Must have 3 or 4 channels.
-//        dst0, dst1, dst2, dst3  - destination images. Must have single channel.
-//               if src has 3 channels, dst3 must be NULL.
-//               if one of the destination images is not NULL,
-//               the corresponding channel is extracted from source image.
-//               Else, all 3 or 4 images must be non NULL and all the source image
-//               channels are written to destination images.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvCvtPixToPlane( const void *src, void *dst0, void *dst1,
-                                  void *dst2, void *dst3 );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvCvtPlaneToPix
-//    Purpose:
-//      Composes destination image from separate single-channel images
-//    Context:
-//    Parameters:
-//        src0, src1, src2, src3  - source images. Must have single channel.
-//              if destination image has 3 channels, src3 must be NULL, else must be
-//              non NULL. Other images must always be non NULL.
-//        dst - destination image. Must have 3 or 4 channels.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvCvtPlaneToPix( const void *src0, const void *src1,
-                                  const void *src2, const void *src3,
-                                  void *dst );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvConvertScale
-//    Purpose:
-//      Converts image from one depth to another with linear transform
-//    Context:
-//    Parameters:
-//        src - source image.
-//        dst - destination image.
-//        scale - multiplier
-//        shift - delta. That is, dst(x,y) = src(x,y)*scale + shift.
-//    Returns:
-//    Notes:
-//        only float->uchar and uchar->float are supported by now.
-//F*/
-OPENCVAPI  void  cvConvertScale( const CvArr *src, CvArr *dst,
-                                 double scale CV_DEFAULT(1),
-                                 double shift CV_DEFAULT(0) );
-#define cvCvtScale cvConvertScale
-#define cvScale  cvConvertScale
-#define cvConvert( src, dst )  cvConvertScale( (src), (dst), 1, 0 )
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvConvertScaleAbs
-//    Purpose:
-//      Converts image from one depth to another
-//    Context:
-//    Parameters:
-//        src - source image.
-//        dst - destination image.
-//        scale - multiplier
-//        shift - delta. That is, dst(x,y) = abs(src(x,y)*scale + shift).
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvConvertScaleAbs( const void *src, void *dst,
-                                    double scale CV_DEFAULT(1),
-                                    double shift CV_DEFAULT(0) );
-#define cvCvtScaleAbs  cvConvertScaleAbs
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvAbsDiff
-//    Purpose:
-//      Finds per-pixel absolute difference between two images
-//    Context:
-//    Parameters:
-//        srcA - first source image.
-//        srcB - second source image
-//        dst  - destination image, May be equal to srcA or srcB
-//    Returns:
-//F*/
-OPENCVAPI  void  cvAbsDiff( const CvArr* srcA, const CvArr* srcB, CvArr* dst );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvAbsDiffS
-//    Purpose:
-//      Finds per-pixel absolute difference between image and scalar value
-//    Context:
-//    Parameters:
-//        src - source image.
-//        dst - destination image, May be equal to srcA or srcB
-//        value - scalar value to compare with
-//    Returns:
-//F*/
-OPENCVAPI  void  cvAbsDiffS( const CvArr* src, CvArr* dst, CvScalar value );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name: cvMatchTemplate
-//    Purpose:
-//      measures similarity between template and overlapped windows in the source image
-//      and fills the resultant image with the measurements.
-//    Context:
-//    Parameters:
-//      img     - source image
-//      templ   - template to find
-//      result  - resultant image. its ROI must have size:
-//                     (img_width - templ_width + 1, img_height - templ_height + 1)
-//      method  - comparison method:
-//---------------------------------------------------------------------------------------
-//             CV_TM_SQDIFF:  res0(i,j)=sum(y=0,TH-1) sum(x=0,TW-1)[I(i+x,j+y)-T(x,y)]^2
-//                    (where  TW - template width, TH - template height
-//                          res0(i,j) - pixel value of result at location(i,j)
-//                                     (zero-th method)
-//                          Iij(x,y) - pixel value of source image at location(i+x,j+y)
-//                                     Iij alone means window of source image
-//                                     with top-left corner(i,j) and template size.
-//                          T(x,y) - pixel value of template at location(x,y)
-//                                   T alone means template.
-//---------------------------------------------------------------------------------------
-//             CV_TM_SQDIFF_NORMED:  res1(i,j) = res0(i,j)/
-//                                             (l2_norm(Iij)*l2_norm(templ);
-//                      where  l2_norm(A) = sqrt(
-//                                     sum(y=0,A_height-1) sum(x=0,A_width-1) A(x,y)^2);
-//---------------------------------------------------------------------------------------
-//             CV_TM_CCORR:  res2(i,j)=sum(y=0,TH-1) sum(x=0,TW-1)[Iij(x,y)*T(x,y)]
-//---------------------------------------------------------------------------------------
-//             CV_TM_CCORR_NORMED:  res3(i,j) = res2(i,j)/[l2_norm(Iij)*l2_norm(templ)];
-//---------------------------------------------------------------------------------------
-//             CV_TM_CCOEFF:  res4(i,j)=sum(y=0,TH-1) sum(x=0,TW-1) [I'ij(x,y)*T'(x,y)]
-//                   where A'(x,y) = A(x,y)-1/(A_width*A_height)*
-//                                   sum(l=0,A_height-1) sum(k=0,A_width-1)A(k,l)
-//---------------------------------------------------------------------------------------
-//             CV_TM_CCOEFF_NORMED:
-//                   res5(i,j)=res4(i,j)/[l2_norm(I'ij)*l2_norm(T')]
-//---------------------------------------------------------------------------------------
-//    Returns:
-//F*/
-/* method for comparing two images */
-typedef enum CvTemplMatchMethod
-{
-    CV_TM_SQDIFF        = 0,
-    CV_TM_SQDIFF_NORMED = 1,
-    CV_TM_CCORR         = 2,
-    CV_TM_CCORR_NORMED  = 3,
-    CV_TM_CCOEFF        = 4,
-    CV_TM_CCOEFF_NORMED = 5
-}
-CvTemplMatchMethod;
-
-OPENCVAPI  void  cvMatchTemplate( const CvArr* array, const CvArr* templ,
-                                  CvArr* result, CvTemplMatchMethod method );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvbFastArctan
-//    Purpose:
-//      Calculates arctangent for arrays of abscissas and ordinates
-//    Context:
-//    Parameters:
-//        y - array of abscissas
-//        x - array of ordinates
-//        angle - array of results: array[i] = arctan(y[i]/x[i])
-//        len - number of elements in arrays
-//    Returns:
-//    Notes:
-//      The function takes into account signs of both argument, so it is similar
-//      to atan2, but it returns angle in degrees(from 0 to 359.999 degrees)
-//      Maximal error is ~0.1 degreee.
-//F*/
-OPENCVAPI  void  cvbFastArctan( const float* y, const float* x, float* angle, int len );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvbCartToPolar
-//    Purpose:
-//      Converts input arrays of abscissas and ordinates to polar form
-//    Context:
-//    Parameters:
-//        y - array of abscissas
-//        x - array of ordinates
-//        magnitude - array of magnitudes: mag[i] = sqrt(y[i]*y[i] + x[i]*x[i])
-//        angle - array of angles: array[i] = arctan(y[i]/x[i])
-//        len - number of elements in arrays
-//    Returns:
-//    Notes:
-//      The function calculates angle(similar to cvbFastArctan) and magnitude for
-//      every 2D vector(x[i],y[i]). Both output arguments are optional. If some
-//      output parameter is absent, corresponding part is not calculated
-//F*/
-OPENCVAPI  void  cvbCartToPolar( const float* y, const float* x,
-                                float* magnitude, float* angle, int len );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvbSqrt
-//    Purpose:
-//      Calculates square root for array of floats
-//    Context:
-//    Parameters:
-//        x - array of arguments
-//        sqrt_x - array of results
-//        len - number of elements in arrays
-//    Returns:
-//    Notes:
-//      Elements of input array must be non-negative, else the result is not defined.
-//      Maximal relative error is ~3e-7
-//F*/
-OPENCVAPI  void  cvbSqrt( const float* x, float* sqrt_x, int len );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvCheckArr
-//    Purpose:
-//      Checks array for bad elements (NaNs, Infinities or just too big
-//                                     positive or negative values)
-//    Context:
-//    Parameters:
-//      arr - input array
-//      flags - operation flags, that may be zero or combination of the following values:
-//               CV_CHECK_RANGE - the function checks that the array elements are
-//                                within [minVal,maxVal) range. By default, only NaNs
-//                                and Infinities are checked.
-//               CV_CHECK_QUIET - do not raise error if some elements is out of
-//                                range. It is not a default mode.
-//    Returns:
-//      1 if array is ok, 0 otherwise. If CV_CHECK_QUIET is not set, function
-//      raises the CV_StsOutOfRange error in the latter case.
-//F*/
-#define  CV_CHECK_RANGE    1
-#define  CV_CHECK_QUIET    2
-OPENCVAPI  int  cvCheckArr( const CvArr* arr, int flags CV_DEFAULT(0),
-                            double minVal CV_DEFAULT(0), double maxVal CV_DEFAULT(0));
-#define cvCheckArray cvCheckArr
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvbInvSqrt
-//    Purpose:
-//      Calculates inverse square root for array of floats
-//    Context:
-//    Parameters:
-//        x - array of arguments
-//        sqrt_x - array of results
-//        len - number of elements in arrays
-//    Returns:
-//    Notes:
-//      Elements of input array must be positive, else the result is not defined.
-//      Maximal relative error is ~2e-7
-//F*/
-OPENCVAPI  void  cvbInvSqrt( const float* x, float* inv_sqrt_x, int len );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvbReciprocal
-//    Purpose:
-//      Calculates inverse value(1/x) for array of floats
-//    Context:
-//    Parameters:
-//        x - array of arguments
-//        inv_x - array of results
-//        len - number of elements in arrays
-//    Returns:
-//    Notes:
-//      For zero elements result is 0.
-//      Maximal relative error is <2e-7
-//F*/
-OPENCVAPI  void  cvbReciprocal( const float* x, float* inv_x, int len );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvbFastExp
-//    Purpose:
-//      Calculates fast exponent approximation for array of floats
-//    Context:
-//    Parameters:
-//        x - array of arguments
-//        exp_x - array of results
-//        len - number of elements in arrays
-//    Returns:
-//    Notes:
-//      Overflow is not handled yet. Underflow is handled.
-//      Maximal relative error is ~7e-6
-//F*/
-OPENCVAPI  void  cvbFastExp( const float* x, double* exp_x, int len );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvbFastLog
-//    Purpose:
-//      Calculates fast logarithm approximation for array of doubles
-//    Context:
-//    Parameters:
-//        x - array of arguments
-//        log_x - array of logarithms of absolute values of arguments
-//        len - number of elements in arrays
-//    Returns:
-//    Notes:
-//      Negative values are negated before logarithm is taken.
-//      Logarithm of 0 gives large negative number(~700)
-//      Maximal relative error is ~3e-7
-//F*/
-OPENCVAPI  void  cvbFastLog( const double* x, float* log_x, int len );
-
-
-/* RNG state */
-typedef struct CvRandState
-{
-    uint64    state;    /* RNG state (the current seed and carry)*/
-    CvScalar  param[2]; /* parameters of RNG */
-}
-CvRandState;
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvRandInit
-//    Purpose:
-//      Initializes random number generator(RNG)
-//    Context:
-//    Parameters:
-//      state - pointer to initialized RNG state
-//      lower - lower bound of random values
-//      upper - upper bound of random values.
-//              Generated random numbers belong to range [lower,upper)
-//      seed  - initializing 32-bit integer for RNG
-//    Returns:
-//F*/
-OPENCVAPI  void  cvRandInit( CvRandState* state, double lower, double upper, int seed );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvRandSetRange
-//    Purpose: sets range of generated random numbers without reinitializing RNG
-//    Context:
-//    Parameters:
-//      state - pointer to state structure
-//      lower - lower bound
-//      upper - upper bound
-//      dim  - optional parameter.
-//             Index of the dimension to set the range for (0th, 1st etc.)
-//             -1 means to set the same range for all dimensions.
-//    Returns:
-//      CV_OK or error code if:
-//         state pointer is zero or
-//         lower bound greater than upper bound.
-//    Notes:
-//F*/
-OPENCVAPI  void  cvRandSetRange( CvRandState* state, double lower, double upper,
-                                 int index CV_DEFAULT(-1));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvbRand
-//    Purpose:
-//      Fills array of floats with random numbers and updates RNG state
-//    Context:
-//    Parameters:
-//      state - RNG state
-//      dst   - destination floating-point array
-//      len   - number of elements in the array.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvbRand( CvRandState* state, float* dst, int len );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvRand
-//    Purpose:
-//      Fills an array with random numbers and updates RNG state
-//    Context:
-//    Parameters:
-//      state - RNG state
-//      arr   - the destination array
-//    Returns:
-//F*/
-OPENCVAPI  void  cvRand( CvRandState* state, CvArr* arr );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//
-//    Name:    cvRandNext
-//    Purpose:
-//      Updates RNG state and returns 32-bit random number
-//    Context:
-//    Parameters:
-//      state - RNG state
-//    Returns:
-//      random number
-//F*/
-OPENCVAPI  unsigned  cvRandNext( CvRandState* state );
-
-
-/****************************************************************************************\
-*                               Motion templates                                         *
-\****************************************************************************************/
-
-/****************************************************************************************\
-*        All the motion template functions work only with single channel images.         *
-*        Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S                   *
-*        Motion history image must have depth IPL_DEPTH_32F,                             *
-*        Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S,                                   *
-*        Motion orientation image - IPL_DEPTH_32F                                        *
-*        Segmentation mask - IPL_DEPTH_32F                                               *
-*        All the angles are in degrees, all the times are in milliseconds                *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvUpdateMotionHistory
-//    Purpose: updates motion history image.
-//    Context:
-//    Parameters:
-//        silhouette  - silhouette image
-//        mhi         - motion history image
-//        timestamp   - current system time
-//        mhiDuration - maximal duration of motion track before it will be removed
-//    Returns:
-//    Notes:
-//      Motion history image is changed by the following algorithm:
-//         for every point(x,y) in the mhi do
-//             if( silhouette(x,y) != 0 )
-//             {
-//                 mhi(x,y) = timestamp;
-//             }
-//             else if( mhi(x,y) < timestamp - mhi_duration )
-//             {
-//                 mhi(x,y) = 0;
-//             }
-//             // else mhi(x,y) remains unchanged
-//F*/
-OPENCVAPI  void    cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
-                                          double timestamp, double mhiDuration );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCalcMotionGradient
-//    Purpose: calculates motion gradient and mask where it is valid
-//    Context:
-//    Parameters:
-//       mhi         - motion history image
-//       mask        -(output image) indicates where <orientation> data is valid
-//       orientation -(output image) contains gradient orientation in degrees
-//       aperture_size - size of the filters for x & y derivatives
-//
-//       maxTDelta   - gradient bounds.
-//       minTDelta   _/
-//    Returns:
-//    Notes:
-//      Function handles both top-left and bottom-left origins of orientation image
-//F*/
-OPENCVAPI  void    cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
-                                         double maxTDelta, double minTDelta,
-                                         int aperture_size CV_DEFAULT(3));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCalcGlobalOrientation
-//    Purpose: calculates general motion direction in the selected region.
-//    Context:
-//    Parameters:
-//         orient       - orientation image
-//         mask         - region mask
-//         mhi          - motion history image
-//         timestamp    - the last timestamp when mhi was updated
-//         mhi_duration - maximal motion track duration.
-//    Returns:
-//      direction of selected region in degrees
-//F*/
-OPENCVAPI  double  cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
-                                            const CvArr* mhi, double curr_mhi_timestamp,
-                                            double mhi_duration );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSegmentMotion
-//    Purpose: splits motion history image into several regions that
-//             move in different directions.
-//    Context:
-//    Parameters:
-//        mhi        - motion history image
-//        seg_mask   - segmentation mask image. It is marked with different values
-//                    (1,2,3...) for every motion component
-//        storage    - where to store motion components
-//        timestamp  - the last timestamp when mhi was updated
-//        seg_thresh - threshold, which is used to split motion components(regions)
-//                     the bigger threshold, the coarse segmentation is.
-//    Returns:
-//      sequence of connected components
-//    Notes:
-//F*/
-OPENCVAPI  CvSeq*  cvSegmentMotion( CvArr* mhi, CvArr* seg_mask,
-                                    CvMemStorage* storage,
-                                    double timestamp, double seg_thresh );
-
-/****************************************************************************************\
-*                               Background Differencing                                  *
-\****************************************************************************************/
-
-OPENCVAPI  void  cvAcc( const CvArr* image, CvArr* sum,
-                        const CvArr* mask CV_DEFAULT(0) );
-
-OPENCVAPI  void  cvSquareAcc( const CvArr* image, CvArr* sqSum,
-                              const CvArr* mask CV_DEFAULT(0) );
-
-OPENCVAPI  void  cvMultiplyAcc( const CvArr* imgA, const CvArr* imgB, CvArr* acc,
-                                const CvArr* mask CV_DEFAULT(0) );
-
-OPENCVAPI  void  cvRunningAvg( const CvArr* imgY, CvArr* imgU, double alpha,
-                               const CvArr* mask CV_DEFAULT(0) );
-
-/****************************************************************************************\
-*                              Dynamic data structures                                   *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateMemStorage
-//    Purpose: creates memory storage
-//    Context:
-//    Parameters:
-//         block_size - size of memory storage blocks.
-//                      If 0, default size( Currently 64K) is set
-//    Returns:
-//      memory storage
-//F*/
-OPENCVAPI  CvMemStorage*  cvCreateMemStorage( int block_size CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateChildMemStorage
-//    Purpose: creates child memory storage
-//            (storage that borrows memory blocks from parent)
-//    Context:
-//    Parameters:
-//         parent - parent memory storage
-//    Returns:
-//      memory storage
-//F*/
-OPENCVAPI  CvMemStorage*  cvCreateChildMemStorage( CvMemStorage* parent );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvReleaseMemStorage
-//    Purpose: releases memory storage.
-//    Context:
-//    Parameters:
-//         storage - double pointer to memory storage
-//    Returns:
-//    Notes:
-//      if memory storage is simple, all its blocks are released,
-//      else(memory storage is child) all its blocks are returned to parent
-//F*/
-OPENCVAPI  void  cvReleaseMemStorage( CvMemStorage** storage );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvClearMemStorage
-//    Purpose: clears memory storage.
-//    Context:
-//    Parameters:
-//         storage - memory storage
-//    Returns:
-//    Notes:
-//      if memory storage is is child, all its blocks are returned to parent,
-//      else the top of the storage is reset
-//F*/
-OPENCVAPI  void  cvClearMemStorage( CvMemStorage* storage );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSaveMemStoragePos
-//    Purpose: saves current top of the storage.
-//    Context:
-//    Parameters:
-//         storage - memory storage
-//         pos - position structure
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvSaveMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvRestoreMemStoragePos
-//    Purpose: restores top of the storage.
-//    Context:
-//    Parameters:
-//         storage - memory storage
-//         pos - position structure that was filled with cvSaveMemStoragePos
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateSeq
-//    Purpose: creates sequence, located on the storage
-//    Context:
-//    Parameters:
-//         seq_flags - flags of created sequence
-//         header_size - size of sequence header. Must be non-less than sizeof(CvSeq)
-//         elem_size - size of sequence elements
-//         storage - memory storage
-//    Returns:
-//      created sequence
-//    Notes:
-//F*/
-OPENCVAPI  CvSeq*  cvCreateSeq( int seq_flags, int header_size,
-                             int elem_size, CvMemStorage* storage );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSetSeqBlockSize
-//    Purpose: adjusts granularity of memory allocation for sequence
-//    Context:
-//    Parameters:
-//         seq - sequence pointer
-//         delta_elements - how many elements to allocate when there is no free space
-//                          in the sequence.
-//    Returns:
-//    Notes:
-//      If this function is not called after sequence is created,
-//      delta_elements is set to ~1K/elem_size
-//F*/
-OPENCVAPI  void  cvSetSeqBlockSize( CvSeq* seq, int delta_elements );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqPush
-//    Purpose: adds element in the end of sequence
-//    Context:
-//    Parameters:
-//         seq - sequence pointer
-//         element - added element
-//    Returns:
-//F*/
-OPENCVAPI  char*  cvSeqPush( CvSeq* seq, void* element CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqPushFront
-//    Purpose: adds element in the beginning of sequence
-//    Context:
-//    Parameters:
-//         seq     - sequence pointer
-//         element - added element
-//    Returns:
-//F*/
-OPENCVAPI  char*  cvSeqPushFront( CvSeq* seq, void* element CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqPop
-//    Purpose: removes element from the end of sequence
-//    Context:
-//    Parameters:
-//         seq     - sequence pointer
-//         element - optional parameter. If pointer is not NULL,
-//                   removed element is copied there.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvSeqPop( CvSeq* seq, void* element );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqPopFront
-//    Purpose: removes element from the beginning of sequence
-//    Context:
-//    Parameters:
-//         seq     - sequence pointer
-//         element - optional parameter. If pointer is not NULL,
-//                   removed element is copied there.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvSeqPopFront( CvSeq* seq, void* element );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqPushMulti
-//    Purpose: adds several elements in the end of sequence
-//    Context:
-//    Parameters:
-//         seq      - sequence pointer
-//         count    - number of added elements
-//         elements - array of added elements.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvSeqPushMulti( CvSeq* seq, void* elements, int count );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqPopMulti
-//    Purpose: removes several elements from the end of sequence
-//    Context:
-//    Parameters:
-//         seq      - sequence pointer
-//         count    - number of removed elements
-//         elements - optional parameter. If not NULL, removed elements are copied there
-//    Returns:
-//F*/
-OPENCVAPI  void  cvSeqPopMulti( CvSeq* seq, void* elements, int count );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqInsert
-//    Purpose: inserts element in the middle of the sequence
-//    Context:
-//    Parameters:
-//         sequence     - sequence pointer
-//         before_index - index of element, before which the element is inserted
-//         element      - inserted element
-//    Returns:
-//F*/
-OPENCVAPI  char*  cvSeqInsert( CvSeq* seq, int before_index,
-                               void* element CV_DEFAULT(0));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqRemove
-//    Purpose: removes element from the middle of the sequence
-//    Context:
-//    Parameters:
-//         seq      - sequence pointer
-//         index    - index of removed element
-//    Returns:
-//F*/
-OPENCVAPI  void  cvSeqRemove( CvSeq* seq, int index );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvClearSeq
-//    Purpose: clears sequence(removes all sequence elements)
-//    Context:
-//    Parameters:
-//         seq - sequence pointer
-//    Returns:
-//F*/
-OPENCVAPI  void  cvClearSeq( CvSeq* seq );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetSeqElem
-//    Purpose: finds sequence element by its index
-//    Context:
-//    Parameters:
-//         seq - sequence pointer
-//         index - element index
-//         block - optional output parameter. Sequence block, containing found element
-//    Returns:
-//         pointer to found element or NULL.
-//    Notes:
-//         index == -1 means last sequence element, -2 - prelast element etc.
-//F*/
-OPENCVAPI  char*  cvGetSeqElem( CvSeq* seq, int index, CvSeqBlock** block CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSeqElemIdx
-//    Purpose: calculates element index from its address
-//    Context:
-//    Parameters:
-//         seq - sequence pointer
-//         element - sequence element
-//         block - optional output parameter. Sequence block, containing found element.
-//    Returns:
-//         index of sequence element
-//F*/
-OPENCVAPI int  cvSeqElemIdx( CvSeq* seq, void* element, CvSeqBlock** block CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvStartAppendToSeq
-//    Purpose: initializes writer state for further writing to sequence
-//    Context:
-//    Parameters:
-//         seq - sequence pointer
-//         writer - pointer to initialized writer state
-//    Returns:
-//F*/
-OPENCVAPI  void  cvStartAppendToSeq( CvSeq* seq, CvSeqWriter* writer );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvStartWriteSeq
-//    Purpose: creates new sequence and initializes writer for it
-//    Context:
-//    Parameters:
-//         seq_flags - flags of created sequence
-//         header_size - size of sequence header. Must be non-less than sizeof(CvSeq)
-//         elem_size - size of sequence elements
-//         storage - memory storage, where the sequence will be located
-//         writer - pointer to initialized writer state
-//    Returns:
-//F*/
-OPENCVAPI  void  cvStartWriteSeq( int seq_flags, int header_size,
-                               int elem_size, CvMemStorage* storage,
-                               CvSeqWriter* writer );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvEndWriteSeq
-//    Purpose: ends writing process and closes writer
-//    Context:
-//    Parameters:
-//         writer - writer state
-//    Returns:
-//         written sequence
-//F*/
-OPENCVAPI  CvSeq*  cvEndWriteSeq( CvSeqWriter* writer );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvFlushSeqWriter
-//    Purpose: updates sequence headers, but don't close writer
-//    Context:
-//    Parameters:
-//         writer - writer state
-//    Returns:
-//F*/
-OPENCVAPI  void   cvFlushSeqWriter( CvSeqWriter* writer );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvStartReadSeq
-//    Purpose: initializes sequence reader
-//    Context:
-//    Parameters:
-//         seq - sequence pointer
-//         reader - pointer to initialized reader state
-//         reverse - if not 0, function moves read position to the end of sequence
-//    Returns:
-//F*/
-OPENCVAPI void cvStartReadSeq( CvSeq* seq, CvSeqReader* reader, int reverse CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetSeqReaderPos
-//    Purpose: returns read position
-//    Context:
-//    Parameters:
-//         reader - reader state
-//    Returns:
-//         read position
-//F*/
-OPENCVAPI  int    cvGetSeqReaderPos( CvSeqReader* reader );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSetSeqReaderPos
-//    Purpose: moves read position
-//    Context:
-//    Parameters:
-//         index  - new read position
-//         is_relative - if not 0, index is offset from current position
-//                      (else it is absolute position). Position is changed cyclically
-//         reader - reader state
-//    Returns:
-//F*/
-OPENCVAPI  void   cvSetSeqReaderPos( CvSeqReader* reader, int index,
-                                  int is_relative CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCvtSeqToArray
-//    Purpose: copies sequence to array
-//    Context:
-//    Parameters:
-//         seq - source sequence
-//         array - destination array. Must have capacity at least
-//                 seq->total*seq->elem_siz bytes
-//    Returns:
-//         pointer to array.
-//F*/
-OPENCVAPI  void*  cvCvtSeqToArray( CvSeq* seq, CvArr* array,
-                                   CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvMakeSeqHeaderForArray
-//    Purpose: wraps array with sequence(without copying data)
-//    Context:
-//    Parameters:
-//         seq_flags - flags of sequence
-//         header_size - size of sequence header. Must be non-less than sizeof(CvSeq)
-//         elem_size - size of sequence elements
-//         array - source array.
-//         total - total number of elements in array
-//         seq   - pointer to local structure CvSeq
-//         block - pointer to local structure CvSeqBlock
-//    Returns:
-//F*/
-OPENCVAPI  void  cvMakeSeqHeaderForArray( int seq_type, int header_size,
-                                          int elem_size, CvArr* array, int total,
-                                          CvSeq* seq, CvSeqBlock* block );
-
-/************ Internal sequence functions ************/
-OPENCVAPI  void  cvChangeSeqBlock( CvSeqReader* reader, int direction );
-OPENCVAPI  void  cvCreateSeqBlock( CvSeqWriter* writer );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateSet
-//    Purpose: creates new set
-//    Context:
-//    Parameters:
-//         set_flags - flags of set
-//         header_size - size of set header. Must be non-less than sizeof(CvSet)
-//         elem_size - size of set elements.
-//                     Must be non-less than 8 bytes, divisible by 4.
-//                     Least significant bit of first 4-byte field of set elements must
-//                     be zero.
-//         storage   - memory storage, where the set will be located
-//    Returns:
-//         created set
-//F*/
-OPENCVAPI  CvSet*   cvCreateSet( int set_flags, int header_size,
-                              int elem_size, CvMemStorage* storage );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSetAdd
-//    Purpose: adds new element to the set
-//    Context:
-//    Parameters:
-//         set - set
-//         element - optional input parameter. If non NULL, it is copied to inserted
-//                   element(starting from second 4-byte field)
-//         inserted_element - optional output parameter. If non NULL, address of inserted
-//                   element is stored there
-//    Returns:
-//         index of added element
-//F*/
-OPENCVAPI  int   cvSetAdd( CvSet* set_struct, CvSetElem* element CV_DEFAULT(0),
-                           CvSetElem** inserted_element CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSetRemove
-//    Purpose: removes element from the set
-//    Context:
-//    Parameters:
-//         set - set
-//         index - index of removed element
-//    Returns:
-//F*/
-OPENCVAPI  void   cvSetRemove( CvSet* set_struct, int index );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetSetElem
-//    Purpose: finds set element by its index
-//    Context:
-//    Parameters:
-//         set - set
-//         index - element index
-//    Returns:
-//         pointer to element or 0 if index is out of range or element at this index
-//         isn't in the set
-//F*/
-OPENCVAPI  CvSetElem*  cvGetSetElem( CvSet* set_struct, int index );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvClearSet
-//    Purpose: clear set(removes all elements from the set)
-//    Context:
-//    Parameters:
-//         set - set
-//    Returns:
-//F*/
-OPENCVAPI  void   cvClearSet( CvSet* set_struct );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateGraph
-//    Purpose: creates graph
-//    Context:
-//    Parameters:
-//         graph_flags - flags of created graph. CV_SEQ_KIND_GRAPH must be set,
-//                       CV_GRAPH_FLAG_ORIENTED(if set) means oriented graph.
-//         header_size - size of graph header. Must be non-less than sizeof(CvGraph)
-//         vtx_size - size of graph vertices. Must be GREATER than sizeof(CvGraphVtx).
-//                   (for example, sizeof(CvGraphVtx2D) can be used
-//                     for simple graphs on the plane)
-//         edge_size - size of graph edges. Must be non-less than sizeof(CvGraphEdge)
-//         storage   - memory storage, where the graph will be located
-//    Returns:
-//         created graph
-//F*/
-OPENCVAPI  CvGraph*   cvCreateGraph( int graph_flags, int header_size,
-                                  int vtx_size, int edge_size,
-                                  CvMemStorage* storage );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGraphAddVtx
-//    Purpose: adds vertex to graph
-//    Context:
-//    Parameters:
-//         graph - graph
-//         vertex - optional input parameter. If pointer to vertex is not NULL,
-//                  it is copied to inserted vertex
-//                 (first sizeof(CvGraphVtx) bytes aren't copied)
-//         inserted_vertex - optional output parameter. If not NULL, pointer to inserted
-//                  vertex is stored there
-//    Returns:
-//         index of inserted vertex
-//F*/
-OPENCVAPI  int   cvGraphAddVtx( CvGraph* graph, CvGraphVtx* vertex CV_DEFAULT(0),
-                                CvGraphVtx** inserted_vertex CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGraphRemoveVtx, cvGraphRemoveVtxByPtr
-//    Purpose: removes vertex from the graph
-//    Context:
-//    Parameters:
-//         graph - graph
-//         index - index of removed vertex
-//         vtx - pointer to removed vertex
-//    Returns:
-//    Notes:
-//      Vertex is removed with all the incident edges
-//F*/
-OPENCVAPI  void   cvGraphRemoveVtx( CvGraph* graph, int index );
-OPENCVAPI  void   cvGraphRemoveVtxByPtr( CvGraph* graph, CvGraphVtx* vtx );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGraphAddEdge, cvGraphAddEdgeByPtr
-//    Purpose: add edge to graph
-//    Context:
-//    Parameters:
-//         graph - graph
-//         start_idx, end_idx - indices of starting and ending vertices
-//         start_vtx, end_vtx - pointers to starting and ending vertices
-//         edge - optional input parameter. If not NULL, the edge is copied to
-//                inserted edge(first sizeof(CvGraphEdge) bytes aren't copied
-//         inserted_edge - optional output parameter. Points to inserted edge.
-//    Returns:
-//    ... 1 if the edge is inserted, 0 if the vertices were connected already,
-//    -1 if a critical error occured (normally, an error message box appears in this case)
-//    Notes:
-//       starting vertex must differ from ending one.
-//F*/
-OPENCVAPI  int  cvGraphAddEdge( CvGraph* graph,
-                                int start_idx, int end_idx,
-                                CvGraphEdge* edge CV_DEFAULT(0),
-                                CvGraphEdge** inserted_edge CV_DEFAULT(0) );
-
-OPENCVAPI  int  cvGraphAddEdgeByPtr( CvGraph* graph,
-                               CvGraphVtx* start_vtx, CvGraphVtx* end_vtx,
-                               CvGraphEdge* edge CV_DEFAULT(0),
-                               CvGraphEdge** inserted_edge CV_DEFAULT(0) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGraphRemoveEdge, cvGraphRemoveEdgeByPtr
-//    Purpose: removes edge to graph
-//    Context:
-//    Parameters:
-//         graph - graph
-//         start_idx, end_idx - indices of starting and ending vertices
-//         start_vtx, end_vtx - pointers to starting and ending vertices
-//    Returns:
-//F*/
-OPENCVAPI  void   cvGraphRemoveEdge( CvGraph* graph, int start_idx, int end_idx );
-OPENCVAPI  void   cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx,
-                                          CvGraphVtx* end_vtx );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvFindGraphEdge, cvFindGraphEdgeByPtr
-//    Purpose: finds edge, connecting two vertices. If graph is orientation, order
-//             of input vertices is taken into account
-//    Context:
-//    Parameters:
-//         graph - graph
-//         start_idx, end_idx - indices of starting and ending vertices
-//         start_vtx, end_vtx - pointers to starting and ending vertices
-//    Returns:
-//F*/
-OPENCVAPI  CvGraphEdge*  cvFindGraphEdge( CvGraph* graph, int start_idx, int end_idx );
-OPENCVAPI  CvGraphEdge*  cvFindGraphEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx,
-                                               CvGraphVtx* end_vtx );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvClearGraph
-//    Purpose: clear graph(removes all the edges and vertices from the graph)
-//    Context:
-//    Parameters:
-//         graph - graph
-//    Returns:
-//F*/
-OPENCVAPI  void  cvClearGraph( CvGraph* graph );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGraphVtxDegree, cvGraphVtxDegreeByPtr
-//    Purpose: counts edges, incident to given vertex
-//    Context:
-//    Parameters:
-//         graph - graph
-//         vtx_idx - vertex index
-//         vtx - pointer to vertex
-//    Returns:
-//      number of incident edges
-//F*/
-OPENCVAPI  int  cvGraphVtxDegree( CvGraph* graph, int vtx_idx );
-OPENCVAPI  int  cvGraphVtxDegreeByPtr( CvGraph* graph, CvGraphVtx* vtx );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGetGraphVtx
-//    Purpose: finds graph vertex by its index
-//    Context:
-//    Parameters:
-//         graph - graph
-//         idx - vertex index
-//    Returns:
-//      pointer to vertex
-//F*/
-#define cvGetGraphVtx( graph, idx ) (CvGraphVtx*)cvGetSetElem((CvSet*)(graph), (idx))
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGraphVtxIdx
-//    Purpose: calculates index of the graph vertex
-//    Context:
-//    Parameters:
-//         graph - graph
-//         vtx - pointer to vertex
-//    Returns:
-//      vertex index
-//F*/
-#define cvGraphVtxIdx( graph, vtx ) cvSeqElemIdx((CvSeq*)(graph),(vtx),0)
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGraphEdgeIdx
-//    Purpose: calculates index of the graph edge
-//    Context:
-//    Parameters:
-//         graph - graph
-//         edge - pointer to graph edge
-//    Returns:
-//      edge index
-//F*/
-#define cvGraphEdgeIdx( graph, edge ) cvSeqElemIdx((CvSeq*)((graph)->edges),(edge),0)
-
-
-/****************************************************************************************\
-*                              Planar subdivisions                                       *
-\****************************************************************************************/
-
-/************ Data structures and related enumerations ************/
-
-typedef long CvSubdiv2DEdge;
-
-#define CV_QUADEDGE2D_FIELDS()     \
-    struct CvSubdiv2DPoint* pt[4]; \
-    CvSubdiv2DEdge  next[4];
-
-#define CV_SUBDIV2D_VIRTUAL_POINT  2
-
-#define CV_SUBDIV2D_POINT_FIELDS()\
-    int            is_virtual; \
-    CvSubdiv2DEdge first;      \
-    CvPoint2D32f   pt;
-
-typedef struct CvQuadEdge2D
-{
-    CV_QUADEDGE2D_FIELDS()
-}
-CvQuadEdge2D;
-
-typedef struct CvSubdiv2DPoint
-{
-    CV_SUBDIV2D_POINT_FIELDS()
-}
-CvSubdiv2DPoint;
-
-#define CV_SUBDIV2D_FIELDS()    \
-    CV_GRAPH_FIELDS()           \
-    int  quad_edges;            \
-    int  is_geometry_valid;     \
-    CvSubdiv2DEdge recent_edge; \
-    CvPoint2D32f  topleft;      \
-    CvPoint2D32f  bottomright;
-    
-typedef struct CvSubdiv2D
-{
-    CV_SUBDIV2D_FIELDS()
-}
-CvSubdiv2D;
-
-
-typedef enum CvSubdiv2DPointLocation
-{
-    CV_PTLOC_ERROR = -2,
-    CV_PTLOC_OUTSIDE_RECT = -1,
-    CV_PTLOC_INSIDE = 0,
-    CV_PTLOC_VERTEX = 1,
-    CV_PTLOC_ON_EDGE = 2
-}
-CvSubdiv2DPointLocation;
-
-typedef enum CvNextEdgeType
-{
-    CV_NEXT_AROUND_ORG   = 0x00,
-    CV_NEXT_AROUND_DST   = 0x22,
-    CV_PREV_AROUND_ORG   = 0x11,
-    CV_PREV_AROUND_DST   = 0x33,
-    CV_NEXT_AROUND_LEFT  = 0x13,
-    CV_NEXT_AROUND_RIGHT = 0x31,
-    CV_PREV_AROUND_LEFT  = 0x20,
-    CV_PREV_AROUND_RIGHT = 0x02
-}
-CvNextEdgeType;
-
-#define  CV_SUBDIV2D_NEXT_EDGE( edge )  (((CvQuadEdge2D*)((edge) & ~3))->next[(edge)&3])
-
-/************ Basic quad-edge navigation and operations ************/
-
-CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DNextEdge( CvSubdiv2DEdge edge );
-CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DNextEdge( CvSubdiv2DEdge edge )
-{
-    return  CV_SUBDIV2D_NEXT_EDGE(edge);
-}
-
-
-CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate );
-CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate )
-{
-    return  (edge & ~3) + ((edge + rotate) & 3);
-}
-
-CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DSymEdge( CvSubdiv2DEdge edge );
-CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DSymEdge( CvSubdiv2DEdge edge )
-{
-    return edge ^ 2;
-}
-
-CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type );
-CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type )
-{
-    CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
-    edge = e->next[(edge + (int)type) & 3];
-    return  (edge & ~3) + ((edge + ((int)type >> 4)) & 3);
-}
-
-
-CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge );
-CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge )
-{
-    CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
-    return e->pt[edge & 3];
-}
-
-
-CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge );
-CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge )
-{
-    CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
-    return e->pt[(edge + 2) & 3];
-}
-
-
-CV_INLINE  double  cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c );
-CV_INLINE  double  cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c )
-{
-    return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
-}
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCreateSubdiv2D
-//    Purpose: creates initially empty planar subdivision structure
-//    Context:
-//    Parameters:
-//      subdiv_type - type of subdivision
-//      header_size - size of header(>= sizeof(CvSubdiv2D))
-//      quadedge_size - size of quad-edges(>= sizeof(CvQuadEdge2D))
-//      vtx_size - size of vertices(>= sizeof(CvSubdiv2DPoint))
-//      storage  - size of memory storage
-//    Returns:
-//      created subdivision
-//F*/
-OPENCVAPI  CvSubdiv2D*  cvCreateSubdiv2D( int subdiv_type, int header_size,
-                                       int vtx_size, int quadedge_size,
-                                       CvMemStorage* storage );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdiv2DMakeEdge
-//    Purpose: creates new isolated quad-edge
-//    Context:
-//    Parameters:
-//      subdiv - subdivision - owner of the quadedge
-//    Returns:
-//      first edge of quad-edge.
-//F*/
-OPENCVAPI  CvSubdiv2DEdge  cvSubdiv2DMakeEdge( CvSubdiv2D* subdiv );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdiv2DAddPoint
-//    Purpose:  basic topological operation: breaks or combines edge rings
-//    Context:
-//    Parameters:
-//      edgeA - first edge
-//      edgeB - second edge
-//F*/
-OPENCVAPI  CvSubdiv2DPoint*   cvSubdiv2DAddPoint( CvSubdiv2D* subdiv,
-                                                  CvPoint2D32f pt, int is_virtual );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdiv2DSplice
-//    Purpose:  basic topological operation: breaks or combines edge rings
-//    Context:
-//    Parameters:
-//      edgeA - first edge
-//      edgeB - second edge
-//F*/
-OPENCVAPI  void  cvSubdiv2DSplice( CvSubdiv2DEdge  edgeA,  CvSubdiv2DEdge  edgeB );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdiv2DSetEdgePoints
-//    Purpose:  assigns edge origin and desination points
-//    Context:
-//    Parameters:
-//      edge - edge
-//      org_pt - point to origin vertex
-//      dst_pt - point to destination vertex
-//F*/
-OPENCVAPI  void  cvSubdiv2DSetEdgePoints( CvSubdiv2DEdge edge,
-                                          CvSubdiv2DPoint* org_pt,
-                                          CvSubdiv2DPoint* dst_pt );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdiv2DDeleteEdge
-//    Purpose:  deletes edge from subdivision.
-//    Context:
-//    Parameters:
-//      subdiv - subdivison
-//      edge - deleted edge
-//F*/
-OPENCVAPI  void  cvSubdiv2DDeleteEdge( CvSubdiv2D* subdiv, CvSubdiv2DEdge edge );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdiv2DConnectEdges
-//    Purpose:  connect destination point of the first edge with
-//              origin point of the second edge
-//    Context:
-//    Parameters:
-//      subdiv - subdivison
-//      edgeA - first edge
-//      edgeB - second edge
-//F*/
-OPENCVAPI  CvSubdiv2DEdge  cvSubdiv2DConnectEdges( CvSubdiv2D* subdiv,
-                                                   CvSubdiv2DEdge edgeA,
-                                                   CvSubdiv2DEdge edgeB );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdiv2DSwapEdges
-//    Purpose:  swap diagonal in two connected Delaunay facets
-//    Context:
-//    Parameters:
-//      subdiv - subdivison
-//      edge - sudivision edge
-//F*/
-OPENCVAPI  void  cvSubdiv2DSwapEdges( CvSubdiv2DEdge edge );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdiv2DLocate
-//    Purpose:  finds location of the point within the Delaunay triangulation
-//              origin point of the second edge
-//    Context:
-//    Parameters:
-//      subdiv - subdivison
-//      pt     - searched point
-//      _edge  - bounding edge for facet, containing the point
-//      _point - vertex(if searched point coincides with the vertex)
-//F*/
-OPENCVAPI  CvSubdiv2DPointLocation  cvSubdiv2DLocate(
-                               CvSubdiv2D* subdiv, CvPoint2D32f pt,
-                               CvSubdiv2DEdge *_edge,
-                               CvSubdiv2DPoint** _point CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvInitSubdivDelaunay2D
-//    Purpose:  connect destination point of the first edge with
-//              origin point of the second edge
-//    Context:
-//    Parameters:
-//      subdiv - subdivison
-//      pt     - searched point
-//      _edge  - bounding edge for facet, containing the point
-//      _point - vertex(if searched point coincides with the vertex)
-//F*/
-OPENCVAPI  void  cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubdivDelaunay2DInsert
-//    Purpose:  insert the point into the triangulation
-//    Context:
-//    Parameters:
-//      subdiv - subdivison
-//      pt     - inserted point
-//F*/
-OPENCVAPI  CvSubdiv2DPoint*  cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt);
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCalcSubdivVoronoi2D
-//    Purpose:  calculates Voronoi tesselation( Coordinates of Voronoi points)
-//    Context:
-//    Parameters:
-//      subdiv - subdivison
-//    Note:
-//      Before calculations the function checks the flag, indicating that
-//      the Voronoi tesselation is already calculated.
-//      If subdivision is modified(some points have been inserted), the flag is cleared.
-//F*/
-OPENCVAPI  void  cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvClearSubdivVoronoi2D
-//    Purpose:  removes all Voronoi points from the tesselation.
-//    Context:
-//    Parameters:
-//      subdiv - subdivison
-//    Note:
-//      The function is called implicitly from the cvCalcSubdivVoronoi2D
-//      before Voronoi tesselation is calculated.
-//F*/
-OPENCVAPI  void  cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv );
-
-
-/****************************************************************************************\
-*                              Contours procceding                                       *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvFindContours
-//    Purpose: finds contours on the binary image
-//    Context:
-//    Parameters:
-//         img - binary image(depth is IPL_DEPTH_8U or IPL_DEPTH_8S, single channel).
-//         storage - memory storage where the contours will be stored
-//         firstContour - output parameter. First contour on the highest level.
-//         headerSize - size of contours headers.
-//         mode - contour retrieving mode.
-//                  CV_RETR_EXTERNAL - get only the most external contours(list).
-//                  CV_RETR_LIST     - get all the contours without any hierarchical links
-//                                    (list).
-//                  CV_RETR_CCOMP    - get all the contours and make holes as child
-//                                     contours of corresponding external contour
-//                                    (two-level hierarchical structure)
-//                  CV_RETR_TREE     - get all the contours and build all
-//                                     hierarchical links(tree).
-//         method - approximation method
-//                CV_CHAIN_CODE    - output contours in chain-coded form(Freeman code).
-//                              The rest of methods approximate chain code with polyline
-//                CV_CHAIN_APPROX_NONE - no compression. Every point of digital curve
-//                                       is coded
-//                CV_CHAIN_APPROX_SIMPLE - horizontal, vertical and diagonal segments are
-//                                         are coded with ending vertices (by default).
-//                CV_CHAIN_APPROX_TC89_L1 - Teh-Chin algorithm, L1 curvature
-//                CV_CHAIN_APPROX_TC89_KCOS - Teh-Chin algorithm, k-cosine curvature
-//    Returns:
-//      Number of contours found.
-//F*/
-/*
-Internal structure that is used for sequental retrieving contours from the image.
-It supports both hierarchical and plane variants of Suzuki algorithm.
-*/
-typedef struct _CvContourScanner* CvContourScanner;
-
-typedef enum CvContourRetrievalMode
-{
-    CV_RETR_EXTERNAL = 0,
-    CV_RETR_LIST     = 1,
-    CV_RETR_CCOMP    = 2,
-    CV_RETR_TREE     = 3
-}
-CvContourRetrievalMode;
-
-typedef enum CvChainApproxMethod
-{
-    CV_CHAIN_CODE             = 0,
-    CV_CHAIN_APPROX_NONE      = 1,
-    CV_CHAIN_APPROX_SIMPLE    = 2,
-    CV_CHAIN_APPROX_TC89_L1   = 3,
-    CV_CHAIN_APPROX_TC89_KCOS = 4
-} CvChainApproxMethod;
-
-OPENCVAPI  int  cvFindContours( CvArr* array, CvMemStorage* storage,
-                           CvSeq**  firstContour,
-                           int  headerSize CV_DEFAULT(sizeof(CvContour)),
-                           CvContourRetrievalMode mode CV_DEFAULT( CV_RETR_LIST ),
-                           CvChainApproxMethod method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvStartFindContours
-//    Purpose: starts iterrative process of contours retrieving
-//    Context:
-//    Parameters:
-//         img - binary image(depth is IPL_DEPTH_8U or IPL_DEPTH_8S, single channel).
-//         storage - memory storage where the contours will be stored
-//         header_size - size of contours headers.
-//         mode - contour retrieving mode(see cvFindContours description)
-//         method - approximation method(see cvFindContours description)
-//    Returns:
-//      contour scanner state.
-//F*/
-OPENCVAPI  CvContourScanner   cvStartFindContours( CvArr* array, CvMemStorage* storage,
-                                        int header_size, CvContourRetrievalMode mode,
-                                        CvChainApproxMethod method );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvFindNextContour
-//    Purpose: finds next contour on the image
-//    Context:
-//    Parameters:
-//         scanner - contour scanner state
-//    Returns:
-//      next contour or NULL, if no more contours on the image
-//F*/
-OPENCVAPI  CvSeq*  cvFindNextContour( CvContourScanner scanner );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvSubstituteContour
-//    Purpose: substitutes retrived contour with another one.
-//    Context:
-//    Parameters:
-//         scanner - contour scanner state
-//         newContour - substituting contour
-//                      (or NULL, if retrived contour should be rejected)
-//    Returns:
-//    Notes:
-//      The function may be called immediately after contour is retrived
-//     (may be, after some processing) before cvFindNextContour is called next time.
-//      It replaces found contour with processed contour, or even rejects it.
-//F*/
-OPENCVAPI  void   cvSubstituteContour( CvContourScanner scanner, CvSeq* newContour );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvEndFindContours
-//    Purpose: finishes process of contours retrieving
-//    Context:
-//    Parameters:
-//         scanner - contour scanner state
-//    Returns:
-//      pointer to first contour on the highest hierarchical level
-//F*/
-OPENCVAPI  CvSeq*  cvEndFindContours( CvContourScanner* scanner );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvApproxChains
-//    Purpose: approximates single(all) chains with polylines.
-//    Context:
-//    Parameters:
-//         src_seq - pointer to chain(which can reffer to other chains).
-//         storage - where to place resultant polylines.
-//         dst_seq - double pointer to first resultant polyline.
-//         method  - approximation method(see cvFindContours description)
-//         parameter - method parameter(is not used now).
-//         minimal_perimeter - approximates only those contours which perimeter is
-//                             not less than <minimal_perimeter>. Other chains
-//                             are removed from resultant structure
-//         recursive - if not 0, approximate all the chains, which can be accessed
-//                     from src_seq. if 0, approximate a single chain
-//    Returns:
-//F*/
-OPENCVAPI  CvSeq* cvApproxChains( CvSeq* src_seq, CvMemStorage* storage,
-                            CvChainApproxMethod method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
-                            double parameter CV_DEFAULT(0),
-                            int  minimal_perimeter CV_DEFAULT(0),
-                            int  recursive CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvStartReadChainPoints
-//    Purpose: starts read successive points of the chain-coded curve
-//    Context:
-//    Parameters:
-//         chain   - chain
-//         reader  - chain reader state
-//    Returns:
-//F*/
-typedef struct CvChainPtReader
-{
-    CV_SEQ_READER_FIELDS()
-    char      code;
-    CvPoint  pt;
-    char      deltas[8][2];
-    int       reserved[2];
-} CvChainPtReader;
-
-OPENCVAPI  void  cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvReadChainPoint
-//    Purpose: read current point of the chain and moves read position to the next code
-//    Context:
-//    Parameters:
-//         reader - chain reader state
-//    Returns:
-//         current point of the chain
-//F*/
-OPENCVAPI  CvPoint   cvReadChainPoint( CvChainPtReader* reader );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvApproxPoly
-//    Purpose: approximates polygonal curve (either closed or not)
-//             with another polygonal curve with desired accuracy
-//    Context:
-//    Parameters:
-//         src_seq - source contour
-//         header_size - size of destination contour header
-//         storage - memory storage for result
-//         dst_seq - destination contour
-//         method  - approximation method. Only a single method is implemented now.
-//                   CV_POLY_APPROX_DP - Douglas-Peucker method.
-//         parameter - depends on method. For CV_POLY_APPROX_DP it is a desired accuracy.
-//         recursive - if not 0, the function approximates all the contours that
-//                     are next to or below the initial contour, otherwise the single
-//                     contour is approximated
-//    Returns:
-//F*/
-typedef enum CvPolyApproxMethod
-{
-    CV_POLY_APPROX_DP = 0
-}
-CvPolyApproxMethod;
-
-OPENCVAPI  CvSeq*  cvApproxPoly( CvSeq* src_seq, int  header_size, CvMemStorage* storage,
-                                 CvPolyApproxMethod  method, double parameter,
-                                 int recursive CV_DEFAULT(0));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvContourPerimeter
-//    Purpose:
-//      Calculates contour perimeter, finds minimal edge and maximal egde lengths
-//    Context:
-//    Parameters:
-//      contour  - source contour
-//      slice    - optional parameter. ending and starting indices of contour section  
-//    Returns:
-//      contour section perimeter
-//      when a part of contour is selected, the function doesn't add
-//      length of chord, connecting starting and ending points
-//F*/
-OPENCVAPI  double  cvContourPerimeter( CvSeq* contour,
-                                       CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvContourBoundingRect
-//    Purpose:
-//      calculates contour bounding rebox
-//    Context:
-//    Parameters:
-//      contour  - pointer to the source contour
-//      update   - attribute of contour bounding box updating
-//                 (if update = 0 the bounding box isn't updated)
-//    Returns:
-//      bounding rectangle
-//F*/
-OPENCVAPI  CvRect  cvContourBoundingRect( CvSeq* contour, int update CV_DEFAULT(0) );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvContourMoments
-//    Purpose:
-//      Calculates spatial and central moments of the contour up to order 3
-//    Context:
-//    Parameters:
-//      contour - the source contour
-//      moments - output parameter. Pointer to the calculated moments
-//
-//F*/
-OPENCVAPI  void  cvContourMoments( CvSeq* contour, CvMoments* moments);
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvContourArea
-//    Purpose:
-//      Calculates area within the contour
-//    Context:
-//    Parameters:
-//      contour - pointer to input contour object.
-//      slice  - optional parameter. ending and starting indices of contour section  
-//    Returns:
-//      Contour section area
-//F*/
-OPENCVAPI  double  cvContourArea( CvSeq* contour,
-                               CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvMatchContours
-//    Purpose:
-//      Compares two contours
-//    Context:
-//    Parameters:
-//      contour1 - pointer to the first input contour object.
-//      contour2 - pointer to the second input contour object.
-//      method - method for the matching calculation
-//     (now CV_CONTOURS_MATCH_I1, CV_CONTOURS_MATCH_I2 or
-//      CV_CONTOURS_MATCH_I3 only  )
-//      parameter - method-specific parameter (is used now)
-//    Returns:
-//      Comparison result
-//F*/
-typedef enum CvContoursMatchMethod
-{
-    CV_CONTOURS_MATCH_I1 = 1,
-    CV_CONTOURS_MATCH_I2 = 2,
-    CV_CONTOURS_MATCH_I3 = 3
-}
-CvContoursMatchMethod;
-
-OPENCVAPI  double  cvMatchContours( CvSeq* contour1, CvSeq* contour2,
-                                 CvContoursMatchMethod method,
-                                 long parameter CV_DEFAULT(0));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCreateContourTree
-//    Purpose:
-//      Creates binary tree representation for the contour
-//    Context:
-//    Parameters:
-//      contour - input contour
-//      storage - storage
-//      tree    - output pointer to the binary tree representation
-//      threshold - threshold for the binary tree building
-//    Returns:
-//      Binary tree
-//F*/
-typedef struct CvContourTree
-{
-    CV_SEQUENCE_FIELDS()
-    CvPoint p1;            /* the first point of the binary tree root segment */
-    CvPoint p2;            /* the last point of the binary tree root segment */
-} CvContourTree;
-
-OPENCVAPI  CvContourTree*   cvCreateContourTree( CvSeq* contour, CvMemStorage* storage,
-                                                 double threshold );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvContourFromContourTree
-//    Purpose:
-//      Reconstructs contour from binary tree representation
-//    Context:
-//    Parameters:
-//      tree   -  input binary tree representation
-//      storage - memory storage
-//      criteria - criteria for the definition threshold value
-//                 for the contour reconstruction(level or precision)
-//    Returns:
-//      Created contour
-//F*/
-OPENCVAPI  CvSeq*  cvContourFromContourTree( CvContourTree *tree,
-                                          CvMemStorage* storage,
-                                          CvTermCriteria criteria );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvMatchContourTrees
-//    Purpose:
-//      Compares two contour trees
-//    Context:
-//    Parameters:
-//      tree1 - pointer to the first input contour tree object.
-//      tree2 - pointer to the second input contour tree object.
-//      method - method for the matching calculation
-//     (now CV_CONTOUR_TREES_MATCH_I1 only  )
-//      threshold - threshold for the contour trees matching
-//    Returns:
-//      comparison result
-//F*/
-typedef enum CvContourTreesMatchMethod
-{
-    CV_CONTOUR_TREES_MATCH_I1 = 1
-}
-CvContourTreesMatchMethod;
-
-OPENCVAPI  double  cvMatchContourTrees( CvContourTree *tree1,
-                                     CvContourTree *tree2,
-                                     CvContourTreesMatchMethod method,
-                                     double threshold );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvDrawContours
-//    Purpose:
-//      Draws one or more contours outlines or their interiors on the image
-//    Context:
-//    Parameters:
-//      img      - destination three-channel image
-//      contour  - pointer to drawn contour(s).
-//      external_color - color to draw external contours with
-//      hole_color - color to draw hole contours with
-//      max_level  - max level of the tree(starting from contour pointer) to draw.
-//                   if it is 0, draw single contour, if 1 - draw the contour and
-//                   other contours at the same level, 2 - draw two levels etc.
-//      thickness - thickness of lines the contours are drawn with. If it is
-//                  equal to CV_FILLED (-1), the contour(s) interior is filled.
-//    Returns:
-//F*/
-OPENCVAPI void  cvDrawContours( void *img, CvSeq* contour,
-                                double external_color, double hole_color,
-                                int max_level, int thickness CV_DEFAULT(1),
-                                int connectivity CV_DEFAULT(8));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcPGH
-//    Purpose:
-//      Calculates PGH(pairwise geometric histogram) for given contour.
-//    Context:
-//    Parameters:
-//      contour  - input contour.
-//      pgh      - output histogram(must be two-dimensional)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvCalcPGH( CvSeq* contour, CvHistogram* hist );
-
-/****************************************************************************************\
-*                          Computational Geometry functions                              *
-\****************************************************************************************/
-
-#define CV_CLOCKWISE         1
-#define CV_COUNTER_CLOCKWISE 2
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvConvexHull
-//    Purpose:
-//      Finds convex hull of points set
-//    Context:
-//    Parameters:
-//      points       - array of points
-//      num_points   - number of input points
-//      bound_rect   - pointer to bounding rectangle(if computed), can be NULL
-//      orientation  - orientation of convex hull you want to get
-//                     can be CV_CLOCKWISE or CV_COUNTER_CLOCKWISE
-//      hull         - pointer to output array
-//      hullsize     - pointer to output value, which is number of convex hull vertices
-//
-//    Returns:
-//    Notes: Function computes convex hull and stores result in "hull" array,
-//           where every vertex of convex hull is represented by index in input array.
-//
-//F*/
-OPENCVAPI void cvConvexHull( CvPoint* points, int num_points, CvRect* bound_rect,
-                          int orientation, int* hull, int* hullsize );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvContourConvexHull
-//    Purpose:
-//      Finds convex hull of contour
-//    Context:
-//    Parameters:
-//      contour      - pointer to CvSeq structure, which elements are CvPoints
-//      orientation  - orientation of convex hull you want to get
-//                     can be CV_CLOCKWISE or CV_COUNTER_CLOCKWISE
-//      storage      - pointer to memory storage, where output sequence will be stored
-//    Returns:
-//      Convex hull
-//    Notes: Function computes convex hull and returns it.
-//           Every vertex of convex hull is represented by pointer to original point,
-//           stored in input sequence, i.e. result is CvSeq which elements
-//           have type CvPoint*
-//F*/
-OPENCVAPI CvSeq*  cvContourConvexHull( CvSeq* contour, int orientation,
-                                    CvMemStorage* storage );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvConvexHullApprox
-//    Purpose:
-//      Finds approximate convex hull of points set
-//    Context:
-//    Parameters:
-//      points       - array of points
-//      num_points   - number of input points
-//      bound_rect   - pointer to bounding rectangle(if computed), can be NULL
-//      bandwidth    - width of band, used in algorithm
-//      orientation  - orientation of convex hull you want to get
-//                     can be CV_CLOCKWISE or CV_COUNTER_CLOCKWISE
-//      hullpoints   - pointer to output array
-//      hullsize     - pointer to output value, which is number of convex hull vertices
-//
-//    Returns:
-//    Notes: Function computes approximate convex hull and stores result in "hull" array,
-//           where every vertex of convex hull is represented by index in input array.
-//           If bandwidth == 1, then exact convex hull is computed.
-//
-//F*/
-OPENCVAPI void  cvConvexHullApprox( CvPoint* points, int num_points,
-                                  CvRect* bound_rect, int bandwidth,
-                                  int orientation, int* hullpoints, int* hullsize );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvContourConvexHullApprox
-//    Purpose:
-//      Finds approximate convex hull of contour
-//    Context:
-//    Parameters:
-//      contour      - pointer to CvSeq structure, which elements are CvPoints
-//      bandwidth    - width of band, used in algorithm
-//      orientation  - orientation of convex hull you want to get
-//                     can be CV_CLOCKWISE or CV_COUNTER_CLOCKWISE
-//      storage      - pointer to memory storage, where output sequence will be stored
-//    Returns:
-//    Notes: Function computes approximate convex hull and returns it.
-//           Every vertex of convex hull is represented by pointer to original point,
-//           stored in input sequence, i.e. result is CvSeq which elements
-//           have type CvPoint*
-//F*/
-OPENCVAPI CvSeq*  cvContourConvexHullApprox( CvSeq* contour, int bandwidth,
-                                          int orientation, CvMemStorage* storage );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCheckContourConvexity
-//    Purpose:
-//      Checks if contour is convex or not
-//    Context:
-//    Parameters:
-//      contour - input contour
-//
-//    Returns: 0 - contour is not convex
-//             1 - contour is convex
-//    Notes:
-//F*/
-OPENCVAPI int  cvCheckContourConvexity( CvSeq* contour );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvConvexityDefects
-//    Purpose:
-//      Computes convexity defects of contour
-//    Context:
-//    Parameters:
-//      contour      - pointer to CvSeq structure, which elements are CvPoints
-//      convexhull   - pointer to convex hull of input contour
-//      storage      - pointer to memory storage, where output sequence will be stored
-//    Returns:
-//      sequence of convexity defects
-//      (i.e. the resultant sequence elements have type CvConvexityDefect).
-//    Notes:
-//F*/
-typedef struct CvConvexityDefect
-{
-    CvPoint* start;
-    CvPoint* end;
-    CvPoint* depth_point;
-    float depth;
-} CvConvexityDefect;
-
-OPENCVAPI CvSeq*  cvConvexityDefects( CvSeq* contour, CvSeq* convexhull,
-                                      CvMemStorage* storage );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvFitEllipse
-//    Purpose:
-//      Fits "least-square optimal" ellipse into the set of points
-//    Context:
-//    Parameters:
-//      points       - array of 2D points with float coordinates
-//      n            - number of input points
-//      box          - output structure which contents center of ellipse
-//                     full sizes of ellipse axis and angle to horisont
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI void  cvFitEllipse( CvPoint2D32f* points, int n, CvBox2D* box );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvMinAreaRect
-//    Purpose:
-//      For set of points finds enclosing rectangle which has minimal area among all such
-//      rectangles. Function uses Toussaint algorithm(rotating calipers)
-//    Context:
-//    Parameters:
-//       points - input points
-//       n      - number of points
-//       left,
-//       bottom,
-//       right,
-//       top    - indices in input array of most left, bottom, right and top points
-//       anchor - coordinates of one of corners of output rectangle
-//       vect1,
-//       vect2  - two vectors, which represents sides of rectangle which are incident
-//                to anchor
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI void  cvMinAreaRect( CvPoint* points, int n,
-                             int left, int bottom, int right, int top,
-                             CvPoint2D32f* anchor,
-                             CvPoint2D32f* vect1,
-                             CvPoint2D32f* vect2 );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvMinEnclosingCircle
-//    Purpose:
-//      Finds minimal enclosing circle for point set
-//    Context:
-//    Parameters:
-//      seq      - sequence of points
-//      center   - center of min enclosing circle
-//      radius   - radius of enclosing circle
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvMinEnclosingCircle( CvSeq* seq, CvPoint2D32f* center, float* radius );
-
-/****************************************************************************************\
-*                                  Histogram functions                                   *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCalcEMD
-//    Purpose:    Computes Earth mover distance(and/or lower bound of it) for given pair
-//                of signatures. Ground distance can calculated as
-//                L1, L2 or C distance between features' coordinate vectors or
-//                using user-defined distance function.
-//    Context:
-//    Parameters:
-//      signature1  - first signature - array of size1 *(dims + 1) elements
-//      signature2  - second signature - array of size2 *(dims + 1) elements
-//      dims        - number of dimensions in feature space. If 0, then
-//                    signature1 and signature2 are considered as simple 1D histograms,
-//                    else both signatures must look as follows:
-//                   (weight_i0, x0_i0, x1_i0, ..., x(dims-1)_i0,
-//                     weight_i1, x0_i1, x1_i1, ..., x(dims-1)_i1,
-//                     ...
-//                     weight_(size1-1),x0_(size1-1),x1_(size1-1,...,x(dims-1)_(size1-1))
-//
-//                     where weight_ik - weight of ik cluster.
-//                     x0_ik,...,x(dims-1)_ik - coordinates of ik cluster.
-//
-//      dist_type   - CV_DIST_L1, CV_DIST_L2, CV_DIST_C mean one of standard metrics.
-//                   ((CvDisType)-1) means user-defined distance function, which is
-//                    passes two coordinate vectors and user parameter, and which returns
-//                    distance between those feature points.
-//      emd         - pointer to calculated emd distance
-//      lower_bound - pointer to calculated lower bound.
-//                    if 0, this quantity is not calculated(only emd is calculated).
-//                    else if calculated lower bound is greater or equal to the value,
-//                    stored at this pointer, then the true emd is not calculated, but
-//                    is set to that lower_bound.
-//    Returns:
-//    Notes:
-//F*/
-CV_EXTERN_C_FUNCPTR( float (CV_CDECL * CvDistanceFunction)
-                     ( const float* a, const float* b, void* user_param ));
-
-OPENCVAPI  float  cvCalcEMD( const float* signature1, int size1,
-                             const float* signature2, int size2,
-                             int dims, CvDisType dist_type,
-                             CvDistanceFunction dist_func,
-                             float* lower_bound,
-                             void* user_param );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCreateHist
-//    Purpose:    Creates histogram
-//    Context:
-//    Parameters:
-//      c_dims - number of dimension in the histogram
-//      dims   - array, containing number of bins per each dimension
-//      type   - type of histogram. Now, CV_HIST_ARRAY is only supported type.
-//      ranges - array of bin ranges.
-//      uniform - flag; non 0 if histogram bins are evenly spaced.
-//    Returns:
-//      Created histogram.
-//F*/
-OPENCVAPI  CvHistogram*  cvCreateHist( int c_dims, int* dims,
-                                    CvHistType type,
-                                    float** ranges CV_DEFAULT(0),
-                                    int uniform CV_DEFAULT(1));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSetHistBinRanges
-//    Purpose:    Sets histogram bins' ranges
-//    Context:
-//    Parameters:
-//      ranges - array of bin ranges.
-//      uniform - flag; non 0 if histogram bins are evenly spaced.
-//    Returns:
-//      nothing
-//    Notes:      if uniform parameter is not NULL then thresh[i][0] - minimum value,
-//                thresh[i][1] - maximum value of thresholds for dimension i
-//F*/
-OPENCVAPI void  cvSetHistBinRanges( CvHistogram* hist, float** ranges,
-                                 int uniform CV_DEFAULT(1));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvMakeHistHeaderForArray
-//    Purpose:    Initializes histogram header and sets
-//                its data pointer to given value
-//    Context:
-//    Parameters:
-//      c_dims - number of dimension in the histogram
-//      dims   - array, containing number of bins per each dimension
-//      hist   - pointer to histogram structure. It will have CV_HIST_ARRAY type.
-//      data   - histogram data
-//    Returns:
-//F*/
-OPENCVAPI  void  cvMakeHistHeaderForArray( int  c_dims, int* dims, CvHistogram* hist,
-                                           float* data, float** ranges CV_DEFAULT(0),
-                                           int uniform CV_DEFAULT(1));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvReleaseHist
-//    Purpose:    Releases histogram header and underlying data
-//    Context:
-//    Parameters:
-//      hist - pointer to released histogram.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvReleaseHist( CvHistogram** hist );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvClearHist
-//    Purpose:    Clears histogram(sets all bins to zero)
-//    Context:
-//    Parameters:
-//      hist - pointer to cleared histogram.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvClearHist( CvHistogram* hist);
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvQueryHistValue....
-//    Purpose:    Returns value or histogram bin, given its cooridinates
-//    Context:
-//    Parameters:
-//      hist - pointer to histogram.
-//      idx0 - index for the 1st dimension
-//      idx1 - index for the 2nd dimension
-//             ...
-//      idx  - array of coordinates(for multi-dimensonal histogram)
-//    Returns:
-//      Value of histogram bin
-//    Notes:
-//      For non-array histogram function returns 0 if the specified element isn't present
-//F*/
-OPENCVAPI  float  cvQueryHistValue_1D( CvHistogram* hist, int idx0 );
-OPENCVAPI  float  cvQueryHistValue_2D( CvHistogram* hist, int idx0, int idx1 );
-OPENCVAPI  float  cvQueryHistValue_3D( CvHistogram* hist, int idx0, int idx1, int idx2 );
-OPENCVAPI  float  cvQueryHistValue_nD( CvHistogram* hist, int* idx );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvGetHistValue....
-//    Purpose:    Returns pointer to histogram bin, given its cooridinates
-//    Context:
-//    Parameters:
-//      hist - pointer to histogram.
-//      idx0 - index for the 1st dimension
-//      idx1 - index for the 2nd dimension
-//             ...
-//      idx  - array of coordinates(for multi-dimensonal histogram).
-//             must have hist->c_dims elements.
-//    Returns:
-//      Pointer to histogram bin
-//    Notes:
-//      For non-array histogram function creates a new element if it is not exists.
-//F*/
-OPENCVAPI  float*  cvGetHistValue_1D( CvHistogram* hist, int idx0 );
-OPENCVAPI  float*  cvGetHistValue_2D( CvHistogram* hist, int idx0, int idx1 );
-OPENCVAPI  float*  cvGetHistValue_3D( CvHistogram* hist, int idx0, int idx1, int idx2 );
-OPENCVAPI  float*  cvGetHistValue_nD( CvHistogram* hist, int* idx );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvGetMinMaxHistValue
-//    Purpose:    Finds coordinates and numerical values of minimum and maximum
-//                histogram bins
-//    Context:
-//    Parameters:
-//      hist - pointer to histogram.
-//      idx_min - pointer to array of coordinates for minimum.
-//                if not NULL, must have hist->c_dims elements.
-//      value_min - pointer to minimum value of histogram( Can be NULL).
-//      idx_max - pointer to array of coordinates for maximum.
-//                if not NULL, must have hist->c_dims elements.
-//      value_max - pointer to maximum value of histogram( Can be NULL).
-//    Returns:
-//F*/
-OPENCVAPI  void  cvGetMinMaxHistValue( CvHistogram* hist,
-                                    float* value_min, float* value_max,
-                                    int* idx_min CV_DEFAULT(0), 
-                                    int* idx_max CV_DEFAULT(0));
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvNormalizeHist
-//    Purpose:  Normalizes histogram(such that sum of histogram bins becomes factor)
-//    Context:
-//    Parameters:
-//      hist - pointer to normalized histogram.
-//    Returns:
-//F*/
-OPENCVAPI  void  cvNormalizeHist( CvHistogram* hist, double factor );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvThreshHist
-//    Purpose:  Clears histogram bins that are below specified level
-//    Context:
-//    Parameters:
-//      hist - pointer to histogram.
-//      thresh - threshold level
-//    Returns:
-//F*/
-OPENCVAPI  void  cvThreshHist( CvHistogram* hist, double thresh );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvCompareHist
-//    Purpose:  compares two histograms using specified method
-//    Context:
-//    Parameters:
-//      hist1 - first compared histogram.
-//      hist2 - second compared histogram.
-//      method - comparison method
-//    Returns:
-//      value, that characterizes similarity(or difference) of two histograms
-//    Notes:
-//F*/
-OPENCVAPI  double  cvCompareHist( CvHistogram*  hist1,
-                               CvHistogram*  hist2,
-                               CvCompareMethod method);
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCopyHist
-//    Purpose:    Copying one histogram to another
-//    Context:
-//    Parameters:
-//      src - source histogram
-//      dst - destination histogram
-//    Returns:
-//    Notes:      if second parameter is pointer to NULL(*dst == 0) then second
-//                histogram will be created.
-//                both histograms(if second histogram present) must be equal
-//                types & sizes
-//F*/
-OPENCVAPI void  cvCopyHist( CvHistogram* src, CvHistogram** dst );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCalcBayesianProb
-//    Purpose:    Calculates bayesian probabilistic histograms
-//    Context:
-//    Parameters:
-//      src - array of source histograms
-//      number - number of source/destination histograms 
-//      dst - array of destination histograms
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI void  cvCalcBayesianProb( CvHistogram** src, int number,
-                                  CvHistogram** dst);
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCalcHist
-//    Purpose:    Calculating histogram from array of one-channel images
-//    Context:
-//    Parameters:
-//      img - array of single-channel images
-//      hist - histogram to be calculated. It must have as many dimensions as number of
-//             images in <img> array.
-//      doNotClear - if not 0, the histogram is not cleared before calculations.
-//      mask - optional mask that determines pixels that participate in histogram
-//             accumulation.
-//    Returns:
-//    Notes:      if doNotClear parameter is NULL then histogram clearing before
-//                calculating(all values sets to NULL)
-//F*/
-OPENCVAPI  void  cvCalcHist( IplImage** img, CvHistogram* hist,
-                          int doNotClear CV_DEFAULT(0),
-                          IplImage* mask CV_DEFAULT(0) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCalcContrastHist
-//    Purpose:    Calculates contrast histogram from array of one-channel images
-//    Context:
-//    Parameters:
-//    Returns:
-//    Notes:      if dont_clear parameter is NULL then histogram clearing before
-//                calculating(all values sets to NULL)
-//F*/
-OPENCVAPI  void   cvCalcContrastHist( IplImage** img, CvHistogram* hist,
-                                   int doNotClear, IplImage* mask );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCalcBackProject
-//    Purpose:    Calculates back project of histogram
-//      img - array of input single-channel images
-//      dst - destination single-channel image
-//      hist - histogram, used for calculating back project. It must have as many
-//             dimensions as the number of images in the <img> array.
-//    Context:
-//    Parameters:
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvCalcBackProject( IplImage** img, IplImage* dst,
-                                 CvHistogram* hist );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCalcBackProjectPatch
-//    Purpose:    Calculating back project patch of histogram
-//    Context:
-//    Parameters:
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvCalcBackProjectPatch( IplImage** img, IplImage* dst, CvSize range,
-                                      CvHistogram* hist, CvCompareMethod method,
-                                      double normFactor );
-
-
-/****************************************************************************************\
-*                                  Active contours                                       *
-\****************************************************************************************/
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSnakeImage
-//    Purpose:    Updates active contour in order to minimize its cummulative (internal
-//                and external) energy.
-//    Context:
-//    Parameters:
-//      src - source image that represent external energy.
-//      points - array of points in the snake.
-//      length - number of points
-//      alpha, beta, gamma - weights of different energy components
-//      coeffUsage - if it is CV_ARRAY then previous three parameters are array of 
-//                   <length> elements, otherwise each of them is a pointer to
-//                   scalar values.
-//      win - half-size of search window. 
-//      criteria - termination criteria.
-//      calcGradient - if not 0, the function uses magnitude of the source image gradient
-//                     as external energy, otherwise the source image pixel values
-//                     are just used for this purpose.  
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvSnakeImage( IplImage* src, CvPoint* points,
-                            int  length, float* alpha,
-                            float* beta, float* gamma,
-                            CvCoeffType coeffUsage, CvSize  win,
-                            CvTermCriteria criteria, int calcGradient CV_DEFAULT(1));
-
-/****************************************************************************************\
-*                              Gesture recognition                                      *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvFindHandRegion
-//    Purpose:  finds hand region in range image data
-//    Context:   
-//    Parameters: 
-//      points - pointer to the input point's set.
-//      count  - the number of the input points.
-//      indexs - pointer to the input sequence of the point's indexes
-//      line   - pointer to the 3D-line
-//      size   - size of the hand in meters 
-//      flag   - hand direction's flag (0 - left, -1 - right, 
-                 otherwise j-index of the initial image center)
-//      center - pointer to the output hand center
-//      storage - pointer to the memory storage  
-//      numbers - pointer to the output sequence of the point's indexes inside
-//                hand region                
-//      
-//    Notes:
-//F*/
-OPENCVAPI  void  cvFindHandRegion (CvPoint3D32f* points, int count,
-                                CvSeq* indexs,
-                                float* line, CvSize2D32f size, int flag,
-                                CvPoint3D32f* center,
-                                CvMemStorage* storage, CvSeq **numbers);
-
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvFindHandRegionA
-//    Purpose:  finds hand region in range image data
-//    Context:
-//    Parameters:
-//      points - pointer to the input point's set.
-//      count  - the number of the input points.
-//      indexs - pointer to the input sequence of the point's indexes
-//      line   - pointer to the 3D-line
-//      size   - size of the hand in meters
-//      jc - j-index of the initial image center
-//      center - pointer to the output hand center
-//      storage - pointer to the memory storage
-//      numbers - pointer to the output sequence of the point's indexes inside
-//                hand region
-//
-//    Notes:
-//F*/
-OPENCVAPI  void  cvFindHandRegionA( CvPoint3D32f* points, int count,
-                                CvSeq* indexs,
-                                float* line, CvSize2D32f size, int jc,
-                                CvPoint3D32f* center,
-                                CvMemStorage* storage, CvSeq **numbers);
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvCalcImageHomography
-//    Purpose:  calculates the cooficients of the homography matrix
-//    Context:
-//    Parameters:
-//      line   - pointer to the input 3D-line
-//      center - pointer to the input hand center
-//      intrinsic - intrinsic camera parameters matrix
-//      homography - result homography matrix
-//
-//    Notes:
-//F*/
-OPENCVAPI  void  cvCalcImageHomography(float *line, CvPoint3D32f* center,
-                                     float intrinsic[3][3], float homography[3][3]);
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvCreateHandMask
-//    Purpose:  creates hand mask image
-//    Context:
-//    Parameters:
-//      numbers - pointer to the input sequence of the point's indexes inside
-//                hand region
-//      img_mask - pointer to the result mask image
-//      roi      - result hand mask ROI
-//
-//    Notes:
-//F*/
-OPENCVAPI  void  cvCreateHandMask( CvSeq* numbers,
-                                IplImage *img_mask, CvRect *roi);
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvCalcProbDensity
-//    Purpose:  calculates hand mask probability density
-//    Context:
-//    Parameters:
-//      hist      - pointer to the input image histogram
-//      hist_mask - pointer to the input image mask histogram
-//      hist_dens - pointer to the result probability density histogram
-//
-//    Notes:
-//F*/
-OPENCVAPI  void  cvCalcProbDensity( CvHistogram* hist, CvHistogram* hist_mask,
-                                 CvHistogram* hist_dens);
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvMaxRect
-//    Purpose:  calculates maximum rectangle
-//    Context:
-//    Parameters:
-//      rect1      - pointer to the first input rectangle
-//      rect2      - pointer to the second input rectangle
-//      max_rect   - pointer to the result maximum rectangle
-//
-//    Notes:
-//F*/
-OPENCVAPI  void  cvMaxRect( CvRect *rect1, CvRect *rect2, CvRect *max_rect );
-
-/****************************************************************************************\
-*                                  Distance Transform                                    *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvDistTransform
-//    Purpose:  calculates distance transform of binary image 
-//    Context:
-//    Parameters:
-//      src - source binary image
-//      dst - output floating-point image, whose pixel values are distances from
-//            the correspondend pixel in the source image to the nearest 0-pixel.
-//      disType - type of metric used
-//      maskSize - size of discrete aperture that approximates the metric; can be 3 or 5.
-//      mask - array of 2 (for 3x3 mask) or 3 numbers (for 5x5 mask) that characterizes
-//             metric if disType is CV_DIST_USER (user-defined metric)
-//    Notes:
-//F*/
-#define CV_DIST_MASK_3   3
-#define CV_DIST_MASK_5   5 
-
-OPENCVAPI  void  cvDistTransform( const CvArr* src, CvArr* dst,
-                                  CvDisType disType CV_DEFAULT(CV_DIST_L2),
-                                  int maskSize CV_DEFAULT(3),
-                                  const float* mask CV_DEFAULT(0));
-
-
-/****************************************************************************************\
-*                                      Thresholds                                        *
-\****************************************************************************************/
-
-/* Defines for Threshold functions */
-typedef enum CvThreshType
-{
-    CV_THRESH_BINARY     = 0,  /* val = (val>thresh? MAX:0)      */
-    CV_THRESH_BINARY_INV = 1,  /* val = (val>thresh? 0:MAX)      */
-    CV_THRESH_TRUNC      = 2,  /* val = (val>thresh? thresh:val) */
-    CV_THRESH_TOZERO     = 3,  /* val = (val>thresh? val:0)      */
-    CV_THRESH_TOZERO_INV = 4   /* val = (val>thresh? 0:val)      */
-} CvThreshType;
-
-typedef enum CvAdaptiveThreshMethod
-{
-    CV_STDDEV_ADAPTIVE_THRESH  = 0   /*  method for the defining local adaptive threshold  */
-}
-CvAdaptiveThreshMethod;
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvThreshold
-//    Purpose: Applies fixed threshold to the grayscale image
-//    Context:
-//    Parameters:
-//      src     - source image
-//      dst     - destination image (can be the same as the source image)
-//      threshold - threshold value
-//      maxValue  - the maximum value of the image pixel
-//      type      - thresholding type, must be one of
-//                  CV_THRESH_BINARY       - val =(val > Thresh ? maxValue : 0)
-//                  CV_THRESH_BINARY_INV   - val =(val > Thresh ? 0   : maxValue)
-//                  CV_THRESH_TOZERO       - val =(val > Thresh ? val : 0)
-//                  CV_THRESH_TOZERO_INV   - val =(val > Thresh ? 0   : val)
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvThreshold( const CvArr*  src, CvArr*  dst,
-                              double  thresh,  double  maxValue,
-                              CvThreshType type );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvAdaptiveThreshold
-//    Purpose: Applies adaptive threshold to the grayscale image
-//    Context:
-//    Parameters:
-//      src     - source image
-//      dst     - destination image
-//      maxValue  - the maximum value of the image pixel
-//      method    - method for the adaptive threshold calculation
-                   (now CV_STDDEF_ADAPTIVE_THRESH only)
-//      type      - thresholding type, must be one of
-//                  CV_THRESH_BINARY       - val =(val > Thresh ? MAX    : 0)
-//                  CV_THRESH_BINARY_INV   - val =(val > Thresh ? 0      : MAX)
-//                  CV_THRESH_TOZERO       - val =(val > Thresh ? val    : 0)
-//                  CV_THRESH_TOZERO_INV   - val =(val > Thresh ? 0      : val)
-//      parameters - pointer to the input parameters(for the
-//                   CV_STDDEF_ADAPTIVE_THRESH method parameters[0] is size of
-//                   the neighborhood thresholding,(one of the 1-(3x3),2-(5x5),or
-//                   3-(7x7)), parameters[1] is the value of the minimum variance
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double maxValue,
-                                      CvAdaptiveThreshMethod method, CvThreshType type,
-                                      double* parameters );
-
-/****************************************************************************************\
-*                                     Flood fill                                         *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvFloodFill, cvFloodFill
-//    Purpose: The function fills the connected domain, starting from seed pixel
-//             while the pixel values in this domain are not far from each other.
-//    Context:
-//    Parameters:
-//      img        - initial image(in the beginning)
-//                   which is "repainted" during the function action,
-//      seedPoint  - coordinates of the seed point inside image ROI,
-//      newVal     - new value of repainted area pixels,
-//      loDiff, upDiff - maximal lower and upper differences of the values of
-//                   appurtenant to repainted area pixel and one of its
-//                   neighbour,
-//      comp       - pointer to connected component structure of the
-//                   repainted area
-//      connectivity - if it is 4, the function looks for 4-connected neighbors,
-//                     otherwise it looks for 8-connected neighbors.
-//    Notes:
-//F*/
-OPENCVAPI  void  cvFloodFill( CvArr* array, CvPoint seedPoint,
-                              double newVal, double loDiff, double upDiff,
-                              CvConnectedComp* comp, int connectivity CV_DEFAULT(4) );
-
-/****************************************************************************************\
-*                                     CAMSHIFT                                           *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCamShift
-//    Purpose:
-//      Implements CAMSHIFT algorithm - determines object position, size and orientation
-//      from the object histogram back project.
-//    Context:
-//    Parameters:
-//      imgProb - back project of the object histogram
-//      windowIn - initial search window
-//      criteria - iterative search termination criteria 
-//      out    - output parameter. Final position of search window and object area
-//      box    - width and height (i.e. length) of the object, its center and orientation
-//    Returns:
-//      Number of iterations made
-//F*/
-OPENCVAPI int  cvCamShift( const CvArr* imgProb, CvRect  windowIn,
-                           CvTermCriteria criteria, CvConnectedComp* out,
-                           CvBox2D* box );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvMeanShift
-//    Purpose:
-//      Implements MeanShift algorithm - determines object position
-//      from the object histogram back project.
-//    Context:
-//    Parameters:
-//      imgProb - back project of the object histogram
-//      windowIn - initial search window
-//      criteria - iterative search termination criteria 
-//      out - output parameter. Final position of search window and object area
-//    Returns:
-//      Number of iterations made
-//    Notes:
-//F*/
-OPENCVAPI int  cvMeanShift( const CvArr* imgProb, CvRect  windowIn,
-                            CvTermCriteria criteria, CvConnectedComp* out );
-
-/****************************************************************************************\
-*                                  Feature detection                                     *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCanny
-//    Purpose: Canny edge detection
-//    Context:
-//    Parameters:
-//      src - source byte-depth, single channel image,
-//      dst - destination byte-depth, single channel image with edges,
-//      apertureSize - size of Sobel operator aperture,
-//      lowThreshold,
-//      highThreshold - tresholds, applied in hysteresis thresholding
-//    Returns:
-//    Notes: image gradient magnitude has scale factor 2^(2*apertureSize-3)
-//           so user must choose appropriate lowThreshold and highThreshold
-//           i.e. if real gradient magnitude is 1, then 3x3 Sobel used in this function
-//           will output 8 for apertureSize == 3.
-//F*/
-OPENCVAPI  void  cvCanny( const CvArr* src, CvArr* dst, double lowThreshold,
-                          double highThreshold, int  apertureSize CV_DEFAULT(3) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:     cvPreCornerDetect
-//    Purpose:  Calculating constraint image for corner detection
-//              Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy
-//    Context:
-//    Parameters:
-//      src - source image
-//      dst - destination feature image
-//      apertureSize - Sobel operator aperture size
-//    Returns:
-//F*/
-OPENCVAPI void cvPreCornerDetect( const CvArr* src, CvArr* dst,
-                                  int apertureSize CV_DEFAULT(3) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCalcCornerEigenValsAndVecs
-//    Purpose:  Calculates eigen values and vectors of 2x2
-//              gradient matrix at every image pixel
-//    Context:
-//    Parameters:
-//      src      - pointer to the source image
-//      eigenvv  - destination image, containing two eigen values and
-//                 components of two eigen vectors for each raster point
-//               ( i.e., this image is 6 times wider than source image )
-//      apertureSize - Sobel operator aperture size
-//      blockSize  - size of block for summation(averaging block)
-//    Returns:
-//F*/
-OPENCVAPI void  cvCornerEigenValsAndVecs( const CvArr* src, CvArr* eigenvv,
-                                          int blockSize,
-                                          int apertureSize CV_DEFAULT(3) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvCornerMinEigenVal
-//    Purpose:  Calculates minimal eigenvalue for 2x2 gradient matrix at
-//              every image pixel
-//    Context:
-//    Parameters:
-//      src        - source image
-//      eigenval   - minimal eigen value for each point of the source image
-//      apertureSize - Sobel operator aperture size
-//      blockSize  - size of block for summation(averaging block)
-//    Returns:
-//F*/
-OPENCVAPI void  cvCornerMinEigenVal( const CvArr* src, CvArr* eigenval,
-                                     int blockSize, int apertureSize CV_DEFAULT(3) );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvFindCornerSubPix
-//    Purpose:
-//      Finds corners on the image with sub-pixel accuracy given
-//      initial guesses for those corners.
-//    Context:
-//    Parameters:
-//      src        - source image
-//      corners    - initial coordinates of corners on input, adjusted coordinates
-//                   on output
-//      count      - number of corner points
-//      win        - search window size for each corner.
-//                   actually, for each corner(x,y), the window
-//                  (x - win.width .. x + win.width,y - win.height .. y + win_height)
-//                   is used.(window  moves with the point after every iteration)
-//      zeroZone   - size of zero zone in the middle of the mask.
-//      criteria   - This parameter specifies, how many times iterate and what precision
-//                   is required.
-//    Returns:
-//      Nothing
-//    Notes:
-//      Size of destination ROI is not passed into the function, because
-//      it assumes dst ROI size:
-//      =(src_size.width - 2, src_size.height - 2) if both kernels are used
-//      =(src_size.width - 2, src_size.height)     if horizontal kernel != 0 only.
-//      =(src_size.width, src_size.height - 2)     if vertical kernel != 0 only.
-F*/
-OPENCVAPI  void  cvFindCornerSubPix( const CvArr* src,CvPoint2D32f*  corners,
-                                     int count, CvSize win,CvSize zeroZone,
-                                     CvTermCriteria  criteria );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvGoodFeaturesToTrack
-//    Purpose:
-//      Finds strong corners on the image
-//    Context:
-//    Parameters:
-//      image    - input image(IPL_DEPTH_8U,IPL_DEPTH_8S or IPL_DEPTH_32F,single channel)
-//      eigImage - temporary image(IPL_DEPTH_32F,single channel),
-//                 which will contain minimal eigen value for each point
-//      tempImage- temporary image(IPL_DEPTH_32F,single channel),
-//                 which is used in non-maxima suppression.
-//      corners  - output corners
-//      corner_count - number of output corners
-//      quality_level - only those corners are selected, which minimal eigen value is
-//                      non-less than maximum of minimal eigen values on the image,
-//                      multiplied by quality_level. For example, quality_level = 0.1
-//                      means that selected corners must be at least 1/10 as good as
-//                      the best corner.
-//      min_distance - The selected corners(after thresholding using quality_level)
-//                     are rerified such that pair-wise distance between them is
-//                     non-less than min_distance
-//    Returns:
-F*/
-OPENCVAPI void  cvGoodFeaturesToTrack( const CvArr* image, CvArr* eigImage,
-                                       CvArr* tempImage, CvPoint2D32f* corners,
-                                       int* corner_count, double  quality_level,
-                                       double  min_distance,
-                                       const CvArr* mask CV_DEFAULT(0));
-
-/****************************************************************************************\
-*                                     Hough Transform                                    *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvHoughLines
-//    Purpose:
-//      Function detects lines on a binary raster image
-//    Context:
-//    Parameters:
-//      image       - input image
-//      rho         - resolution in rho(the minimum difference between two values)
-//      theta       - resolution in theta(the minimum difference between two values)
-//      threshold   - the pixels number which is enough to plot a line through
-//      lines       - output parameters of a line
-//                    i line is rho = lines[2*i], theta = lines[2*i + 1]
-//      linesNumber - 2*linesNumber is the size of the lines buffer
-//    Returns:
-//    Notes:
-//      the Standard Hough Transform is used in the function
-//F*/
-OPENCVAPI  int  cvHoughLines( IplImage* image, double rho, double theta, int threshold,
-                              float* lines, int linesNumber );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvHoughLinesP
-//    Purpose:
-//      Function detects lines on a binary raster image
-//    Context:
-//    Parameters:
-//      image       - input image
-//      rho         - resolution in rho(the minimum difference between two values)
-//      theta       - resolution in theta(the minimum difference between two values)
-//      threshold   - the pixels number which is enough to plot a line through
-//      lineLength  - the minimum accepted length of lines
-//      lineGap     - the maximum accepted gap in a line(in pixels)
-//      lines       - output parameters of a line
-//                      the i line starts in x1 = lines[4*i], y1 = lines[4*i + 1] and
-//                      finishes in x2 = lines[4*i + 2], y2 = lines[4*i + 3]
-//      linesNumber - 4*linesNumber is the size of lines buffer
-//      linesToFind - the maximum number of lines to detect
-//    Returns:
-//      The number of found lines
-//    Notes:
-//    The Progressive Probabilistic Hough Transform is implemented in the function. It
-//      searches for linesToFind number of lines, taking only those that contain more than
-//      lineLength pixels and return. Effectively detects long lines on an image with
-//      strong noise.
-//F*/
-OPENCVAPI  int  cvHoughLinesP( IplImage* image, double rho, double theta, int threshold,
-                            int lineLength, int lineGap, int* lines, int linesNumber );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvHoughLinesSDiv
-//    Purpose:
-//      Function detects lines on a binary raster image
-//    Context:
-//    Parameters:
-//      image       - input image
-//      rho         - rough resolution in rho(the minimum difference between two values)
-//      srn         - the scale factor of a rough rho resolution to a high one
-//      theta       - rough resolution in theta(the minimum difference between two values)
-//      stn         - the scale factor of a rough theta resolution to a high one
-//      threshold   - the pixels number which is enough to plot a line through
-//      lines       - output parameters of a line
-//                      i line is rho = lines[2*i], theta = lines[2*i + 1]
-//      linesNumber - 2*linesNumber is the size of the lines buffer
-//    Returns:
-//      the number of lines found
-//    Notes:
-//    the Standard Hough Transform is used in the function
-//F*/
-OPENCVAPI  int  cvHoughLinesSDiv( IplImage* image, double rho, int srn,
-                                  double theta, int stn, int threshold,
-                                  float* lines, int lines_number );
-
-/****************************************************************************************\
-*                              Geometry functions                                        *
-\****************************************************************************************/
-
-OPENCVAPI  void  cvProject3D( CvPoint3D32f* points3D, int count,
-                              CvPoint2D32f* points2D, int xIndx, int yIndx );
-
-OPENCVAPI  void  cvFitLine3D( CvPoint3D32f* points, int count, CvDisType dist,
-                              void *param, float reps, float aeps, float* line );
-
-OPENCVAPI  void  cvFitLine2D( CvPoint2D32f* points, int count, CvDisType dist,
-                              void *param, float reps, float aeps, float* line );
-
-
-/****************************************************************************************\
-*                              Optical Flow functions                                    *
-\****************************************************************************************/
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcOpticalFlowLK( Lucas & Kanade method )
-//    Purpose: calculate Optical flow for 2 images using Lucas & Kanade algorithm
-//    Context:
-//    Parameters:
-//            srcA,         // first image
-//            srcB,         // second image
-//            winSize,      // size of the averaging window used for grouping
-//            velx,         //  horizontal
-//            vely          //  vertical components of optical flow
-//
-//    Returns:
-//
-//    Notes:  1.Optical flow to be computed for every pixel in ROI
-//            2.For calculating spatial derivatives we use 3x3 Sobel operator.
-//            3.We use the following border mode.
-//              The last row or column is replicated for the border
-//            ( IPL_BORDER_REPLICATE in IPL ).
-//
-//F*/
-OPENCVAPI  void  cvCalcOpticalFlowLK( const CvArr* srcA, const CvArr* srcB,
-                                      CvSize winSize, CvArr* velx, CvArr* vely );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcOpticalFlowBM
-//    Purpose: calculate Optical flow for 2 images using block matching algorithm
-//    Context:
-//    Parameters:
-//            srcA,         // first image
-//            srcB,         // second image
-//            blockSize,    // size of basic blocks which are compared
-//            shiftSize,    // coordinates increments.
-//            maxRange,     // size of the scanned neighborhood.
-//            usePrevious,  // use previous(input) velocity field.
-//            velx,         //  horizontal
-//            vely          //  vertical components of optical flow
-//
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvCalcOpticalFlowBM( const CvArr* srcA, const CvArr* srcB,
-                                      CvSize blockSize, CvSize shiftSize,
-                                      CvSize maxRange, int usePrevious,
-                                      CvArr* velx, CvArr* vely );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcOpticalFlowHS(Horn & Schunck method )
-//    Purpose: calculate Optical flow for 2 images using Horn & Schunck algorithm
-//    Context:
-//    Parameters:
-//            srcA,         // first image
-//            srcB,         // second image
-//            int usePrevious, // use previous(input) velocity field.
-//            velx,         //  horizontal
-//            vely          //  vertical components of optical flow
-//            double lambda, // Lagrangian multiplier
-//            criteria       // criteria of process termination
-//
-//    Returns:
-//
-//    Notes:  1.Optical flow to be computed for every pixel in ROI
-//            2.For calculating spatial derivatives we use 3x3 Sobel operator.
-//            3.We use the following border mode.
-//              The first and last rows and columns are replicated for the border
-//            ( IPL_BORDER_REPLICATE in IPL ).
-//F*/
-OPENCVAPI  void  cvCalcOpticalFlowHS( const CvArr* srcA, const CvArr* srcB,
-                                      int usePrevious, CvArr* velx, CvArr* vely,
-                                      double lambda, CvTermCriteria criteria );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcOpticalFlowPyrLK
-//    Purpose:
-//      It is Lucas & Kanade method, modified to use pyramids.
-//      Also it does several iterations to get optical flow for
-//      every point at every pyramid level.
-//      Calculates optical flow between two images for certain set of points.
-//    Context:
-//    Parameters:
-//            imgA     - first frame(time t)
-//            imgB     - second frame(time t+1)
-//            pyrA     - buffer for pyramid for the first frame.
-//                       if the pointer is not NULL, the buffer must have size enough to
-//                       store pyramid(from level 1 to level #<level>(see below))
-//                      (total size of(imgSize.width+8)*imgSize.height/3
-//                        bytes will be enough)).
-//            pyrB     - similar to pyrA, but for the second frame.
-//
-//                       for both parameters above the following rules work:
-//                           If image pointer is 0, the function allocates the buffer
-//                           internally, calculates pyramid and releases the buffer after
-//                           processing.
-//                           Else(image should be large enough then) the function calculates
-//                           pyramid and stores it in the buffer unless the
-//                           CV_LKFLOW_PYR_A[B]_READY flag is set. After function call
-//                           both pyramids are calculated and ready-flag for corresponding
-//                           image can be set.
-//
-//            count    - number of feature points
-//            winSize  - size of search window on each pyramid level
-//            level    - maximal pyramid level number
-//                        (if 0, pyramids are not used(single level),
-//                          if 1, two levels are used etc.)
-//
-//            next parameters are arrays of <count> elements.
-//            ------------------------------------------------------
-//            featuresA - array of points, for which the flow needs to be found
-//            featuresB - array of 2D points, containing calculated
-//                       new positions of input features(in the second image).
-//            status   - array, every element of which will be set to 1 if the flow for the
-//                       corresponding feature has been found, 0 else.
-//            error    - array of double numbers, containing difference between
-//                       patches around the original and moved points
-//                      (it is optional parameter, can be NULL).
-//            ------------------------------------------------------
-//            criteria   - specifies when to stop the iteration process of finding flow
-//                         for each point on each pyramid level
-//
-//            flags      - miscellaneous flags:
-//                            CV_LKFLOW_PYR_A_READY - pyramid for the first frame
-//                                                    is precalculated before call
-//                            CV_LKFLOW_PYR_B_READY - pyramid for the second frame
-//                                                    is precalculated before call
-//                            CV_LKFLOW_INITIAL_GUESSES - featuresB array holds initial
-//                                                        guesses about new features'
-//                                                        locations before function call.
-//    Returns:
-//    Notes:  For calculating spatial derivatives 3x3 Sharr operator is used.
-//            The values of pixels beyond the image are determined using border
-//            replication.
-//F*/
-#define  CV_LKFLOW_PYR_A_READY       1
-#define  CV_LKFLOW_PYR_B_READY       2
-#define  CV_LKFLOW_INITIAL_GUESSES   4
-
-OPENCVAPI  void  cvCalcOpticalFlowPyrLK( const CvArr*  imgA, const CvArr*  imgB,
-                                         CvArr*  pyrA, CvArr*  pyrB,
-                                         CvPoint2D32f* featuresA,
-                                         CvPoint2D32f* featuresB,
-                                         int       count,
-                                         CvSize    winSize,
-                                         int       level,
-                                         char*     status,
-                                         float*    error,
-                                         CvTermCriteria criteria,
-                                         int       flags );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcAffineFlowPyrLK
-//    Purpose:
-//      It is Lucas & Kanade affine tracking method, modified to use pyramids.
-//      Also it does several iterations to find flow for
-//      every point at every pyramid level.
-//      Calculates affine flow between two images for certain set of points.
-//    Context:
-//    Parameters:
-//            imgA     - first frame(time t)
-//            imgB     - second frame(time t+1)
-//            pyrA     - buffer for pyramid for the first frame.
-//                       if the pointer is not NULL, the buffer must have size enough to
-//                       store pyramid(from level 1 to level #<level>(see below))
-//                      (total size of(imgSize.width+8)*imgSize.height/3
-//                        bytes will be enough)).
-//            pyrB     - similar to pyrA, but for the second frame.
-//
-//                       for both parameters above the following rules work:
-//                           If image pointer is 0, the function allocates the buffer
-//                           internally, calculates pyramid and releases the buffer after
-//                           processing.
-//                           Else(image should be large enough then) the function calculates
-//                           pyramid and stores it in the buffer unless the
-//                           CV_LKFLOW_PYR_A[B]_READY flag is set. After function call
-//                           both pyramids are calculated and ready-flag for corresponding
-//                           image can be set.
-//
-//            count    - number of feature points
-//            winSize  - size of search window on each pyramid level
-//            level    - maximal pyramid level number
-//                        (if 0, pyramids are not used(single level),
-//                          if 1, two levels are used etc.)
-//
-//            next parameters are arrays of <count> elements.
-//            ------------------------------------------------------
-//            featuresA - array of points, for which the flow needs to be found
-//            featuresB - array of 2D points, containing calculated
-//                       new positions of input features(in the second image).
-//            matrices - affine transformation matrices,
-//            status   - array, every element of which will be set to 1 if the flow for the
-//                       corresponding feature has been found, 0 else.
-//            error    - array of double numbers, containing difference between
-//                       patches around the original and moved points
-//                      (it is optional parameter, can be NULL).
-//            ------------------------------------------------------
-//            criteria   - specifies when to stop the iteration process of finding flow
-//                         for each point on each pyramid level
-//
-//            flags      - miscellaneous flags:
-//                            CV_LKFLOW_PYR_A_READY - pyramid for the first frame
-//                                                    is precalculated before call
-//                            CV_LKFLOW_PYR_B_READY - pyramid for the second frame
-//                                                    is precalculated before call
-//                            CV_LKFLOW_INITIAL_GUESSES - featuresB array holds initial
-//                                                        guesses about new features'
-//                                                        locations before function call,
-//                                                        matrices array contains guesses
-//                                                        about local transformations in
-//                                                        the features' neighborhoods.
-//    Returns:
-//    Notes:  For calculating spatial derivatives 3x3 Sharr operator is used.
-//            The values of pixels beyond the image are determined using border
-//            replication.
-//F*/
-OPENCVAPI  void  cvCalcAffineFlowPyrLK( const CvArr*  imgA, const CvArr*  imgB,
-                                        CvArr*  pyrA, CvArr*  pyrB,
-                                        CvPoint2D32f* featuresA,
-                                        CvPoint2D32f* featuresB,
-                                        float*  matrices, int  count,
-                                        CvSize  winSize, int  level,
-                                        char*  status, float* error,
-                                        CvTermCriteria criteria, int flags );
-
-
-/****************************************************************************************\
-*                              Eigen objects functions                                   *
-\****************************************************************************************/
-
-#define CV_EIGOBJ_NO_CALLBACK     0
-#define CV_EIGOBJ_INPUT_CALLBACK  1
-#define CV_EIGOBJ_OUTPUT_CALLBACK 2
-#define CV_EIGOBJ_BOTH_CALLBACK   3
-
-typedef CvStatus (CV_CDECL * CvCallback)( int index, void* buffer, void* userData );
-
-typedef union
-{
-    CvCallback callback;
-    void* data;
-}
-CvInput;
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcCovarMatrixEx
-//    Purpose: The function calculates a covariance matrix for a group of input objects
-//            (images, vectors, etc.).
-//    Context:
-//    Parameters:  nObjects    - number of source objects
-//                 input       - pointer either to array of input objects
-//                               or to read callback function(depending on ioFlags)
-//                 ioFlags     - input/output flags(see Notes to
-//                               cvCalcEigenObjects function)
-//                 ioBufSize   - input/output buffer size
-//                 userData    - pointer to the structure which contains all necessary
-//                               data for the callback functions
-//                 avg         - averaged object
-//                 covarMatrix - covariance matrix(output parameter; must be allocated
-//                               before call)
-//
-//    Notes:  See Notes to cvCalcEigenObjects function
-//F*/
-OPENCVAPI  void  cvCalcCovarMatrixEx( int nObjects, void* input, int ioFlags,
-                                      int ioBufSize, uchar* buffer, void* userData,
-                                      IplImage* avg, float* covarMatrix );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcEigenObjects
-//    Purpose: The function calculates an orthonormal eigen basis and a mean(averaged)
-//             object for a group of input objects(images, vectors, etc.).
-//    Context:
-//    Parameters: nObjects  - number of source objects
-//                input     - pointer either to array of input objects
-//                            or to read callback function(depending on ioFlags)
-//                output    - pointer either to output eigen objects
-//                            or to write callback function(depending on ioFlags)
-//                ioFlags   - input/output flags(see Notes)
-//                ioBufSize - input/output buffer size
-//                userData  - pointer to the structure which contains all necessary
-//                            data for the callback functions
-//                calcLimit - determines the calculation finish conditions
-//                avg       - averaged object(has the same size as ROI)
-//                eigVals   - pointer to corresponding eigen values(array of <nObjects>
-//                            elements in descending order)
-//
-//    Notes: 1. input/output data(that is, input objects and eigen ones) may either
-//              be allocated in the RAM or be read from/written to the HDD(or any
-//              other device) by read/write callback functions. It depends on the
-//              value of ioFlags paramater, which may be the following:
-//                  CV_EIGOBJ_NO_CALLBACK, or 0;
-//                  CV_EIGOBJ_INPUT_CALLBACK;
-//                  CV_EIGOBJ_OUTPUT_CALLBACK;
-//                  CV_EIGOBJ_BOTH_CALLBACK, or
-//                            CV_EIGOBJ_INPUT_CALLBACK | CV_EIGOBJ_OUTPUT_CALLBACK.
-//              The callback functions as well as the user data structure must be
-//              developed by the user.
-//
-//           2. If ioBufSize = 0, or it's too large, the function dermines buffer size
-//              itself.
-//
-//           3. Depending on calcLimit parameter, calculations are finished either if
-//              eigenfaces number comes up to certain value or the relation of the
-//              current eigenvalue and the largest one comes down to certain value
-//             (or any of the above conditions takes place). The calcLimit->type value
-//              must be CV_TERMCRIT_NUMB, CV_TERMCRIT_EPS or
-//              CV_TERMCRIT_NUMB | CV_TERMCRIT_EPS. The function returns the real
-//              values calcLimit->maxIter and calcLimit->epsilon.
-//
-//           4. eigVals may be equal to NULL(if you don't need eigen values in further).
-//
-//F*/
-OPENCVAPI  void  cvCalcEigenObjects( int nObjects, void* input, void* output,
-                                    int ioFlags, int ioBufSize, void* userData,
-                                    CvTermCriteria* calcLimit, IplImage* avg,
-                                    float* eigVals );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCalcDecompCoeff
-//    Purpose: The function calculates one decomposition coefficient of input object
-//             using previously calculated eigen object and the mean(averaged) object
-//    Context:
-//    Parameters:  obj     - input object
-//                 eigObj  - eigen object
-//                 avg     - averaged object
-//
-//    Returns: decomposition coefficient value or large negative value(if error)
-//
-//    Notes:
-//F*/
-OPENCVAPI  double  cvCalcDecompCoeff( IplImage* obj, IplImage* eigObj, IplImage* avg );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Names: cvEigenDecomposite
-//    Purpose: The function calculates all decomposition coefficients for input object
-//             using previously calculated eigen objects basis and the mean(averaged)
-//             object
-//
-//    Parameters:  obj         - input object
-//                 nEigObjs    - number of eigen objects
-//                 eigInput    - pointer either to array of pointers to eigen objects
-//                               or to read callback function(depending on ioFlags)
-//                 ioFlags     - input/output flags
-//                 userData    - pointer to the structure which contains all necessary
-//                               data for the callback function
-//                 avg         - averaged object
-//                 coeffs      - calculated coefficients(output data)
-//
-//    Notes:   see notes to cvCalcEigenObjects function
-//F*/
-OPENCVAPI  void  cvEigenDecomposite( IplImage* obj, int nEigObjs, void* eigInput,
-                                    int ioFlags, void* userData, IplImage* avg,
-                                    float* coeffs );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvEigenProjection
-//    Purpose: The function calculates object projection to the eigen sub-space(restores
-//             an object) using previously calculated eigen objects basis, mean(averaged)
-//             object and decomposition coefficients of the restored object
-//    Context:
-//    Parameters:  nEigObjs    - number of eigen objects
-//                 eigInput    - pointer either to array of pointers to eigen objects
-//                               or to read callback function(depending on ioFlags)
-//                 ioFlags     - input/output flags
-//                 userData    - pointer to the structure which contains all necessary
-//                               data for the callback function
-//                 coeffs      - array of decomposition coefficients
-//                 avg         - averaged object
-//                 proj        - object projection(output data)
-//
-//    Notes:   see notes for cvCalcEigenObjects function
-//F*/
-OPENCVAPI  void  cvEigenProjection( void* eigInput, int nEigObjs, int ioFlags,
-                                   void* userData, float* coeffs, IplImage* avg,
-                                   IplImage* proj );
-
-/****************************************************************************************\
-*                              HMM(Hidden Markov Models)                                *
-\****************************************************************************************/
-
-/*********************************** HMM structures *************************************/
-typedef struct CvEHMMState
-{
-    int num_mix;      /*number of mixtures in this state*/
-    float* mu;        /*mean vectors corresponding to each mixture*/
-    float* inv_var; /* square root of inversed variances corresp. to each mixture*/
-    float* log_var_val; /* sum of 0.5 (LN2PI + ln(variance[i]) ) for i=1,n */
-    float* weight;   /*array of mixture weights. Summ of all weights in state is 1. */
-
-} CvEHMMState;
-
-typedef struct CvEHMM
-{
-    int level; /* 0 - lowest(i.e its states are real states), ..... */
-    int num_states; /* number of HMM states */
-    float*  transP;/*transition probab. matrices for states */
-    float** obsProb; /* if level == 0 - array of brob matrices corresponding to hmm
-                        if level == 1 - martix of matrices */
-    union
-    {
-        CvEHMMState* state; /* if level == 0 points to real states array,
-                               if not - points to embedded hmms */
-        struct CvEHMM* ehmm; /* pointer to an embedded model or NULL, if it is a leaf */
-    } u;
-
-} CvEHMM;
-
-//*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCreate2DHMM
-//    Purpose: The function allocates memory for 2-dimensional embedded HMM model
-//             after you finish work with created HMM you must free memory
-//             by calling cvRelease2DHMM function
-//    Context:
-//    Parameters: stateNumber - array of hmm sizes(size of array == state_number[0]+1 )
-//                numMix - number of gaussian mixtures in low-level HMM states
-//                          size of array is defined by previous array values
-//                obsSize - length of observation vectors
-//
-//    Returns:
-//      Created 2D HMM.
-//    Notes: stateNumber[0] - number of states in external HMM.
-//           stateNumber[i] - number of states in embedded HMM
-//
-//           example for face recognition: state_number = { 5 3 6 6 6 3 },
-//                                         length of num_mix array = 3+6+6+6+3 = 24
-//
-//F*/
-OPENCVAPI  CvEHMM*  cvCreate2DHMM( int* stateNumber, int* numMix, int obsSize );
-
-
-//*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvRelease2DHMM
-//    Purpose: The function free memory used by CvEHMM structure
-//    Context:
-//    Parameters: hmm - address of pointer to CvEHMM structure
-//    Returns:
-//    Notes:  function set *hmm = 0
-//F*/
-OPENCVAPI  void  cvRelease2DHMM( CvEHMM** hmm );
-
-
-//*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvCreateObsInfo
-//    Purpose: The function allocates memory for CvImgObsInfo structure
-//             after you finish working with allocated structure - destroy it
-//             by  cvReleaseObsInfo
-//
-//    Context:
-//    Parameters: numObs  - number of horizontal and vertical observations.
-//                          Total number of allocated observation vectors
-//                          will be   num_obs.width*num_obs.height
-//                obsSize - length of observation vector
-//
-//    Returns:  Parameter obs_info is filled.
-//
-//    Notes: If you extract observations from an image, use CV_COUNT_OBS macro
-//           to compute "numObs" parameter:
-//
-//           CV_COUNT_OBS( &roi, &obs, &delta, &numObs),
-//
-//                          where CvSize roi   - image ROI
-//                                CvSize obs   - size of image block (a single observation)
-//                                CvSize delta - horizontal and vertical shift
-//                                           (i.e. because observation blocks overlap if
-//                                            delta.width < obs.width or
-//                                            delta.height < obs.height )
-//                                CvSize numObs - output parameter to be computed
-//
-//F*/
-#define CV_COUNT_OBS(roi, win, delta, numObs )                                       \
-{                                                                                    \
-   (numObs)->width  =((roi)->width  -(win)->width  +(delta)->width)/(delta)->width;  \
-   (numObs)->height =((roi)->height -(win)->height +(delta)->height)/(delta)->height;\
-}
-
-typedef struct CvImgObsInfo
-{
-    int obs_x;
-    int obs_y;
-    int obs_size;
-    float* obs;//consequtive observations
-
-    int* state;/* array of pairs superstate/state to which observation belong */
-    int* mix;  /* number of mixture to which observation belong */
-
-} CvImgObsInfo;/*struct for 1 image*/
-
-OPENCVAPI  CvImgObsInfo*  cvCreateObsInfo( CvSize numObs, int obsSize );
-
-//*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvReleaseObsInfo
-//    Purpose: The function free memory used by CvImgObsInfo structure
-//
-//    Context:
-//    Parameters: obs_info - address of pointer to CvImgObsInfo structure
-//    Returns:
-//    Notes:  function sets *obs_info = 0
-//F*/
-OPENCVAPI  void  cvReleaseObsInfo( CvImgObsInfo** obs_info );
-
-
-//*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvImgToObs_DCT
-//    Purpose: The function takes as input an image and returns the sequnce of observations
-//             to be used with an embedded HMM; Each observation is top-left block of DCT
-//             coefficient matrix.
-//    Context:
-//    Parameters: img     - pointer to the original image
-//                obs     - pointer to resultant observation vectors
-//                dctSize - size of the block for which DCT is calculated
-//                obsSize - size of top-left block of DCT coeffs matrix, which is treated
-//                          as observation. Each observation vector consists of
-//                          obsSize.width * obsSize.height floats.
-//                          The following conditions should be satisfied:
-//                          0 < objSize.width <= dctSize.width,
-//                          0 < objSize.height <= dctSize.height.
-//                delta   - dctBlocks are overlapped and this parameter specifies horizontal
-//                          and vertical shift.
-//    Returns:
-//
-//    Notes:
-//      The algorithm is following:
-//          1. First, number of observation vectors per row and per column are calculated:
-//
-//             Nx = floor((roi.width - dctSize.width + delta.width)/delta.width);
-//             Ny = floor((roi.height - dctSize.height + delta.height)/delta.height);
-//
-//             So, total number of observation vectors is Nx*Ny, and total size of
-//             array obs must be >= Nx*Ny*obsSize.width*obsSize.height*sizeof(float).
-//          2. Observation vectors are calculated in the following loop
-//             ( actual implementation may be different ), where
-//               I[x1:x2,y1:y2] means block of pixels from source image with
-//               x1 <= x < x2, y1 <= y < y2,
-//               D[x1:x2,y1:y2] means sub matrix of DCT matrix D.
-//               O[x,y] means observation vector that corresponds to position
-//              (x*delta.width,y*delta.height) in the source image
-//             ( all indices are counted from 0 ).
-//
-//               for( y = 0; y < Ny; y++ )
-//               {
-//                   for( x = 0; x < Nx; x++ )
-//                   {
-//                       D = DCT(I[x*delta.width : x*delta.width + dctSize.width,
-//                                  y*delta.height : y*delta.height + dctSize.height]);
-//                       O[x,y] = D[0:obsSize.width, 0:obsSize.height];
-//                   }
-//               }
-//F*/
-OPENCVAPI  void  cvImgToObs_DCT( const CvArr* array, float* obs, CvSize dctSize,
-                                 CvSize obsSize, CvSize delta );
-
-
-//*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvUniformImgSegm
-//    Purpose: The uniformly segments all observation vectors extracted from image
-//    Context:
-//    Parameters: obs_info - observations structure
-//                hmm      - 2D embedded HMM structure
-//
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvUniformImgSegm( CvImgObsInfo* obs_info, CvEHMM* ehmm );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvInitMixSegm
-//    Purpose: The function implements the mixture segmentation of the states
-//             of the embedded HMM
-//
-//    Context: used with the Viterbi training of the embedded HMM
-//             Function uses K-Means algorithm for clustering.
-//
-//    Parameters:  obs_info_array - array of pointers to image observations
-//                 num_img - length of above array
-//                 hmm - pointer to HMM structure
-//
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvInitMixSegm( CvImgObsInfo** obs_info_array,
-                               int num_img, CvEHMM* hmm );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvEstimHMMStateParams
-//    Purpose: function calculates means, variances, weights of every Gaussian mixture
-//             of every low-level state of embedded HMM
-//    Context:
-//    Parameters:  obs_info_array - array of pointers to observation structures
-//                 num_img  - length of above array
-//                 hmm      - hmm structure
-//
-//    Returns:
-//
-//    Notes:
-//F*/
-OPENCVAPI  void  cvEstimateHMMStateParams( CvImgObsInfo** obs_info_array,
-                                        int num_img, CvEHMM* hmm );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvEstimateTransProb
-//    Purpose: function computes transition probability matrices of embedded HMM
-//             given observations segmentation
-//
-//    Context:
-//    Parameters:  obs_info_array - array of pointers to observation structures
-//                 num_img  - length of above array
-//                 hmm      - hmm structure
-//
-//    Returns:
-//
-//    Notes:
-//F*/
-OPENCVAPI  void  cvEstimateTransProb( CvImgObsInfo** obs_info_array,
-                                   int num_img, CvEHMM* hmm );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvEstimateTransProb
-//    Purpose: function computes probabilities of appearing observations at any state
-//           ( i.e. compute P(obs|state) for every pair(obs,state) )
-//    Context:
-//    Parameters:  obs_info - observations structure
-//                 hmm      - hmm structure
-//
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvEstimateObsProb( CvImgObsInfo* obs_info,
-                                   CvEHMM* hmm );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvEViterbi  (Embedded Viterbi)
-//    Purpose: The function calculates the embedded Viterbi algorithm
-//    Context:
-//    Parameters:
-//                obs_info - observations structure
-//                hmm      - hmm structure
-//
-//    Returns: the Embedded Viterbi logarithmic probability.
-//             Observations, stored in of obs_info structure are segmented
-//           ( but new segmentation does not affect mixture segmentation or
-//               states parameters )
-//    Notes:
-//F*/
-OPENCVAPI  float  cvEViterbi( CvImgObsInfo* obs_info, CvEHMM* hmm );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvMixSegmL2
-//    Purpose: function clusters observation vectors from several images
-//             given observations segmentation.
-//             Euclidean distance used for clustering vectors.
-//             Centers of clusters are given means of every mixture
-//
-//    Context: in HMM face recognition used after Viterbi segmentation
-//    Parameters:  obs_info_array - array of pointers to observation structures
-//                 num_img  - length of above array
-//                 hmm      - hmm structure
-//
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvMixSegmL2( CvImgObsInfo** obs_info_array,
-                             int num_img, CvEHMM* hmm );
-
-/* end of HMM functions*/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name: KMeans
-//    Purpose: The function implements the K means algorithm, to cluster an array of sample
-//             vectors in a number of classes specified by numClusters
-//    Context:
-//    Parameters:  numClunster - the number of clusters
-//                 samples - the array of sample vectors
-//                 numSamples - the number of samples
-//                 VecSize - the size of each sample vector
-//                 termcrit.eps - the convergence error; the iterations to find the best cluster
-//                         centers will stop, when the value of the cost function at consecutive
-//                         iterations falls below this threshold
-//                 cluster - characteristic array. for every input vector indicates cluster
-//
-//    Returns: error code
-//
-//    Notes:
-//F*/
-OPENCVAPI  void  cvKMeans( int num_clusters, CvVect32f* samples, int num_samples,
-                          int vec_size, CvTermCriteria termcrit, int* cluster  );
-
-
-/****************************************************************************************\
-*                               Undistortion functions                                  *
-\****************************************************************************************/
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvUnDistortOnce
-//    Purpose: The function corrects radial and tangential image distortion using known
-//             matrix of the camera intrinsic parameters and distortion coefficients
-//    Context:
-//    Parameters:  srcImage    - source(distorted) image
-//                 dstImage    - output(undistorted) image
-//                 intrMatrix  - matrix of the camera intrinsic parameters
-//                 distCoeffs  - vector of the distortion coefficients(k1, k2, p1 and p2)
-//                 interpolate - interpolation flag (turned on by default)
-//F*/
-OPENCVAPI  void  cvUnDistortOnce( const CvArr* srcImage, CvArr* dstImage,
-                                  const float* intrMatrix,
-                                  const float* distCoeffs,
-                                  int interpolate CV_DEFAULT(1) );
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvUnDistortInit
-//    Purpose: The function calculates arrays of distorted points indices and
-//             interpolation coefficients for cvUnDistort function using known
-//             matrix of the camera intrinsic parameters and distortion coefficients
-//    Context:
-//    Parameters:  srcImage    - source(distorted) image
-//                 intrMatrix  - matrix of the camera intrinsic parameters
-//                 distCoeffs  - vector of the distortion coefficients(k1, k2, p1 and p2)
-//                 undistMap   - distortion data array (CV_32SC1)
-//                 interpolate - interpolation flag (turned on by default)
-//F*/
-OPENCVAPI  void  cvUnDistortInit( const CvArr* srcImage, CvArr* undistMap,
-                                  const float* intrMatrix,
-                                  const float* distCoeffs,
-                                  int interpolate CV_DEFAULT(1) );
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvUnDistort
-//    Purpose: The function corrects radial and tangential distortion in the frame
-//             using previousely calculated arrays of distorted points indices and
-//             undistortion coefficients. The function can be also used
-//             for arbitrary pre-calculated geometrical transformation.
-//             The function processes as following:
-//                 for (x,y) in dstImage:
-//                    dstImage(x,y) = srcImage[ undistMap(x,y) ].
-//    Context:
-//    Parameters:  srcImage  - source(distorted) image (width x height x 8uC1/8uC3)
-//                 dstImage  - output(undistorted) image (width x height x 8uC1/8uC3)
-//                 undistMap - distortion data array:
-//                                 (width x height x 32sC3) or
-//                                 (width*3 x height x 32sC1) if interpolation is enabled;
-//                                 (width x height x 32sC1) if interpolation is disabled;
-//                             This array can be calculated from camera
-//                             lens distortion parameters using cvUnDistortInit or
-//                             from arbitrary floating-point map using cvConvertMap
-//                 interpolate - interpolation flag (turned on by default)
-//F*/
-OPENCVAPI  void  cvUnDistort( const CvArr* srcImage, CvArr* dstImage,
-                              const CvArr* undistMap, int interpolate CV_DEFAULT(1));
-#define cvRemap cvUnDistort
-
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvConvertMap
-//    Purpose: The function converts floating-point pixel coordinate map to
-//             faster fixed-point map, used within cvUnDistort (cvRemap)
-//    Context:
-//    Parameters:  srcImage  - sample image which header parameters (step and datatype)
-//                             are used to prepare map.
-//                 flUndistMap - source map: (width x height x 32fC2) or
-//                                           (width*2 x height x 32fC1).
-//                               each pair are pixel coordinates (x,y) in a source image.
-//                 undistMap - resultant map: (width x height x 32sC3) or
-//                                 (width*3 x height x 32sC1) if interpolation is enabled;
-//                                 (width x height x 32sC1) if interpolation is disabled;
-//                 interpolate - interpolation flag (turned on by default)
-//F*/
-OPENCVAPI  void  cvConvertMap( const CvArr* srcImage, const CvArr* flUndistMap,
-                               CvArr* undistMap, int iterpolate CV_DEFAULT(1) );
-
-/****************************************************************************************\
-*                               Calibration functions                                   *
-\****************************************************************************************/
-OPENCVAPI  void  cvCalibrateCamera( int           numImages,
-                                    int*          numPoints,
-                                    CvSize        imageSize,
-                                    CvPoint2D32f* imagePoints32f,
-                                    CvPoint3D32f* objectPoints32f,
-                                    CvVect32f     distortion32f,
-                                    CvMatr32f     cameraMatrix32f,
-                                    CvVect32f     transVects32f,
-                                    CvMatr32f     rotMatrs32f,
-                                    int           useIntrinsicGuess);
-
-OPENCVAPI  void  cvCalibrateCamera_64d( int           numImages,
-                                       int*          numPoints,
-                                       CvSize        imageSize,
-                                       CvPoint2D64d* imagePoints,
-                                       CvPoint3D64d* objectPoints,
-                                       CvVect64d     distortion,
-                                       CvMatr64d     cameraMatrix,
-                                       CvVect64d     transVects,
-                                       CvMatr64d     rotMatrs,
-                                       int           useIntrinsicGuess );
-
-
-OPENCVAPI  void  cvFindExtrinsicCameraParams( int           numPoints,
-                                             CvSize        imageSize,
-                                             CvPoint2D32f* imagePoints32f,
-                                             CvPoint3D32f* objectPoints32f,
-                                             CvVect32f     focalLength32f,
-                                             CvPoint2D32f  principalPoint32f,
-                                             CvVect32f     distortion32f,
-                                             CvVect32f     rotVect32f,
-                                             CvVect32f     transVect32f);
-
-
-OPENCVAPI  void  cvFindExtrinsicCameraParams_64d( int           numPoints,
-                                                 CvSize        imageSize,
-                                                 CvPoint2D64d* imagePoints,
-                                                 CvPoint3D64d* objectPoints,
-                                                 CvVect64d     focalLength,
-                                                 CvPoint2D64d  principalPoint,
-                                                 CvVect64d     distortion,
-                                                 CvVect64d     rotVect,
-                                                 CvVect64d     transVect);
-
-
-/* Rodrigues transform */
-typedef enum CvRodriguesType
-{
-    CV_RODRIGUES_M2V = 0,
-    CV_RODRIGUES_V2M = 1
-}
-CvRodriguesType;
-
-OPENCVAPI  void  cvRodrigues( CvMat* rotMatrix, CvMat* rotVector,
-                              CvMat* jacobian, CvRodriguesType convType);
-
-OPENCVAPI  void  cvProjectPoints( int             numPoints,
-                                 CvPoint3D64d*   objectPoints,
-                                 CvVect64d       rotVect,
-                                 CvVect64d       transVect,
-                                 CvVect64d       focalLength,
-                                 CvPoint2D64d    principalPoint,
-                                 CvVect64d       distortion,
-                                 CvPoint2D64d*   imagePoints,
-                                 CvVect64d       derivPointsRot,
-                                 CvVect64d       derivPointsTrans,
-                                 CvVect64d       derivPointsFocal,
-                                 CvVect64d       derivPointsPrincipal,
-                                 CvVect64d       derivPointsDistort);
-
-OPENCVAPI void cvProjectPointsSimple(  int numPoints,
-                                    CvPoint3D64d * objectPoints,
-                                    CvVect64d rotMatr,
-                                    CvVect64d transVect,
-                                    CvMatr64d cameraMatrix,
-                                    CvVect64d distortion,
-                                    CvPoint2D64d* imagePoints);
-                                    
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    cvFindChessBoardCornerGuesses
-//    Purpose:
-//      Function finds first approximation of internal corners on the chess board.
-//    Context:
-//    Parameters:
-//      img      - source halftone image
-//      thresh   - temporary image where the thresholded source image will be stored.
-//      etalon_size - number of corners per each column and each row
-//      corners  - pointer to found points array
-//                 (must have at least etalon_size.width*etalon.height element).
-//      corner_count - number of found corners
-//    Returns:
-//
-//F*/
-OPENCVAPI  int  cvFindChessBoardCornerGuesses( const CvArr* array, CvArr* thresh,
-                                               CvMemStorage* storage, CvSize etalon_size,
-                                               CvPoint2D32f* corners,
-                                               int *corner_count CV_DEFAULT(0));
-
-
-/****************************************************************************************\
-*                                      POSIT(POse from ITeration)                       *
-\****************************************************************************************/
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCreatePOSITObject
-//    Purpose:    Allocate and Initialize CvPOSITObject structure
-//                before process cvPOSIT
-//    Context:
-//    Parameters:
-//                  points - pointer to source object points given in
-//                           object related coordinate system
-//                  numPoints - number of object points
-//                  ppObject - address of pointer to CvPOSITObject(returned)
-//    Returns:
-//    Notes:
-//F*/
-typedef struct CvPOSITObject CvPOSITObject;
-
-OPENCVAPI  CvPOSITObject*  cvCreatePOSITObject( CvPoint3D32f* points, int numPoints );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvPOSIT
-//    Purpose:    performs POSIT algorithm
-//
-//    Context:
-//    Parameters:
-//                  pObject - pointer to CvPOSITObject filled with prev. function
-//                  imagePoints - pointer to source object image points given in
-//                                camera related coordinate system
-//                  focalLength - focal length of camera
-//                  criteria - stop criteria.
-//                  rotation - rotation matrix
-//                  translation - translation vector(from camera to
-//                                first point of object )
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvPOSIT(  CvPOSITObject* pObject, CvPoint2D32f* imagePoints,
-                           double focalLength, CvTermCriteria criteria,
-                           CvMatr32f rotation, CvVect32f translation);
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvReleasePOSITObject
-//    Purpose:    free CvPOSITObject structure
-//    Context:
-//    Parameters:
-//      ppObject - address of pointer to CvPOSITObject
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvReleasePOSITObject( CvPOSITObject**  ppObject );
-
-
-/****************************************************************************************\
-*                                      ViewMorphing                                      *
-\****************************************************************************************/
-
-OPENCVAPI  void  cvFindFundamentalMatrix( int*       points1,
-                                        int*       points2,
-                                        int        numpoints,
-                                        int        method,
-                                        float* matrix );
-
-OPENCVAPI  void  cvMakeScanlines( const CvMatrix3* matrix,
-                                CvSize     imgSize,
-                                int*       scanlines_1,
-                                int*       scanlines_2,
-                                int*       lens_1,
-                                int*       lens_2,
-                                int*       numlines);
-
-OPENCVAPI  void  cvPreWarpImage( int       numLines,
-                               IplImage* img,
-                               uchar*    dst,
-                               int*      dst_nums,
-                               int*      scanlines);
-
-OPENCVAPI  void  cvFindRuns( int    numLines,
-                           uchar* prewarp_1,
-                           uchar* prewarp_2,
-                           int*   line_lens_1,
-                           int*   line_lens_2,
-                           int*   runs_1,
-                           int*   runs_2,
-                           int*   num_runs_1,
-                           int*   num_runs_2);
-
-OPENCVAPI  void  cvDynamicCorrespondMulti( int  lines,
-                                         int* first,
-                                         int* first_runs,
-                                         int* second,
-                                         int* second_runs,
-                                         int* first_corr,
-                                         int* second_corr);
-
-
-OPENCVAPI  void  cvMakeAlphaScanlines( int*  scanlines_1,
-                                     int*  scanlines_2,
-                                     int*  scanlines_a,
-                                     int*  lens,
-                                     int   numlines,
-                                     float alpha);
-
-OPENCVAPI  void  cvMorphEpilinesMulti( int    lines,
-                                     uchar* first_pix,
-                                     int*   first_num,
-                                     uchar* second_pix,
-                                     int*   second_num,
-                                     uchar* dst_pix,
-                                     int*   dst_num,
-                                     float  alpha,
-                                     int*   first,
-                                     int*   first_runs,
-                                     int*   second,
-                                     int*   second_runs,
-                                     int*   first_corr,
-                                     int*   second_corr);
-
-OPENCVAPI  void  cvDeleteMoire( IplImage*  img);
-
-OPENCVAPI  void  cvPostWarpImage( int       numLines,
-                                uchar*    src,
-                                int*      src_nums,
-                                IplImage* img,
-                                int*      scanlines);
-
-
-/****************************************************************************************\
-*                                      Matrix Functions                                  *
-\****************************************************************************************/
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvAdd
-//    Purpose:    Adds one array to another
-//    Context:
-//    Parameters:
-//      srcA - first source array
-//      srcB - second source array
-//      dst  - destination array: dst = srcA + srcB
-//      mask - optional mask
-//    Returns:
-//F*/
-OPENCVAPI  void  cvAdd( const CvArr* srcA, const CvArr* srcB, CvArr* dst,
-                        const CvArr* mask CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvAddS
-//    Purpose:    Adds array to scalar
-//    Context:
-//    Parameters:
-//      src  - source array
-//      value - added scalar
-//      dst  - destination array: dst = src + value
-//      mask - optional mask
-//    Returns:
-//F*/
-OPENCVAPI  void  cvAddS( const CvArr* src, CvScalar value, CvArr* dst,
-                         const CvArr* mask CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSub
-//    Purpose:    Subtracts one array from another
-//    Context:
-//    Parameters:
-//      srcA - first source array
-//      srcB - second source array 
-//      dst  - destination array: dst = srcA - srcB
-//    Returns:
-//F*/
-OPENCVAPI  void  cvSub( const CvArr* srcA, const CvArr* srcB, CvArr* dst,
-                        const CvArr* mask CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSubS
-//    Purpose:    Subtracts a scalar value from array
-//    Context:
-//    Parameters:
-//      src - source array
-//      value - subtracted scalar
-//      dst  - destination array: dst = src - value
-//      mask - optional mask
-//    Returns:
-//F*/
-CV_INLINE  void  cvSubS( const CvArr* src, CvScalar value, CvArr* dst,
-                         const CvArr* mask CV_DEFAULT(0));
-CV_INLINE  void  cvSubS( const CvArr* src, CvScalar value, CvArr* dst,
-                         const CvArr* mask )
-{
-    cvAddS( src, cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]),
-            dst, mask );
-}
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSubRS
-//    Purpose:    Subtracts a scalar value from array
-//    Context:
-//    Parameters:
-//      src - source array
-//      value - scalar to subtract from
-//      dst  - destination array: dst = value - src
-//      mask - optional mask
-//    Returns:
-//F*/
-OPENCVAPI  void  cvSubRS( const CvArr* src, CvScalar value, CvArr* dst,
-                          const CvArr* mask CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvMul
-//    Purpose:    Multiplies two arrays
-//    Context:
-//    Parameters:
-//      srcA - first source array
-//      srcB - second source array
-//      dst  - destination array: dst(x,y) = srcA(x,y) * srcB(x,y)
-//    Returns:
-//F*/
-OPENCVAPI  void  cvMul( const CvArr* srcA, const CvArr* srcB, CvArr* dst);
-
-/* dst(idx) = lower(idx) <= src(idx) < upper(idx) */
-OPENCVAPI void cvInRange( const CvArr* src, const CvArr* lower,
-                          const CvArr* upper, CvArr* dst );
-
-/* dst(idx) = lower <= src(idx) < upper */
-OPENCVAPI void cvInRangeS( const CvArr* src, CvScalar lower,
-                           CvScalar upper, CvArr* dst );
-
-/****************************************************************************************\
-*                                      Logic Operations                                  *
-\****************************************************************************************/
-
-/* dst(idx) = src1(idx) & src2(idx) */
-OPENCVAPI void cvAnd( const CvArr* src1, const CvArr* src2,
-                      CvArr* dst, const CvArr* mask CV_DEFAULT(0));
-
-/* dst(idx) = src(idx) & value */
-OPENCVAPI void cvAndS( const CvArr* src, CvScalar value,
-                       CvArr* dst, const CvArr* mask CV_DEFAULT(0));
-
-/* dst(idx) = src1(idx) | src2(idx) */
-OPENCVAPI void cvOr( const CvArr* src1, const CvArr* src2,
-                     CvArr* dst, const CvArr* mask CV_DEFAULT(0));
-
-/* dst(idx) = src(idx) | value */
-OPENCVAPI void cvOrS( const CvArr* src, CvScalar value,
-                      CvArr* dst, const CvArr* mask CV_DEFAULT(0));
-
-/* dst(idx) = src1(idx) ^ src2(idx) */
-OPENCVAPI void cvXor( const CvArr* src1, const CvArr* src2,
-                      CvArr* dst, const CvArr* mask CV_DEFAULT(0));
-
-/* dst(idx) = src(idx) ^ value */
-OPENCVAPI void cvXorS( const CvArr* src, CvScalar value,
-                       CvArr* dst, const CvArr* mask CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvScaleAdd
-//    Purpose:    Multiplies all array elements by a scalar value and
-//                adds another scalar to the scaled array
-//    Context:
-//    Parameters:
-//      src - source array
-//      scale - scale factor
-//      delta - shift value
-//      dst - destination array
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvScaleAdd( const CvArr* src1, CvScalar scale,
-                             const CvArr* src2, CvArr* dst );
-#define cvMulAddS cvScaleAdd
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvDotProduct
-//    Purpose:    Evaluates dot product of two vectors
-//    Context:
-//    Parameters:
-//      srcA - first source array
-//      srcB - second source array
-//
-//    Returns:
-//      Dot product of srcA and srcB:  sum(srcA(i,j)*srcB(i,j))
-//                                     i,j
-//F*/
-OPENCVAPI  double  cvDotProduct( const CvArr* srcA, const CvArr* srcB );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvCrossProduct
-//    Purpose:    Evaluates cross product of two 3d vectors
-//    Context:
-//    Parameters: srcA - first source vector
-//                srcB - second source vector
-//                dst  - destination vector
-//    Returns:
-//
-//F*/
-OPENCVAPI  void  cvCrossProduct( const CvArr* srcA, const CvArr* srcB, CvArr* dst );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvMatMulAdd
-//    Purpose:    Evaluates product of two matrices and
-//                adds the third matrix to the product
-//    Context:
-//    Parameters:
-//      srcA - first source matrix
-//      srcB - second source matrix
-//      srcC - added matrix
-//      dst  - destination matrix
-//    Returns:
-//
-//F*/
-OPENCVAPI  void  cvMatMulAdd( const CvArr* srcA, const CvArr* srcB,
-                              const CvArr* srcC, CvArr* dst );
-#define cvMatMul( srcA, srcB, dst )  cvMatMulAdd( (srcA), (srcB), 0, (dst))
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvMatMulAddS
-//    Purpose:    Performs matrix transformation for every vector of the source array
-//    Context:
-//    Parameters:
-//      srcr - source array
-//      dst  - destination array
-//      transform - transformation matrix
-//      shiftvec - optional shift (may be encoded in the matrix as well)
-//    Returns:
-//
-//F*/
-OPENCVAPI  void  cvMatMulAddS( const CvArr* src, CvArr* dst,
-                               const CvArr* transform,
-                               const CvArr* shiftvec CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvMulTransposed
-//    Purpose:    Evaluates product of matix by itself transposed
-//    Context:
-//    Parameters:
-//      srcarr - the source matrix
-//      dstarr - the destination matrix
-//      order - determines the order of multiplication
-//              if order = 0, function evaluates A*At
-//              if order = 1, function evaluates At*A
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI void cvMulTransposed( const CvArr* srcarr,
-                                CvArr* dstarr, int order );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvTranspose
-//    Purpose:    Transposes matrix
-//    Context:
-//    Parameters:
-//      src - source matrix
-//      dst - destination matrix
-//    Returns:
-//    Notes:
-//      square matrices can be transposed in-place.
-//F*/
-OPENCVAPI  void  cvTranspose( const CvArr* src, CvArr* dst );
-#define cvT cvTranspose
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvFlip
-//    Purpose:    Mirrors the matrix around vertical or horizontal axis
-//    Context:
-//    Parameters:
-//      src - source matrix
-//      dst - destination matrix
-//      flipAxis - 0: horizontal axis
-//                 1: vertical axis
-//                -1: both axis
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvFlip( const CvArr* src, CvArr* dst, int flip_mode );
-#define cvMirror cvFlip
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvInvert
-//    Purpose:    Inverts Matrix using LU decomposition
-//    Context:
-//    Parameters:
-//      src - source matrix
-//      dst - destination matrix
-//    Returns:
-//      1 if the matrix inverted and 0 if it is a singular (or very close to it)
-//    Notes:
-//F*/
-OPENCVAPI  int  cvInvert( const CvArr* src, CvArr* dst );
-#define cvInv cvInvert
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSolve
-//    Purpose:    Solves linear system Ax = b using LU decomposition
-//    Context:
-//    Parameters:
-//      A - the matrix
-//      b - the "right side" of the system
-//      x - destination array (solution of the system)
-//    Returns:
-//      1 if the system is solved and 0 if the matrix is a singular (or very close to it)
-//    Notes:
-//F*/
-OPENCVAPI  int  cvSolve( const CvArr* A, const CvArr* b, CvArr* x );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvDet
-//    Purpose:    Calculates determinant of the matrix
-//    Context:
-//    Parameters:
-//      mat - source matrix
-//    Returns:
-//      Matrix determinant
-//    Notes:
-//F*/
-OPENCVAPI  double cvDet( const CvArr* mat );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvTrace
-//    Purpose:    Calculates trace of the matrix (sum of elements on the main diagonal) 
-//    Context:
-//    Parameters:
-//      mat - source matrix
-//    Returns:
-//      Matrix determinant
-//    Notes:
-//F*/
-OPENCVAPI  CvScalar cvTrace( const CvArr* mat );
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSVD
-//    Purpose:    Calculates Singular Value Decomposition for the input matrix: 
-//       A = U W V',   U & V are orthogonal, W is diagonal matrix that can be
-//                     either real matrix (the same size as A) or a vector of
-//                     size min(A->rows,A->cols).
-//       U & V are optional,
-//       flags:  0th bit, reset to 0, means that A is copyied before processing,
-//                        otherwise it is modified during the processing, which is
-//                        faster.
-//               1st bit, reset to 0, means that U is returned normal, otherwise it
-//                        is returned transposed, which is faster.
-//               2nd bit, reset to 0, means that V is returned normal, otherwise it
-//                        is returned transposed, which is faster.
-//F*/
-#define CV_SVD_MODIFY_A   1
-#define CV_SVD_U_T        2
-#define CV_SVD_V_T        4
-
-OPENCVAPI  void   cvSVD( CvArr* A, CvArr* W CV_DEFAULT(0),
-                         CvArr* U CV_DEFAULT(0),
-                         CvArr* V CV_DEFAULT(0),
-                         int flag CV_DEFAULT(0));
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvPseudoInv
-//    Purpose:    Calculates inverse or pseudo-inverse matrix for the input matrix.
-//       if A is (m x n) matrix, B will be (n x m) matrix, such that
-//       AB = I(m x m), BA = I(n x n).
-//
-//       flags:  0th bit, reset to 0, means that A is copyied before processing,
-//                        otherwise it is modified during the processing, which is
-//                        faster.
-//    Return value:
-//       The function returns condition number or DBL_MAX if the matrix is signular.
-//F*/
-OPENCVAPI  double  cvPseudoInverse( CvArr* A, CvArr* B,
-                                    int flags CV_DEFAULT(0));
-#define cvPseudoInv cvPseudoInverse
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvEigenVV
-//    Purpose:    Finds eigenvalues & eigenvectors of a symmetric matrix:
-//    Context:
-//    Parameters:
-//      src - source symmetric matrix,
-//      evects - matrix of its eigenvectors
-//               (i-th row is an i-th eigenvector),
-//      evals - vector of its eigenvalues
-//              (i-th element is an i-th eigenvalue),
-//      eps - accuracy of diagonalization.
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvEigenVV( CvArr* src, CvArr* evects, CvArr* evals, double eps );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSetZero
-//    Purpose:    Clears all the matrix elements (sets them to 0)
-//    Context:
-//    Parameters: mat  - matrix
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvSetZero( CvArr* mat );
-#define cvZero  cvSetZero
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvSetIdentity
-//    Purpose:    Fills identity matrix
-//    Context:
-//    Parameters:
-//      mat - matrix
-//    Returns:
-//    Notes:
-//F*/
-OPENCVAPI  void  cvSetIdentity( CvArr* mat );
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvMahalanobis
-//    Purpose:    Calculates Mahalanobis(weighted) distance.
-//    Context:
-//    Parameters:
-//      srcA - first source vector
-//      srcB - second source vector
-//      matr - covariance matrix
-//    Returns:
-//      Mahalanobis distance
-//    Notes:
-//F*/
-OPENCVAPI  double  cvMahalanobis( const CvArr* srcA, const CvArr* srcB, CvArr* mat );
-#define cvMahalonobis  cvMahalanobis
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:       cvPerspectiveTransform
-//    Purpose:    Applies perspective transform to the array of vectors
-//    Context:
-//    Parameters: mat - matrix
-//                src - source array
-//                dst - destination array
-//    Returns:
-//    Notes:
-//F*/
-
-OPENCVAPI  void  cvPerspectiveTransform( const CvArr* src, CvArr* dst, const CvArr* mat );
-
-/****************************************************************************************\
-*                    CONditional DENsity PropogaTION tracking                            *
-\****************************************************************************************/
-
-typedef struct 
-{
-    int MP;
-    int DP;
-    float* DynamMatr;       /* Matrix of the linear Dynamics system  */
-    float* State;           /* Vector of State                       */
-    int SamplesNum;         /* Number of the Samples                 */
-    float** flSamples;      /* array of the Sample Vectors           */
-    float** flNewSamples;   /* temporary array of the Sample Vectors */
-    float* flConfidence;    /* Confidence for each Sample            */
-    float* flCumulative;    /* Cumulative confidence                 */
-    float* Temp;            /* Temporary vector                      */
-    float* RandomSample;    /* RandomVector to update sample set     */
-    CvRandState* RandS;     /* Array of structures to generate random vectors */
-
-} CvConDensation;
-
-OPENCVAPI CvConDensation*  cvCreateConDensation( int DP, int MP, int SamplesNum);
-OPENCVAPI void  cvReleaseConDensation( CvConDensation** ConDensation);
-OPENCVAPI void  cvConDensUpdateByTime( CvConDensation* ConDens);
-OPENCVAPI void  cvConDensInitSampleSet( CvConDensation* conDens, CvMat* lowerBound,CvMat* upperBound);
-
-/****************************************************************************************\
-*                                      Kalman Filtering                                  *
-\****************************************************************************************/
-
-typedef struct 
-{
-    int MP;
-    int DP;
-    float* PosterState;          /* Vector of State of the System in k-th step  */
-    float* PriorState;           /* Vector of State of the System in (k-1)-th step */
-    float* DynamMatr;            /* Matrix of the linear Dynamics system */
-                                 /* (Must be updated by LinearizedDynamics function on each step*/
-                                 /*  for nonlinear systems)*/
-    float* MeasurementMatr;      /* Matrix of linear measurement (Must be updated by */
-                                 /* LinearizedMeasurement function on each step*/
-                                 /* for nonlinear measurements)*/
-    float* MNCovariance;         /* Matrix of measurement noice covariance*/
-                                 /* Initializes to Zero matrix, or sets by SetMeasureNoiseCov*/
-                                 /* method  */
-    float* PNCovariance;         /* Matrix of process noice covariance*/
-                                 /* Initializes to Identity matrix, or sets by SetProcessNoiseCov*/
-                                 /* method */
-    float* KalmGainMatr;         /* Kalman Gain Matrix*/
-    float* PriorErrorCovariance; /*Prior Error Covariance matrix*/
-    float* PosterErrorCovariance;/*Poster Error Covariance matrix*/
-    float* Temp1;                 /* Temporary Matrix */
-    float* Temp2;
-
-} CvKalman;
-
-OPENCVAPI CvKalman* cvCreateKalman( int DynamParams, int MeasureParams);
-OPENCVAPI void  cvReleaseKalman( CvKalman** Kalman);
-OPENCVAPI void  cvKalmanUpdateByTime( CvKalman* Kalman);
-OPENCVAPI void  cvKalmanUpdateByMeasurement( CvKalman* Kalman, CvMat* Measurement);
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvLoadPrimitives
-//    Purpose: The function loads primitives
-//    Context:
-//    Parameters:  dllName        - name of dll to be loaded(without prefix) or NULL
-//                                  for default dll
-//                 processor_type - needep processor type or NULL for automatic processor
-//                                  detection
-//    Return value: number of loaded functions
-//    Notes:   full dll name is consists from dllName + processor_type.dll(or
-//             dllName + processor_type + "d".dll for debug configuration)
-//F*/
-OPENCVAPI  int  cvLoadPrimitives( const char* proc_type CV_DEFAULT(0) );
-OPENCVAPI  int  cvFillInternalFuncsTable(void* table);
-
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvAlloc and cvFree
-//    Purpose: The functions allocate/deallocate plain memory buffers
-//F*/
-OPENCVAPI  void*  cvAlloc( int size );
-OPENCVAPI  void   cvFree( void** ptr );
-
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvGetLibraryInfo
-//    Purpose: The function returns information about current version of library and
-//             loaded/non loaded primitives dll
-//    Context:
-//    Parameters:  version  - pointer to pointer to version of OpenCV - build date
-//                           (or NULL if not needed)
-//                 loaded   - pointer to flag of loaded primitives, nonzero value
-//                            after returning from function indicates that primitives
-//                            are loaded(NULL if not needed)
-//                 loaded_modules - comma-separated list of loaded optimized dlls
-//                           (NULL if not needed)
-//
-//    Notes:   
-//F*/
-OPENCVAPI  void  cvGetLibraryInfo( const char** version, int* loaded,
-                                   const char** loaded_modules );
-
-/* **************************** Error handling ************************* */
-
-/* /////////////////////////////////////////////////////////////////////////
-// Name:       cvGetErrStatus
-// Purpose:    Gets last error status
-// Returns:
-// Parameters:
-//
-// Notes:
-*/
-OPENCVAPI CVStatus cvGetErrStatus( void );
-
-/* /////////////////////////////////////////////////////////////////////////
-// Name:       cvSetErrStatus
-// Purpose:    Sets error status
-// Returns:
-// Parameters:
-//
-// Notes:
-*/
-OPENCVAPI void cvSetErrStatus( CVStatus status );
-
-
-/* /////////////////////////////////////////////////////////////////////////
-// Name:       cvGetErrMode, cvSetErrMode
-// Purpose:    gets/sets error mode
-// Returns:
-// Parameters:
-//
-// Notes:
-*/
-OPENCVAPI int  cvGetErrMode( void );
-OPENCVAPI void cvSetErrMode( int mode );
-
-/* /////////////////////////////////////////////////////////////////////////
-// Name:       cvError
-// Purpose:    performs basic error handling
-// Returns:    last status
-// Parameters:
-//
-// Notes:
-*/
-
-OPENCVAPI CVStatus cvError( CVStatus code, const char *func,
-                         const char *context, const char *file, int line);
-
-/* /////////////////////////////////////////////////////////////////////////
-// Name:       cvErrorStr
-// Purpose:    translates an error status code into a textual description
-// Returns:
-// Parameters:
-//
-// Notes:
-*/
-OPENCVAPI const char* cvErrorStr( CVStatus status );
-
-
-/* /////////////////////////////////////////////////////////////////////////
-// Name:       cvRedirectError
-// Purpose:    assigns a new error-handling function
-// Returns:    old error-handling function
-// Parameters: new error-handling function
-//
-// Notes:
-*/
-
-OPENCVAPI CVErrorCallBack cvRedirectError(CVErrorCallBack cvErrorFunc);
-
-
-/*-----------------  Predefined error-handling functions  -----------------*/
-
-/*
-    Output to:
-        cvNulDevReport - nothing
-        cvStdErrReport - console(printf)
-        cvGuiBoxReport - MessageBox(WIN32)
-*/
-OPENCVAPI CVStatus cvNulDevReport( CVStatus status, const char *funcName,
-                                const char *context, const char *file, int line );
-
-OPENCVAPI CVStatus cvStdErrReport( CVStatus status, const char *funcName,
-                                const char *context, const char *file, int line );
-
-OPENCVAPI CVStatus cvGuiBoxReport( CVStatus status, const char *funcName,
-                                const char *context, const char *file, int line);
-
-OPENCVAPI void cvGetCallStack(CvStackRecord** stack, int* size);
-
-OPENCVAPI void cvStartProfile( const char* call, const char* file, int line );
-OPENCVAPI void cvEndProfile( const char* file, int line );
-
-/* management functions */
-OPENCVAPI void cvSetProfile( void (CV_CDECL *startprofile_f)(const char*, const char*, int),
-                          void (CV_CDECL *endprofile_f)(const char*, int) ); 
-OPENCVAPI void cvRemoveProfile();                  
-
-OPENCVAPI void cvSetMemoryManager( void* (CV_STDCALL *allocFunc)(int, const char*, int) CV_DEFAULT(0),
-                           int (CV_STDCALL *freeFunc)(void**, const char*, int) CV_DEFAULT(0));
-
-OPENCVAPI void cvGetCallStack(CvStackRecord** stack, int* size);
-
-
-
-CV_EXTERN_C_FUNCPTR(IplImage* (CV_STDCALL* Cv_iplCreateImageHeader)
-                            (int,int,int,char*,char*,int,int,int,int,int,
-                            IplROI*,IplImage*,void*,IplTileInfo*));
-CV_EXTERN_C_FUNCPTR(void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int));
-
-CV_EXTERN_C_FUNCPTR(void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int));
-
-CV_EXTERN_C_FUNCPTR(IplROI* (CV_STDCALL* Cv_iplCreateROI)(int,int,int,int,int));
-
-CV_EXTERN_C_FUNCPTR(IplImage* (CV_STDCALL* Cv_iplCloneImage)(const IplImage*));
-
-
-/* //////////////////////////////////////////////////////////////////////////////////
-// Name:    cvSetIPLAllocators
-// Purpose:  Makes OpenCV to use IPL functions for image allocation/deallocation
-// Returns:
-// Parameters:
-//
-// Notes:
-*/
-OPENCVAPI void
-cvSetIPLAllocators( Cv_iplCreateImageHeader createHeader,
-                    Cv_iplAllocateImageData allocateData,
-                    Cv_iplDeallocate deallocate,
-                    Cv_iplCreateROI createROI,
-                    Cv_iplCloneImage cloneImage );
-
-#define CV_TURN_ON_IPL_COMPATIBILITY()                                  \
-    cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImageData,     \
-                        iplDeallocate, iplCreateROI, iplCloneImage )
-
-/****************************************************************************************\
-*                                 Backward compatibility                                 *
-\****************************************************************************************/
-
-#ifndef _CV_NO_BACKWARD_COMPATIBILITY
-#include "cvcompat.h"
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_CV_H_*/
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+\r
+#ifndef _CV_H_\r
+#define _CV_H_\r
+\r
+#ifdef __IPL_H__\r
+#define HAVE_IPL /* On Windows IPL is needed by default */\r
+#endif\r
+\r
+#if defined(_CH_)\r
+#include <dlfcn.h>\r
+void *_ChCv_handle = _dlopen("libcv.dl", RTLD_LAZY);\r
+if(_ChCv_handle == NULL) {\r
+   fprintf(_stderr, "Error: dlopen(): %s\n", dlerror());\r
+   fprintf(_stderr, "       cannot get _ChCv_handle in cv.h\n");\r
+   exit(-1);\r
+} \r
+void _dlclose_libcv(void) {\r
+  dlclose(_ChCv_handle);\r
+}\r
+_atexit(_dlclose_libcv);\r
+#endif\r
+\r
+\r
+#ifdef HAVE_IPL\r
+#ifndef _INC_WINDOWS\r
+    #define CV_PRETEND_WINDOWS\r
+    #define _INC_WINDOWS\r
+    typedef struct tagBITMAPINFOHEADER BITMAPINFOHEADER;\r
+    typedef int BOOL;\r
+#endif\r
+#include "ipl.h"\r
+#ifdef CV_PRETEND_WINDOWS\r
+    #undef _INC_WINDOWS\r
+#endif\r
+#endif\r
+\r
+#include "cvtypes.h"\r
+#include "cverror.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/****************************************************************************************\\r
+*                                     Allocation/deallocation                            *\r
+\****************************************************************************************/\r
+\r
+/* <malloc> wrapper.\r
+   If there is no enough memory the function\r
+   (as well as other OpenCV functions that call cvAlloc)\r
+   raises an error. */\r
+OPENCVAPI  void*  cvAlloc( int size );\r
+\r
+/* <free> wrapper.\r
+   Here and further all the memory releasing functions\r
+   (that all call cvFree) take double pointer which is used\r
+   to clear user pointer to the data after releasing it.\r
+   Passing pointer to NULL pointer is Ok: nothing happens in this case\r
+*/\r
+OPENCVAPI  void   cvFree( void** ptr );\r
+\r
+/* Allocates and initializes IplImage header */\r
+OPENCVAPI  IplImage*  cvCreateImageHeader( CvSize size, int depth, int channels );\r
+\r
+/* Inializes IplImage header */\r
+OPENCVAPI IplImage* cvInitImageHeader( IplImage* image, CvSize size, int depth,\r
+                                       int channels, int origin CV_DEFAULT(0),\r
+                                       int align CV_DEFAULT(4));\r
+\r
+/* Creates IPL image (header and data) */\r
+OPENCVAPI  IplImage*  cvCreateImage( CvSize size, int depth, int channels );\r
+\r
+/* Releases (i.e. deallocates) IPL image header */\r
+OPENCVAPI  void  cvReleaseImageHeader( IplImage** image );\r
+\r
+/* Releases IPL image header and data */\r
+OPENCVAPI  void  cvReleaseImage( IplImage** image );\r
+\r
+/* Creates a copy of IPL image (widthStep may differ) */\r
+OPENCVAPI IplImage* cvCloneImage( const IplImage* image );\r
+\r
+/* Sets a Channel Of Interest (only a few functions support COI) - \r
+   use cvCopy to extract the selected channel and/or put it back */\r
+OPENCVAPI  void  cvSetImageCOI( IplImage* image, int coi );\r
+\r
+/* Retrieves image Channel Of Interest */\r
+OPENCVAPI  int  cvGetImageCOI( IplImage* image );\r
+\r
+/* Sets image ROI (region of interest) (COI is not changed) */\r
+OPENCVAPI  void  cvSetImageROI( IplImage* image, CvRect rect );\r
+\r
+/* Resets image ROI and COI */\r
+OPENCVAPI  void  cvResetImageROI( IplImage* image );\r
+\r
+/* Retrieves image ROI */\r
+OPENCVAPI  CvRect cvGetImageROI( const IplImage* image );\r
+\r
+/* Allocates and initalizes CvMat header */\r
+OPENCVAPI  CvMat*  cvCreateMatHeader( int rows, int cols, int type );\r
+\r
+#define CV_AUTOSTEP  0x7fffffff\r
+\r
+/* Initializes CvMat header */\r
+OPENCVAPI CvMat* cvInitMatHeader( CvMat* mat, int rows, int cols,\r
+                                  int type, void* data CV_DEFAULT(NULL),\r
+                                  int step CV_DEFAULT(CV_AUTOSTEP) );\r
+\r
+/* Allocates and initializes CvMat header and allocates data */\r
+OPENCVAPI  CvMat*  cvCreateMat( int rows, int cols, int type );\r
+\r
+/* Releases CvMat header and deallocates matrix data\r
+   (reference counting is used for data) */\r
+OPENCVAPI  void  cvReleaseMat( CvMat** mat );\r
+\r
+/* Decrements CvMat data reference counter and deallocates the data if\r
+   it reaches 0 */\r
+CV_INLINE  void  cvDecRefData( CvArr* arr );\r
+CV_INLINE  void  cvDecRefData( CvArr* arr )\r
+{\r
+    if( CV_IS_MAT( arr ) || CV_IS_MATND( arr ))\r
+    {\r
+        CvMat* mat = (CvMat*)arr; /* the first few fields of CvMat and CvMatND are the same */\r
+        mat->data.ptr = NULL;\r
+        if( mat->refcount != NULL && --*mat->refcount == 0 )\r
+        {\r
+            uchar* data = (uchar*)mat->refcount + 2*sizeof(mat->refcount);\r
+            cvFree( (void**)&data );\r
+        }\r
+        mat->refcount = NULL;\r
+    }\r
+}\r
+\r
+/* Increments CvMat data reference counter */\r
+CV_INLINE  int  cvIncRefData( CvArr* arr );\r
+CV_INLINE  int  cvIncRefData( CvArr* arr )\r
+{\r
+    int refcount = 0;\r
+    if( CV_IS_MAT( arr ) || CV_IS_MATND( arr ))\r
+    {\r
+        CvMat* mat = (CvMat*)arr;\r
+        if( mat->refcount != NULL )\r
+            refcount = ++*mat->refcount;\r
+    }\r
+    return refcount;\r
+}\r
+\r
+\r
+/* Creates an exact copy of the input matrix (except, may be, step value) */\r
+OPENCVAPI CvMat* cvCloneMat( const CvMat* mat );\r
+\r
+\r
+/* Makes a new matrix from <rect> subrectangle of input array.\r
+   No data is copied */\r
+OPENCVAPI CvMat* cvGetSubRect( const CvArr* arr, CvMat* submat, CvRect rect );\r
+#define cvGetSubArr cvGetSubRect\r
+\r
+/* Partial case of the cvGetSubArr:\r
+    row span of the input array is selected\r
+    (end_row is not included into the span). */\r
+OPENCVAPI CvMat* cvGetRows( const CvArr* arr, CvMat* submat,\r
+                            int start_row, int end_row );\r
+\r
+CV_INLINE  void  cvGetRow( const CvArr* arr, CvMat* submat, int row );\r
+CV_INLINE  void  cvGetRow( const CvArr* arr, CvMat* submat, int row )\r
+{\r
+    cvGetRows( arr, submat, row, row + 1 );\r
+}\r
+\r
+\r
+/* Partial case of the cvGetSubArr:\r
+    column span of the input array is selected\r
+    (end_col is not included into the span) */\r
+OPENCVAPI CvMat* cvGetCols( const CvArr* arr, CvMat* submat,\r
+                               int start_col, int end_col );\r
+\r
+CV_INLINE  void  cvGetCol( const CvArr* arr, CvMat* submat, int col );\r
+CV_INLINE  void  cvGetCol( const CvArr* arr, CvMat* submat, int col )\r
+{\r
+    cvGetCols( arr, submat, col, col + 1 );\r
+}\r
+\r
+/* Partial case of the cvGetSubArr:\r
+    a single diagonal of the input array is selected\r
+   (diag = 0 means main diagonal, >0 means some diagonal above the main one,\r
+   <0 - below the main one).\r
+   The diagonal will be represented as a column (nx1 matrix). */\r
+OPENCVAPI CvMat* cvGetDiag( const CvArr* arr, CvMat* submat,\r
+                            int diag CV_DEFAULT(0));\r
+\r
+/* low-level scalar <-> raw data conversion functions */\r
+OPENCVAPI void cvScalarToRawData( const CvScalar* scalar, void* data, int type,\r
+                                  int extend_to_12 CV_DEFAULT(0) );\r
+\r
+OPENCVAPI void cvRawDataToScalar( const void* data, int type, CvScalar* scalar );\r
+\r
+/* Allocates and initializes CvMatND header */\r
+OPENCVAPI  CvMatND*  cvCreateMatNDHeader( int dims, const int* sizes, int type );\r
+\r
+/* Allocates and initializes CvMatND header and allocates data */\r
+OPENCVAPI  CvMatND*  cvCreateMatND( int dims, const int* sizes, int type );\r
+\r
+/* Initializes preallocated CvMatND header */\r
+OPENCVAPI  CvMatND*  cvInitMatNDHeader( CvMatND* mat, int dims, const int* sizes,\r
+                                        int type, void* data CV_DEFAULT(NULL) );\r
+\r
+/* Releases CvMatND */\r
+CV_INLINE  void  cvReleaseMatND( CvMatND** mat );\r
+CV_INLINE  void  cvReleaseMatND( CvMatND** mat )\r
+{\r
+    cvReleaseMat( (CvMat**)mat );\r
+}\r
+\r
+/* Creates a copy of CvMatND (except, may be, steps) */\r
+OPENCVAPI  CvMatND* cvCloneMatND( const CvMatND* mat );\r
+\r
+/* Allocates and initializes CvSparseMat header and allocates data */\r
+OPENCVAPI  CvSparseMat*  cvCreateSparseMat( int dims, const int* sizes, int type );\r
+\r
+/* Releases CvSparseMat */\r
+OPENCVAPI  void  cvReleaseSparseMat( CvSparseMat** mat );\r
+\r
+/* Creates a copy of CvSparseMat (except, may be, zero items) */\r
+OPENCVAPI  CvSparseMat* cvCloneSparseMat( const CvSparseMat* mat );\r
+\r
+/* Initializes sparse array iterator\r
+   (returns the first node or NULL if the array is empty) */\r
+OPENCVAPI  CvSparseNode* cvInitSparseMatIterator( const CvSparseMat* mat,\r
+                                                  CvSparseMatIterator* matIterator );\r
+\r
+// returns next sparse array node (or NULL if there is no more nodes)\r
+CV_INLINE CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* matIterator );\r
+CV_INLINE CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* matIterator )\r
+{\r
+    if( matIterator->node->next )\r
+        return matIterator->node = matIterator->node->next;\r
+    else\r
+    {\r
+        int idx;\r
+        for( idx = ++matIterator->curidx; idx < matIterator->mat->hashsize; idx++ )\r
+        {\r
+            CvSparseNode* node = (CvSparseNode*)matIterator->mat->hashtable[idx];\r
+            if( node )\r
+            {\r
+                matIterator->curidx = idx;\r
+                return matIterator->node = node;\r
+            }\r
+        }\r
+        return NULL;\r
+    }\r
+}\r
+\r
+/* Returns type of array elements:\r
+   CV_8UC1 ... CV_64FC4 ... */\r
+OPENCVAPI  int cvGetElemType( const CvArr* arr );\r
+\r
+/* Retrieves number of an array dimensions and\r
+   optionally sizes of the dimensions */\r
+OPENCVAPI  int cvGetDims( const CvArr* arr, int* sizes CV_DEFAULT(NULL) );\r
+\r
+\r
+/* Retrieves size of a particular array dimension.\r
+   For 2d arrays cvGetDimSize(arr,0) returns number of rows (image height)\r
+   and cvGetDimSize(arr,1) returns number of columns (image width) */\r
+OPENCVAPI  int cvGetDimSize( const CvArr* arr, int index );\r
+\r
+\r
+/* ptr = &arr(idx1,idx2,...). All indexes are zero-based,\r
+   the major dimensions go first (e.g. (y,x) for 2D, (z,y,x) for 3D */\r
+OPENCVAPI uchar* cvPtr1D( const CvArr* arr, int idx1, int* type CV_DEFAULT(NULL));\r
+OPENCVAPI uchar* cvPtr2D( const CvArr* arr, int idx1, int idx2, int* type CV_DEFAULT(NULL) );\r
+OPENCVAPI uchar* cvPtr3D( const CvArr* arr, int idx1, int idx2, int idx3,\r
+                          int* type CV_DEFAULT(NULL));\r
+\r
+/* For CvMat or IplImage number of indices should be 2\r
+   (row index (y) goes first, column index (x) goes next).\r
+   For CvMatND or CvSparseMat number of infices should match number of <dims> and\r
+   indices order should match the array dimension order. */\r
+OPENCVAPI uchar* cvPtrND( const CvArr* arr, int* idx, int* type CV_DEFAULT(NULL) );\r
+\r
+/* value = arr(idx1,idx2,...) */\r
+OPENCVAPI CvScalar cvGet1D( const CvArr* arr, int idx1 );\r
+OPENCVAPI CvScalar cvGet2D( const CvArr* arr, int idx1, int idx2 );\r
+OPENCVAPI CvScalar cvGet3D( const CvArr* arr, int idx1, int idx2, int idx3 );\r
+OPENCVAPI CvScalar cvGetND( const CvArr* arr, int* idx );\r
+\r
+/* for 1-channel arrays */\r
+OPENCVAPI double cvGetReal1D( const CvArr* arr, int idx1 );\r
+OPENCVAPI double cvGetReal2D( const CvArr* arr, int idx1, int idx2 );\r
+OPENCVAPI double cvGetReal3D( const CvArr* arr, int idx1, int idx2, int idx3 );\r
+OPENCVAPI double cvGetRealND( const CvArr* arr, int* idx );\r
+\r
+/* arr(idx1,idx2,...) = value */\r
+OPENCVAPI void cvSet1D( CvArr* arr, int idx1, CvScalar value );\r
+OPENCVAPI void cvSet2D( CvArr* arr, int idx1, int idx2, CvScalar value );\r
+OPENCVAPI void cvSet3D( CvArr* arr, int idx1, int idx2, int idx3, CvScalar value );\r
+OPENCVAPI void cvSetND( CvArr* arr, int* idx, CvScalar value );\r
+\r
+/* for 1-channel arrays */\r
+OPENCVAPI void cvSetReal1D( CvArr* arr, int idx1, double value );\r
+OPENCVAPI void cvSetReal2D( CvArr* arr, int idx1, int idx2, double value );\r
+OPENCVAPI void cvSetReal3D( CvArr* arr, int idx1,\r
+                            int idx2, int idx3, double value );\r
+OPENCVAPI void cvSetRealND( CvArr* arr, int* idx, double value );\r
+\r
+/* Converts CvArr (IplImage or CvMat,...) to CvMat.\r
+   If the last parameter is non-zero, function can\r
+   convert multi(>2)-dimensional array to CvMat as long as\r
+   the last array's dimension is continous. The resultant\r
+   matrix will be have appropriate (a huge) number of rows */\r
+OPENCVAPI CvMat* cvGetMat( const CvArr* src, CvMat* header,\r
+                           int* coi CV_DEFAULT(NULL),\r
+                           int allowND CV_DEFAULT(0));\r
+\r
+/* Converts CvArr (IplImage or CvMat) to IplImage */\r
+OPENCVAPI IplImage* cvGetImage( const CvArr* array, IplImage* img );\r
+\r
+\r
+/* Changes a shape of multi-dimensional array.\r
+   new_cn == 0 means that number of channels remains unchanged.\r
+   new_dims == 0 means that number and sizes of dimensions remain the same\r
+   (unless they need to be changed to set the new number of channels)\r
+   if new_dims == 1, there is no need to specify new dimension sizes\r
+   The resultant configuration should be achievable w/o data copying.\r
+   If the resultant array is sparse, CvSparseMat header should be passed\r
+   to the function else if the result is 1 or 2 dimensional,\r
+   CvMat header should be passed to the function\r
+   else CvMatND header should be passed */\r
+OPENCVAPI CvArr* cvReshapeMatND( const CvArr* array,\r
+                                 int sizeof_header, CvArr* header,\r
+                                 int new_cn, int new_dims, int* new_sizes );\r
+\r
+#define cvReshapeND( arr, header, new_cn, new_dims, new_sizes )   \\r
+      cvReshapeMatND( (arr), sizeof(*(header)), (header),         \\r
+                      (new_cn), (new_dims), (new_sizes))\r
+\r
+OPENCVAPI CvMat* cvReshape( const CvArr* array, CvMat* header,\r
+                            int new_cn, int new_rows CV_DEFAULT(0) );\r
+\r
+/* Repeats source 2d array several times in both horizontal and\r
+   vertical direction to fit destination array */\r
+OPENCVAPI void cvRepeat( const CvArr* src, CvArr* dst );\r
+\r
+/* Allocates array data */\r
+OPENCVAPI  void  cvCreateData( CvArr* array );\r
+\r
+/* Releases array data */\r
+OPENCVAPI  void  cvReleaseData( CvArr* array );\r
+\r
+/* Attaches user data to the array header. The step is reffered to\r
+   the pre-last dimension. That is, all the planes of the array\r
+   must be joint (w/o gaps) */\r
+OPENCVAPI  void  cvSetData( CvArr* array, void* data, int step );\r
+\r
+/* Retrieves raw data of CvMat, IplImage or CvMatND.\r
+   In the latter case the function raises an error if\r
+   the array can not be represented as a matrix */\r
+OPENCVAPI void cvGetRawData( const CvArr* array, uchar** data,\r
+                             int* step CV_DEFAULT(NULL),\r
+                             CvSize* roi_size CV_DEFAULT(NULL));\r
+\r
+/* Returns width and height of array in elements */\r
+OPENCVAPI  CvSize cvGetSize( const CvArr* arr );\r
+\r
+/* Copies source array to destination array */\r
+OPENCVAPI  void  cvCopy( const CvArr* src, CvArr* dst,\r
+                         const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Sets all or "masked" elements of input array\r
+   to the same <scalar> value*/\r
+OPENCVAPI  void  cvSet( CvArr* arr, CvScalar scalar,\r
+                        const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Clears all the array elements (sets them to 0) */\r
+OPENCVAPI  void  cvSetZero( CvArr* mat );\r
+#define cvZero  cvSetZero\r
+\r
+\r
+/* Splits a multi-channel array into the set of single-channel arrays or\r
+   extracts particular [color] plane */\r
+OPENCVAPI  void  cvCvtPixToPlane( const void *src, void *dst0, void *dst1,\r
+                                  void *dst2, void *dst3 );\r
+\r
+/* Merges a set of single-channel arrays into the single multi-channel array\r
+   or inserts one particular [color] plane to the array */\r
+OPENCVAPI  void  cvCvtPlaneToPix( const void *src0, const void *src1,\r
+                                  const void *src2, const void *src3,\r
+                                  void *dst );\r
+\r
+/* Performs linear transformation on every source array element:\r
+   dst(x,y,c) = scale*src(x,y,c)+shift.\r
+   Arbitrary combination of input and output array depths are allowed\r
+   (number of channels must be the same), thus the function can be used\r
+   for depth conversion */\r
+OPENCVAPI  void  cvConvertScale( const CvArr *src, CvArr *dst,\r
+                                 double scale CV_DEFAULT(1),\r
+                                 double shift CV_DEFAULT(0) );\r
+#define cvCvtScale cvConvertScale\r
+#define cvScale  cvConvertScale\r
+#define cvConvert( src, dst )  cvConvertScale( (src), (dst), 1, 0 )\r
+\r
+\r
+/* Performs linear transformation on every source array element,\r
+   stores absolute value of the result:\r
+   dst(x,y,c) = abs(scale*src(x,y,c)+shift).\r
+   destination array must have 8u type.\r
+   In other cases one may use cvConvertScale + cvAbsDiffS */\r
+OPENCVAPI  void  cvConvertScaleAbs( const void *src, void *dst,\r
+                                    double scale CV_DEFAULT(1),\r
+                                    double shift CV_DEFAULT(0) );\r
+#define cvCvtScaleAbs  cvConvertScaleAbs\r
+\r
+\r
+/* Finds minimum rectangle containing two given rectangles */\r
+OPENCVAPI  CvRect  cvMaxRect( const CvRect* rect1, const CvRect* rect2 );\r
+\r
+/* Finds coordinates of the box vertices */\r
+OPENCVAPI  void cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] );\r
+\r
+\r
+/****************************************************************************************\\r
+*                   Arithmetic, logic and comparison operations                          *\r
+\****************************************************************************************/\r
+\r
+/* dst(mask) = srcA(mask) + srcB(mask) */\r
+OPENCVAPI  void  cvAdd( const CvArr* srcA, const CvArr* srcB, CvArr* dst,\r
+                        const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(mask) = src(mask) + value */\r
+OPENCVAPI  void  cvAddS( const CvArr* src, CvScalar value, CvArr* dst,\r
+                         const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(mask) = srcA(mask) - srcB(mask) */\r
+OPENCVAPI  void  cvSub( const CvArr* srcA, const CvArr* srcB, CvArr* dst,\r
+                        const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(mask) = src(mask) - value = src(mask) + (-value) */\r
+CV_INLINE  void  cvSubS( const CvArr* src, CvScalar value, CvArr* dst,\r
+                         const CvArr* mask CV_DEFAULT(NULL));\r
+CV_INLINE  void  cvSubS( const CvArr* src, CvScalar value, CvArr* dst,\r
+                         const CvArr* mask )\r
+{\r
+    cvAddS( src, cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]),\r
+            dst, mask );\r
+}\r
+\r
+/* dst(mask) = value - src(mask) */\r
+OPENCVAPI  void  cvSubRS( const CvArr* src, CvScalar value, CvArr* dst,\r
+                          const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = srcA(idx) * srcB(idx) * scale (element-wise multiplication with scale) */\r
+OPENCVAPI  void  cvMul( const CvArr* srcA, const CvArr* srcB,\r
+                        CvArr* dst, double scale CV_DEFAULT(1) );\r
+\r
+/* element-wise division/inversion with scaling: \r
+    dst(idx) = srcA(idx) * scale / srcB(idx)\r
+    or dst(idx) = scale / srcB(idx) if srcA == 0 */\r
+OPENCVAPI  void  cvDiv( const CvArr* srcA, const CvArr* srcB,\r
+                        CvArr* dst, double scale CV_DEFAULT(1));\r
+\r
+/* dst = srcA * scale + srcB */\r
+OPENCVAPI  void  cvScaleAdd( const CvArr* srcA, CvScalar scale,\r
+                             const CvArr* srcB, CvArr* dst );\r
+\r
+/* dst = srcA * alpha + srcB * beta + gamma */\r
+OPENCVAPI  void  cvAddWeighted( const CvArr* srcA, double alpha,\r
+                                const CvArr* srcB, double beta,\r
+                                double gamma, CvArr* dst );\r
+\r
+/* result = sum(srcA(i) * srcB*(i))  (srcB is conjugated)\r
+             i                                           */\r
+OPENCVAPI  double  cvDotProduct( const CvArr* srcA, const CvArr* srcB );\r
+\r
+\r
+/* dst(idx) = src1(idx) & src2(idx) */\r
+OPENCVAPI void cvAnd( const CvArr* src1, const CvArr* src2,\r
+                      CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src(idx) & value */\r
+OPENCVAPI void cvAndS( const CvArr* src, CvScalar value,\r
+                       CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src1(idx) | src2(idx) */\r
+OPENCVAPI void cvOr( const CvArr* src1, const CvArr* src2,\r
+                     CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src(idx) | value */\r
+OPENCVAPI void cvOrS( const CvArr* src, CvScalar value,\r
+                      CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src1(idx) ^ src2(idx) */\r
+OPENCVAPI void cvXor( const CvArr* src1, const CvArr* src2,\r
+                      CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = src(idx) ^ value */\r
+OPENCVAPI void cvXorS( const CvArr* src, CvScalar value,\r
+                       CvArr* dst, const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/* dst(idx) = ~src(idx) */\r
+OPENCVAPI void cvNot( const CvArr* src, CvArr* dst );\r
+\r
+/* dst(idx) = lower(idx) <= src(idx) < upper(idx) */\r
+OPENCVAPI void cvInRange( const CvArr* src, const CvArr* lower,\r
+                          const CvArr* upper, CvArr* dst );\r
+\r
+/* dst(idx) = lower <= src(idx) < upper */\r
+OPENCVAPI void cvInRangeS( const CvArr* src, CvScalar lower,\r
+                           CvScalar upper, CvArr* dst );\r
+\r
+#define CV_CMP_EQ   0\r
+#define CV_CMP_GT   1\r
+#define CV_CMP_GE   2\r
+#define CV_CMP_LT   3\r
+#define CV_CMP_LE   4\r
+#define CV_CMP_NE   5\r
+\r
+/* The comparison operation support single-channel arrays only.\r
+   Destination image should be 8uC1 or 8sC1 */\r
+\r
+/* dst(idx) = src1(idx) _cmp_op_ src2(idx) */\r
+OPENCVAPI void cvCmp( const CvArr* src1, const CvArr* src2, CvArr* dst, int cmpOp );\r
+\r
+/* dst(idx) = src1(idx) _cmp_op_ scalar */\r
+OPENCVAPI void cvCmpS( const CvArr* src1, double scalar, CvArr* dst, int cmpOp );\r
+\r
+/* dst(idx) = min(src1(idx),src2(idx)) */\r
+OPENCVAPI void cvMin( const CvArr* src1, const CvArr* src2, CvArr* dst );\r
+\r
+/* dst(idx) = max(src1(idx),src2(idx)) */\r
+OPENCVAPI void cvMax( const CvArr* src1, const CvArr* src2, CvArr* dst );\r
+\r
+/* dst(idx) = min(src(idx),scalar) */\r
+OPENCVAPI void cvMinS( const CvArr* src, double scalar, CvArr* dst );\r
+\r
+/* dst(idx) = max(src(idx),scalar) */\r
+OPENCVAPI void cvMaxS( const CvArr* src, double scalar, CvArr* dst );\r
+\r
+\r
+/****************************************************************************************\\r
+*                                Math operations                                         *\r
+\****************************************************************************************/\r
+\r
+/* Does cartesian->polar coordinates conversion.\r
+   Either of output components (magnitude or angle) is optional */\r
+OPENCVAPI  void  cvCartToPolar( const CvArr* x, const CvArr* y,\r
+                                CvArr* magnitude, CvArr* angle CV_DEFAULT(NULL),\r
+                                int angle_in_degrees CV_DEFAULT(0));\r
+\r
+/* Does polar->cartesian coordinates conversion.\r
+   Either of output components (magnitude or angle) is optional.\r
+   If magnitude is missing it is assumed to be all 1's */\r
+OPENCVAPI  void  cvPolarToCart( const CvArr* magnitude, const CvArr* angle,\r
+                                CvArr* x, CvArr* y,\r
+                                int angle_in_degrees CV_DEFAULT(0));\r
+\r
+/* Does powering: dst(idx) = src(idx)^power */\r
+OPENCVAPI  void  cvPow( const CvArr* src, CvArr* dst, double power );\r
+\r
+/* Does exponention: dst(idx) = exp(src(idx)).\r
+   Overflow is not handled yet. Underflow is handled.\r
+   Maximal relative error is ~7e-6 */\r
+OPENCVAPI  void  cvExp( const CvArr* src, CvArr* dst );\r
+\r
+/* Calculates natural logarithms: dst(idx) = log(abs(src(idx))).\r
+   Logarithm of 0 gives large negative number(~-700)\r
+   Maximal relative error is ~3e-7\r
+*/\r
+OPENCVAPI  void  cvLog( const CvArr* src, CvArr* dst );\r
+\r
+/* Checks array values for NaNs, Infs or simply for too large numbers\r
+   (if CV_CHECK is set). If CV_CHECK_QUIET is set,\r
+   no runtime errors is raised (function returns zero value in case of "bad" values).\r
+   Otherwise cvError is called */ \r
+#define  CV_CHECK_RANGE    1\r
+#define  CV_CHECK_QUIET    2\r
+OPENCVAPI  int  cvCheckArr( const CvArr* arr, int flags CV_DEFAULT(0),\r
+                            double minVal CV_DEFAULT(0), double maxVal CV_DEFAULT(0));\r
+#define cvCheckArray cvCheckArr\r
+\r
+/* RNG state */\r
+typedef struct CvRandState\r
+{\r
+    uint64    state;    /* RNG state (the current seed and carry)*/\r
+    int       disttype; /* distribution type */\r
+    CvScalar  param[2]; /* parameters of RNG */\r
+}\r
+CvRandState;\r
+\r
+/* Initalized RNG state */\r
+#define CV_RAND_UNI      0\r
+#define CV_RAND_NORMAL   1\r
+OPENCVAPI  void  cvRandInit( CvRandState* state, double param1,\r
+                             double param2, int seed,\r
+                             int disttype CV_DEFAULT(CV_RAND_UNI));\r
+\r
+/* Changes RNG range while preserving RNG state */\r
+OPENCVAPI  void  cvRandSetRange( CvRandState* state, double param1, double param2,\r
+                                 int index CV_DEFAULT(-1));\r
+\r
+/* Fills array with random numbers */\r
+OPENCVAPI  void  cvRand( CvRandState* state, CvArr* arr );\r
+\r
+/* Returns 32-bit random number (ranges are not used)\r
+   and updates RNG state */\r
+CV_INLINE  unsigned  cvRandNext( CvRandState* state );\r
+CV_INLINE  unsigned  cvRandNext( CvRandState* state )\r
+{\r
+    uint64 temp = 0;\r
+\r
+    if( state )\r
+    {\r
+        temp = state->state;\r
+        temp = (uint64)(unsigned)temp*1554115554 + (temp >> 32);\r
+        state->state = temp;\r
+    }\r
+\r
+    return (unsigned)temp;\r
+}\r
+\r
+\r
+/****************************************************************************************\\r
+*                                Matrix operations                                       *\r
+\****************************************************************************************/\r
+\r
+/* Calculates cross product of two 3d vectors */\r
+OPENCVAPI  void  cvCrossProduct( const CvArr* srcA, const CvArr* srcB, CvArr* dst );\r
+\r
+/* Matrix transform: dst = A*B + C, C is optional */\r
+OPENCVAPI  void  cvMatMulAdd( const CvArr* srcA, const CvArr* srcB,\r
+                              const CvArr* srcC, CvArr* dst );\r
+#define cvMatMul( srcA, srcB, dst )  cvMatMulAdd( (srcA), (srcB), NULL, (dst))\r
+\r
+#define CV_GEMM_A_T 1\r
+#define CV_GEMM_B_T 2\r
+#define CV_GEMM_C_T 4\r
+/* Extended matrix transform:\r
+   dst = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T */\r
+OPENCVAPI  void  cvGEMM( const CvArr* srcA, const CvArr* srcB, double alpha,\r
+                         const CvArr* srcC, double beta, CvArr* dst,\r
+                         int tABC CV_DEFAULT(0));\r
+#define cvMatMulAddEx cvGEMM\r
+\r
+/* Transforms each element of source array and stores\r
+   resultant vectors in destination array */\r
+OPENCVAPI  void  cvMatMulAddS( const CvArr* src, CvArr* dst,\r
+                               const CvMat* transform,\r
+                               const CvMat* shiftvec CV_DEFAULT(NULL));\r
+#define cvTransform cvMatMulAddS\r
+\r
+/* Calculates A*A^T (order=0) or A^T*A (order=1) */\r
+OPENCVAPI void cvMulTransposed( const CvArr* srcarr,\r
+                                CvArr* dstarr, int order );\r
+\r
+/* Tranposes matrix. Square matrices can be transposed in-place */\r
+OPENCVAPI  void  cvTranspose( const CvArr* src, CvArr* dst );\r
+#define cvT cvTranspose\r
+\r
+\r
+/* Mirror array data around horizontal (flip=0),\r
+   vertical (flip=1) or both(flip=-1) axises:\r
+   cvFlip(src) flips images vertically and sequences horizontally (inplace) */\r
+OPENCVAPI  void  cvFlip( const CvArr* src, CvArr* dst CV_DEFAULT(NULL),\r
+                         int flip_mode CV_DEFAULT(0));\r
+#define cvMirror cvFlip\r
+\r
+\r
+#define CV_SVD_MODIFY_A   1\r
+#define CV_SVD_U_T        2\r
+#define CV_SVD_V_T        4\r
+\r
+/* Performs Singular Value Decomposition of a matrix */\r
+OPENCVAPI  void   cvSVD( CvArr* A, CvArr* W CV_DEFAULT(NULL),\r
+                         CvArr* U CV_DEFAULT(NULL),\r
+                         CvArr* V CV_DEFAULT(NULL),\r
+                         int flags CV_DEFAULT(0));\r
+\r
+/* Performs Singular Value Back Substitution:\r
+   flags must be the same as in cvSVD */\r
+OPENCVAPI  void   cvSVBkSb( const CvArr* warr, const CvArr* uarr,\r
+                            const CvArr* varr, const CvArr* barr,\r
+                            CvArr* xarr, int flags );\r
+\r
+#define CV_LU  0\r
+#define CV_SVD 1\r
+/* Inverts matrix */\r
+OPENCVAPI  double  cvInvert( const CvArr* src, CvArr* dst,\r
+                             int method CV_DEFAULT(CV_LU));\r
+#define cvInv cvInvert\r
+\r
+/* Solves linear system Ax = b\r
+   (returns 0 if A is singular) */\r
+OPENCVAPI  int  cvSolve( const CvArr* A, const CvArr* b, CvArr* x,\r
+                         int method CV_DEFAULT(CV_LU));\r
+\r
+/* Calculates determinant of input matrix */\r
+OPENCVAPI  double cvDet( const CvArr* mat );\r
+\r
+/* Calculates trace of the matrix (sum of elements on the main diagonal) */\r
+OPENCVAPI  CvScalar cvTrace( const CvArr* mat );\r
+\r
+/* Finds eigen values and vectors of a _symmetric_ matrix */\r
+OPENCVAPI  void  cvEigenVV( CvArr* src, CvArr* evects, CvArr* evals, double eps );\r
+\r
+/* Makes an identity matrix (mat_ij = i == j) */\r
+OPENCVAPI  void  cvSetIdentity( CvArr* mat, CvScalar value CV_DEFAULT(cvScalar(1)) );\r
+\r
+/* Does perspective transform on every element of input array */\r
+OPENCVAPI  void  cvPerspectiveTransform( const CvArr* src, CvArr* dst, const CvArr* mat );\r
+\r
+/* Calculates covariation matrix for a set of vectors */\r
+OPENCVAPI  void  cvCalcCovarMatrix( const CvArr** vects, CvArr* covarMatrix, CvArr* avg );\r
+\r
+/* Calculates Mahalanobis(weighted) distance */\r
+OPENCVAPI  double  cvMahalanobis( const CvArr* srcA, const CvArr* srcB, CvArr* mat );\r
+#define cvMahalonobis  cvMahalanobis\r
+\r
+/****************************************************************************************\\r
+*                                    Array Statistics                                    *\r
+\****************************************************************************************/\r
+\r
+/* Finds sum of array elements */\r
+OPENCVAPI  CvScalar  cvSum( const CvArr* array );\r
+\r
+\r
+/* Calculates number of non-zero pixels */\r
+OPENCVAPI  int  cvCountNonZero( const CvArr* array );\r
+\r
+\r
+/* Calculates mean value of array elements */\r
+OPENCVAPI  CvScalar  cvAvg( const CvArr* array, const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Calculates mean and standard deviation of pixel values */\r
+OPENCVAPI  void  cvAvgSdv( const CvArr* array, CvScalar* mean, CvScalar* std_dev,\r
+                           const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Finds global minimum, maximum among the input array elements and positions\r
+   of the extremums */\r
+OPENCVAPI  void  cvMinMaxLoc( const CvArr* array, double* min_val, double* max_val,\r
+                              CvPoint* min_loc CV_DEFAULT(NULL),\r
+                              CvPoint* max_loc CV_DEFAULT(NULL),\r
+                              const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* spatial and central moments */\r
+typedef struct CvMoments\r
+{\r
+    double  m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; /* spatial moments */\r
+    double  mu20, mu11, mu02, mu30, mu21, mu12, mu03; /* central moments */\r
+    double  inv_sqrt_m00; /* m00 != 0 ? 1/sqrt(m00) : 0 */\r
+} CvMoments;\r
+\r
+/* Calculates all spatial and central moments up to the 3rd order */\r
+OPENCVAPI void cvMoments( const CvArr* array, CvMoments* moments, int binary CV_DEFAULT(0));\r
+\r
+/* Retrieve particular spatial, central or normalized central moments */\r
+OPENCVAPI  double  cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order );\r
+OPENCVAPI  double  cvGetCentralMoment( CvMoments* moments, int x_order, int y_order );\r
+OPENCVAPI  double  cvGetNormalizedCentralMoment( CvMoments* moments,\r
+                                                 int x_order, int y_order );\r
+\r
+/* Hu invariants */\r
+typedef struct CvHuMoments\r
+{\r
+    double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /* Hu invariants */\r
+} CvHuMoments;\r
+\r
+/* Calculates 7 Hu's invariants from precalculated spatial and central moments */\r
+OPENCVAPI void cvGetHuMoments( CvMoments*  moments, CvHuMoments*  hu_moments );\r
+\r
+/* types of array norm */\r
+#define CV_C            1\r
+#define CV_L1           2\r
+#define CV_L2           4\r
+#define CV_NORM_MASK    7\r
+#define CV_RELATIVE     8\r
+#define CV_DIFF         16\r
+\r
+#define CV_DIFF_C       (CV_DIFF | CV_C)\r
+#define CV_DIFF_L1      (CV_DIFF | CV_L1)\r
+#define CV_DIFF_L2      (CV_DIFF | CV_L2)\r
+#define CV_RELATIVE_C   (CV_RELATIVE | CV_C)\r
+#define CV_RELATIVE_L1  (CV_RELATIVE | CV_L1)\r
+#define CV_RELATIVE_L2  (CV_RELATIVE | CV_L2)\r
+\r
+/* Finds norm, difference norm or relative difference norm for an array (two arrays) */\r
+OPENCVAPI  double  cvNorm( const CvArr* imgA, const CvArr* imgB CV_DEFAULT(NULL),\r
+                           int normType CV_DEFAULT(CV_L2),\r
+                           const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/****************************************************************************************\\r
+*                              Dynamic data structures                                   *\r
+\****************************************************************************************/\r
+\r
+/* Creates new memory storage.\r
+   block_size == 0 means that default,\r
+   somewhat optimal size, is used (currently, it is 64K) */\r
+OPENCVAPI  CvMemStorage*  cvCreateMemStorage( int block_size CV_DEFAULT(0));\r
+\r
+\r
+/* Creates a memory storage that will borrow memory blocks from parent storage */\r
+OPENCVAPI  CvMemStorage*  cvCreateChildMemStorage( CvMemStorage* parent );\r
+\r
+\r
+/* Releases memory storage. All the children of a parent must be released before\r
+   the parent. A child storage returns all the blocks to parent when it is released */\r
+OPENCVAPI  void  cvReleaseMemStorage( CvMemStorage** storage );\r
+\r
+\r
+/* Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos)\r
+   to reuse memory allocated for the storage - cvClearSeq,cvClearSet ...\r
+   do not free any memory.\r
+   A child storage returns all the blocks to the parent when it is cleared */\r
+OPENCVAPI  void  cvClearMemStorage( CvMemStorage* storage );\r
+\r
+/* Remember a storage "free memory" position */\r
+OPENCVAPI  void  cvSaveMemStoragePos( const CvMemStorage* storage, CvMemStoragePos* pos );\r
+\r
+/* Restore a storage "free memory" position */\r
+OPENCVAPI  void  cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos );\r
+\r
+/* Allocates continuous buffer of the specified size in the storage */\r
+OPENCVAPI  void* cvMemStorageAlloc( CvMemStorage* storage, int size );\r
+\r
+/* Creates new empty sequence that will reside in the specified storage */\r
+OPENCVAPI  CvSeq*  cvCreateSeq( int seq_flags, int header_size,\r
+                             int elem_size, CvMemStorage* storage );\r
+\r
+/* Changes default size (granularity) of sequence blocks.\r
+   The default size is ~1Kbyte */\r
+OPENCVAPI  void  cvSetSeqBlockSize( CvSeq* seq, int delta_elements );\r
+\r
+\r
+/* Adds new element to the end of sequence. Returns pointer to the element */\r
+OPENCVAPI  char*  cvSeqPush( CvSeq* seq, void* element CV_DEFAULT(NULL));\r
+\r
+\r
+/* Adds new element to the beginning of sequence. Returns pointer to it */\r
+OPENCVAPI  char*  cvSeqPushFront( CvSeq* seq, void* element CV_DEFAULT(NULL));\r
+\r
+\r
+/* Removes the last element from sequence and optionally saves it */\r
+OPENCVAPI  void  cvSeqPop( CvSeq* seq, void* element CV_DEFAULT(NULL));\r
+\r
+\r
+/* Removes the first element from sequence and optioanally saves it */\r
+OPENCVAPI  void  cvSeqPopFront( CvSeq* seq, void* element CV_DEFAULT(NULL));\r
+\r
+\r
+#define CV_FRONT 1\r
+#define CV_BACK 0\r
+/* Adds several new elements to the end of sequence */\r
+OPENCVAPI  void  cvSeqPushMulti( CvSeq* seq, void* elements,\r
+                                 int count, int in_front CV_DEFAULT(0) );\r
+\r
+/* Removes several elements from the end of sequence and optionally saves them */\r
+OPENCVAPI  void  cvSeqPopMulti( CvSeq* seq, void* elements,\r
+                                int count, int in_front CV_DEFAULT(0) );\r
+\r
+/* Inserts a new element in the middle of sequence.\r
+   cvSeqInsert(seq,0,elem) == cvSeqPushFront(seq,elem) */\r
+OPENCVAPI  char*  cvSeqInsert( CvSeq* seq, int before_index,\r
+                               void* element CV_DEFAULT(NULL));\r
+\r
+/* Removes specified sequence element */\r
+OPENCVAPI  void  cvSeqRemove( CvSeq* seq, int index );\r
+\r
+\r
+/* Removes all the elements from the sequence. The freed memory\r
+   can be reused later only by the same sequence unless cvClearMemStorage\r
+   or cvRestoreMemStoragePos is called */\r
+OPENCVAPI  void  cvClearSeq( CvSeq* seq );\r
+\r
+\r
+/* Retrives pointer to specified sequence element.\r
+   Negative indices are supported and mean counting from the end\r
+   (e.g -1 means the last sequence element) */\r
+OPENCVAPI  char*  cvGetSeqElem( CvSeq* seq, int index, CvSeqBlock** block CV_DEFAULT(NULL) );\r
+\r
+\r
+/* Calculates index of the specified sequence element.\r
+   Returns -1 if element does not belong to the sequence */\r
+OPENCVAPI int  cvSeqElemIdx( const CvSeq* seq, const void* element,\r
+                             CvSeqBlock** block CV_DEFAULT(NULL) );\r
+\r
+/* Initializes sequence writer. The new elements will be added to the end of sequence */\r
+OPENCVAPI  void  cvStartAppendToSeq( CvSeq* seq, CvSeqWriter* writer );\r
+\r
+\r
+/* Combination of cvCreateSeq and cvStartAppendToSeq */\r
+OPENCVAPI  void  cvStartWriteSeq( int seq_flags, int header_size,\r
+                                  int elem_size, CvMemStorage* storage,\r
+                                  CvSeqWriter* writer );\r
+\r
+/* Closes sequence writer, updates sequence header and returns pointer\r
+   to the resultant sequence\r
+   (which may be useful if the sequence was created using cvStartWriteSeq))\r
+*/\r
+OPENCVAPI  CvSeq*  cvEndWriteSeq( CvSeqWriter* writer );\r
+\r
+\r
+/* Updates sequence header. May be useful to get access to some of previously\r
+   written elements via cvGetSeqElem or sequence reader */\r
+OPENCVAPI  void   cvFlushSeqWriter( CvSeqWriter* writer );\r
+\r
+\r
+/* Initializes sequence reader.\r
+   The sequence can be read in forward or backward direction */\r
+OPENCVAPI void cvStartReadSeq( const CvSeq* seq, CvSeqReader* reader,\r
+                               int reverse CV_DEFAULT(0) );\r
+\r
+\r
+/* Returns current sequence reader position (currently observed sequence element) */\r
+OPENCVAPI  int  cvGetSeqReaderPos( CvSeqReader* reader );\r
+\r
+\r
+/* Changes sequence reader position. It may seek to an absolute or\r
+   to relative to the current position */\r
+OPENCVAPI  void   cvSetSeqReaderPos( CvSeqReader* reader, int index,\r
+                                     int is_relative CV_DEFAULT(0));\r
+\r
+/* Copies sequence content to an array */\r
+OPENCVAPI  void*  cvCvtSeqToArray( CvSeq* seq, CvArr* array,\r
+                                   CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) );\r
+\r
+/* Creates sequence header for array.\r
+   After that all the operations on sequences that do not alter the content\r
+   can be applied to the resultant sequence */\r
+OPENCVAPI  CvSeq* cvMakeSeqHeaderForArray( int seq_type, int header_size,\r
+                                           int elem_size, void* elements, int total,\r
+                                           CvSeq* seq, CvSeqBlock* block );\r
+\r
+/* Extracts sequence slice (with or without copying sequence elements */\r
+OPENCVAPI CvSeq* cvSeqSlice( CvSeq* seq, CvSlice slice,\r
+                             CvMemStorage* storage CV_DEFAULT(NULL),\r
+                             int copy_data CV_DEFAULT(0));\r
+\r
+CV_INLINE CvSeq* cvCloneSeq( CvSeq* seq, CvMemStorage* storage CV_DEFAULT(NULL));\r
+CV_INLINE CvSeq* cvCloneSeq( CvSeq* seq, CvMemStorage* storage )\r
+{\r
+    return cvSeqSlice( seq, CV_WHOLE_SEQ, storage, 1 );\r
+}\r
+\r
+/* Removes sequence slice */\r
+OPENCVAPI  void  cvSeqRemoveSlice( CvSeq* seq, CvSlice slice );\r
+\r
+/* Inserts a sequence or array into another sequence */\r
+OPENCVAPI  void  cvSeqInsertSlice( CvSeq* seq, int index, const CvArr* from_arr );\r
+\r
+/* a < b ? -1 : a > b ? 1 : 0 */\r
+CV_EXTERN_C_FUNCPTR( int (CV_CDECL* CvCmpFunc)\r
+                     (const void* a, const void* b, void* userdata ));\r
+\r
+/* Sorts sequence in-place given element comparison function */\r
+OPENCVAPI  void cvSeqSort( CvSeq* seq, CvCmpFunc func, void* userdata );\r
+\r
+/* Reverses order of sequence elements in-place */\r
+OPENCVAPI  void cvSeqInvert( CvSeq* seq );\r
+\r
+/* Splits sequence into set of equivalency classes\r
+   using specified equivalency criteria */\r
+OPENCVAPI  int  cvPartitionSeq( CvSeq* seq, CvMemStorage* storage, CvSeq** comps,\r
+                                CvCmpFunc is_equal, void* userdata, int is_set );\r
+\r
+/************ Internal sequence functions ************/\r
+OPENCVAPI  void  cvChangeSeqBlock( CvSeqReader* reader, int direction );\r
+OPENCVAPI  void  cvCreateSeqBlock( CvSeqWriter* writer );\r
+\r
+\r
+/* Creates a new set */\r
+OPENCVAPI  CvSet*  cvCreateSet( int set_flags, int header_size,\r
+                                int elem_size, CvMemStorage* storage );\r
+\r
+/* Adds new element to the set and returns pointer to it */\r
+OPENCVAPI  int  cvSetAdd( CvSet* set_header, CvSetElem* element CV_DEFAULT(NULL),\r
+                          CvSetElem** inserted_element CV_DEFAULT(NULL) );\r
+\r
+/* Fast variant of cvSetAdd */\r
+CV_INLINE  CvSetElem* cvSetNew( CvSet* set_header );\r
+CV_INLINE  CvSetElem* cvSetNew( CvSet* set_header )\r
+{\r
+    CvSetElem* elem = set_header->free_elems;\r
+    if( elem )\r
+    {\r
+        set_header->free_elems = elem->next_free;\r
+        elem->flags = elem->flags & CV_SET_ELEM_IDX_MASK;\r
+    }\r
+    else\r
+        cvSetAdd( set_header, NULL, (CvSetElem**)&elem );\r
+    return elem;\r
+}\r
+\r
+/* Removes set element given its pointer */\r
+CV_INLINE  void cvSetRemoveByPtr( CvSet* set_header, void* _elem );\r
+CV_INLINE  void cvSetRemoveByPtr( CvSet* set_header, void* _elem )\r
+{\r
+    CvSetElem* elem = (CvSetElem*)_elem;\r
+    assert( elem->flags >= 0 && (elem->flags & CV_SET_ELEM_IDX_MASK) < set_header->total );\r
+    elem->next_free = set_header->free_elems;\r
+    elem->flags = (elem->flags & CV_SET_ELEM_IDX_MASK) | CV_SET_ELEM_FREE_FLAG;\r
+    set_header->free_elems = elem;\r
+}\r
+\r
+\r
+/* Removes element from the set by its index  */\r
+OPENCVAPI  void   cvSetRemove( CvSet* set_header, int index );\r
+\r
+\r
+/* Returns a set element by index. If the element doesn't belong to the set,\r
+   NULL is returned */\r
+OPENCVAPI  CvSetElem*  cvGetSetElem( CvSet* set_header, int index );\r
+\r
+\r
+/* Removes all the elements from the set */\r
+OPENCVAPI  void  cvClearSet( CvSet* set_header );\r
+\r
+\r
+/* Creates new graph */\r
+OPENCVAPI  CvGraph*   cvCreateGraph( int graph_flags, int header_size,\r
+                                  int vtx_size, int edge_size,\r
+                                  CvMemStorage* storage );\r
+\r
+/* Adds new vertex to the graph */\r
+OPENCVAPI  int  cvGraphAddVtx( CvGraph* graph, CvGraphVtx* vertex CV_DEFAULT(NULL),\r
+                               CvGraphVtx** inserted_vertex CV_DEFAULT(NULL) );\r
+\r
+\r
+/* Removes vertex from the graph together with all incident edges */\r
+OPENCVAPI  void   cvGraphRemoveVtx( CvGraph* graph, int index );\r
+OPENCVAPI  void   cvGraphRemoveVtxByPtr( CvGraph* graph, CvGraphVtx* vtx );\r
+\r
+\r
+/* Link two vertices specifed by indices or pointers if they\r
+   are not connected or return pointer to already existing edge\r
+   connecting the vertices.\r
+   Functions return 1 if a new edge was created, 0 otherwise */\r
+OPENCVAPI  int  cvGraphAddEdge( CvGraph* graph,\r
+                                int start_idx, int end_idx,\r
+                                CvGraphEdge* edge CV_DEFAULT(NULL),\r
+                                CvGraphEdge** inserted_edge CV_DEFAULT(NULL) );\r
+\r
+OPENCVAPI  int  cvGraphAddEdgeByPtr( CvGraph* graph,\r
+                               CvGraphVtx* start_vtx, CvGraphVtx* end_vtx,\r
+                               CvGraphEdge* edge CV_DEFAULT(NULL),\r
+                               CvGraphEdge** inserted_edge CV_DEFAULT(NULL) );\r
+\r
+/* Remove edge connecting two vertices */\r
+OPENCVAPI  void  cvGraphRemoveEdge( CvGraph* graph, int start_idx, int end_idx );\r
+OPENCVAPI  void  cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx,\r
+                                         CvGraphVtx* end_vtx );\r
+\r
+/* Find edge connecting two vertices */\r
+OPENCVAPI  CvGraphEdge*  cvFindGraphEdge( CvGraph* graph, int start_idx, int end_idx );\r
+OPENCVAPI  CvGraphEdge*  cvFindGraphEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx,\r
+                                               CvGraphVtx* end_vtx );\r
+#define cvGraphFindEdge cvFindGraphEdge\r
+#define cvGraphFindEdgeByPtr cvFindGraphEdgeByPtr\r
+\r
+/* Remove all vertices and edges from the graph */\r
+OPENCVAPI  void  cvClearGraph( CvGraph* graph );\r
+\r
+\r
+/* Count number of edges incident to the vertex */\r
+OPENCVAPI  int  cvGraphVtxDegree( CvGraph* graph, int vtx_idx );\r
+OPENCVAPI  int  cvGraphVtxDegreeByPtr( CvGraph* graph, CvGraphVtx* vtx );\r
+\r
+\r
+/* Retrieves graph vertex by given index */\r
+#define cvGetGraphVtx( graph, idx ) (CvGraphVtx*)cvGetSetElem((CvSet*)(graph), (idx))\r
+\r
+/* Retrieves index of a graph vertex given its pointer */\r
+#define cvGraphVtxIdx( graph, vtx ) ((vtx)->flags & CV_SET_ELEM_IDX_MASK)\r
+\r
+/* Retrieves index of a graph edge given its pointer */\r
+#define cvGraphEdgeIdx( graph, edge ) ((edge)->flags & CV_SET_ELEM_IDX_MASK)\r
+\r
+\r
+#define  CV_GRAPH_VERTEX        1\r
+#define  CV_GRAPH_TREE_EDGE     2\r
+#define  CV_GRAPH_BACK_EDGE     4\r
+#define  CV_GRAPH_FORWARD_EDGE  8\r
+#define  CV_GRAPH_CROSS_EDGE    16\r
+#define  CV_GRAPH_ANY_EDGE      30\r
+#define  CV_GRAPH_NEW_TREE      32\r
+#define  CV_GRAPH_BACKTRACKING  64\r
+#define  CV_GRAPH_OVER          -1\r
+\r
+#define  CV_GRAPH_ALL_ITEMS    -1\r
+\r
+/* flags for graph vertices and edges */\r
+#define  CV_GRAPH_ITEM_VISITED_FLAG  (1 << 30)\r
+#define  CV_IS_GRAPH_VERTEX_VISITED(vtx) \\r
+    (((CvGraphVtx*)(vtx))->flags & CV_GRAPH_ITEM_VISITED_FLAG)\r
+#define  CV_IS_GRAPH_EDGE_VISITED(edge) \\r
+    (((CvGraphEdge*)(edge))->flags & CV_GRAPH_ITEM_VISITED_FLAG)\r
+#define  CV_GRAPH_SEARCH_TREE_NODE_FLAG   (1 << 29)\r
+#define  CV_GRAPH_FORWARD_EDGE_FLAG       (1 << 28)\r
+\r
+typedef struct CvGraphScanner\r
+{\r
+    CvGraphVtx* vtx;       /* current graph vertex (or current edge origin) */\r
+    CvGraphVtx* dst;       /* current graph edge destination vertex */\r
+    CvGraphEdge* edge;     /* current edge */\r
+\r
+    CvGraph* graph;        /* the graph */\r
+    CvSeq*   stack;        /* the graph vertex stack */\r
+    int      index;        /* the lower bound of certainly visited vertices */\r
+    int      mask;         /* event mask */\r
+}\r
+CvGraphScanner;\r
+\r
+/* Initializes graph traversal process.\r
+   <mask> indicates what events one wants to handle. */\r
+OPENCVAPI void  cvStartScanGraph( CvGraph* graph, CvGraphScanner* scanner,\r
+                                  CvGraphVtx* vtx CV_DEFAULT(NULL),\r
+                                  int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS));\r
+\r
+/* Initializes graph traversal process.\r
+   <mask> indicates what events one wants to handle. */\r
+OPENCVAPI void  cvEndScanGraph( CvGraphScanner* scanner );\r
+\r
+/* Get next graph element */\r
+OPENCVAPI int  cvNextGraphItem( CvGraphScanner* scanner );\r
+\r
+/* Creates a copy of graph */\r
+OPENCVAPI CvGraph* cvCloneGraph( const CvGraph* graph, CvMemStorage* storage );\r
+\r
+/****************************************************************************************\\r
+*                                    Image Processing                                    *\r
+\****************************************************************************************/\r
+\r
+/* Does look-up transformation. Elements of the source array\r
+   (that should be 8uC1 or 8sC1) are used as indexes in lutarr 256-element table */\r
+OPENCVAPI  void cvLUT( const CvArr* srcarr, CvArr* dstarr, const CvArr* lutarr );\r
+\r
+\r
+/* Smoothes array (remove noise) */\r
+#define CV_BLUR_NO_SCALE 0\r
+#define CV_BLUR  1\r
+#define CV_GAUSSIAN  2\r
+#define CV_MEDIAN 3\r
+#define CV_BILATERAL 4\r
+\r
+OPENCVAPI  void cvSmooth( const CvArr* srcarr, CvArr* dstarr,\r
+                          int smoothtype CV_DEFAULT(CV_GAUSSIAN),\r
+                          int param1 CV_DEFAULT(3),\r
+                          int param2 CV_DEFAULT(0));\r
+\r
+/* Finds integral image: SUM(X,Y) = sum(x<X,y<Y)I(x,y) */\r
+OPENCVAPI void cvIntegral( const CvArr* image, CvArr* sumImage,\r
+                           CvArr* sumSqImage CV_DEFAULT(NULL),\r
+                           CvArr* tiltedSumImage CV_DEFAULT(NULL));\r
+\r
+/*\r
+   Down-samples image with prior gaussian smoothing.\r
+   dst_width = floor(src_width/2)[+1],\r
+   dst_height = floor(src_height/2)[+1]\r
+*/\r
+OPENCVAPI  void  cvPyrDown( const CvArr* src, CvArr* dst,\r
+                            int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );\r
+\r
+/* \r
+   Up-samples image with posterior gaussian smoothing.\r
+   dst_width = src_width*2,\r
+   dst_height = src_height*2\r
+*/\r
+OPENCVAPI  void  cvPyrUp( const CvArr* src, CvArr* dst,\r
+                          int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );\r
+\r
+\r
+/* Builds the whole pyramid at once. Output array of CvMat headers (levels[*])\r
+   is initialized with the headers of subsequent pyramid levels */\r
+/*OPENCVAPI  void  cvCalcPyramid( const CvArr* src, CvArr* container,\r
+                                CvMat* levels, int levelCount,\r
+                                int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );*/\r
+\r
+\r
+/* Segments image using son-father links (modification of Burt's algorithm).\r
+   CvSeq<CvConnectedComp*> is returned to *comp */\r
+OPENCVAPI void cvPyrSegmentation( IplImage* src,\r
+                               IplImage* dst,\r
+                               CvMemStorage *storage,\r
+                               CvSeq **comp,\r
+                               int level, double threshold1,\r
+                               double threshold2 );\r
+\r
+\r
+#define CV_SCHARR -1\r
+\r
+/* calculates some image derivative using Sobel (apertureSize = 1,3,5,7)\r
+   or Scharr (apertureSize = -1) operator.\r
+   Scharr can be used only for the first dx or dy derivative */\r
+OPENCVAPI void cvSobel( const CvArr* src, CvArr* dst,\r
+                        int xorder, int yorder,\r
+                        int apertureSize CV_DEFAULT(3));\r
+\r
+/* Calculates Laplace operator: (d2/dx + d2/dy)I */\r
+OPENCVAPI void cvLaplace( const CvArr* src, CvArr* dst,\r
+                          int apertureSize CV_DEFAULT(3) );\r
+\r
+/* Constants for color conversion */\r
+#define  CV_BGR2BGRA    0\r
+#define  CV_RGB2RGBA    CV_BGR2BGRA\r
+\r
+#define  CV_BGRA2BGR    1\r
+#define  CV_RGBA2RGB    CV_BGRA2BGR\r
+\r
+#define  CV_BGR2RGBA    2\r
+#define  CV_RGB2BGRA    CV_BGR2RGBA\r
+\r
+#define  CV_RGBA2BGR    3\r
+#define  CV_BGRA2RGB    CV_RGBA2BGR\r
+\r
+#define  CV_BGR2RGB     4\r
+#define  CV_RGB2BGR     CV_BGR2RGB\r
+\r
+#define  CV_BGRA2RGBA   5\r
+#define  CV_RGBA2BGRA   CV_BGRA2RGBA\r
+\r
+#define  CV_BGR2GRAY    6\r
+#define  CV_RGB2GRAY    7\r
+#define  CV_GRAY2BGR    8\r
+#define  CV_GRAY2RGB    CV_GRAY2BGR\r
+#define  CV_GRAY2BGRA   9\r
+#define  CV_GRAY2RGBA   CV_GRAY2BGRA\r
+#define  CV_BGRA2GRAY   10\r
+#define  CV_RGBA2GRAY   11\r
+\r
+#define  CV_BGR2BGR565  12\r
+#define  CV_RGB2BGR565  13\r
+#define  CV_BGR5652BGR  14\r
+#define  CV_BGR5652RGB  15\r
+#define  CV_BGRA2BGR565 16\r
+#define  CV_RGBA2BGR565 17\r
+#define  CV_BGR5652BGRA 18\r
+#define  CV_BGR5652RGBA 19\r
+\r
+#define  CV_GRAY2BGR565 20\r
+#define  CV_BGR5652GRAY 21\r
+\r
+#define  CV_BGR2XYZ     22\r
+#define  CV_RGB2XYZ     23\r
+#define  CV_XYZ2BGR     24\r
+#define  CV_XYZ2RGB     25\r
+\r
+#define  CV_BGR2YCrCb   26\r
+#define  CV_RGB2YCrCb   27\r
+#define  CV_YCrCb2BGR   28\r
+#define  CV_YCrCb2RGB   29\r
+\r
+#define  CV_BGR2HSV     30\r
+#define  CV_RGB2HSV     31\r
+\r
+#define  CV_BGR2Lab     34\r
+#define  CV_RGB2Lab     35\r
+\r
+#define  CV_BayerBG2BGR 40\r
+#define  CV_BayerGB2BGR 41\r
+#define  CV_BayerRG2BGR 42\r
+#define  CV_BayerGR2BGR 43\r
+\r
+#define  CV_BayerBG2RGB CV_BayerRG2BGR\r
+#define  CV_BayerGB2RGB CV_BayerGR2BGR\r
+#define  CV_BayerRG2RGB CV_BayerBG2BGR\r
+#define  CV_BayerGR2RGB CV_BayerGB2BGR\r
+\r
+#define  CV_COLORCVT_MAX  48\r
+\r
+/* Converts input array from one color space to another.\r
+   Only 8-bit images are supported now */\r
+OPENCVAPI  void  cvCvtColor( const CvArr* src, CvArr* dst, int colorCvtCode );\r
+\r
+\r
+#define  CV_INTER_NN        0\r
+#define  CV_INTER_LINEAR    1\r
+/*#define  CV_INTER_CUBIC     2 - not implemented yet */\r
+\r
+/* Resizes 1D-2D array. Destination size is determined by the size of destination array */\r
+OPENCVAPI  void  cvResize( const CvArr* src, CvArr* dst,\r
+                           int method CV_DEFAULT( CV_INTER_LINEAR ));\r
+\r
+\r
+#define  CV_SHAPE_RECT      0\r
+#define  CV_SHAPE_CROSS     1\r
+#define  CV_SHAPE_ELLIPSE   2\r
+#define  CV_SHAPE_CUSTOM    100\r
+\r
+/* creates structuring element used for morphological operations */\r
+OPENCVAPI  IplConvKernel*  cvCreateStructuringElementEx(\r
+            int  cols, int  rows, int  anchorX, int  anchorY,\r
+            int shape, int* values CV_DEFAULT(NULL) );\r
+\r
+/* releases structuring element */\r
+OPENCVAPI  void  cvReleaseStructuringElement( IplConvKernel** element );\r
+\r
+\r
+/* erodes input image (applies minimum filter) one or more times.\r
+   If element pointer is NULL, 3x3 rectangular element is used */\r
+OPENCVAPI  void  cvErode( const CvArr* src, CvArr* dst,\r
+                          IplConvKernel* element CV_DEFAULT(NULL),\r
+                          int iterations CV_DEFAULT(1) );\r
+\r
+/* dilates input image (applies maximum filter) one or more times.\r
+   If element pointer is NULL, 3x3 rectangular element is used */\r
+OPENCVAPI  void  cvDilate( const CvArr* src, CvArr* dst,\r
+                           IplConvKernel* element CV_DEFAULT(NULL),\r
+                           int iterations CV_DEFAULT(1) );\r
+\r
+#define CV_MOP_OPEN         2\r
+#define CV_MOP_CLOSE        3\r
+#define CV_MOP_GRADIENT     4\r
+#define CV_MOP_TOPHAT       5\r
+#define CV_MOP_BLACKHAT     6\r
+\r
+/* performs complex morphological transformation */\r
+OPENCVAPI  void  cvMorphologyEx( const CvArr* src, CvArr* dst,\r
+                                 CvArr* temp, IplConvKernel* element,\r
+                                 int operation, int iterations CV_DEFAULT(1) );\r
+\r
+\r
+/****************************************************************************************\\r
+*                                     Drawing                                            *\r
+\****************************************************************************************/\r
+\r
+/****************************************************************************************\\r
+*       Drawing functions work with arbitrary 8-bit images or single-channel images      *\r
+*       with larger depth: 16s, 32s, 32f, 64f                                            *\r
+*       All the functions include parameter color that means rgb value (that may be      *\r
+*       constructed with CV_RGB macro) for color images and brightness                   *\r
+*       for grayscale images.                                                            *\r
+*       If a drawn figure is partially or completely outside the image, it is clipped.   *\r
+\****************************************************************************************/\r
+\r
+#define CV_RGB( r, g, b )  (int)((uchar)(b) + ((uchar)(g) << 8) + ((uchar)(r) << 16))\r
+#define CV_FILLED -1\r
+\r
+/* Draws 4-connected or 8-connected line segment connecting two points */\r
+OPENCVAPI  void  cvLine( CvArr* array, CvPoint pt1, CvPoint pt2,\r
+                         double color, int thickness CV_DEFAULT(1),\r
+                         int connectivity CV_DEFAULT(8) );\r
+\r
+/* Draws 8-connected line segment connecting two points with antialiazing.\r
+   Ending coordinates may be specified with sub-pixel accuracy\r
+   (scale is number of fractional bits in the coordinates) */\r
+OPENCVAPI  void  cvLineAA( CvArr* array, CvPoint pt1, CvPoint pt2,\r
+                           double color, int scale CV_DEFAULT(0));\r
+\r
+/* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2),\r
+   if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn */\r
+OPENCVAPI  void  cvRectangle( CvArr* array, CvPoint pt1, CvPoint pt2,\r
+                              double color, int thickness CV_DEFAULT(1));\r
+\r
+/* Draws a circle with specified center and radius.\r
+   Thickness works in the same way as with cvRectangle */\r
+OPENCVAPI  void  cvCircle( CvArr* array, CvPoint center, int radius,\r
+                           double color, int thickness CV_DEFAULT(1));\r
+\r
+/* Draws antialiazed circle with specified center and radius.\r
+   Both the center and radius can be specified with sub-pixel accuracy */\r
+OPENCVAPI  void  cvCircleAA( CvArr* array, CvPoint center, int radius,\r
+                             double color, int scale CV_DEFAULT(0) );\r
+\r
+/* Draws ellipse outline, filled ellipse, elliptic arc or filled elliptic sector,\r
+   depending on <thickness>, <startAngle> and <endAngle> parameters. The resultant figure\r
+   is rotated by <angle>. All the angles are in degrees */\r
+OPENCVAPI  void  cvEllipse( CvArr* array, CvPoint center, CvSize axes,\r
+                            double angle, double startAngle, double endAngle,\r
+                            double color, int thickness CV_DEFAULT(1));\r
+\r
+CV_INLINE  void  cvEllipseBox( CvArr* array, CvBox2D box,\r
+                               double color, int thickness CV_DEFAULT(1));\r
+CV_INLINE  void  cvEllipseBox( CvArr* array, CvBox2D box,\r
+                               double color, int thickness )\r
+{\r
+    cvEllipse( array, cvPointFrom32f( box.center ),\r
+               cvSize( cvRound(box.size.height*0.5),\r
+                       cvRound(box.size.width*0.5)),\r
+               box.angle*180/CV_PI, 0, 360, color, thickness );\r
+}\r
+\r
+\r
+/* Draws the whole ellipse or elliptic arc with antialiazing */\r
+OPENCVAPI  void  cvEllipseAA( CvArr* array, CvPoint center, CvSize axes,\r
+                              double angle, double startAngle,\r
+                              double endAngle, double color,\r
+                              int scale CV_DEFAULT(0) );\r
+\r
+/* Fills convex or monotonous (every horizontal line intersects the polygon twice at the most,\r
+   except, may be, horizontal sides) polygon. Connectivity or monotony is not checked */\r
+OPENCVAPI  void  cvFillConvexPoly( CvArr* array, CvPoint* pts, int npts, double color );\r
+\r
+\r
+/* Fills an area bounded by one or more arbitrary polygons (with possible intersections or\r
+   self-intersections */\r
+OPENCVAPI  void  cvFillPoly( CvArr* array, CvPoint** pts,\r
+                             int* npts, int contours, double color );\r
+\r
+/* Draws one or more polygonal curves */\r
+OPENCVAPI  void  cvPolyLine( CvArr* array, CvPoint** pts, int* npts, int contours,\r
+                             int closed, double color,\r
+                             int thickness CV_DEFAULT(1),\r
+                             int connectivity CV_DEFAULT(8));\r
+\r
+/* Draws one or more antialiazed polygonal curves */\r
+OPENCVAPI  void  cvPolyLineAA( CvArr* array, CvPoint** pts, int* npts, int contours,\r
+                               int closed, double color, int scale CV_DEFAULT(0) );\r
+\r
+/* Font metrics and structure */\r
+#define CV_FONT_VECTOR0  0\r
+\r
+typedef struct CvFont\r
+{\r
+    const int*  data; /* font data and metrics */\r
+    CvSize      size; /* horizontal and vertical scale factors,\r
+                         (8:8) fix-point numbers */\r
+    int         italic_scale; /* slope coefficient: 0 - normal, >0 - italic */\r
+    int         thickness; /* letters thickness */\r
+    int         dx; /* horizontal interval between letters */\r
+} CvFont;\r
+\r
+/* Initializes font structure used further in cvPutText */\r
+OPENCVAPI  void  cvInitFont( CvFont* font, int font_face,\r
+                             double hscale, double vscale,\r
+                             double italic_scale CV_DEFAULT(0),\r
+                             int thickness CV_DEFAULT(1) );\r
+\r
+/* Renders text stroke with specified font and color at specified location.\r
+   CvFont should be initialized with cvInitFont */\r
+OPENCVAPI  void  cvPutText( CvArr* array, const char* text, CvPoint org,\r
+                            CvFont* font, double color );\r
+\r
+/* Calculates bounding box of text stroke (useful for alignment) */\r
+OPENCVAPI  void  cvGetTextSize( const char* text_string, CvFont* font,\r
+                                CvSize* text_size, int* ymin );\r
+\r
+\r
+/*********************************** data sampling **************************************/\r
+\r
+/* Line iterator state */\r
+typedef struct CvLineIterator\r
+{\r
+    uchar* ptr;\r
+    int  err;\r
+    int  plus_delta;\r
+    int  minus_delta;\r
+    int  plus_step;\r
+    int  minus_step;\r
+} CvLineIterator;\r
+\r
+/* Initializes line iterator. Initially ptr will point to pt1 location in the array.\r
+   Returns the number of points on the line between the endings. */\r
+OPENCVAPI  int  cvInitLineIterator( const CvArr* array, CvPoint pt1, CvPoint pt2,\r
+                                    CvLineIterator* lineIterator,\r
+                                    int connectivity CV_DEFAULT(8));\r
+\r
+/* Moves iterator to the next line point */\r
+#define CV_NEXT_LINE_POINT( iterator )                                          \\r
+{                                                                               \\r
+    int mask =  (iterator).err < 0 ? -1 : 0;                                    \\r
+    (iterator).err += (iterator).minus_delta + ((iterator).plus_delta & mask);  \\r
+    (iterator).ptr += (iterator).minus_step + ((iterator).plus_step & mask);    \\r
+}\r
+\r
+/* Grabs the raster line data into the destination buffer.\r
+   Returns the number of retrieved points. */\r
+OPENCVAPI  int  cvSampleLine( const CvArr* array, CvPoint pt1, CvPoint pt2, void* buffer,\r
+                              int connectivity CV_DEFAULT(8));\r
+\r
+/* Retrieves the rectangular image region with specified center from the input array.\r
+ dst(x,y) <- src(x + center.x - dst_width/2, y + center.y - dst_height/2).\r
+ Values of pixels with fractional coordinates are retrieved using bilinear interpolation*/\r
+OPENCVAPI  void  cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center );\r
+\r
+\r
+/* Retrieves quadrangle from the input array.\r
+    matrixarr = ( a11  a12 | b1 )   dst(x,y) <- src(A[x y]' + b)\r
+                ( a21  a22 | b2 )   (bilinear interpolation is used to retrieve pixels\r
+                                     with fractional coordinates)\r
+*/\r
+OPENCVAPI  void  cvGetQuadrangleSubPix( const CvArr* src, CvArr* dstarr,\r
+                                        const CvArr* matrixarr,\r
+                                        int fillOutliers CV_DEFAULT(0),\r
+                                        CvScalar fillvalue CV_DEFAULT(cvScalarAll(0)));\r
+\r
+/* Methods for comparing two array */\r
+#define  CV_TM_SQDIFF        0\r
+#define  CV_TM_SQDIFF_NORMED 1\r
+#define  CV_TM_CCORR         2\r
+#define  CV_TM_CCORR_NORMED  3\r
+#define  CV_TM_CCOEFF        4\r
+#define  CV_TM_CCOEFF_NORMED 5\r
+\r
+/* Measures similarity between template and overlapped windows in the source image\r
+   and fills the resultant image with the measurements */\r
+OPENCVAPI  void  cvMatchTemplate( const CvArr* array, const CvArr* templ,\r
+                                  CvArr* result, int method );\r
+\r
+CV_EXTERN_C_FUNCPTR( float (CV_CDECL * CvDistanceFunction)\r
+                     ( const float* a, const float* b, void* user_param ));\r
+\r
+/* Computes earth mover distance between two weigted point sets\r
+   (called signatures in image retrieval terminology) */\r
+OPENCVAPI  float  cvCalcEMD2( const CvArr* signature1,\r
+                              const CvArr* signature2,\r
+                              CvDisType dist_type,\r
+                              CvDistanceFunction dist_func CV_DEFAULT(0),\r
+                              const CvArr* cost_matrix CV_DEFAULT(0),\r
+                              CvArr* flow CV_DEFAULT(0),\r
+                              float* lower_bound CV_DEFAULT(0),\r
+                              void* user_param CV_DEFAULT(0));\r
+\r
+/****************************************************************************************\\r
+*                              Contours retrieving                                       *\r
+\****************************************************************************************/\r
+\r
+/*\r
+Internal structure that is used for sequental retrieving contours from the image.\r
+It supports both hierarchical and plane variants of Suzuki algorithm.\r
+*/\r
+typedef struct _CvContourScanner* CvContourScanner;\r
+\r
+typedef enum CvContourRetrievalMode\r
+{\r
+    CV_RETR_EXTERNAL = 0,\r
+    CV_RETR_LIST     = 1,\r
+    CV_RETR_CCOMP    = 2,\r
+    CV_RETR_TREE     = 3\r
+}\r
+CvContourRetrievalMode;\r
+\r
+typedef enum CvChainApproxMethod\r
+{\r
+    CV_CHAIN_CODE             = 0,\r
+    CV_CHAIN_APPROX_NONE      = 1,\r
+    CV_CHAIN_APPROX_SIMPLE    = 2,\r
+    CV_CHAIN_APPROX_TC89_L1   = 3,\r
+    CV_CHAIN_APPROX_TC89_KCOS = 4,\r
+    CV_LINK_RUNS              = 5\r
+} CvChainApproxMethod;\r
+\r
+\r
+/* Retrieves outer and possibly inner boundaries of white (non-zero) connected\r
+   components on the black (zero) background */\r
+OPENCVAPI  int  cvFindContours( CvArr* array, CvMemStorage* storage,\r
+                           CvSeq**  firstContour,\r
+                           int  headerSize CV_DEFAULT(sizeof(CvContour)),\r
+                           CvContourRetrievalMode mode CV_DEFAULT( CV_RETR_LIST ),\r
+                           CvChainApproxMethod method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE));\r
+\r
+\r
+/* Initalizes contour retrieving process.\r
+   Call cvStartFindContours.\r
+   Call cvFindNextContour until null pointer is returned\r
+   or some other condition becomes true.\r
+   Call cvEndFindContours at the end. */\r
+OPENCVAPI  CvContourScanner   cvStartFindContours( CvArr* array, CvMemStorage* storage,\r
+                                        int header_size, CvContourRetrievalMode mode,\r
+                                        CvChainApproxMethod method );\r
+\r
+/* Retrieves next contour */\r
+OPENCVAPI  CvSeq*  cvFindNextContour( CvContourScanner scanner );\r
+\r
+\r
+/* Substitutes the last retrieved contour with the new one\r
+   (if the substitutor is null, the last retrieved contour is removed from the tree) */\r
+OPENCVAPI  void   cvSubstituteContour( CvContourScanner scanner, CvSeq* newContour );\r
+\r
+\r
+/* Releases contour scanner and returns pointer to the first outer contour */\r
+OPENCVAPI  CvSeq*  cvEndFindContours( CvContourScanner* scanner );\r
+\r
+/* Draws contour outlines or filled interiors on the image */\r
+OPENCVAPI void  cvDrawContours( CvArr *img, CvSeq* contour,\r
+                                double external_color, double hole_color,\r
+                                int max_level, int thickness CV_DEFAULT(1),\r
+                                int connectivity CV_DEFAULT(8));\r
+\r
+/******************* Iteration through the sequence tree *****************/\r
+typedef struct CvTreeNodeIterator\r
+{\r
+    const void* node;\r
+    int level;\r
+    int maxLevel;\r
+}\r
+CvTreeNodeIterator;\r
+\r
+OPENCVAPI void cvInitTreeNodeIterator( CvTreeNodeIterator* treeIterator,\r
+                                   const void* first, int maxLevel );\r
+OPENCVAPI void* cvNextTreeNode( CvTreeNodeIterator* treeIterator );\r
+OPENCVAPI void* cvPrevTreeNode( CvTreeNodeIterator* treeIterator );\r
+\r
+/* Inserts sequence into tree with specified "parent" sequence.\r
+   If parent is equal to frame (e.g. the most external contour),\r
+   then added contour will have null pointer to parent. */\r
+OPENCVAPI void cvInsertNodeIntoTree( void* node, void* parent, void* frame );\r
+\r
+/* Removes contour from tree (together with the contour children). */\r
+OPENCVAPI void cvRemoveNodeFromTree( void* node, void* frame );\r
+\r
+/* Gathers pointers to all the sequences,\r
+   accessible from the <first>, to the single sequence */\r
+OPENCVAPI CvSeq* cvTreeToNodeSeq( const void* first, int header_size,\r
+                                  CvMemStorage* storage );\r
+\r
+/* Approximates a single Freeman chain or a tree of chains to polygonal curves */\r
+OPENCVAPI  CvSeq* cvApproxChains( CvSeq* src_seq, CvMemStorage* storage,\r
+                            CvChainApproxMethod method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),\r
+                            double parameter CV_DEFAULT(0),\r
+                            int  minimal_perimeter CV_DEFAULT(0),\r
+                            int  recursive CV_DEFAULT(0));\r
+\r
+\r
+/* Freeman chain reader state */\r
+typedef struct CvChainPtReader\r
+{\r
+    CV_SEQ_READER_FIELDS()\r
+    char      code;\r
+    CvPoint  pt;\r
+    char      deltas[8][2];\r
+    int       reserved[2];\r
+} CvChainPtReader;\r
+\r
+/* Initalizes Freeman chain reader.\r
+   The reader is used to iteratively get coordinates of all the chain points.\r
+   If the original codes should be read, a simple sequence reader can be used */\r
+OPENCVAPI  void  cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader );\r
+\r
+/* Retrieve the next chain point */\r
+OPENCVAPI  CvPoint   cvReadChainPoint( CvChainPtReader* reader );\r
+\r
+\r
+/****************************************************************************************\\r
+*                                  Motion Analysis                                       *\r
+\****************************************************************************************/\r
+\r
+/********************************** change detection ************************************/\r
+\r
+/* Finds absolute difference between to arrays\r
+   dst(x,y,c) = abs(srcA(x,y,c) - srcB(x,y,c)) */\r
+OPENCVAPI  void  cvAbsDiff( const CvArr* srcA, const CvArr* srcB, CvArr* dst );\r
+\r
+\r
+/* Finds absolute difference between an array and scalar\r
+   dst(x,y,c) = abs(srcA(x,y,c) - value(c)) */\r
+OPENCVAPI  void  cvAbsDiffS( const CvArr* src, CvArr* dst, CvScalar value );\r
+#define cvAbs( src, dst ) cvAbsDiffS( (src), (dst), cvScalarAll(0))\r
+\r
+/************************************ optical flow ***************************************/\r
+\r
+/* Calculates optical flow for 2 images using classical Lucas & Kanade algorithm */\r
+OPENCVAPI  void  cvCalcOpticalFlowLK( const CvArr* srcA, const CvArr* srcB,\r
+                                      CvSize winSize, CvArr* velx, CvArr* vely );\r
+\r
+/* Calculates optical flow for 2 images using block matching algorithm */\r
+OPENCVAPI  void  cvCalcOpticalFlowBM( const CvArr* srcA, const CvArr* srcB,\r
+                                      CvSize blockSize, CvSize shiftSize,\r
+                                      CvSize maxRange, int usePrevious,\r
+                                      CvArr* velx, CvArr* vely );\r
+\r
+/* Calculates Optical flow for 2 images using Horn & Schunck algorithm */\r
+OPENCVAPI  void  cvCalcOpticalFlowHS( const CvArr* srcA, const CvArr* srcB,\r
+                                      int usePrevious, CvArr* velx, CvArr* vely,\r
+                                      double lambda, CvTermCriteria criteria );\r
+\r
+#define  CV_LKFLOW_PYR_A_READY       1\r
+#define  CV_LKFLOW_PYR_B_READY       2\r
+#define  CV_LKFLOW_INITIAL_GUESSES   4\r
+\r
+/* It is Lucas & Kanade method, modified to use pyramids.\r
+   Also it does several iterations to get optical flow for\r
+   every point at every pyramid level.\r
+   Calculates optical flow between two images for certain set of points (i.e.\r
+   it is a "sparse" optical flow, which is opposite to the previous 3 methods) */\r
+OPENCVAPI  void  cvCalcOpticalFlowPyrLK( const CvArr*  imgA, const CvArr*  imgB,\r
+                                         CvArr*  pyrA, CvArr*  pyrB,\r
+                                         CvPoint2D32f* featuresA,\r
+                                         CvPoint2D32f* featuresB,\r
+                                         int       count,\r
+                                         CvSize    winSize,\r
+                                         int       level,\r
+                                         char*     status,\r
+                                         float*    error,\r
+                                         CvTermCriteria criteria,\r
+                                         int       flags );\r
+\r
+\r
+/* Modification of a previous sparse optical flow algorithm to calculate\r
+   affine flow */\r
+OPENCVAPI  void  cvCalcAffineFlowPyrLK( const CvArr*  imgA, const CvArr*  imgB,\r
+                                        CvArr*  pyrA, CvArr*  pyrB,\r
+                                        CvPoint2D32f* featuresA,\r
+                                        CvPoint2D32f* featuresB,\r
+                                        float*  matrices, int  count,\r
+                                        CvSize  winSize, int  level,\r
+                                        char*  status, float* error,\r
+                                        CvTermCriteria criteria, int flags );\r
+\r
+/********************************* motion templates *************************************/\r
+\r
+/****************************************************************************************\\r
+*        All the motion template functions work only with single channel images.         *\r
+*        Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S                   *\r
+*        Motion history image must have depth IPL_DEPTH_32F,                             *\r
+*        Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S,                                   *\r
+*        Motion orientation image - IPL_DEPTH_32F                                        *\r
+*        Segmentation mask - IPL_DEPTH_32F                                               *\r
+*        All the angles are in degrees, all the times are in milliseconds                *\r
+\****************************************************************************************/\r
+\r
+/* Updates motion history image given motion silhouette */\r
+OPENCVAPI  void    cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,\r
+                                          double timestamp, double mhiDuration );\r
+\r
+/* Calculates gradient of the motion history image and fills\r
+   a mask indicating where the gradient is valid */\r
+OPENCVAPI  void    cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,\r
+                                         double delta1, double delta2,\r
+                                         int aperture_size CV_DEFAULT(3));\r
+\r
+/* Calculates average motion direction within a selected motion region \r
+   (region can be selected by setting ROIs and/or by composing a valid gradient mask\r
+   with the region mask) */\r
+OPENCVAPI  double  cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,\r
+                                            const CvArr* mhi, double curr_mhi_timestamp,\r
+                                            double mhi_duration );\r
+\r
+/* Splits a motion history image into a few parts corresponding to separate independent motions\r
+   (e.g. left hand, right hand) */\r
+OPENCVAPI  CvSeq*  cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,\r
+                                    CvMemStorage* storage,\r
+                                    double timestamp, double seg_thresh );\r
+\r
+/*********************** Background statistics accumulation *****************************/\r
+\r
+/* Adds image to accumulator */\r
+OPENCVAPI  void  cvAcc( const CvArr* image, CvArr* sum,\r
+                        const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Adds squared image to accumulator */\r
+OPENCVAPI  void  cvSquareAcc( const CvArr* image, CvArr* sqSum,\r
+                              const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Adds a product of two images to accumulator */\r
+OPENCVAPI  void  cvMultiplyAcc( const CvArr* imgA, const CvArr* imgB, CvArr* acc,\r
+                                const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+/* Adds image to accumulator with weights: imgU = imgU*(1-alpha) + imgY*alpha */\r
+OPENCVAPI  void  cvRunningAvg( const CvArr* imgY, CvArr* imgU, double alpha,\r
+                               const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+\r
+/****************************************************************************************\\r
+*                                       Tracking                                         *\r
+\****************************************************************************************/\r
+\r
+/* Implements CAMSHIFT algorithm - determines object position, size and orientation\r
+   from the object histogram back project (extension of meanshift) */\r
+OPENCVAPI int  cvCamShift( const CvArr* imgProb, CvRect  windowIn,\r
+                           CvTermCriteria criteria, CvConnectedComp* out,\r
+                           CvBox2D* box );\r
+\r
+/* Implements MeanShift algorithm - determines object position\r
+   from the object histogram back project */\r
+OPENCVAPI int  cvMeanShift( const CvArr* imgProb, CvRect  windowIn,\r
+                            CvTermCriteria criteria, CvConnectedComp* out );\r
+\r
+typedef struct CvConDensation\r
+{\r
+    int MP;\r
+    int DP;\r
+    float* DynamMatr;       /* Matrix of the linear Dynamics system  */\r
+    float* State;           /* Vector of State                       */\r
+    int SamplesNum;         /* Number of the Samples                 */\r
+    float** flSamples;      /* array of the Sample Vectors           */\r
+    float** flNewSamples;   /* temporary array of the Sample Vectors */\r
+    float* flConfidence;    /* Confidence for each Sample            */\r
+    float* flCumulative;    /* Cumulative confidence                 */\r
+    float* Temp;            /* Temporary vector                      */\r
+    float* RandomSample;    /* RandomVector to update sample set     */\r
+    CvRandState* RandS;     /* Array of structures to generate random vectors */\r
+} CvConDensation;\r
+\r
+/* Creates ConDensation filter state */\r
+OPENCVAPI CvConDensation*  cvCreateConDensation( int DP, int MP, int SamplesNum);\r
+\r
+/* Releases ConDensation filter state */\r
+OPENCVAPI void  cvReleaseConDensation( CvConDensation** ConDensation);\r
+\r
+/* Updates ConDensation filter by time (predict future state of the system) */\r
+OPENCVAPI void  cvConDensUpdateByTime( CvConDensation* ConDens);\r
+\r
+/* Initializes ConDensation filter samples  */\r
+OPENCVAPI void  cvConDensInitSampleSet( CvConDensation* conDens, CvMat* lowerBound,CvMat* upperBound);\r
+\r
+\r
+typedef struct CvKalman\r
+{\r
+    int MP;\r
+    int DP;\r
+    float* PosterState;          /* Vector of State of the System in k-th step  */\r
+    float* PriorState;           /* Vector of State of the System in (k-1)-th step */\r
+    float* DynamMatr;            /* Matrix of the linear Dynamics system */\r
+                                 /* (Must be updated by LinearizedDynamics function on each step*/\r
+                                 /*  for nonlinear systems)*/\r
+    float* MeasurementMatr;      /* Matrix of linear measurement (Must be updated by */\r
+                                 /* LinearizedMeasurement function on each step*/\r
+                                 /* for nonlinear measurements)*/\r
+    float* MNCovariance;         /* Matrix of measurement noice covariance*/\r
+                                 /* Initializes to Zero matrix, or sets by SetMeasureNoiseCov*/\r
+                                 /* method  */\r
+    float* PNCovariance;         /* Matrix of process noice covariance*/\r
+                                 /* Initializes to Identity matrix, or sets by SetProcessNoiseCov*/\r
+                                 /* method */\r
+    float* KalmGainMatr;         /* Kalman Gain Matrix*/\r
+    float* PriorErrorCovariance; /*Prior Error Covariance matrix*/\r
+    float* PosterErrorCovariance;/*Poster Error Covariance matrix*/\r
+    float* Temp1;                 /* Temporary Matrix */\r
+    float* Temp2;\r
+\r
+} CvKalman;\r
+\r
+/* Creates Kalman filter state */\r
+OPENCVAPI CvKalman* cvCreateKalman( int DynamParams, int MeasureParams);\r
+\r
+/* Releases Kalman filter state */\r
+OPENCVAPI void  cvReleaseKalman( CvKalman** Kalman);\r
+\r
+/* Updates Kalman filter by time (predicts future state of the system) */\r
+OPENCVAPI void  cvKalmanUpdateByTime( CvKalman* Kalman);\r
+\r
+/* Updates Kalman filter by measurement\r
+   (corrects state of the system and internal matrices) */\r
+OPENCVAPI void  cvKalmanUpdateByMeasurement( CvKalman* Kalman, CvMat* Measurement);\r
+\r
+\r
+/****************************************************************************************\\r
+*                              Planar subdivisions                                       *\r
+\****************************************************************************************/\r
+\r
+/************ Data structures and related enumerations ************/\r
+\r
+typedef long CvSubdiv2DEdge;\r
+\r
+#define CV_QUADEDGE2D_FIELDS()     \\r
+    int flags;                     \\r
+    struct CvSubdiv2DPoint* pt[4]; \\r
+    CvSubdiv2DEdge  next[4];\r
+\r
+#define CV_SUBDIV2D_POINT_FIELDS()\\r
+    int            flags;      \\r
+    CvSubdiv2DEdge first;      \\r
+    CvPoint2D32f   pt;\r
+\r
+#define CV_SUBDIV2D_VIRTUAL_POINT_FLAG (1 << 30)\r
+\r
+typedef struct CvQuadEdge2D\r
+{\r
+    CV_QUADEDGE2D_FIELDS()\r
+}\r
+CvQuadEdge2D;\r
+\r
+typedef struct CvSubdiv2DPoint\r
+{\r
+    CV_SUBDIV2D_POINT_FIELDS()\r
+}\r
+CvSubdiv2DPoint;\r
+\r
+#define CV_SUBDIV2D_FIELDS()    \\r
+    CV_GRAPH_FIELDS()           \\r
+    int  quad_edges;            \\r
+    int  is_geometry_valid;     \\r
+    CvSubdiv2DEdge recent_edge; \\r
+    CvPoint2D32f  topleft;      \\r
+    CvPoint2D32f  bottomright;\r
+    \r
+typedef struct CvSubdiv2D\r
+{\r
+    CV_SUBDIV2D_FIELDS()\r
+}\r
+CvSubdiv2D;\r
+\r
+\r
+typedef enum CvSubdiv2DPointLocation\r
+{\r
+    CV_PTLOC_ERROR = -2,\r
+    CV_PTLOC_OUTSIDE_RECT = -1,\r
+    CV_PTLOC_INSIDE = 0,\r
+    CV_PTLOC_VERTEX = 1,\r
+    CV_PTLOC_ON_EDGE = 2\r
+}\r
+CvSubdiv2DPointLocation;\r
+\r
+typedef enum CvNextEdgeType\r
+{\r
+    CV_NEXT_AROUND_ORG   = 0x00,\r
+    CV_NEXT_AROUND_DST   = 0x22,\r
+    CV_PREV_AROUND_ORG   = 0x11,\r
+    CV_PREV_AROUND_DST   = 0x33,\r
+    CV_NEXT_AROUND_LEFT  = 0x13,\r
+    CV_NEXT_AROUND_RIGHT = 0x31,\r
+    CV_PREV_AROUND_LEFT  = 0x20,\r
+    CV_PREV_AROUND_RIGHT = 0x02\r
+}\r
+CvNextEdgeType;\r
+\r
+/* get the next edge with the same origin point (counterwise) */\r
+#define  CV_SUBDIV2D_NEXT_EDGE( edge )  (((CvQuadEdge2D*)((edge) & ~3))->next[(edge)&3])\r
+\r
+\r
+/* Initializes Delaunay triangulation */\r
+OPENCVAPI  void  cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect );\r
+\r
+/* Creates new subdivision */\r
+OPENCVAPI  CvSubdiv2D*  cvCreateSubdiv2D( int subdiv_type, int header_size,\r
+                                       int vtx_size, int quadedge_size,\r
+                                       CvMemStorage* storage );\r
+\r
+/************************* high-level subdivision functions ***************************/\r
+\r
+/* Simplified Delaunay diagram creation */\r
+CV_INLINE  CvSubdiv2D* cvCreateSubdivDelaunay2D( CvRect rect, CvMemStorage* storage );\r
+CV_INLINE  CvSubdiv2D* cvCreateSubdivDelaunay2D( CvRect rect, CvMemStorage* storage )\r
+{\r
+    CvSubdiv2D* subdiv = cvCreateSubdiv2D( CV_SEQ_KIND_SUBDIV2D, sizeof(*subdiv),\r
+                         sizeof(CvSubdiv2DPoint), sizeof(CvQuadEdge2D), storage );\r
+\r
+    cvInitSubdivDelaunay2D( subdiv, rect );\r
+    return subdiv;\r
+}\r
+\r
+\r
+/* Inserts new point to the Delaunay triangulation */\r
+OPENCVAPI  CvSubdiv2DPoint*  cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt);\r
+\r
+/* Locates a point within the Delaunay triangulation (finds the edge\r
+   the point is left to or belongs to, or the triangulation point the given\r
+   point coinsides with */\r
+OPENCVAPI  CvSubdiv2DPointLocation  cvSubdiv2DLocate(\r
+                               CvSubdiv2D* subdiv, CvPoint2D32f pt,\r
+                               CvSubdiv2DEdge *_edge,\r
+                               CvSubdiv2DPoint** _point CV_DEFAULT(NULL) );\r
+\r
+/* Calculates Voronoi tesselation (i.e. coordinates of Voronoi points) */\r
+OPENCVAPI  void  cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv );\r
+\r
+\r
+/* Removes all Voronoi points from the tesselation */\r
+OPENCVAPI  void  cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv );\r
+\r
+\r
+/* Finds the nearest to the given point vertex in subdivision. */\r
+OPENCVAPI CvSubdiv2DPoint* cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt );\r
+\r
+\r
+/************ Basic quad-edge navigation and operations ************/\r
+\r
+CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DNextEdge( CvSubdiv2DEdge edge );\r
+CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DNextEdge( CvSubdiv2DEdge edge )\r
+{\r
+    return  CV_SUBDIV2D_NEXT_EDGE(edge);\r
+}\r
+\r
+\r
+CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate );\r
+CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate )\r
+{\r
+    return  (edge & ~3) + ((edge + rotate) & 3);\r
+}\r
+\r
+CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DSymEdge( CvSubdiv2DEdge edge );\r
+CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DSymEdge( CvSubdiv2DEdge edge )\r
+{\r
+    return edge ^ 2;\r
+}\r
+\r
+CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type );\r
+CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type )\r
+{\r
+    CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);\r
+    edge = e->next[(edge + (int)type) & 3];\r
+    return  (edge & ~3) + ((edge + ((int)type >> 4)) & 3);\r
+}\r
+\r
+\r
+CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge );\r
+CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge )\r
+{\r
+    CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);\r
+    return e->pt[edge & 3];\r
+}\r
+\r
+\r
+CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge );\r
+CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge )\r
+{\r
+    CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);\r
+    return e->pt[(edge + 2) & 3];\r
+}\r
+\r
+\r
+CV_INLINE  double  cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c );\r
+CV_INLINE  double  cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c )\r
+{\r
+    return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);\r
+}\r
+\r
+\r
+/****************************************************************************************\\r
+*                            Contour Processing and Shape Analysis                       *\r
+\****************************************************************************************/\r
+\r
+#define CV_POLY_APPROX_DP 0\r
+\r
+/* Approximates a single polygonal curve (contour) or\r
+   a tree of polygonal curves (contours) */\r
+OPENCVAPI  CvSeq*  cvApproxPoly( const void* src_seq,\r
+                                 int header_size, CvMemStorage* storage,\r
+                                 int method, double parameter,\r
+                                 int parameter2 CV_DEFAULT(0));\r
+\r
+/* Calculates perimeter of a contour or a part of contour */\r
+OPENCVAPI  double  cvArcLength( const void* curve,\r
+                                CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ),\r
+                                int is_closed CV_DEFAULT(-1));\r
+#define cvContourPerimeter( contour ) cvArcLength( contour, CV_WHOLE_SEQ, 1 )\r
+\r
+/* Calculates contour boundning rectangle (update=1) or\r
+   just retrieves pre-calculated rectangle (update=0) */\r
+OPENCVAPI  CvRect  cvBoundingRect( const void* points, int update CV_DEFAULT(0) );\r
+\r
+/* Calculates area of a contour or contour segment */\r
+OPENCVAPI  double  cvContourArea( const void* contour,\r
+                                  CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));\r
+\r
+/* Finds minimum area rotated rectangle bounding a set of points */\r
+OPENCVAPI  CvBox2D  cvMinAreaRect2( const void* points,\r
+                                    CvMemStorage* storage CV_DEFAULT(NULL));\r
+\r
+/* Finds minimum enclosing circle for a set of points */\r
+OPENCVAPI  void  cvMinEnclosingCircle( const void* points,\r
+                                       CvPoint2D32f* center, float* radius );\r
+\r
+#define CV_CONTOURS_MATCH_I1  1\r
+#define CV_CONTOURS_MATCH_I2  2\r
+#define CV_CONTOURS_MATCH_I3  3\r
+\r
+/* Compares two contours by matching their moments */\r
+OPENCVAPI  double  cvMatchShapes( const void* contour1, const void* contour2,\r
+                                  int method, double parameter CV_DEFAULT(0));\r
+\r
+/* Contour tree header */\r
+typedef struct CvContourTree\r
+{\r
+    CV_SEQUENCE_FIELDS()\r
+    CvPoint p1;            /* the first point of the binary tree root segment */\r
+    CvPoint p2;            /* the last point of the binary tree root segment */\r
+} CvContourTree;\r
+\r
+/* Builds hierarhical representation of a contour */\r
+OPENCVAPI  CvContourTree*   cvCreateContourTree( CvSeq* contour, CvMemStorage* storage,\r
+                                                 double threshold );\r
+\r
+/* Reconstruct (completelly or partially) contour a from contour tree */\r
+OPENCVAPI  CvSeq*  cvContourFromContourTree( CvContourTree *tree,\r
+                                          CvMemStorage* storage,\r
+                                          CvTermCriteria criteria );\r
+\r
+/* Compares two contour trees */\r
+#define  CV_CONTOUR_TREES_MATCH_I1  1\r
+\r
+OPENCVAPI  double  cvMatchContourTrees( CvContourTree *tree1,\r
+                                        CvContourTree *tree2,\r
+                                        int method, double threshold );\r
+\r
+/* Calculates histogram of a contour */\r
+OPENCVAPI  void  cvCalcPGH( const CvSeq* contour, CvHistogram* hist );\r
+\r
+#define CV_CLOCKWISE         1\r
+#define CV_COUNTER_CLOCKWISE 2\r
+\r
+/* Calculates exact convex hull of 2d point set */\r
+OPENCVAPI CvSeq* cvConvexHull2( const CvArr* input,\r
+                                void* hull_storage CV_DEFAULT(NULL),\r
+                                int orientation CV_DEFAULT(CV_CLOCKWISE),\r
+                                int return_points CV_DEFAULT(0));\r
+\r
+/* Checks whether the contour is convex or not (returns 1 if convex, 0 if not) */\r
+OPENCVAPI  int  cvCheckContourConvexity( const CvArr* contour );\r
+\r
+/* Finds a sequence of convexity defects of given contour */\r
+typedef struct CvConvexityDefect\r
+{\r
+    CvPoint* start; /* point of the contour where the defect begins */\r
+    CvPoint* end; /* point of the contour where the defect ends */\r
+    CvPoint* depth_point; /* the farthest from the convex hull point within the defect */\r
+    float depth; /* distance between the farthest point and the convex hull */\r
+} CvConvexityDefect;\r
+\r
+\r
+/* Finds convexity defects for the contour */\r
+OPENCVAPI CvSeq*  cvConvexityDefects( const CvArr* contour, const CvArr* convexhull,\r
+                                      CvMemStorage* storage CV_DEFAULT(NULL));\r
+\r
+/* Fits ellipse into a set of 2d points */\r
+OPENCVAPI CvBox2D cvFitEllipse2( const CvArr* points );\r
+\r
+/****************************************************************************************\\r
+*                                  Histogram functions                                   *\r
+\****************************************************************************************/\r
+\r
+/* Creates new histogram */\r
+OPENCVAPI  CvHistogram*  cvCreateHist( int dims, int* sizes, int type,\r
+                                       float** ranges CV_DEFAULT(NULL),\r
+                                       int uniform CV_DEFAULT(1));\r
+\r
+/* Assignes histogram bin ranges */\r
+OPENCVAPI void  cvSetHistBinRanges( CvHistogram* hist, float** ranges,\r
+                                    int uniform CV_DEFAULT(1));\r
+\r
+/* Creates histogram header for array */\r
+OPENCVAPI  CvHistogram*  cvMakeHistHeaderForArray(\r
+                            int  dims, int* sizes, CvHistogram* hist,\r
+                            float* data, float** ranges CV_DEFAULT(NULL),\r
+                            int uniform CV_DEFAULT(1));\r
+\r
+/* Releases histogram */\r
+OPENCVAPI  void  cvReleaseHist( CvHistogram** hist );\r
+\r
+/* Clears all the histogram bins */\r
+OPENCVAPI  void  cvClearHist( CvHistogram* hist );\r
+\r
+/* Finds indices and values of minimum and maximum histogram bins */\r
+OPENCVAPI  void  cvGetMinMaxHistValue( const CvHistogram* hist,\r
+                                    float* value_min, float* value_max,\r
+                                    int* idx_min CV_DEFAULT(NULL),\r
+                                    int* idx_max CV_DEFAULT(NULL));\r
+\r
+\r
+/* Normalizes histogram by dividing all bins by sum of the bins, multiplied by <factor>.\r
+   After that sum of histogram bins is equal to <factor> */\r
+OPENCVAPI  void  cvNormalizeHist( CvHistogram* hist, double factor );\r
+\r
+\r
+/* Clear all histogram bins that are below the threshold */\r
+OPENCVAPI  void  cvThreshHist( CvHistogram* hist, double thresh );\r
+\r
+#define CV_COMP_CORREL      0\r
+#define CV_COMP_CHISQR      1\r
+#define CV_COMP_INTERSECT   2\r
+\r
+/* Compares two histogram */\r
+OPENCVAPI  double  cvCompareHist( const CvHistogram* hist1,\r
+                                  const CvHistogram* hist2,\r
+                                  int method);\r
+\r
+/* Copies one histogram to another. Destination histogram is created if\r
+   the destination pointer is NULL */\r
+OPENCVAPI void  cvCopyHist( const CvHistogram* src, CvHistogram** dst );\r
+\r
+\r
+/* Calculates bayesian probabilistic histograms\r
+   (each or src and dst is an array of <number> histograms */\r
+OPENCVAPI void  cvCalcBayesianProb( CvHistogram** src, int number,\r
+                                    CvHistogram** dst);\r
+\r
+/* Calculates array histogram */\r
+OPENCVAPI  void  cvCalcArrHist( CvArr** arr, CvHistogram* hist,\r
+                                int doNotClear CV_DEFAULT(0),\r
+                                const CvArr* mask CV_DEFAULT(NULL) );\r
+\r
+CV_INLINE  void  cvCalcHist( IplImage** img, CvHistogram* hist,\r
+                             int doNotClear CV_DEFAULT(0),\r
+                             const CvArr* mask CV_DEFAULT(NULL) );\r
+CV_INLINE  void  cvCalcHist( IplImage** img, CvHistogram* hist,\r
+                             int doNotClear, const CvArr* mask )\r
+{\r
+    cvCalcArrHist( (CvArr**)img, hist, doNotClear, mask );\r
+}\r
+\r
+/* Calculates contrast histogram */\r
+OPENCVAPI  void  cvCalcContrastHist( CvArr** img, CvHistogram* hist,\r
+                                     int doNotClear, IplImage* mask );\r
+\r
+/* Calculates back project */\r
+OPENCVAPI  void  cvCalcArrBackProject( CvArr** img, CvArr* dst,\r
+                                       const CvHistogram* hist );\r
+#define  cvCalcBackProject(img, dst, hist) cvCalcArrBackProject((CvArr**)img, dst, hist)\r
+\r
+\r
+/* Does some sort of template matching but compares histograms of\r
+   template and each window location */\r
+OPENCVAPI  void  cvCalcArrBackProjectPatch( CvArr** img, CvArr* dst, CvSize range,\r
+                                            CvHistogram* hist, int method,\r
+                                            double normFactor );\r
+#define  cvCalcBackProjectPatch( img, dst, range, hist, method, normFactor ) \\r
+     cvCalcArrBackProjectPatch( (CvArr**)img, dst, range, hist, method, normFactor )\r
+\r
+\r
+/* calculates probabilistic density (divides one histogram by another) */\r
+OPENCVAPI  void  cvCalcProbDensity( CvHistogram* hist, CvHistogram* hist_mask,\r
+                                    CvHistogram* hist_dens, double scale CV_DEFAULT(255) );\r
+\r
+\r
+#define  CV_VALUE  1\r
+#define  CV_ARRAY  2\r
+/* Updates active contour in order to minimize its cummulative\r
+   (internal and external) energy. */\r
+OPENCVAPI  void  cvSnakeImage( const IplImage* src, CvPoint* points,\r
+                            int  length, float* alpha,\r
+                            float* beta, float* gamma,\r
+                            int coeffUsage, CvSize  win,\r
+                            CvTermCriteria criteria, int calcGradient CV_DEFAULT(1));\r
+\r
+/* Finds hand region in range image data */\r
+OPENCVAPI  void  cvFindHandRegion (CvPoint3D32f* points, int count,\r
+                                CvSeq* indexs,\r
+                                float* line, CvSize2D32f size, int flag,\r
+                                CvPoint3D32f* center,\r
+                                CvMemStorage* storage, CvSeq **numbers);\r
+\r
+/* Finds hand region in range image data (advanced version) */\r
+OPENCVAPI  void  cvFindHandRegionA( CvPoint3D32f* points, int count,\r
+                                CvSeq* indexs,\r
+                                float* line, CvSize2D32f size, int jc,\r
+                                CvPoint3D32f* center,\r
+                                CvMemStorage* storage, CvSeq **numbers);\r
+\r
+/* Calculates the cooficients of the homography matrix */\r
+OPENCVAPI  void  cvCalcImageHomography(float *line, CvPoint3D32f* center,\r
+                                     float* intrinsic, float* homography);\r
+\r
+/* Creates hand mask image given several points on the hand */\r
+OPENCVAPI  void  cvCreateHandMask( CvSeq* hand_points,\r
+                                   IplImage *img_mask, CvRect *roi);\r
+\r
+\r
+#define CV_DIST_MASK_3   3\r
+#define CV_DIST_MASK_5   5 \r
+\r
+/* Applies distance transform to binary image */\r
+OPENCVAPI  void  cvDistTransform( const CvArr* src, CvArr* dst,\r
+                                  CvDisType disType CV_DEFAULT(CV_DIST_L2),\r
+                                  int maskSize CV_DEFAULT(3),\r
+                                  const float* mask CV_DEFAULT(NULL));\r
+\r
+\r
+/* Defines for Threshold functions */\r
+#define CV_THRESH_BINARY      0  /* val = (val>thresh? MAX:0)      */\r
+#define CV_THRESH_BINARY_INV  1  /* val = (val>thresh? 0:MAX)      */\r
+#define CV_THRESH_TRUNC       2  /* val = (val>thresh? thresh:val) */\r
+#define CV_THRESH_TOZERO      3  /* val = (val>thresh? val:0)      */\r
+#define CV_THRESH_TOZERO_INV  4  /* val = (val>thresh? 0:val)      */\r
+\r
+/* Applies fixed-level threshold to grayscale image. This is the basic operation\r
+   to be performed before retrieving contours */\r
+OPENCVAPI  void  cvThreshold( const CvArr*  src, CvArr*  dst,\r
+                              double  thresh, double  maxValue, int type );\r
+\r
+#define CV_ADAPTIVE_THRESH_MEAN_C  0\r
+#define CV_ADAPTIVE_THRESH_GAUSSIAN_C  1\r
+\r
+/* Applies adaptive threshold to grayscale image.\r
+   The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and\r
+   CV_ADAPTIVE_THRESH_GAUSSIAN_C are:\r
+   neighborhood size (3, 5, 7 etc.),\r
+   and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) */\r
+OPENCVAPI  void  cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double maxValue,\r
+                                      int method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C),\r
+                                      int type CV_DEFAULT(CV_THRESH_BINARY),\r
+                                      int blockSize CV_DEFAULT(3),\r
+                                      double param1 CV_DEFAULT(5));\r
+\r
+#define CV_FLOODFILL_FIXED_RANGE (1 << 16)\r
+#define CV_FLOODFILL_MASK_ONLY   (1 << 17)\r
+\r
+/* Fills the connected component until the color difference gets large enough */\r
+OPENCVAPI  void  cvFloodFill( CvArr* array, CvPoint seedPoint,\r
+                              double newVal, double loDiff CV_DEFAULT(0),\r
+                              double upDiff CV_DEFAULT(0),\r
+                              CvConnectedComp* comp CV_DEFAULT(NULL),\r
+                              int flags CV_DEFAULT(4),\r
+                              CvArr* mask CV_DEFAULT(NULL));\r
+\r
+/****************************************************************************************\\r
+*                                  Feature detection                                     *\r
+\****************************************************************************************/\r
+\r
+/* Runs canny edge detector */\r
+OPENCVAPI  void  cvCanny( const CvArr* src, CvArr* dst, double low_threshold,\r
+                          double high_threshold, int  aperture_size CV_DEFAULT(3) );\r
+\r
+/* Calculates constraint image for corner detection\r
+   Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy.\r
+   Applying threshold to the result gives coordinates of corners */\r
+OPENCVAPI void cvPreCornerDetect( const CvArr* src, CvArr* dst,\r
+                                  int aperture_size CV_DEFAULT(3) );\r
+\r
+/* Calculates eigen values and vectors of 2x2\r
+   gradient matrix at every image pixel */\r
+OPENCVAPI void  cvCornerEigenValsAndVecs( const CvArr* src, CvArr* eigenvv,\r
+                                          int blockSize,\r
+                                          int aperture_size CV_DEFAULT(3) );\r
+\r
+/* Calculates minimal eigenvalue for 2x2 gradient matrix at\r
+   every image pixel */\r
+OPENCVAPI void  cvCornerMinEigenVal( const CvArr* src, CvArr* eigenval,\r
+                                     int blockSize, int aperture_size CV_DEFAULT(3) );\r
+\r
+/* Adjust corner position using some sort of gradient search */\r
+OPENCVAPI  void  cvFindCornerSubPix( const CvArr* src,CvPoint2D32f*  corners,\r
+                                     int count, CvSize win,CvSize zero_zone,\r
+                                     CvTermCriteria  criteria );\r
+\r
+/* Finds a sparse set of points within the selected region\r
+   that seem to be easy to track */\r
+OPENCVAPI void  cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image,\r
+                                       CvArr* temp_image, CvPoint2D32f* corners,\r
+                                       int* corner_count, double  quality_level,\r
+                                       double  min_distance,\r
+                                       const CvArr* mask CV_DEFAULT(NULL));\r
+\r
+#define CV_HOUGH_STANDARD 0\r
+#define CV_HOUGH_PROBABILISTIC 1\r
+#define CV_HOUGH_MULTI_SCALE 2\r
+\r
+/* Finds lines on binary image using one of several methods.\r
+   lineStorage is either memory storage or 1 x maxNumberOfLines CvMat, its\r
+   number of columns is changed by the function.\r
+   method is one of CV_HOUGH_*;\r
+   rho, theta and threshold are used for each of those methods;\r
+   param1 ~ lineLength, param2 ~ lineGap - for probabilistic,\r
+   param1 ~ srn, param2 ~ stn - for multi-scale */\r
+OPENCVAPI  CvSeq*  cvHoughLines2( CvArr* image, void* line_storage, int method, \r
+                                  double rho, double theta, int threshold,\r
+                                  double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0));\r
+\r
+/* Projects 2d points to one of standard coordinate planes\r
+   (i.e. removes one of coordinates) */\r
+OPENCVAPI  void  cvProject3D( CvPoint3D32f* points3D, int count,\r
+                              CvPoint2D32f* points2D, int xIndx, int yIndx );\r
+\r
+/* Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) */\r
+OPENCVAPI  void  cvFitLine( const CvArr* points, CvDisType dist, double param,\r
+                            double reps, double aeps, float* line );\r
+\r
+\r
+#define CV_EIGOBJ_NO_CALLBACK     0\r
+#define CV_EIGOBJ_INPUT_CALLBACK  1\r
+#define CV_EIGOBJ_OUTPUT_CALLBACK 2\r
+#define CV_EIGOBJ_BOTH_CALLBACK   3\r
+\r
+\r
+CV_EXTERN_C_FUNCPTR(CvStatus (CV_CDECL * CvCallback)\r
+                    (int index, void* buffer, void* userData));\r
+\r
+typedef union\r
+{\r
+    CvCallback callback;\r
+    void* data;\r
+}\r
+CvInput;\r
+\r
+/* Calculates covariation matrix of a set of arrays */\r
+OPENCVAPI  void  cvCalcCovarMatrixEx( int nObjects, void* input, int ioFlags,\r
+                                      int ioBufSize, uchar* buffer, void* userData,\r
+                                      IplImage* avg, float* covarMatrix );\r
+\r
+/* Calculates eigen values and vectors of covariation matrix of a set of\r
+   arrays */\r
+OPENCVAPI  void  cvCalcEigenObjects( int nObjects, void* input, void* output,\r
+                                    int ioFlags, int ioBufSize, void* userData,\r
+                                    CvTermCriteria* calcLimit, IplImage* avg,\r
+                                    float* eigVals );\r
+\r
+/* Calculates dot product (obj - avg) * eigObj (i.e. projects image to eigen vector) */\r
+OPENCVAPI  double  cvCalcDecompCoeff( IplImage* obj, IplImage* eigObj, IplImage* avg );\r
+\r
+/* Projects image to eigen space (finds all decomposion coefficients */\r
+OPENCVAPI  void  cvEigenDecomposite( IplImage* obj, int nEigObjs, void* eigInput,\r
+                                    int ioFlags, void* userData, IplImage* avg,\r
+                                    float* coeffs );\r
+\r
+/* Projects original objects used to calculate eigen space basis to that space */\r
+OPENCVAPI  void  cvEigenProjection( void* eigInput, int nEigObjs, int ioFlags,\r
+                                   void* userData, float* coeffs, IplImage* avg,\r
+                                   IplImage* proj );\r
+\r
+/*********************************** HMM structures *************************************/\r
+typedef struct CvEHMMState\r
+{\r
+    int num_mix;      /*number of mixtures in this state*/\r
+    float* mu;        /*mean vectors corresponding to each mixture*/\r
+    float* inv_var; /* square root of inversed variances corresp. to each mixture*/\r
+    float* log_var_val; /* sum of 0.5 (LN2PI + ln(variance[i]) ) for i=1,n */\r
+    float* weight;   /*array of mixture weights. Summ of all weights in state is 1. */\r
+\r
+} CvEHMMState;\r
+\r
+typedef struct CvEHMM\r
+{\r
+    int level; /* 0 - lowest(i.e its states are real states), ..... */\r
+    int num_states; /* number of HMM states */\r
+    float*  transP;/*transition probab. matrices for states */\r
+    float** obsProb; /* if level == 0 - array of brob matrices corresponding to hmm\r
+                        if level == 1 - martix of matrices */\r
+    union\r
+    {\r
+        CvEHMMState* state; /* if level == 0 points to real states array,\r
+                               if not - points to embedded hmms */\r
+        struct CvEHMM* ehmm; /* pointer to an embedded model or NULL, if it is a leaf */\r
+    } u;\r
+\r
+} CvEHMM;\r
+\r
+/* Creates 2D HMM */\r
+OPENCVAPI  CvEHMM*  cvCreate2DHMM( int* stateNumber, int* numMix, int obsSize );\r
+\r
+\r
+/* Releases HMM */\r
+OPENCVAPI  void  cvRelease2DHMM( CvEHMM** hmm );\r
+\r
+\r
+\r
+#define CV_COUNT_OBS(roi, win, delta, numObs )                                       \\r
+{                                                                                    \\r
+   (numObs)->width  =((roi)->width  -(win)->width  +(delta)->width)/(delta)->width;  \\r
+   (numObs)->height =((roi)->height -(win)->height +(delta)->height)/(delta)->height;\\r
+}\r
+\r
+typedef struct CvImgObsInfo\r
+{\r
+    int obs_x;\r
+    int obs_y;\r
+    int obs_size;\r
+    float* obs;//consequtive observations\r
+\r
+    int* state;/* array of pairs superstate/state to which observation belong */\r
+    int* mix;  /* number of mixture to which observation belong */\r
+\r
+} CvImgObsInfo;/*struct for 1 image*/\r
+\r
+/* Creates storage for observation vectors */\r
+OPENCVAPI  CvImgObsInfo*  cvCreateObsInfo( CvSize numObs, int obsSize );\r
+\r
+/* Releases storage for observation vectors */\r
+OPENCVAPI  void  cvReleaseObsInfo( CvImgObsInfo** obs_info );\r
+\r
+\r
+/* The function takes an image on input and and returns the sequnce of observations\r
+   to be used with an embedded HMM; Each observation is top-left block of DCT\r
+   coefficient matrix */\r
+OPENCVAPI  void  cvImgToObs_DCT( const CvArr* array, float* obs, CvSize dctSize,\r
+                                 CvSize obsSize, CvSize delta );\r
+\r
+\r
+/* Uniformly segments all observation vectors extracted from image */\r
+OPENCVAPI  void  cvUniformImgSegm( CvImgObsInfo* obs_info, CvEHMM* ehmm );\r
+\r
+/* Does mixture segmentation of the states of embedded HMM */\r
+OPENCVAPI  void  cvInitMixSegm( CvImgObsInfo** obs_info_array,\r
+                               int num_img, CvEHMM* hmm );\r
+\r
+/* Function calculates means, variances, weights of every Gaussian mixture\r
+   of every low-level state of embedded HMM */\r
+OPENCVAPI  void  cvEstimateHMMStateParams( CvImgObsInfo** obs_info_array,\r
+                                        int num_img, CvEHMM* hmm );\r
+\r
+/* Function computes transition probability matrices of embedded HMM\r
+   given observations segmentation */\r
+OPENCVAPI  void  cvEstimateTransProb( CvImgObsInfo** obs_info_array,\r
+                                   int num_img, CvEHMM* hmm );\r
+\r
+/* Function computes probabilities of appearing observations at any state\r
+   (i.e. computes P(obs|state) for every pair(obs,state)) */\r
+OPENCVAPI  void  cvEstimateObsProb( CvImgObsInfo* obs_info,\r
+                                   CvEHMM* hmm );\r
+\r
+/* Runs Viterbi algorithm for embedded HMM */\r
+OPENCVAPI  float  cvEViterbi( CvImgObsInfo* obs_info, CvEHMM* hmm );\r
+\r
+\r
+/* Function clusters observation vectors from several images\r
+   given observations segmentation.\r
+   Euclidean distance used for clustering vectors.\r
+   Centers of clusters are given means of every mixture */\r
+OPENCVAPI  void  cvMixSegmL2( CvImgObsInfo** obs_info_array,\r
+                             int num_img, CvEHMM* hmm );\r
+\r
+/* The function implements the K-means algorithm for clustering an array of sample\r
+   vectors in a specified number of classes */\r
+OPENCVAPI  void  cvKMeans2( const CvArr* samples, int cluster_count,\r
+                            CvArr* cluster_idx, CvTermCriteria termcrit );\r
+\r
+/****************************************************************************************\\r
+*                     Camera Calibration and Rectification functions                     *\r
+\****************************************************************************************/\r
+\r
+/* The function corrects radial and tangential image distortion using known\r
+   matrix of the camera intrinsic parameters and distortion coefficients */\r
+OPENCVAPI  void  cvUnDistortOnce( const CvArr* srcImage, CvArr* dstImage,\r
+                                  const float* intrMatrix,\r
+                                  const float* distCoeffs,\r
+                                  int interpolate CV_DEFAULT(1) );\r
+\r
+/* The function calculates map of distorted points indices and\r
+   interpolation coefficients for cvUnDistort function using known\r
+   matrix of the camera intrinsic parameters and distortion coefficients */\r
+OPENCVAPI  void  cvUnDistortInit( const CvArr* srcImage, CvArr* undistMap,\r
+                                  const float* intrMatrix,\r
+                                  const float* distCoeffs,\r
+                                  int interpolate CV_DEFAULT(1) );\r
+\r
+/* The function corrects radial and tangential image distortion\r
+   using previousely calculated (via cvUnDistortInit) map */\r
+OPENCVAPI  void  cvUnDistort( const CvArr* srcImage, CvArr* dstImage,\r
+                              const CvArr* undistMap, int interpolate CV_DEFAULT(1));\r
+#define cvRemap cvUnDistort\r
+\r
+\r
+/* The function converts floating-point pixel coordinate map to\r
+   faster fixed-point map, used by cvUnDistort (cvRemap) */\r
+OPENCVAPI  void  cvConvertMap( const CvArr* srcImage, const CvArr* flUndistMap,\r
+                               CvArr* undistMap, int iterpolate CV_DEFAULT(1) );\r
+\r
+/* Calibrates camera using multiple views of calibration pattern */\r
+OPENCVAPI  void  cvCalibrateCamera( int           numImages,\r
+                                    int*          numPoints,\r
+                                    CvSize        imageSize,\r
+                                    CvPoint2D32f* imagePoints32f,\r
+                                    CvPoint3D32f* objectPoints32f,\r
+                                    CvVect32f     distortion32f,\r
+                                    CvMatr32f     cameraMatrix32f,\r
+                                    CvVect32f     transVects32f,\r
+                                    CvMatr32f     rotMatrs32f,\r
+                                    int           useIntrinsicGuess);\r
+\r
+/* Variant of the previous function that takes double-precision parameters */\r
+OPENCVAPI  void  cvCalibrateCamera_64d( int           numImages,\r
+                                       int*          numPoints,\r
+                                       CvSize        imageSize,\r
+                                       CvPoint2D64d* imagePoints,\r
+                                       CvPoint3D64d* objectPoints,\r
+                                       CvVect64d     distortion,\r
+                                       CvMatr64d     cameraMatrix,\r
+                                       CvVect64d     transVects,\r
+                                       CvMatr64d     rotMatrs,\r
+                                       int           useIntrinsicGuess );\r
+\r
+/* Find 3d position of object given intrinsic camera parameters,\r
+   3d model of the object and projection of the object into view plane */\r
+OPENCVAPI  void  cvFindExtrinsicCameraParams( int           numPoints,\r
+                                             CvSize        imageSize,\r
+                                             CvPoint2D32f* imagePoints32f,\r
+                                             CvPoint3D32f* objectPoints32f,\r
+                                             CvVect32f     focalLength32f,\r
+                                             CvPoint2D32f  principalPoint32f,\r
+                                             CvVect32f     distortion32f,\r
+                                             CvVect32f     rotVect32f,\r
+                                             CvVect32f     transVect32f);\r
+\r
+/* Variant of the previous function that takes double-precision parameters */\r
+OPENCVAPI  void  cvFindExtrinsicCameraParams_64d( int           numPoints,\r
+                                                 CvSize        imageSize,\r
+                                                 CvPoint2D64d* imagePoints,\r
+                                                 CvPoint3D64d* objectPoints,\r
+                                                 CvVect64d     focalLength,\r
+                                                 CvPoint2D64d  principalPoint,\r
+                                                 CvVect64d     distortion,\r
+                                                 CvVect64d     rotVect,\r
+                                                 CvVect64d     transVect);\r
+\r
+\r
+/* Rodrigues transform */\r
+#define CV_RODRIGUES_M2V  0\r
+#define CV_RODRIGUES_V2M  1\r
+\r
+/* Converts rotation matrix to rotation vector or vice versa */\r
+OPENCVAPI  void  cvRodrigues( CvMat* rotMatrix, CvMat* rotVector,\r
+                              CvMat* jacobian, int convType);\r
+\r
+/* Does reprojection of 3d object points to the view plane */\r
+OPENCVAPI  void  cvProjectPoints( int             numPoints,\r
+                                 CvPoint3D64d*   objectPoints,\r
+                                 CvVect64d       rotVect,\r
+                                 CvVect64d       transVect,\r
+                                 CvVect64d       focalLength,\r
+                                 CvPoint2D64d    principalPoint,\r
+                                 CvVect64d       distortion,\r
+                                 CvPoint2D64d*   imagePoints,\r
+                                 CvVect64d       derivPointsRot,\r
+                                 CvVect64d       derivPointsTrans,\r
+                                 CvVect64d       derivPointsFocal,\r
+                                 CvVect64d       derivPointsPrincipal,\r
+                                 CvVect64d       derivPointsDistort);\r
+\r
+/* Simpler version of the previous function */\r
+OPENCVAPI void cvProjectPointsSimple(  int numPoints,\r
+                                    CvPoint3D64d * objectPoints,\r
+                                    CvVect64d rotMatr,\r
+                                    CvVect64d transVect,\r
+                                    CvMatr64d cameraMatrix,\r
+                                    CvVect64d distortion,\r
+                                    CvPoint2D64d* imagePoints);\r
+                                    \r
+/* Detects corners on a chess-board - "brand" OpenCV calibration pattern */\r
+OPENCVAPI  int  cvFindChessBoardCornerGuesses( const CvArr* array, CvArr* thresh,\r
+                                               CvMemStorage* storage, CvSize etalon_size,\r
+                                               CvPoint2D32f* corners,\r
+                                               int *corner_count CV_DEFAULT(NULL));\r
+\r
+\r
+typedef struct CvPOSITObject CvPOSITObject;\r
+\r
+/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */\r
+OPENCVAPI  CvPOSITObject*  cvCreatePOSITObject( CvPoint3D32f* points, int numPoints );\r
+\r
+\r
+/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of\r
+   an object given its model and projection in a weak-perspective case */\r
+OPENCVAPI  void  cvPOSIT(  CvPOSITObject* pObject, CvPoint2D32f* imagePoints,\r
+                           double focalLength, CvTermCriteria criteria,\r
+                           CvMatr32f rotation, CvVect32f translation);\r
+\r
+/* Releases CvPOSITObject structure */\r
+OPENCVAPI  void  cvReleasePOSITObject( CvPOSITObject**  ppObject );\r
+\r
+\r
+/****************************************************************************************\\r
+*                                      ViewMorphing                                      *\r
+\****************************************************************************************/\r
+OPENCVAPI void cvMake2DPoints(CvMat* srcPoint,CvMat* dstPoint);\r
+OPENCVAPI void cvMake3DPoints(CvMat* srcPoint,CvMat* dstPoint);\r
+OPENCVAPI int cvSolveCubic(CvMat* coeffs,CvMat* result);\r
+\r
+/*F///////////////////////////////////////////////////////////////////////////////////////\r
+//    Name:    cvFindFundamentalMat\r
+//    Purpose: find fundamental matrix for given points using different methods\r
+//    Context:\r
+//    Parameters:\r
+//      points1  - points on first image. Size of matrix 2xN or 3xN\r
+//      points2  - points on second image Size of matrix 2xN or 3xN\r
+//      fundMatr - found fundamental matrixes. Size 3x3. Or 9x3 for 7-point algorithm only.\r
+//                 (7-point algorith can returns 3 fundamental matrixes)\r
+//      method   - method for computing fundamental matrix\r
+//                 CV_FM_7POINT - for 7-point algorithm. Number of points == 7\r
+//                 CV_FM_8POINT - for 8-point algorithm. Number of points >= 8\r
+//                 CV_FM_RANSAC - for RANSAC  algorithm. Number of points >= 8\r
+//                 CV_FM_LMEDS  - for LMedS   algorithm. Number of points >= 8\r
+//      param1 and param2 uses for RANSAC and LMedS method.\r
+//         param1 - threshold distance from point to epipolar line.\r
+//                  If distance less than threshold point is good.\r
+//         param2 - probability. Usually = 0.99\r
+//         status - array, every element of which will be set to 1 if the point was good,\r
+//                  0 else. (for RANSAC and LMedS only)\r
+//                  For other methods all points status set to 1)\r
+//                  (it is optional parameter, can be NULL)\r
+//\r
+//    Returns:\r
+//      number of found fundamental matrixes\r
+//F*/\r
+#define CV_FM_7POINT 1\r
+#define CV_FM_8POINT 2\r
+#define CV_FM_RANSAC 3\r
+#define CV_FM_LMEDS  4 \r
+\r
+OPENCVAPI  int cvFindFundamentalMat(    CvMat* points1,\r
+                                CvMat* points2,\r
+                                CvMat* fundMatr,\r
+                                int    method,\r
+                                double param1,\r
+                                double param2,\r
+                                CvMat* status);\r
+\r
+/*F///////////////////////////////////////////////////////////////////////////////////////\r
+//    Name:    cvComputeCorrespondEpilines\r
+//    Purpose: computes correspondence piline for given point and fundamental matrix\r
+//    Context:\r
+//    Parameters:\r
+//      points  - points on image. Size of matrix 2xN or 3xN\r
+//      pointImageID - image on which points are located. 1 or 2 \r
+//      fundMatr - fundamental matrix\r
+//      corrLines - found correspondence lines for each point. Size of matrix 3xN,\r
+//                  Each line given by a,b,c. (ax+by+c=0)\r
+//\r
+//    Returns:\r
+//     \r
+//F*/\r
+OPENCVAPI  void cvComputeCorrespondEpilines(CvMat* points,\r
+                                            int pointImageID,\r
+                                            CvMat* fundMatr,\r
+                                            CvMat* corrLines);\r
+\r
+/* The order of the function corresponds to the order they should appear in\r
+   the view morphing pipeline */ \r
+\r
+/* Finds ending points of scanlines on left and right images of stereo-pair */\r
+OPENCVAPI  void  cvMakeScanlines( const CvMatrix3* matrix,\r
+                                CvSize     imgSize,\r
+                                int*       scanlines_1,\r
+                                int*       scanlines_2,\r
+                                int*       lens_1,\r
+                                int*       lens_2,\r
+                                int*       numlines);\r
+\r
+/* Grab pixel values from scanlines and stores them sequentially\r
+   (some sort of perspective image transform) */\r
+OPENCVAPI  void  cvPreWarpImage( int       numLines,\r
+                               IplImage* img,\r
+                               uchar*    dst,\r
+                               int*      dst_nums,\r
+                               int*      scanlines);\r
+\r
+/* Approximate each grabbed scanline by a sequence of runs\r
+   (lossy run-length compression) */\r
+OPENCVAPI  void  cvFindRuns( int    numLines,\r
+                           uchar* prewarp_1,\r
+                           uchar* prewarp_2,\r
+                           int*   line_lens_1,\r
+                           int*   line_lens_2,\r
+                           int*   runs_1,\r
+                           int*   runs_2,\r
+                           int*   num_runs_1,\r
+                           int*   num_runs_2);\r
+\r
+/* Compares two sets of compressed scanlines */\r
+OPENCVAPI  void  cvDynamicCorrespondMulti( int  lines,\r
+                                         int* first,\r
+                                         int* first_runs,\r
+                                         int* second,\r
+                                         int* second_runs,\r
+                                         int* first_corr,\r
+                                         int* second_corr);\r
+\r
+/* Finds scanline ending coordinates for some intermediate "virtual" camera position */\r
+OPENCVAPI  void  cvMakeAlphaScanlines( int*  scanlines_1,\r
+                                     int*  scanlines_2,\r
+                                     int*  scanlines_a,\r
+                                     int*  lens,\r
+                                     int   numlines,\r
+                                     float alpha);\r
+\r
+/* Blends data of the left and right image scanlines to get\r
+   pixel values of "virtual" image scanlines */\r
+OPENCVAPI  void  cvMorphEpilinesMulti( int    lines,\r
+                                     uchar* first_pix,\r
+                                     int*   first_num,\r
+                                     uchar* second_pix,\r
+                                     int*   second_num,\r
+                                     uchar* dst_pix,\r
+                                     int*   dst_num,\r
+                                     float  alpha,\r
+                                     int*   first,\r
+                                     int*   first_runs,\r
+                                     int*   second,\r
+                                     int*   second_runs,\r
+                                     int*   first_corr,\r
+                                     int*   second_corr);\r
+\r
+/* Does reverse warping of the morphing result to make\r
+   it fill the destination image rectangle */\r
+OPENCVAPI  void  cvPostWarpImage( int       numLines,\r
+                                uchar*    src,\r
+                                int*      src_nums,\r
+                                IplImage* img,\r
+                                int*      scanlines);\r
+\r
+/* Deletes Moire (missed pixels that appear due to discretization) */\r
+OPENCVAPI  void  cvDeleteMoire( IplImage*  img);\r
+\r
+/****************************************************************************************\\r
+*                                    System functions                                    *\r
+\****************************************************************************************/\r
+\r
+/* Loads optimized libraries (with manual and automatical processor type specification) */\r
+OPENCVAPI  int  cvLoadPrimitives( const char* proc_type CV_DEFAULT(NULL) );\r
+\r
+/* Exports low-level functions from OpenCV */\r
+OPENCVAPI  int  cvFillInternalFuncsTable(void* table);\r
+\r
+/* Retrieves information about OpenCV and loaded optimized primitives */\r
+OPENCVAPI  void  cvGetLibraryInfo( const char** version, int* loaded,\r
+                                   const char** loaded_modules );\r
+\r
+/* Get current OpenCV error status */\r
+OPENCVAPI CVStatus cvGetErrStatus( void );\r
+\r
+/* Sets error status silently */\r
+OPENCVAPI void cvSetErrStatus( CVStatus status );\r
+\r
+\r
+/* Retrives current error processing mode */\r
+OPENCVAPI int  cvGetErrMode( void );\r
+\r
+/* Sets error processing mode */\r
+OPENCVAPI void cvSetErrMode( int mode );\r
+\r
+/* Sets error status and performs some additonal actions (error message box,\r
+   writing message to stderr, terminate application etc.)\r
+   depending on the current error mode */\r
+OPENCVAPI CVStatus cvError( CVStatus code, const char *func,\r
+                         const char *context, const char *file, int line);\r
+\r
+/* Retrieves textual description of the error given its code */\r
+OPENCVAPI const char* cvErrorStr( CVStatus status );\r
+\r
+\r
+/* Assigns a new error-handling function */\r
+OPENCVAPI CVErrorCallBack cvRedirectError(CVErrorCallBack cvErrorFunc);\r
+\r
+\r
+/*\r
+    Output to:\r
+        cvNulDevReport - nothing\r
+        cvStdErrReport - console(printf)\r
+        cvGuiBoxReport - MessageBox(WIN32)\r
+*/\r
+OPENCVAPI CVStatus cvNulDevReport( CVStatus status, const char *funcName,\r
+                                const char *context, const char *file, int line );\r
+\r
+OPENCVAPI CVStatus cvStdErrReport( CVStatus status, const char *funcName,\r
+                                const char *context, const char *file, int line );\r
+\r
+OPENCVAPI CVStatus cvGuiBoxReport( CVStatus status, const char *funcName,\r
+                                const char *context, const char *file, int line);\r
+\r
+/* Get call stack */\r
+OPENCVAPI void cvGetCallStack(CvStackRecord** stack, int* size);\r
+\r
+/* Push the record to the call stack */\r
+OPENCVAPI void cvStartProfile( const char* call, const char* file, int line );\r
+\r
+/* Pop the record from the stack */\r
+OPENCVAPI void cvEndProfile( const char* file, int line );\r
+\r
+CV_EXTERN_C_FUNCPTR(void (CV_CDECL* CvStartProfileFunc)(const char*,const char*,int));\r
+CV_EXTERN_C_FUNCPTR(void (CV_CDECL* CvEndProfileFunc)(const char*,int));\r
+\r
+/* management functions */\r
+OPENCVAPI void cvSetProfile( CvStartProfileFunc startProfile,\r
+                             CvEndProfileFunc endProfile );\r
\r
+OPENCVAPI void cvRemoveProfile();                  \r
+\r
+\r
+CV_EXTERN_C_FUNCPTR(void* (CV_STDCALL *CvAllocFunc)(int, const char*, int));\r
+CV_EXTERN_C_FUNCPTR(int (CV_STDCALL *CvFreeFunc)(void**, const char*, int));\r
+\r
+/* Set user-defined memory managment functions (substitutors for malloc and free) that\r
+   will be called by cvAlloc, cvFree and higher-level functions (e.g. cvCreateImage) */\r
+OPENCVAPI void cvSetMemoryManager( CvAllocFunc allocFunc CV_DEFAULT(0),\r
+                                   CvFreeFunc freeFunc CV_DEFAULT(0));\r
+\r
+\r
+CV_EXTERN_C_FUNCPTR(IplImage* (CV_STDCALL* Cv_iplCreateImageHeader)\r
+                            (int,int,int,char*,char*,int,int,int,int,int,\r
+                            IplROI*,IplImage*,void*,IplTileInfo*));\r
+CV_EXTERN_C_FUNCPTR(void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int));\r
+\r
+CV_EXTERN_C_FUNCPTR(void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int));\r
+\r
+CV_EXTERN_C_FUNCPTR(IplROI* (CV_STDCALL* Cv_iplCreateROI)(int,int,int,int,int));\r
+\r
+CV_EXTERN_C_FUNCPTR(IplImage* (CV_STDCALL* Cv_iplCloneImage)(const IplImage*));\r
+\r
+\r
+/* Makes OpenCV use IPL functions for IplImage allocation/deallocation */\r
+OPENCVAPI void\r
+cvSetIPLAllocators( Cv_iplCreateImageHeader createHeader,\r
+                    Cv_iplAllocateImageData allocateData,\r
+                    Cv_iplDeallocate deallocate,\r
+                    Cv_iplCreateROI createROI,\r
+                    Cv_iplCloneImage cloneImage );\r
+\r
+#define CV_TURN_ON_IPL_COMPATIBILITY()                                  \\r
+    cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImage,         \\r
+                        iplDeallocate, iplCreateROI, iplCloneImage )\r
+\r
+/****************************************************************************************\\r
+*                                    Data Persistence                                    *\r
+\****************************************************************************************/\r
+\r
+/********************************** High-level functions ********************************/\r
+\r
+/* "black box" file storage */\r
+typedef struct CvFileStorage CvFileStorage;\r
+\r
+/* storage flags */\r
+#define CV_STORAGE_READ          0\r
+#define CV_STORAGE_WRITE_TEXT    1\r
+#define CV_STORAGE_WRITE_BINARY  2\r
+\r
+/* write flags */\r
+#define CV_WRITE_TREE      2 /* flag for storing sequence trees */\r
+\r
+/* opens existing or creates new file storage */\r
+OPENCVAPI  CvFileStorage*  cvOpenFileStorage( const char* filename,\r
+                                              CvMemStorage* storage,\r
+                                              int flags );\r
+\r
+/* closes file storage and deallocates buffers */\r
+OPENCVAPI  void cvReleaseFileStorage( CvFileStorage** storage );\r
+\r
+/* list of attributes */\r
+typedef struct CvAttrList\r
+{\r
+    char** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs */\r
+    struct CvAttrList* next; /* pointer to next chunk of the attributes list */\r
+}\r
+CvAttrList;\r
+\r
+CV_INLINE CvAttrList cvAttrList( char** attr CV_DEFAULT(NULL),\r
+                                 CvAttrList* next CV_DEFAULT(NULL) );\r
+CV_INLINE CvAttrList cvAttrList( char** attr, CvAttrList* next )\r
+{\r
+    CvAttrList list;\r
+    list.attr = attr;\r
+    list.next = next;\r
+\r
+    return list;\r
+}\r
+\r
+struct CvTypeInfo;\r
+\r
+typedef struct CvFileNode\r
+{\r
+    CV_TREE_NODE_FIELDS(CvFileNode)\r
+    const char* tagname;\r
+    const char* name;\r
+    CvAttrList* attr;\r
+    struct CvFileNode* hash_next;\r
+    unsigned hash_val;\r
+    int elem_size;\r
+    struct CvTypeInfo* typeinfo;\r
+    const char* body;\r
+    const void* content;\r
+}\r
+CvFileNode;\r
+\r
+\r
+/* writes matrix, image, sequence, graph etc. */\r
+OPENCVAPI  void cvWrite( CvFileStorage* storage, const char* name,\r
+                         const void* struct_ptr,\r
+                         CvAttrList attributes CV_DEFAULT(cvAttrList()),\r
+                         int flags CV_DEFAULT(0));\r
+\r
+/* writes opening tag of a compound object (used internally by cvWrite) */\r
+OPENCVAPI  void cvStartWriteStruct( CvFileStorage* storage, const char* name,\r
+                                    const char* type_name CV_DEFAULT(NULL),\r
+                                    const void* struct_ptr CV_DEFAULT(NULL),\r
+                                    CvAttrList attributes CV_DEFAULT(cvAttrList()));\r
+\r
+/* writes closing tag of a compound object (used internally by cvWrite) */\r
+OPENCVAPI  void cvEndWriteStruct( CvFileStorage* storage );\r
+\r
+/* writes a basic type value or a C structure of such values */\r
+OPENCVAPI  void cvWriteElem( CvFileStorage* storage,\r
+                             const char* name,\r
+                             const char* elem_spec,\r
+                             const void* data_ptr );\r
+\r
+/* finds the specified noe of file storage */\r
+OPENCVAPI  CvFileNode* cvGetFileNode( CvFileStorage* storage, const char* name );\r
+\r
+/* reads matrix, image, sequence, graph etc. */\r
+OPENCVAPI  const void* cvReadFileNode( CvFileStorage* storage, CvFileNode* node,\r
+                                       CvAttrList** list CV_DEFAULT(NULL));\r
+\r
+CV_INLINE  const void* cvRead( CvFileStorage* storage, const char* name,\r
+                               CvAttrList** list CV_DEFAULT(NULL) );\r
+CV_INLINE  const void* cvRead( CvFileStorage* storage, const char* name, CvAttrList** list )\r
+{\r
+    return cvReadFileNode( storage, cvGetFileNode( storage, name ), list );\r
+}\r
+\r
+/* read a basic type value or a C structure of such values */\r
+OPENCVAPI  int cvReadElem( CvFileStorage* storage, const char* name, void* data_ptr );\r
+\r
+/*********************************** Adding own types ***********************************/\r
+\r
+CV_EXTERN_C_FUNCPTR(int (CV_CDECL *CvIsInstanceFunc)(const void* struct_ptr));\r
+CV_EXTERN_C_FUNCPTR(void (CV_CDECL *CvReleaseFunc)(void** struct_dblptr));\r
+CV_EXTERN_C_FUNCPTR(void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage,\r
+                                                  CvFileNode* node ));\r
+CV_EXTERN_C_FUNCPTR(void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage,\r
+                                                  const char* name,\r
+                                                  const void* struct_ptr,\r
+                                                  CvAttrList attributes,\r
+                                                  int flags ));\r
+CV_EXTERN_C_FUNCPTR(void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr));\r
+\r
+typedef struct CvTypeInfo\r
+{\r
+    int flags;\r
+    int header_size;\r
+    struct CvTypeInfo* prev;\r
+    struct CvTypeInfo* next;\r
+    const char* type_name;\r
+    CvIsInstanceFunc is_instance;\r
+    CvReleaseFunc release;\r
+    CvReadFunc read;\r
+    CvWriteFunc write;\r
+    CvCloneFunc clone;\r
+}\r
+CvTypeInfo;\r
+\r
+OPENCVAPI  CvTypeInfo* cvRegisterType( CvTypeInfo* info_data );\r
+OPENCVAPI  void        cvUnregisterType( const char* type_name );\r
+OPENCVAPI  CvTypeInfo* cvFirstType(void);\r
+OPENCVAPI  CvTypeInfo* cvFindType( const char* type_name );\r
+OPENCVAPI  CvTypeInfo* cvTypeOf( const void* struct_ptr );\r
+\r
+/* universal functions */\r
+OPENCVAPI void cvRelease( void** struct_ptr );\r
+OPENCVAPI void* cvClone( const void* struct_ptr );\r
+\r
+/****************************************************************************************\\r
+*                                 Backward compatibility                                 *\r
+\****************************************************************************************/\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#ifndef _CV_NO_BACKWARD_COMPATIBILITY\r
+#include "cvcompat.h"\r
+#endif\r
+\r
+#endif /*_CV_H_*/\r
index c637a2c423ea63f9e310117e5acfb87b43d64e48..93a39e666fdd7a263b05375d8f410b3216dc9c9f 100644 (file)
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-//  By downloading, copying, installing or using the software you agree to this license.
-//  If you do not agree to this license, do not download, install,
-//  copy or use the software.
-//
-//
-//                        Intel License Agreement
-//                For Open Source Computer Vision Library
-//
-// Copyright (C) 2000, Intel Corporation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-//   * Redistribution's of source code must retain the above copyright notice,
-//     this list of conditions and the following disclaimer.
-//
-//   * Redistribution's in binary form must reproduce the above copyright notice,
-//     this list of conditions and the following disclaimer in the documentation
-//     and/or other materials provided with the distribution.
-//
-//   * The name of Intel Corporation may not be used to endorse or promote products
-//     derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-// (including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort (including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-//#ifdef WIN32
-
-#ifndef _CV_HPP_
-#define _CV_HPP_
-
-#include "cv.h"
-
-#ifdef __cplusplus
-
-#if _MSC_VER >= 1200
-
-#pragma warning(disable : 4710) /* function not inlined */
-#pragma warning(disable : 4711)
-#pragma warning(disable : 4514)
-
-#endif
-
-/* high-level C interface */
-#include <assert.h>
-
-#if defined _MSC_VER || defined __ICL || defined __BORLANDC__
-
-#define CVH_DECLARE_STORAGE
-#include "cvstorage.hpp"
-
-
-/****************************************************************************************\
-*                          Template classes for dynamic data structures                  *
-\****************************************************************************************/
-
-template<class Val> class CvArrayIterator
-{
-public:
-    typedef  Val  value_type;
-    typedef  int  idx_type;
-    typedef  CvArrayIterator<value_type>  iterator;
-
-    value_type& operator *() const {return *current;}
-    idx_type    get_idx() const {return current - begin;}
-    
-    iterator& operator ++() { current++; return *this; }
-    const iterator operator ++(int) { iterator temp = *this; current++; return temp; }
-
-    operator value_type*() {return *current;}
-
-    CvArrayIterator() {current = begin = 0;}
-    CvArrayIterator( value_type* _begin ) {begin = current = _begin;}
-    
-    CvArrayIterator( value_type* _begin, value_type* _current )
-        {begin = _begin; current = _current;}
-
-    CvArrayIterator( const iterator& another ) {*this = another;}
-
-    void init( value_type* _begin, value_type* _current )
-        {begin = _begin; current = _current;}
-
-    bool operator == ( const iterator& another ) const
-        {return (current == another.current) && (begin == another.begin);}
-    bool operator != ( const iterator& another ) const
-        {return (current != another.current) || (begin != another.begin);}
-
-    value_type* get_begin(){ return begin; }
-    value_type* get_current(){ return current; }
-
-protected:
-    value_type*  current;
-    value_type*  begin;
-};
-
-
-template<class Node> class CvTreeIterator
-{
-public:
-    typedef  Node  node_type;
-    typedef  typename node_type::value_type value_type;
-    typedef  typename node_type::idx_type   idx_type;
-    typedef  CvTreeIterator<node_type>  iterator;
-
-    value_type& operator *() { assert( node != 0 ); return node->val; }
-    idx_type    get_idx()    { assert( node != 0 ); return node->idx; }
-    node_type*  get_node()   { assert( node != 0 ); return node; }
-    
-    iterator   operator ++();
-    iterator   operator ++(int);
-    iterator&  operator =( const iterator& _iterator )
-        { node = _iterator.node; return *this; }
-
-    CvTreeIterator() { node = 0; }
-    CvTreeIterator( const iterator& another ) { node = another.node; }
-    CvTreeIterator( node_type* root_node ) { node = root_node; }
-
-    void init( node_type* _node ) { node = _node; }
-
-    bool operator==( const iterator& another ) { return node == another.node; }
-    bool operator!=( const iterator& another ) { return node != another.node; }
-
-protected:
-    node_type*  node;
-    node_type*  next();
-};
-
-template<class Node> class _CvNodeManager
-{
-public:
-    typedef  Node  node_type;
-    typedef  node_type::value_type value_type;
-    typedef  node_type::idx_type idx_type;
-    typedef  _CvNodeBlock<node_type>  block_type;
-    typedef  CvNodeIterator<node_type> iterator;
-    typedef  _CvNodeManager<node_type> manager_type;
-
-    _CvNodeManager();
-    ~_CvNodeManager() { destroy(); }
-
-    void  destroy();
-    void  clear();
-    node_type* new_node();
-    void  release_node( node_type* _node );
-
-    iterator     begin() const { return iterator( first_block ); }
-    iterator     end() const { return iterator( last_block, block_type::block_nodes - 1 ); }
-
-protected:
-    node_type*   first_free;
-    block_type*  first_block;
-    block_type*  last_block;
-    node_type*   allocate_new_block();
-};
-
-
-/************************* tree class *******************************/ 
-template<class Val, class Idx = int> class CvTree
-{
-public:
-
-    typedef  Val  value_type;
-    typedef  Idx  idx_type;
-    typedef  _CvTreeNode<value_type, idx_type> node_type;
-    typedef  _CvNodeManager<node_type>  node_manager;
-    typedef  CvNodeIterator<node_type>  raw_iterator;
-    typedef  CvTreeIterator<node_type>  iterator;
-    typedef  CvTree<value_type,idx_type> storage;
-
-    value_type query( idx_type idx ) const;
-
-    value_type& operator []( idx_type idx )
-        { assert( size == 0 || idx < size ); return create_node( idx )->val; }
-
-    void  remove( idx_type idx );
-    void  clear() { root = 0; size = 0; manager.clear(); }
-    void  destroy() { root = 0; size = 0; manager.destroy(); }
-
-    idx_type  get_size() const { return size; }
-    
-    iterator  begin() const;
-    iterator  end() const;
-
-    raw_iterator raw_begin() const { return manager.begin(); }
-    raw_iterator raw_end() const { return manager.end(); }
-
-    void  set_size( idx_type _size ) { size = _size; }
-
-    CvTree() {root = 0; size = 0;}
-    CvTree( idx_type _size ) { root = 0; size = _size; }
-    CvTree( const storage& another );
-
-    storage& operator = ( const storage& another );
-
-    template<class Op> double operate_with( const storage& another, Op operation ) const
-    {
-        iterator iter1 = begin();
-        iterator iter2 = another.begin();
-        iterator  end1 = end();
-        iterator  end2 = another.end();
-
-        Op::result_type s = 0.0;
-        value_type val = 0;
-
-        do{
-            if( iter1.get_idx() > iter2.get_idx() )
-                s = operation( s, val, *iter2++ );
-            else if( iter1.get_idx() < iter2.get_idx() )
-                s = operation( s, *iter1++, (value_type)0 );
-            else if( iter1.get_idx() == iter2.get_idx() )
-                s = operation( s, *iter1++, *iter2++ );
-        }while( iter1 != end1 && iter2 != end2 );
-        if( iter1.get_idx() == iter2.get_idx() ) s = operation( s, *iter1, *iter2 );
-        return s;
-    }
-
-    node_type* get_root() const { return root; }
-    
-protected:
-
-    node_type*    root;
-    node_manager  manager;
-    idx_type      size;
-
-    node_type* create_node( idx_type idx );
-};
-
-
-/************************* array class *******************************/ 
-template<class Val> class CvArray
-{
-public:
-
-    typedef  Val   value_type;
-    typedef  int   idx_type;
-    typedef  CvArrayIterator<value_type>  iterator;
-    typedef  iterator  raw_iterator;
-    typedef  CvArray<value_type>  storage;
-    
-    value_type   query( idx_type idx ) const
-        { assert( size == 0 || idx < size );
-          return array[idx]; }
-    
-    value_type&  operator []( idx_type idx )
-        { assert( size == 0 || idx < size ); return array[idx]; }
-
-    void  remove( idx_type idx );
-    void  clear();
-    void  destroy();
-
-    idx_type    get_size() const { return size; };
-    idx_type    get_capacity(){ return capacity; };
-    value_type* get_array() const { return array; }
-    
-    iterator  begin() const;
-    iterator  end() const;
-
-    raw_iterator raw_begin() const;
-    raw_iterator raw_end() const;
-
-    void  set_size( idx_type _size );
-    void  set_capacity( idx_type _capacity );
-
-    CvArray() { array = 0; size = capacity = 0; }
-    CvArray( idx_type _size );
-    CvArray( idx_type _size, idx_type _capacity );
-    CvArray( const storage& another );
-
-    ~CvArray() { if( array != 0 ) delete array; }
-
-    storage& operator = ( const storage& another );
-
-    template<class Op> double operate_with( const storage& another, Op operation ) const
-    {
-        Op::result_type s = 0.0;
-        for( idx_type i = 0; i < size; i++ )
-            s = operation( s, array[i], another.array[i] );
-        return s;
-    }
-
-protected:
-
-    value_type* array;
-    idx_type    size;
-    idx_type    capacity;
-};
-
-/****************************************************************************************\
-*                             Multi-dimensional histogram                                *
-\****************************************************************************************/
-
-template <class Storage = CvArray<class Val> > class CVHistogram
-{
-public:
-
-    typedef  Storage  storage_type;
-    typedef  storage_type::value_type value_type;  // type of histogram bins
-    typedef  storage_type::idx_type   idx_type;    // type of bin indices
-    typedef  typename storage_type::iterator iterator;
-    typedef  typename storage_type::raw_iterator  raw_iterator;
-    typedef  CVHistogram<storage_type> histogram; 
-
-    void     create( int bins0, int bins1 = 0, int bins2 = 0,
-                     int bins3 = 0, int bins4 = 0, int bins5 = 0 );
-    void     clear() { storage.clear(); } // clear histogram
-    void     destroy() { storage.destroy(); dims = 0; } // clear and free memory
-
-    //  lookup operations  
-    value_type  query( int i0 ) const { return storage.query( i0 ); }
-    value_type  query( int i0, int i1 ) const
-        { return storage.query( i0 + i1 * mbins[1] ); }
-    value_type  query( int i0, int i1, int i2 ) const
-        { return storage.query( i0 + i1 * mbins[1] + i2 * mbins[2] ); }
-    value_type  query( int i0, int i1, int i2, int i3, int i4 = 0, int i5 = 0 ) const
-        { return storage.query( get_idx( i0, i1, i2, i3, i4, i5 ) ); }
-    value_type  query( const int* idxs ) const;
-
-    // retrieving references to bins
-    value_type&  operator []( int i0 ) { return storage[i0]; }
-    value_type&  operator ()( int i0 ) { return storage[i0]; }
-    value_type&  operator ()( int i0, int i1 ) { return storage[i0 + i1 * mbins[1]]; }
-    value_type&  operator ()( int i0, int i1, int i2 )
-        { return storage[i0 + i1 * mbins[1] + i2 * mbins[2]]; }
-    value_type&  operator ()( int i0, int i1, int i2, int i3, int i4 = 0, int i5 = 0 )
-        { return storage[get_idx( i0, i1, i2, i3, i4, i5 )]; }
-    value_type&  operator ()( const int* idxs );
-
-    // hi-level iterators
-    iterator  begin() const { return storage.begin(); }
-    iterator  end() const { return storage.end(); }
-    
-    // low-level iterators
-    raw_iterator raw_begin() const { return storage.raw_begin(); }
-    raw_iterator raw_end() const { return storage.raw_end(); }
-    
-    // normalizing
-    void  normalize( value_type norm_factor = 1 );
-    void  normalize( histogram& result, value_type norm_factor = 1 ) const;
-    // thresholding
-    void  threshold( value_type threshold );
-    void  threshold( value_type threshold, histogram& result );
-
-    histogram& operator -= (value_type val);
-    histogram& operator *= (value_type val);
-    double mean() const;
-    
-    // some other operations: -=val, *=val, blur, mean ...
-    
-    // constructors/destructor 
-    CVHistogram() { dims = 0; }
-    CVHistogram( int bins0, int bins1 = 0, int bins2 = 0, 
-                  int bins3 = 0, int bins4 = 0, int bins5 = 0 )
-    { create( bins0, bins1, bins2, bins3, bins4, bins5 ); }
-    CVHistogram( const histogram& another );
-    ~CVHistogram() { destroy(); }
-
-    // copy operation
-    histogram& operator = (const histogram& another);
-    
-    int   get_dims() const { return dims; }
-    int   get_dim_size(int n = 0) const { return bins[n]; };
-
-   // helper template method for histograms comparing
-    template<class Op> double operate_with( const histogram& another, Op operation ) const
-    {
-        return storage.operate_with( another.storage, operation );
-    }
-
-    bool  check_size_equality( const histogram& another )
-    {
-        if( dims != another.dims ) return false;
-        for( int i = 0; i < dims; i++ ) if( bins[i] != another.bins[i] ) return false;
-        return true;
-    }
-
-    enum { max_dims = 6 };
-
-protected:
-
-    int           dims;
-    int           bins[max_dims];
-    int           mbins[max_dims];
-    storage_type  storage;
-
-    idx_type get_idx( int bin0, int bin1 = 0, int bin2 = 0,
-                      int bin3 = 0, int bin4 = 0, int bin5 = 0 ) const
-        { return bin0 * mbins[0] + bin1 * mbins[1] + bin2 * mbins[2] + bin3 * mbins[3]
-               + bin4 * mbins[4] + bin5 * mbins[5]; }
-};
-
-
-template <class Hist> inline double calc_histogram_intersection( const Hist& hist1,
-                                                                 const Hist& hist2 );
-
-template <class Hist> inline double calc_histogram_chi_square( const Hist& hist1,
-                                                               const Hist& hist2 );
-
-template <class Hist> inline double calc_histogram_correlation( const Hist& hist1,
-                                                                const Hist& hist2 );
-
-template<class Histogram, class SrcType, class ThreshType> void
-    calc_histogram_from_images( Histogram& hist, SrcType** src,
-                                CvSize roi, int  step, ThreshType** thresh );
-
-template<class Histogram, class SrcType, class ThreshType, class DstType> void 
-    calc_back_project_from_images( Histogram&   Hmodel,
-                                   SrcType*     src,
-                                   CvSize      roi,
-                                   int          src_step,
-                                   ThreshType** thresh,
-                                   DstType*     measure,
-                                   int          dst_step,
-                                   DstType      threshold = 0 );
-
-#define CvBackProject calc_back_project_from_images
-#define CvCalculateC1 calc_histogram_from_images
-
-
-#define CVH_IMPLEMENT_STORAGE
-#include "cvstorage.hpp"
-
-
-#endif /* #if defined _MSC_VER || defined __ICL || defined __BORLANDC__ */
-
-/****************************************************************************************\
-*                                      Image class                                       *
-\****************************************************************************************/
-
-struct CV_DLL_ENTRY CvImage : public IplImage
-{
-    CvImage();
-    CvImage( CvSize size, int depth, int channels );
-    ~CvImage();
-
-    uchar* image_data();
-    const uchar* image_data() const;
-
-    CvSize image_roi_size() const;
-    int    byte_per_pixel() const;
-
-    CvImage& operator = ( const CvImage& another )
-    { return copy( another ); }
-    
-    CvImage& copy( const CvImage& another );
-};
-
-
-class CV_DLL_ENTRY CvImageGroup
-{
-public:
-    enum{ max_count = 7 };
-    
-    CvImageGroup( int _count = 0 )
-    { assert( _count < max_count ); clear(); operator=(_count); }
-
-
-    ~CvImageGroup() { destroy(); }
-    
-    CvImage& operator[]( int count ) { return (CvImage&)*image[count]; }
-
-    CvImageGroup& operator=( const CvImageGroup& another )
-    { return copy( another ); }
-
-    CvImageGroup& operator=( const CvImage& another )
-    { return copy( another ); }
-
-    CvImageGroup& copy( const CvImageGroup& another );
-
-    CvImageGroup& copy( const CvImage& another );
-    CvImageGroup& operator=( int _count );
-
-    int get_count() const { return count; }
-
-    void destroy();
-    void clear() { for( int i = 0; i < max_count; i++ ) image[i] = 0; }
-    IplImage** get_group() { return &image[0]; };
-
-protected:
-    int       count;
-    IplImage* image[max_count];
-};
-
-class CV_DLL_ENTRY CvCamShiftTracker
-{
-public:
-    
-    // constructor
-    CvCamShiftTracker();
-    // destructor
-    virtual ~CvCamShiftTracker();
-    
-    // get- properties
-    
-    // Characteristics of the object, 
-    // which are calculated by track_object method
-    float   get_orientation()  // orientation of the object in degrees 
-    { return orientation; }
-    float   get_length()       // the larger linear size of the object
-    { return length; }
-    float   get_width()        // the smaller linear size of the object
-    { return width; }
-    CvRect get_window()       // bounding rectangle for the object
-    { return window; }
-    
-    // Tracking parameters
-    int     get_threshold()  // thresholding value that applied to back project
-    { return threshold; }
-    int     get_hist_dims( int* dims = 0 ); // returns number of histogram dimensions and sets
-    // dims[0] to number of bins on 1st dimension,
-    // dims[1] -||- on 2nd dimension etc. 
-    // (if dims pointer is not 0).
-    
-    int     get_min_ch_val( int channel )  // Given channel index, returns 
-    { return min_ch_val[channel]; }        // the minimum value of that channel, 
-                                           // starting from which the pixel
-                                           // is counted during histogram calculation.
-    
-    int     get_max_ch_val( int channel )  // Get maximum channel value.
-    { return max_ch_val[channel]; }
-    
-    
-    // Background differencing parameters
-    
-    // set- properties
-    // Object characteristics
-    bool    set_window( CvRect _window) // set initial bounding rectangle for the object
-    { window = _window; return true; }
-    
-    // Tracking parameters
-    bool    set_threshold( int _threshold ) // threshold level that applied 
-    { threshold = _threshold; return true; }
-
-    // to back project.
-    bool    set_hist_dims( int c_dims, int* dims );// histogram dimensions.
-    
-    bool    set_min_ch_val( int channel, int val ) // Given channel index, sets 
-    { min_ch_val[channel] = val; return true; }    // the minimum value of that channel, 
-                                                   // starting from which the pixel
-                                                   // is counted during histogram calculation.
-    
-    bool    set_max_ch_val( int channel, int val ) // Set maximum value for the channel.
-    { max_ch_val[channel] = val; return true; }
-
-    bool    set_thresh( int channel, int min, int max );
-    
-    bool    set_hist_mapping( int* /*channels*/ )
-    { return 0; }
-    // selects the channels from
-    // resulting image 
-    // (before histogram/back prj calculation)
-    // for using them in histogram/back prj
-    // calculation. 
-    // That is, channel #(channels[0]) is 
-    // corresponds to first histogram 
-    // dimension, channel #(channels[1])
-    // to 2nd etc.
-    
-    // Backgournd differencing ...
-    
-    // can be used (and overrided) if histogram is built from several frames
-    virtual void  reset_histogram() { cvClearHist( hist ); }
-    
-    // main pipeline for object tracking 
-    virtual void  track_object( CvImage* src_image )
-    {
-        trackobj_find( calc_back_project( trackobj_post_color(
-            trackobj_color_transform( trackobj_pre_color( src_image )))));
-    }
-    
-    // main pipeline for histogram calculation
-    virtual void update_histogram( CvImage* src_image )
-    {
-        calc_histogram( hist_post_color(
-            hist_color_transform( hist_pre_color( src_image ))));
-    }
-
-
-    virtual CvImage* get_back_project()
-    { return &calc_back_project_image; }
-
-
-    virtual int get_shift_parameter()
-    { return shift; }
-
-
-    virtual bool set_shift_parameter(int _shift)
-    { shift = _shift; return true; }
-
-
-    virtual int query( int bin )
-    { return cvRound(cvQueryHistValue_1D( hist, bin )); }
-    
-protected:
-    typedef CvHistogram  hist_type;
-
-    hist_type* hist;
-
-    float      orientation;
-    float      width;
-    float      length;
-    CvRect     window;
-
-    int        min_ch_val[6];
-    int        max_ch_val[6];
-
-    int        shift;
-
-    float*     thresh[CvImageGroup::max_count];
-    float      thresh_buf[CvImageGroup::max_count*2];
-    int        threshold;
-
-    CvImageGroup   color_transform_image_group;
-    CvImage        trackobj_pre_color_image;
-    CvImage        calc_back_project_image;
-    
-    // Internal pipeline functions
-    
-    // Common
-    
-    // common color transform
-    virtual CvImageGroup* color_transform( CvImage* src_image );
-    
-    // Specific for object tracking
-    // preprocessing before color transformation
-    virtual CvImage* trackobj_pre_color( CvImage* src_image );
-    
-    // color transformation. do common transform by default
-    virtual CvImageGroup* trackobj_color_transform( CvImage* src_image )
-    { return color_transform( src_image ); }
-    
-    // postprocessing after color transformation before back project
-    virtual CvImageGroup* trackobj_post_color( CvImageGroup* src_image );
-    
-    // calculation of back project
-    virtual CvImage* calc_back_project( CvImageGroup* src_image );
-    
-    // apply camshift algorithm to calculate object parameters
-    virtual void  trackobj_find( CvImage* src_image );
-    
-    
-    // Specific for histogram calculation   
-    
-    // preprocessing before color transformation
-    virtual CvImage* hist_pre_color( CvImage* src_image )
-    { return trackobj_pre_color( src_image ); }
-
-    // color transformation. do common transform by default
-    virtual CvImageGroup* hist_color_transform( CvImage* src_image )
-    { return color_transform( src_image ); }
-    
-    // postprocessing after color transformation before back project
-    virtual CvImageGroup* hist_post_color( CvImageGroup* src_image )
-    { return trackobj_post_color( src_image ); }
-    
-    // histogram calculation
-    virtual void calc_histogram( CvImageGroup* src_image );
-    
-    
-};
-
-#include "cvstorage.hpp"
-
-#endif /* __cplusplus */
-
-#endif /* _CV_HPP */
-
-
-/* End of file. */
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+//#ifdef WIN32\r
+\r
+#ifndef _CV_HPP_\r
+#define _CV_HPP_\r
+\r
+#include "cv.h"\r
+\r
+#ifdef __cplusplus\r
+\r
+/****************************************************************************************\\r
+*                                      Image class                                       *\r
+\****************************************************************************************/\r
+\r
+struct CV_DLL_ENTRY CvImage : public IplImage\r
+{\r
+    CvImage();\r
+    CvImage( CvSize size, int depth, int channels );\r
+    ~CvImage();\r
+\r
+    uchar* image_data();\r
+    const uchar* image_data() const;\r
+\r
+    CvSize image_roi_size() const;\r
+    int    byte_per_pixel() const;\r
+\r
+    CvImage& operator = ( const CvImage& another )\r
+    { return copy( another ); }\r
+    \r
+    CvImage& copy( const CvImage& another );\r
+};\r
+\r
+\r
+class CV_DLL_ENTRY CvImageGroup\r
+{\r
+public:\r
+    enum{ max_count = 7 };\r
+    \r
+    CvImageGroup( int _count = 0 )\r
+    { assert( _count < max_count ); clear(); operator=(_count); }\r
+\r
+\r
+    ~CvImageGroup() { destroy(); }\r
+    \r
+    CvImage& operator[]( int count ) { return (CvImage&)*image[count]; }\r
+\r
+    CvImageGroup& operator=( const CvImageGroup& another )\r
+    { return copy( another ); }\r
+\r
+    CvImageGroup& operator=( const CvImage& another )\r
+    { return copy( another ); }\r
+\r
+    CvImageGroup& copy( const CvImageGroup& another );\r
+\r
+    CvImageGroup& copy( const CvImage& another );\r
+    CvImageGroup& operator=( int _count );\r
+\r
+    int get_count() const { return count; }\r
+\r
+    void destroy();\r
+    void clear() { for( int i = 0; i < max_count; i++ ) image[i] = 0; }\r
+    IplImage** get_group() { return &image[0]; };\r
+\r
+protected:\r
+    int       count;\r
+    IplImage* image[max_count];\r
+};\r
+\r
+\r
+class CV_DLL_ENTRY CvCamShiftTracker\r
+{\r
+public:\r
+    \r
+    // constructor\r
+    CvCamShiftTracker();\r
+    // destructor\r
+    virtual ~CvCamShiftTracker();\r
+    \r
+    // get- properties\r
+    \r
+    // Characteristics of the object, \r
+    // which are calculated by track_object method\r
+    float   get_orientation()  // orientation of the object in degrees \r
+    { return orientation; }\r
+    float   get_length()       // the larger linear size of the object\r
+    { return length; }\r
+    float   get_width()        // the smaller linear size of the object\r
+    { return width; }\r
+    CvRect get_window()       // bounding rectangle for the object\r
+    { return window; }\r
+    \r
+    // Tracking parameters\r
+    int     get_threshold()  // thresholding value that applied to back project\r
+    { return threshold; }\r
+    int     get_hist_dims( int* dims = 0 ); // returns number of histogram dimensions and sets\r
+    // dims[0] to number of bins on 1st dimension,\r
+    // dims[1] -||- on 2nd dimension etc. \r
+    // (if dims pointer is not 0).\r
+    \r
+    int     get_min_ch_val( int channel )  // Given channel index, returns \r
+    { return min_ch_val[channel]; }        // the minimum value of that channel, \r
+                                           // starting from which the pixel\r
+                                           // is counted during histogram calculation.\r
+    \r
+    int     get_max_ch_val( int channel )  // Get maximum channel value.\r
+    { return max_ch_val[channel]; }\r
+    \r
+    \r
+    // Background differencing parameters\r
+    \r
+    // set- properties\r
+    // Object characteristics\r
+    bool    set_window( CvRect _window) // set initial bounding rectangle for the object\r
+    { window = _window; return true; }\r
+    \r
+    // Tracking parameters\r
+    bool    set_threshold( int _threshold ) // threshold level that applied \r
+    { threshold = _threshold; return true; }\r
+\r
+    // to back project.\r
+    bool    set_hist_dims( int c_dims, int* dims );// histogram dimensions.\r
+    \r
+    bool    set_min_ch_val( int channel, int val ) // Given channel index, sets \r
+    { min_ch_val[channel] = val; return true; }    // the minimum value of that channel, \r
+                                                   // starting from which the pixel\r
+                                                   // is counted during histogram calculation.\r
+    \r
+    bool    set_max_ch_val( int channel, int val ) // Set maximum value for the channel.\r
+    { max_ch_val[channel] = val; return true; }\r
+\r
+    bool    set_thresh( int channel, int min, int max );\r
+    \r
+    bool    set_hist_mapping( int* /*channels*/ )\r
+    { return 0; }\r
+    // selects the channels from\r
+    // resulting image \r
+    // (before histogram/back prj calculation)\r
+    // for using them in histogram/back prj\r
+    // calculation. \r
+    // That is, channel #(channels[0]) is \r
+    // corresponds to first histogram \r
+    // dimension, channel #(channels[1])\r
+    // to 2nd etc.\r
+    \r
+    // Backgournd differencing ...\r
+    \r
+    // can be used (and overrided) if histogram is built from several frames\r
+    virtual void  reset_histogram() { cvClearHist( hist ); }\r
+    \r
+    // main pipeline for object tracking \r
+    virtual void  track_object( CvImage* src_image )\r
+    {\r
+        trackobj_find( calc_back_project( trackobj_post_color(\r
+            trackobj_color_transform( trackobj_pre_color( src_image )))));\r
+    }\r
+    \r
+    // main pipeline for histogram calculation\r
+    virtual void update_histogram( CvImage* src_image )\r
+    {\r
+        calc_histogram( hist_post_color(\r
+            hist_color_transform( hist_pre_color( src_image ))));\r
+    }\r
+\r
+\r
+    virtual CvImage* get_back_project()\r
+    { return &calc_back_project_image; }\r
+\r
+\r
+    virtual int get_shift_parameter()\r
+    { return shift; }\r
+\r
+\r
+    virtual bool set_shift_parameter(int _shift)\r
+    { shift = _shift; return true; }\r
+\r
+\r
+    virtual int query( int bin )\r
+    { return cvRound(cvQueryHistValue_1D( hist, bin )); }\r
+    \r
+protected:\r
+    typedef CvHistogram  hist_type;\r
+\r
+    hist_type* hist;\r
+\r
+    float      orientation;\r
+    float      width;\r
+    float      length;\r
+    CvRect     window;\r
+\r
+    int        min_ch_val[6];\r
+    int        max_ch_val[6];\r
+\r
+    int        shift;\r
+\r
+    float*     thresh[CvImageGroup::max_count];\r
+    float      thresh_buf[CvImageGroup::max_count*2];\r
+    int        threshold;\r
+\r
+    CvImageGroup   color_transform_image_group;\r
+    CvImage        trackobj_pre_color_image;\r
+    CvImage        calc_back_project_image;\r
+    \r
+    // Internal pipeline functions\r
+    \r
+    // Common\r
+    \r
+    // common color transform\r
+    virtual CvImageGroup* color_transform( CvImage* src_image );\r
+    \r
+    // Specific for object tracking\r
+    // preprocessing before color transformation\r
+    virtual CvImage* trackobj_pre_color( CvImage* src_image );\r
+    \r
+    // color transformation. do common transform by default\r
+    virtual CvImageGroup* trackobj_color_transform( CvImage* src_image )\r
+    { return color_transform( src_image ); }\r
+    \r
+    // postprocessing after color transformation before back project\r
+    virtual CvImageGroup* trackobj_post_color( CvImageGroup* src_image );\r
+    \r
+    // calculation of back project\r
+    virtual CvImage* calc_back_project( CvImageGroup* src_image );\r
+    \r
+    // apply camshift algorithm to calculate object parameters\r
+    virtual void  trackobj_find( CvImage* src_image );\r
+    \r
+    \r
+    // Specific for histogram calculation   \r
+    \r
+    // preprocessing before color transformation\r
+    virtual CvImage* hist_pre_color( CvImage* src_image )\r
+    { return trackobj_pre_color( src_image ); }\r
+\r
+    // color transformation. do common transform by default\r
+    virtual CvImageGroup* hist_color_transform( CvImage* src_image )\r
+    { return color_transform( src_image ); }\r
+    \r
+    // postprocessing after color transformation before back project\r
+    virtual CvImageGroup* hist_post_color( CvImageGroup* src_image )\r
+    { return trackobj_post_color( src_image ); }\r
+    \r
+    // histogram calculation\r
+    virtual void calc_histogram( CvImageGroup* src_image );\r
+    \r
+    \r
+};\r
+\r
+#endif /* __cplusplus */\r
+\r
+#endif /* _CV_HPP */\r
+\r
+\r
+/* End of file. */\r
index f259be9e641ba1f12d05e40c5efc57a6e3521e53..5d37d90100f1782069ba5f832dff0eb4c0aea563 100644 (file)
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-//  By downloading, copying, installing or using the software you agree to this license.
-//  If you do not agree to this license, do not download, install,
-//  copy or use the software.
-//
-//
-//                        Intel License Agreement
-//                For Open Source Computer Vision Library
-//
-// Copyright( C) 2000, Intel Corporation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-//   * Redistribution's of source code must retain the above copyright notice,
-//     this list of conditions and the following disclaimer.
-//
-//   * Redistribution's in binary form must reproduce the above copyright notice,
-//     this list of conditions and the following disclaimer in the documentation
-//     and/or other materials provided with the distribution.
-//
-//   * The name of Intel Corporation may not be used to endorse or promote products
-//     derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-//(including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort(including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-/*
-   This is a set of macros and definitions intended to provide backward compatibility
-   with the previous versions of OpenCV
-*/
-
-#ifndef _CVCOMPAT_H_
-#define _CVCOMPAT_H_
-
-#define CvMatType int
-#define CvDisMaskType int
-#define CvMatArray CvMat
-
-#define  CV_MAT32F      CV_32FC1
-#define  CV_MAT3x1_32F  CV_32FC1
-#define  CV_MAT4x1_32F  CV_32FC1
-#define  CV_MAT3x3_32F  CV_32FC1
-#define  CV_MAT4x4_32F  CV_32FC1
-
-#define  CV_MAT64D      CV_64FC1
-#define  CV_MAT3x1_64D  CV_64FC1
-#define  CV_MAT4x1_64D  CV_64FC1
-#define  CV_MAT3x3_64D  CV_64FC1
-#define  CV_MAT4x4_64D  CV_64FC1
-
-#define  IPL_GAUSSIAN_5x5   7
-#define  CvBox2D32f     CvBox2D
-
-/* allocation/deallocation macros */
-#define cvCreateImageData   cvCreateData
-#define cvReleaseImageData  cvReleaseData
-#define cvSetImageData      cvSetData
-#define cvGetImageRawData   cvGetRawData
-
-#define cvmAlloc            cvCreateData
-#define cvmFree             cvReleaseData
-#define cvmAllocArray       cvCreateData
-#define cvmFreeArray        cvReleaseData
-
-CV_INLINE CvMat cvMatArray( int rows, int cols, int type,
-                            int count, void* data CV_DEFAULT(0));
-CV_INLINE CvMat cvMatArray( int rows, int cols, int type,
-                            int count, void* data )
-{
-    return cvMat( rows*count, cols, type, data );    
-}
-
-#define cvUpdateMHIByTime  cvUpdateMotionHistory
-
-#define cvAccMask cvAcc
-#define cvSquareAccMask cvSquareAcc
-#define cvMultiplyAccMask cvMultiplyAcc
-#define cvRunningAvgMask(imgY, imgU, mask, alpha) cvRunningAvg(imgY, imgU, alpha, mask)
-
-#define cvSetHistThresh  cvSetHistBinRanges
-#define cvCalcHistMask(img, mask, hist, doNotClear) cvCalcHist(img, hist, doNotClear, mask)
-
-CV_INLINE double cvMean( const CvArr* image, const CvArr* mask CV_DEFAULT(0));
-CV_INLINE double cvMean( const CvArr* image, const CvArr* mask )
-{
-    CvScalar mean = cvAvg( image, mask );
-    return mean.val[0];
-}
-
-#define cvSumPixels( img )  ((cvSum( img )).val[0])
-
-CV_INLINE void  cvMean_StdDev( const CvArr* image, double* mean, double* sdv,
-                               const CvArr* mask CV_DEFAULT(0));
-CV_INLINE void  cvMean_StdDev( const CvArr* image, double* mean,
-                               double* sdv, const CvArr* mask )
-{
-    CvScalar _mean, _sdv;
-    cvAvgSdv( image, &_mean, &_sdv, mask );
-
-    if( mean )
-        *mean = _mean.val[0];
-
-    if( sdv )
-        *sdv = _sdv.val[0];
-}
-
-
-CV_INLINE void cvmPerspectiveProject( const CvArr* mat, const CvArr* src,
-                                      CvArr* dst );
-CV_INLINE void cvmPerspectiveProject( const CvArr* mat, const CvArr* src,
-                                      CvArr* dst )
-{
-    CvMat tsrc, tdst;
-
-    cvReshape( src, &tsrc, 3, 0 );
-    cvReshape( dst, &tdst, 3, 0 );
-
-    cvPerspectiveTransform( &tsrc, &tdst, mat );
-}
-
-
-CV_INLINE void cvFillImage( CvArr* mat, double color );
-CV_INLINE void cvFillImage( CvArr* mat, double color )
-{
-    CvPoint left_top = { 0, 0 }, right_bottom = { 0, 0 };
-
-    cvGetRawData( mat, 0, 0, (CvSize*)&right_bottom );
-    right_bottom.x--;
-    right_bottom.y--;
-
-    cvRectangle( mat, left_top, right_bottom, color, CV_FILLED );
-}
-
-
-#define cvMeanMask  cvMean
-#define cvMean_StdDevMask(img,mask,mean,sdv) cvMean_StdDev(img,mean,sdv,mask)
-
-#define cvNormMask(imgA,imgB,mask,normType) cvNorm(imgA,imgB,normType,mask)
-
-#define cvMinMaxLocMask(img, mask, min_val, max_val, min_loc, max_loc) \
-        cvMinMaxLoc(img, min_val, max_val, min_loc, max_loc, mask)
-
-#define cvRemoveMemoryManager  cvSetMemoryManager
-
-#define cvmSetZero( mat )               cvSetZero( mat )
-#define cvmSetIdentity( mat )           cvSetIdentity( mat )
-#define cvmAdd( src1, src2, dst )       cvAdd( src1, src2, dst, 0 )
-#define cvmSub( src1, src2, dst )       cvSub( src1, src2, dst, 0 )
-#define cvmCopy( src, dst )             cvCopy( src, dst, 0 )
-#define cvmMul( src1, src2, dst )       cvMatMulAdd( src1, src2, 0, dst )
-#define cvmTranspose( src, dst )        cvT( src, dst )
-#define cvmInvert( src, dst )           cvInv( src, dst )
-#define cvmMahalanobis(vec1, vec2, mat) cvMahalanobis( vec1, vec2, mat )
-#define cvmDotProduct( vec1, vec2 )     cvDotProduct( vec1, vec2 )
-#define cvmCrossProduct(vec1, vec2,dst) cvCrossProduct( vec1, vec2, dst )
-#define cvmTrace( mat )                 (cvTrace( mat )).val[0]
-#define cvmMulTransposed( src, dst, order ) cvMulTransposed( src, dst, order )
-#define cvmEigenVV( mat, evec, eval, eps)   cvEigenVV( mat, evec, eval, eps )
-#define cvmDet( mat )                   cvDet( mat )
-#define cvmScale( src, dst, scale )     cvScale( src, dst, scale )
-
-#define cvCopyImage( src, dst )         cvCopy( src, dst, 0 )
-
-#endif/*_CVCOMPAT_H_*/
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright( C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+//(including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort(including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+/*\r
+   This is a set of macros and definitions intended to provide backward compatibility\r
+   with the previous versions of OpenCV\r
+*/\r
+\r
+#ifndef _CVCOMPAT_H_\r
+#define _CVCOMPAT_H_\r
+\r
+#include <string.h>\r
+\r
+#define CvMatType int\r
+#define CvDisMaskType int\r
+#define CvMatArray CvMat\r
+\r
+#define CvThreshType int\r
+#define CvAdaptiveThreshMethod int\r
+#define CvCompareMethod int\r
+#define CvFontFace int\r
+#define CvPolyApproxMethod int\r
+#define CvContoursMatchMethod int\r
+#define CvContourTreesMatchMethod int\r
+#define CvCoeffType int\r
+#define CvRodriguesType int\r
+#define CvElementShape int\r
+#define CvMorphOp int\r
+#define CvTemplMatchMethod int\r
+\r
+#define  CV_MAT32F      CV_32FC1\r
+#define  CV_MAT3x1_32F  CV_32FC1\r
+#define  CV_MAT4x1_32F  CV_32FC1\r
+#define  CV_MAT3x3_32F  CV_32FC1\r
+#define  CV_MAT4x4_32F  CV_32FC1\r
+\r
+#define  CV_MAT64D      CV_64FC1\r
+#define  CV_MAT3x1_64D  CV_64FC1\r
+#define  CV_MAT4x1_64D  CV_64FC1\r
+#define  CV_MAT3x3_64D  CV_64FC1\r
+#define  CV_MAT4x4_64D  CV_64FC1\r
+\r
+#define  IPL_GAUSSIAN_5x5   7\r
+#define  CvBox2D32f     CvBox2D\r
+\r
+/* allocation/deallocation macros */\r
+#define cvCreateImageData   cvCreateData\r
+#define cvReleaseImageData  cvReleaseData\r
+#define cvSetImageData      cvSetData\r
+#define cvGetImageRawData   cvGetRawData\r
+\r
+#define cvmAlloc            cvCreateData\r
+#define cvmFree             cvReleaseData\r
+#define cvmAllocArray       cvCreateData\r
+#define cvmFreeArray        cvReleaseData\r
+\r
+#define cvIntegralImage     cvIntegral\r
+#define cvMatchContours     cvMatchShapes\r
+\r
+CV_INLINE CvMat cvMatArray( int rows, int cols, int type,\r
+                            int count, void* data CV_DEFAULT(0));\r
+CV_INLINE CvMat cvMatArray( int rows, int cols, int type,\r
+                            int count, void* data )\r
+{\r
+    return cvMat( rows*count, cols, type, data );    \r
+}\r
+\r
+#define cvUpdateMHIByTime  cvUpdateMotionHistory\r
+\r
+#define cvAccMask cvAcc\r
+#define cvSquareAccMask cvSquareAcc\r
+#define cvMultiplyAccMask cvMultiplyAcc\r
+#define cvRunningAvgMask(imgY, imgU, mask, alpha) cvRunningAvg(imgY, imgU, alpha, mask)\r
+\r
+#define cvSetHistThresh  cvSetHistBinRanges\r
+#define cvCalcHistMask(img, mask, hist, doNotClear) cvCalcHist(img, hist, doNotClear, mask)\r
+\r
+CV_INLINE double cvMean( const CvArr* image, const CvArr* mask CV_DEFAULT(0));\r
+CV_INLINE double cvMean( const CvArr* image, const CvArr* mask )\r
+{\r
+    CvScalar mean = cvAvg( image, mask );\r
+    return mean.val[0];\r
+}\r
+\r
+#define cvSumPixels( img )  ((cvSum( img )).val[0])\r
+\r
+CV_INLINE void  cvMean_StdDev( const CvArr* image, double* mean, double* sdv,\r
+                               const CvArr* mask CV_DEFAULT(0));\r
+CV_INLINE void  cvMean_StdDev( const CvArr* image, double* mean,\r
+                               double* sdv, const CvArr* mask )\r
+{\r
+    CvScalar _mean, _sdv;\r
+    cvAvgSdv( image, &_mean, &_sdv, mask );\r
+\r
+    if( mean )\r
+        *mean = _mean.val[0];\r
+\r
+    if( sdv )\r
+        *sdv = _sdv.val[0];\r
+}\r
+\r
+\r
+CV_INLINE void cvmPerspectiveProject( const CvArr* mat, const CvArr* src,\r
+                                      CvArr* dst );\r
+CV_INLINE void cvmPerspectiveProject( const CvArr* mat, const CvArr* src,\r
+                                      CvArr* dst )\r
+{\r
+    CvMat tsrc, tdst;\r
+\r
+    cvReshape( src, &tsrc, 3, 0 );\r
+    cvReshape( dst, &tdst, 3, 0 );\r
+\r
+    cvPerspectiveTransform( &tsrc, &tdst, mat );\r
+}\r
+\r
+\r
+CV_INLINE void cvFillImage( CvArr* mat, double color );\r
+CV_INLINE void cvFillImage( CvArr* mat, double color )\r
+{\r
+    CvPoint left_top = { 0, 0 }, right_bottom = { 0, 0 };\r
+\r
+    cvGetRawData( mat, 0, 0, (CvSize*)&right_bottom );\r
+    right_bottom.x--;\r
+    right_bottom.y--;\r
+\r
+    cvRectangle( mat, left_top, right_bottom, color, CV_FILLED );\r
+}\r
+\r
+\r
+CV_INLINE void cvbRand( CvRandState* state, float* dst, int len );\r
+CV_INLINE void cvbRand( CvRandState* state, float* dst, int len )\r
+{\r
+    CvMat mat = cvMat( 1, len, CV_32F, (void*)dst );\r
+    cvRand( state, &mat );\r
+}\r
+\r
+\r
+CV_INLINE void  cvbCartToPolar( const float* y, const float* x,\r
+                                float* magnitude, float* angle, int len );\r
+CV_INLINE void  cvbCartToPolar( const float* y, const float* x,\r
+                                float* magnitude, float* angle, int len )\r
+{\r
+    CvMat mx = cvMat( 1, len, CV_32F, (void*)x );\r
+    CvMat my = mx;\r
+    CvMat mm = mx;\r
+    CvMat ma = mx;\r
+\r
+    my.data.fl = (float*)y;\r
+    mm.data.fl = (float*)magnitude;\r
+    ma.data.fl = (float*)angle;\r
+\r
+    cvCartToPolar( &mx, &my, &mm, angle ? &ma : NULL, 1 );\r
+}\r
+\r
+\r
+CV_INLINE void  cvbFastArctan( const float* y, const float* x,\r
+                               float* angle, int len );\r
+CV_INLINE void  cvbFastArctan( const float* y, const float* x,\r
+                               float* angle, int len )\r
+{\r
+    CvMat mx = cvMat( 1, len, CV_32F, (void*)x );\r
+    CvMat my = mx;\r
+    CvMat ma = mx;\r
+\r
+    my.data.fl = (float*)y;\r
+    ma.data.fl = (float*)angle;\r
+\r
+    cvCartToPolar( &mx, &my, NULL, &ma, 1 );\r
+}\r
+\r
+\r
+CV_INLINE  void  cvbSqrt( const float* x, float* y, int len );\r
+CV_INLINE  void  cvbSqrt( const float* x, float* y, int len )\r
+{\r
+    CvMat mx = cvMat( 1, len, CV_32F, (void*)x );\r
+    CvMat my = mx;\r
+    my.data.fl = (float*)y;\r
+\r
+    cvPow( &mx, &my, 0.5 );\r
+}\r
+\r
+\r
+CV_INLINE  void  cvbInvSqrt( const float* x, float* y, int len );\r
+CV_INLINE  void  cvbInvSqrt( const float* x, float* y, int len )\r
+{\r
+    CvMat mx = cvMat( 1, len, CV_32F, (void*)x );\r
+    CvMat my = mx;\r
+    my.data.fl = (float*)y;\r
+\r
+    cvPow( &mx, &my, -0.5 );\r
+}\r
+\r
+\r
+CV_INLINE  void  cvbReciprocal( const float* x, float* y, int len );\r
+CV_INLINE  void  cvbReciprocal( const float* x, float* y, int len )\r
+{\r
+    CvMat mx = cvMat( 1, len, CV_32F, (void*)x );\r
+    CvMat my = mx;\r
+    my.data.fl = (float*)y;\r
+\r
+    cvPow( &mx, &my, -1 );\r
+}\r
+\r
+\r
+CV_INLINE  void  cvbFastExp( const float* x, double* y, int len );\r
+CV_INLINE  void  cvbFastExp( const float* x, double* y, int len )\r
+{\r
+    CvMat mx = cvMat( 1, len, CV_32F, (void*)x );\r
+    CvMat my = cvMat( 1, len, CV_64F, y );\r
+    cvExp( &mx, &my );\r
+}\r
+\r
+\r
+CV_INLINE  void  cvbFastLog( const double* x, float* y, int len );\r
+CV_INLINE  void  cvbFastLog( const double* x, float* y, int len )\r
+{\r
+    CvMat mx = cvMat( 1, len, CV_64F, (void*)x );\r
+    CvMat my = cvMat( 1, len, CV_32F, y );\r
+    cvLog( &mx, &my );\r
+}\r
+\r
+\r
+CV_INLINE  CvRect  cvContourBoundingRect( const void* point_set, int update CV_DEFAULT(0));\r
+CV_INLINE  CvRect  cvContourBoundingRect( const void* point_set, int update )\r
+{\r
+    return cvBoundingRect( point_set, update );\r
+}\r
+\r
+\r
+CV_INLINE double cvPseudoInverse( const CvArr* src, CvArr* dst,\r
+                                  int flags CV_DEFAULT(0));\r
+CV_INLINE double cvPseudoInverse( const CvArr* src, CvArr* dst, int flags )\r
+{\r
+    flags; /* unused parameter */\r
+    return cvInvert( src, dst, CV_SVD );\r
+}\r
+\r
+#define cvPseudoInv cvPseudoInverse\r
+\r
+#define cvContourMoments( contour, moments ) \\r
+    cvMoments( contour, moments, 0 )\r
+\r
+#define cvGetPtrAt              cvPtr2D\r
+#define cvGetAt                 cvGet2D\r
+#define cvSetAt(arr,val,y,x)    cvSet2D((arr),(y),(x),(val))\r
+\r
+#define cvMeanMask  cvMean\r
+#define cvMean_StdDevMask(img,mask,mean,sdv) cvMean_StdDev(img,mean,sdv,mask)\r
+\r
+#define cvNormMask(imgA,imgB,mask,normType) cvNorm(imgA,imgB,normType,mask)\r
+\r
+#define cvMinMaxLocMask(img, mask, min_val, max_val, min_loc, max_loc) \\r
+        cvMinMaxLoc(img, min_val, max_val, min_loc, max_loc, mask)\r
+\r
+#define cvRemoveMemoryManager  cvSetMemoryManager\r
+\r
+#define cvmSetZero( mat )               cvSetZero( mat )\r
+#define cvmSetIdentity( mat )           cvSetIdentity( mat )\r
+#define cvmAdd( src1, src2, dst )       cvAdd( src1, src2, dst, 0 )\r
+#define cvmSub( src1, src2, dst )       cvSub( src1, src2, dst, 0 )\r
+#define cvmCopy( src, dst )             cvCopy( src, dst, 0 )\r
+#define cvmMul( src1, src2, dst )       cvMatMulAdd( src1, src2, 0, dst )\r
+#define cvmTranspose( src, dst )        cvT( src, dst )\r
+#define cvmInvert( src, dst )           cvInv( src, dst )\r
+#define cvmMahalanobis(vec1, vec2, mat) cvMahalanobis( vec1, vec2, mat )\r
+#define cvmDotProduct( vec1, vec2 )     cvDotProduct( vec1, vec2 )\r
+#define cvmCrossProduct(vec1, vec2,dst) cvCrossProduct( vec1, vec2, dst )\r
+#define cvmTrace( mat )                 (cvTrace( mat )).val[0]\r
+#define cvmMulTransposed( src, dst, order ) cvMulTransposed( src, dst, order )\r
+#define cvmEigenVV( mat, evec, eval, eps)   cvEigenVV( mat, evec, eval, eps )\r
+#define cvmDet( mat )                   cvDet( mat )\r
+#define cvmScale( src, dst, scale )     cvScale( src, dst, scale )\r
+\r
+#define cvCopyImage( src, dst )         cvCopy( src, dst, 0 )\r
+#define cvReleaseMatHeader              cvReleaseMat\r
+\r
+/* Calculates exact convex hull of 2d point set */\r
+CV_INLINE void cvConvexHull( CvPoint* points, int num_points, CvRect* bound_rect,\r
+                             int orientation, int* hull, int* hullsize );\r
+CV_INLINE void cvConvexHull( CvPoint* points, int num_points, CvRect* bound_rect,\r
+                             int orientation, int* hull, int* hullsize )\r
+{\r
+    CvMat points1 = cvMat( 1, num_points, CV_32SC2, points );\r
+    CvMat hull1 = cvMat( 1, num_points, CV_32SC1, hull );\r
+\r
+    bound_rect; /* to avoid "unused parameter" warning */\r
+\r
+    cvConvexHull2( &points1, &hull1, orientation, 0 );\r
+    *hullsize = hull1.cols;\r
+}\r
+\r
+/* Calculates exact convex hull of 2d point set stored in a sequence */\r
+#define cvContourConvexHull( contour, orientation, storage ) \\r
+    cvConvexHull2( contour, storage, orientation )\r
+\r
+/* Calculates approximate convex hull of 2d point set */\r
+#define cvConvexHullApprox( points, num_points, bound_rect, bandwidth,      \\r
+                            orientation, hull, hullsize )                   \\r
+cvConvexHull( points, num_points, bound_rect, orientation, hull, hullsize )\r
+\r
+/* Calculates approximate convex hull of 2d point set stored in a sequence */\r
+#define cvContourConvexHullApprox( contour, bandwidth, orientation, storage )   \\r
+    cvConvexHull2( contour, storage, orientation )\r
+\r
+\r
+CV_INLINE void cvMinAreaRect( CvPoint* points, int n,\r
+                              int left, int bottom, int right, int top,\r
+                              CvPoint2D32f* anchor,\r
+                              CvPoint2D32f* vect1,\r
+                              CvPoint2D32f* vect2 );\r
+CV_INLINE void cvMinAreaRect( CvPoint* points, int n,\r
+                              int left, int bottom, int right, int top,\r
+                              CvPoint2D32f* anchor,\r
+                              CvPoint2D32f* vect1,\r
+                              CvPoint2D32f* vect2 )\r
+{\r
+    CvMat mat = cvMat( 1, n, CV_32SC2, points );\r
+    CvBox2D box = cvMinAreaRect2( &mat, 0 );\r
+    CvPoint2D32f pt[4];\r
+\r
+    cvBoxPoints( box, pt );\r
+    *anchor = pt[0];\r
+    vect1->x = pt[1].x - pt[0].x;\r
+    vect1->y = pt[1].y - pt[0].y;\r
+    vect2->x = pt[3].x - pt[0].x;\r
+    vect2->y = pt[3].y - pt[0].y;\r
+\r
+    left, bottom, right, top; /* to avoid "unused parameter" warning */\r
+}\r
+\r
+\r
+CV_INLINE  void  cvFitLine3D( CvPoint3D32f* points, int count, CvDisType dist,\r
+                              void *param, float reps, float aeps, float* line );\r
+CV_INLINE  void  cvFitLine3D( CvPoint3D32f* points, int count, CvDisType dist,\r
+                              void *param, float reps, float aeps, float* line )\r
+{\r
+    CvMat mat = cvMat( 1, count, CV_32FC3, points );\r
+    float _param = param != NULL ? *(float*)param : 0.f;\r
+    assert( dist != CV_DIST_USER );\r
+    cvFitLine( &mat, dist, _param, reps, aeps, line );\r
+}\r
+\r
+/* Fits a line into set of 2d points in a robust way (M-estimator technique) */ \r
+CV_INLINE  void  cvFitLine2D( CvPoint2D32f* points, int count, CvDisType dist,\r
+                              void *param, float reps, float aeps, float* line );\r
+CV_INLINE  void  cvFitLine2D( CvPoint2D32f* points, int count, CvDisType dist,\r
+                              void *param, float reps, float aeps, float* line )\r
+{\r
+    CvMat mat = cvMat( 1, count, CV_32FC2, points );\r
+    float _param = param != NULL ? *(float*)param : 0.f;\r
+    assert( dist != CV_DIST_USER );\r
+    cvFitLine( &mat, dist, _param, reps, aeps, line );\r
+}\r
+\r
+\r
+CV_INLINE  void cvFitEllipse( const CvPoint2D32f* points, int count, CvBox2D* box );\r
+CV_INLINE  void cvFitEllipse( const CvPoint2D32f* points, int count, CvBox2D* box )\r
+{\r
+    CvMat mat = cvMat( 1, count, CV_32FC2, (void*)points );\r
+    *box = cvFitEllipse2( &mat );\r
+}\r
+\r
+\r
+/* Retrieves value of the particular bin\r
+   of x-dimensional (x=1,2,3,...) histogram */\r
+#define cvQueryHistValue_1D( hist, idx0 ) \\r
+    ((float)cvGetReal1D( (hist)->bins, (idx0)))\r
+#define cvQueryHistValue_2D( hist, idx0, idx1 ) \\r
+    ((float)cvGetReal2D( (hist)->bins, (idx0), (idx1)))\r
+#define cvQueryHistValue_3D( hist, idx0, idx1, idx2 ) \\r
+    ((float)cvGetReal3D( (hist)->bins, (idx0), (idx1), (idx2)))\r
+#define cvQueryHistValue_nD( hist, idx ) \\r
+    ((float)cvGetRealND( (hist)->bins, (idx)))\r
+\r
+/* Returns pointer to the particular bin of x-dimesional histogram.\r
+   For sparse histogram the bin is created if it didn't exist before */\r
+#define cvGetHistValue_1D( hist, idx0 ) \\r
+    ((float*)cvPtr1D( (hist)->bins, (idx0), 0))\r
+#define cvGetHistValue_2D( hist, idx0, idx1 ) \\r
+    ((float*)cvPtr2D( (hist)->bins, (idx0), (idx1), 0))\r
+#define cvGetHistValue_3D( hist, idx0, idx1, idx2 ) \\r
+    ((float*)cvPtr3D( (hist)->bins, (idx0), (idx1), (idx2), 0))\r
+#define cvGetHistValue_nD( hist, idx ) \\r
+    ((float*)cvPtrND( (hist)->bins, (idx), 0))\r
+\r
+\r
+#define CV_IS_SET_ELEM_EXISTS CV_IS_SET_ELEM\r
+\r
+\r
+CV_INLINE  int  cvHoughLines( CvArr* image, double rho,\r
+                              double theta, int threshold,\r
+                              float* lines, int linesNumber );\r
+CV_INLINE  int  cvHoughLines( CvArr* image, double rho,\r
+                              double theta, int threshold,\r
+                              float* lines, int linesNumber )\r
+{\r
+    CvMat linesMat = cvMat( 1, linesNumber, CV_32FC2, lines ); \r
+    cvHoughLines2( image, &linesMat, CV_HOUGH_STANDARD,\r
+                   rho, theta, threshold, 0, 0 );\r
+\r
+    return linesMat.rows;\r
+}\r
+\r
+\r
+CV_INLINE  int  cvHoughLinesP( CvArr* image, double rho,\r
+                               double theta, int threshold,\r
+                               int lineLength, int lineGap,\r
+                               int* lines, int linesNumber );\r
+CV_INLINE  int  cvHoughLinesP( CvArr* image, double rho,\r
+                               double theta, int threshold,\r
+                               int lineLength, int lineGap,\r
+                               int* lines, int linesNumber )\r
+{\r
+    CvMat linesMat = cvMat( 1, linesNumber, CV_32SC4, lines ); \r
+    cvHoughLines2( image, &linesMat, CV_HOUGH_PROBABILISTIC,\r
+                   rho, theta, threshold, lineLength, lineGap );\r
+\r
+    return linesMat.rows;\r
+}\r
+\r
+\r
+CV_INLINE  int  cvHoughLinesSDiv( CvArr* image, double rho, int srn,\r
+                                  double theta, int stn, int threshold,\r
+                                  float* lines, int linesNumber );\r
+CV_INLINE  int  cvHoughLinesSDiv( CvArr* image, double rho, int srn,\r
+                                  double theta, int stn, int threshold,\r
+                                  float* lines, int linesNumber )\r
+{\r
+    CvMat linesMat = cvMat( 1, linesNumber, CV_32FC2, lines ); \r
+    cvHoughLines2( image, &linesMat, CV_HOUGH_MULTI_SCALE,\r
+                   rho, theta, threshold, srn, stn );\r
+\r
+    return linesMat.rows;\r
+}\r
+\r
+\r
+/* Find fundamental matrix */\r
+CV_INLINE  void  cvFindFundamentalMatrix( int* points1, int* points2,\r
+                            int numpoints, int method, float* matrix );\r
+CV_INLINE  void  cvFindFundamentalMatrix( int* points1, int* points2,\r
+                            int numpoints, int method, float* matrix )\r
+{\r
+    CvMat* pointsMat1;\r
+    CvMat* pointsMat2;\r
+    CvMat fundMatr = cvMat(3,3,CV_32F,matrix);\r
+    int i, curr = 0;\r
+    method = method;\r
+\r
+    pointsMat1 = cvCreateMat(3,numpoints,CV_64F);\r
+    pointsMat2 = cvCreateMat(3,numpoints,CV_64F);\r
+\r
+    for( i = 0; i < numpoints; i++ )\r
+    {\r
+        cvmSet(pointsMat1,0,i,points1[curr]);//x\r
+        cvmSet(pointsMat1,1,i,points1[curr+1]);//y\r
+        cvmSet(pointsMat1,2,i,1.0);\r
+\r
+        cvmSet(pointsMat2,0,i,points2[curr]);//x\r
+        cvmSet(pointsMat2,1,i,points2[curr+1]);//y\r
+        cvmSet(pointsMat2,2,i,1.0);\r
+        curr += 2;\r
+    }\r
+\r
+    cvFindFundamentalMat(pointsMat1,pointsMat2,&fundMatr,CV_FM_RANSAC,1,0.99,0);\r
+\r
+    cvReleaseMat(&pointsMat1);\r
+    cvReleaseMat(&pointsMat2);\r
+}\r
+\r
+\r
+CV_INLINE  float  cvCalcEMD( const float* signature1, int size1,\r
+                             const float* signature2, int size2,\r
+                             int dims, CvDisType dist_type CV_DEFAULT(CV_DIST_L2),\r
+                             CvDistanceFunction dist_func CV_DEFAULT(0),\r
+                             float* lower_bound CV_DEFAULT(0),\r
+                             void* user_param CV_DEFAULT(0));\r
+CV_INLINE  float  cvCalcEMD( const float* signature1, int size1,\r
+                             const float* signature2, int size2,\r
+                             int dims, CvDisType dist_type,\r
+                             CvDistanceFunction dist_func,\r
+                             float* lower_bound, void* user_param )\r
+{\r
+    CvMat sign1 = cvMat( size1, dims + 1, CV_32FC1, (void*)signature1 );\r
+    CvMat sign2 = cvMat( size2, dims + 1, CV_32FC1, (void*)signature2 );\r
+\r
+    return cvCalcEMD2( &sign1, &sign2, dist_type, dist_func, 0, 0, lower_bound, user_param ); \r
+}\r
+\r
+\r
+CV_INLINE  void  cvKMeans( int num_clusters, float** samples,\r
+                           int num_samples, int vec_size,\r
+                           CvTermCriteria termcrit, int* cluster_idx );\r
+CV_INLINE  void  cvKMeans( int num_clusters, float** samples,\r
+                           int num_samples, int vec_size,\r
+                           CvTermCriteria termcrit, int* cluster_idx )\r
+{\r
+    CvMat* samples_mat = cvCreateMat( num_samples, vec_size, CV_32FC1 );\r
+    CvMat cluster_idx_mat = cvMat( num_samples, 1, CV_32SC1, cluster_idx );\r
+    int i;\r
+    for( i = 0; i < num_samples; i++ )\r
+        memcpy( samples_mat->data.fl + i*vec_size, samples[i], vec_size*sizeof(float));\r
+    cvKMeans2( samples_mat, num_clusters, &cluster_idx_mat, termcrit );\r
+    cvReleaseMat( &samples_mat );\r
+}\r
+\r
+\r
+/****************************************************************************************\\r
+*                                   Pixel Access Macros                                  *\r
+\****************************************************************************************/\r
+\r
+typedef struct _CvPixelPosition8u\r
+{\r
+    unsigned char*   currline;      /* pointer to the start of the current pixel line   */\r
+    unsigned char*   topline;       /* pointer to the start of the top pixel line       */\r
+    unsigned char*   bottomline;    /* pointer to the start of the first line           */\r
+                                    /* which is below the image                         */\r
+    int     x;                      /* current x coordinate ( in pixels )               */\r
+    int     width;                  /* width of the image  ( in pixels )                */\r
+    int     height;                 /* height of the image  ( in pixels )               */\r
+    int     step;                   /* distance between lines ( in elements of single   */\r
+                                    /* plane )                                          */\r
+    int     step_arr[3];            /* array: ( 0, -step, step ). It is used for        */\r
+                                    /* vertical moving                                  */\r
+} CvPixelPosition8u;\r
+\r
+/* this structure differs from the above only in data type */\r
+typedef struct _CvPixelPosition8s\r
+{\r
+    char*   currline;\r
+    char*   topline;\r
+    char*   bottomline;\r
+    int     x;\r
+    int     width;\r
+    int     height;\r
+    int     step;\r
+    int     step_arr[3];\r
+} CvPixelPosition8s;\r
+\r
+/* this structure differs from the CvPixelPosition8u only in data type */\r
+typedef struct _CvPixelPosition32f\r
+{\r
+    float*  currline;\r
+    float*  topline;\r
+    float*  bottomline;\r
+    int     x;\r
+    int     width;\r
+    int     height;\r
+    int     step;\r
+    int     step_arr[3];\r
+} CvPixelPosition32f;\r
+\r
+\r
+/* Initialize one of the CvPixelPosition structures.   */\r
+/*  pos    - initialized structure                     */\r
+/*  origin - pointer to the left-top corner of the ROI */\r
+/*  step   - width of the whole image in bytes         */\r
+/*  roi    - width & height of the ROI                 */\r
+/*  x, y   - initial position                          */\r
+#define CV_INIT_PIXEL_POS(pos, origin, _step, roi, _x, _y, orientation)    \\r
+    (                                                                        \\r
+    (pos).step = (_step)/sizeof((pos).currline[0]) * (orientation ? -1 : 1), \\r
+    (pos).width = (roi).width,                                               \\r
+    (pos).height = (roi).height,                                             \\r
+    (pos).bottomline = (origin) + (pos).step*(pos).height,                   \\r
+    (pos).topline = (origin) - (pos).step,                                   \\r
+    (pos).step_arr[0] = 0,                                                   \\r
+    (pos).step_arr[1] = -(pos).step,                                         \\r
+    (pos).step_arr[2] = (pos).step,                                          \\r
+    (pos).x = (_x),                                                          \\r
+    (pos).currline = (origin) + (pos).step*(_y) )\r
+\r
+\r
+/* Move to specified point ( absolute shift ) */\r
+/*  pos    - position structure               */\r
+/*  x, y   - coordinates of the new position  */\r
+/*  cs     - number of the image channels     */\r
+#define CV_MOVE_TO( pos, _x, _y, cs )                                                   \\r
+((pos).currline = (_y) >= 0 && (_y) < (pos).height ? (pos).topline + ((_y)+1)*(pos).step : 0, \\r
+ (pos).x = (_x) >= 0 && (_x) < (pos).width ? (_x) : 0, (pos).currline + (_x) * (cs) )\r
+\r
+/* Get current coordinates                    */\r
+/*  pos    - position structure               */\r
+/*  x, y   - coordinates of the new position  */\r
+/*  cs     - number of the image channels     */\r
+#define CV_GET_CURRENT( pos, cs )  ((pos).currline + (pos).x * (cs))\r
\r
+/* Move by one pixel relatively to current position */\r
+/*  pos    - position structure                     */\r
+/*  cs     - number of the image channels           */\r
\r
+/* left */\r
+#define CV_MOVE_LEFT( pos, cs ) \\r
+ ( --(pos).x >= 0 ? (pos).currline + (pos).x*(cs) : 0 )\r
\r
+/* right */\r
+#define CV_MOVE_RIGHT( pos, cs ) \\r
+ ( ++(pos).x < (pos).width ? (pos).currline + (pos).x*(cs) : 0 )\r
\r
+/* up */\r
+#define CV_MOVE_UP( pos, cs ) \\r
+ (((pos).currline -= (pos).step) != (pos).topline ? (pos).currline + (pos).x*(cs) : 0 )\r
\r
+/* down */\r
+#define CV_MOVE_DOWN( pos, cs ) \\r
+ (((pos).currline += (pos).step) != (pos).bottomline ? (pos).currline + (pos).x*(cs) : 0 )\r
\r
+/* left up */\r
+#define CV_MOVE_LU( pos, cs ) ( CV_MOVE_LEFT(pos, cs), CV_MOVE_UP(pos, cs))\r
\r
+/* right up */\r
+#define CV_MOVE_RU( pos, cs ) ( CV_MOVE_RIGHT(pos, cs), CV_MOVE_UP(pos, cs))\r
\r
+/* left down */\r
+#define CV_MOVE_LD( pos, cs ) ( CV_MOVE_LEFT(pos, cs), CV_MOVE_DOWN(pos, cs))\r
\r
+/* right down */\r
+#define CV_MOVE_RD( pos, cs ) ( CV_MOVE_RIGHT(pos, cs), CV_MOVE_DOWN(pos, cs))\r
\r
\r
\r
+/* Move by one pixel relatively to current position with wrapping when the position     */\r
+/* achieves image boundary                                                              */\r
+/*  pos    - position structure                                                         */\r
+/*  cs     - number of the image channels                                               */\r
\r
+/* left */\r
+#define CV_MOVE_LEFT_WRAP( pos, cs ) \\r
+ ((pos).currline + ( --(pos).x >= 0 ? (pos).x : ((pos).x = (pos).width-1))*(cs))\r
\r
+/* right */\r
+#define CV_MOVE_RIGHT_WRAP( pos, cs ) \\r
+ ((pos).currline + ( ++(pos).x < (pos).width ? (pos).x : ((pos).x = 0))*(cs) )\r
\r
+/* up */\r
+#define CV_MOVE_UP_WRAP( pos, cs ) \\r
+    ((((pos).currline -= (pos).step) != (pos).topline ? \\r
+    (pos).currline : ((pos).currline = (pos).bottomline - (pos).step)) + (pos).x*(cs) )\r
\r
+/* down */\r
+#define CV_MOVE_DOWN_WRAP( pos, cs ) \\r
+    ((((pos).currline += (pos).step) != (pos).bottomline ? \\r
+    (pos).currline : ((pos).currline = (pos).topline + (pos).step)) + (pos).x*(cs) )\r
\r
+/* left up */\r
+#define CV_MOVE_LU_WRAP( pos, cs ) ( CV_MOVE_LEFT_WRAP(pos, cs), CV_MOVE_UP_WRAP(pos, cs))\r
+/* right up */\r
+#define CV_MOVE_RU_WRAP( pos, cs ) ( CV_MOVE_RIGHT_WRAP(pos, cs), CV_MOVE_UP_WRAP(pos, cs))\r
+/* left down */\r
+#define CV_MOVE_LD_WRAP( pos, cs ) ( CV_MOVE_LEFT_WRAP(pos, cs), CV_MOVE_DOWN_WRAP(pos, cs))\r
+/* right down */\r
+#define CV_MOVE_RD_WRAP( pos, cs ) ( CV_MOVE_RIGHT_WRAP(pos, cs), CV_MOVE_DOWN_WRAP(pos, cs))\r
\r
+/* Numeric constants which used for moving in arbitrary direction  */\r
+#define CV_SHIFT_NONE   2\r
+#define CV_SHIFT_LEFT   1\r
+#define CV_SHIFT_RIGHT  3\r
+#define CV_SHIFT_UP     6\r
+#define CV_SHIFT_DOWN  10\r
+#define CV_SHIFT_LU     5\r
+#define CV_SHIFT_RU     7\r
+#define CV_SHIFT_LD     9\r
+#define CV_SHIFT_RD    11\r
\r
+/* Move by one pixel in specified direction                                     */\r
+/*  pos    - position structure                                                 */\r
+/*  shift  - direction ( it's value must be one of the CV_SHIFT_\85 constants ) */\r
+/*  cs     - number of the image channels                                       */\r
+#define CV_MOVE_PARAM( pos, shift, cs )                                           \\r
+    ( (pos).currline += (pos).step_arr[(shift)>>2], (pos).x += ((shift)&3)-2,       \\r
+    ((pos).currline != (pos).topline && (pos).currline != (pos).bottomline &&       \\r
+    (pos).x >= 0 && (pos).x < (pos).width) ? (pos).currline + (pos).x*(cs) : 0 )\r
\r
+/* Move by one pixel in specified direction with wrapping when the               */\r
+/* position achieves image boundary                                              */\r
+/*  pos    - position structure                                                  */\r
+/*  shift  - direction ( it's value must be one of the CV_SHIFT_\85 constants )  */\r
+/*  cs     - number of the image channels                                        */\r
+#define CV_MOVE_PARAM_WRAP( pos, shift, cs )                                      \\r
+    ( (pos).currline += (pos).step_arr[(shift)>>2],                                 \\r
+    (pos).currline = ((pos).currline == (pos).topline ?                             \\r
+    (pos).bottomline - (pos).step :                                                 \\r
+    (pos).currline == (pos).bottomline ?                                            \\r
+    (pos).topline + (pos).step : (pos).currline),                                   \\r
+                                                                                    \\r
+    (pos).x += ((shift)&3)-2,                                                       \\r
+    (pos).x = ((pos).x < 0 ? (pos).width-1 : (pos).x >= (pos).width ? 0 : (pos).x), \\r
+                                                                                    \\r
+    (pos).currline + (pos).x*(cs) )\r
+\r
+#endif/*_CVCOMPAT_H_*/\r
index c1f8f944a7976a3d04fd05817ace518069f50353..b8ff95fd78cf885ba33692ed1c41e318e4a7dd35 100644 (file)
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-//  By downloading, copying, installing or using the software you agree to this license.
-//  If you do not agree to this license, do not download, install,
-//  copy or use the software.
-//
-//
-//                        Intel License Agreement
-//                For Open Source Computer Vision Library
-//
-// Copyright (C) 2000, Intel Corporation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-//   * Redistribution's of source code must retain the above copyright notice,
-//     this list of conditions and the following disclaimer.
-//
-//   * Redistribution's in binary form must reproduce the above copyright notice,
-//     this list of conditions and the following disclaimer in the documentation
-//     and/or other materials provided with the distribution.
-//
-//   * The name of Intel Corporation may not be used to endorse or promote products
-//     derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-// (including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort (including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-#ifndef _CVTYPES_H_
-#define _CVTYPES_H_
-
-#include <assert.h>
-
-#ifndef WIN32
-    #define CV_CDECL
-    #define CV_STDCALL
-#else
-    #define CV_CDECL __cdecl
-    #define CV_STDCALL __stdcall
-#endif
-
-#ifndef CV_EXTERN_C
-    #ifdef __cplusplus
-        #define CV_EXTERN_C extern "C"
-        #define CV_DEFAULT(val) = val
-    #else
-        #define CV_EXTERN_C
-        #define CV_DEFAULT(val)
-    #endif
-#endif
-
-#ifndef CV_EXTERN_C_FUNCPTR
-    #ifdef __cplusplus
-        #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
-    #else
-        #define CV_EXTERN_C_FUNCPTR(x) typedef x
-    #endif
-#endif
-
-#if defined WIN32 && defined CV_DLL
-    #define CV_DLL_ENTRY __declspec(dllexport)
-#else
-    #define CV_DLL_ENTRY
-#endif
-
-#ifndef OPENCVAPI
-    #define OPENCVAPI CV_EXTERN_C CV_DLL_ENTRY
-#endif
-
-#ifndef CV_INLINE
-#ifdef WIN32
-    #define CV_INLINE __inline
-#elif defined __cplusplus
-    #define CV_INLINE inline
-#else
-    #define CV_INLINE static
-#endif
-#endif /* CV_INLINE */
-
-#if defined _MSC_VER || defined __BORLANDC__
-typedef __int64 int64;
-typedef unsigned __int64 uint64;
-#else
-typedef long long int64;
-typedef unsigned long long uint64;
-typedef long long _int64;
-#endif
-
-#ifndef __IPL_H__
-typedef unsigned char uchar;
-#endif
-
-#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
-
-#ifndef MIN
-#define MIN(a,b)  ((a) > (b) ? (b) : (a))
-#endif
-
-#ifndef MAX
-#define MAX(a,b)  ((a) < (b) ? (b) : (a))
-#endif
-
-/**********************************************************************************\
-*                            Types of Matrix data                                  *
-\**********************************************************************************/
-
-#define CV_8U   0
-#define CV_8S   1
-#define CV_16S  2
-#define CV_32S  3
-#define CV_32F  4
-#define CV_64F  5
-
-#define CV_8UC1 (CV_8U + 0*8)
-#define CV_8UC2 (CV_8U + 1*8)
-#define CV_8UC3 (CV_8U + 2*8)
-#define CV_8UC4 (CV_8U + 3*8)
-
-#define CV_8SC1 (CV_8S + 0*8)
-#define CV_8SC2 (CV_8S + 1*8)
-#define CV_8SC3 (CV_8S + 2*8)
-#define CV_8SC4 (CV_8S + 3*8)
-
-#define CV_16SC1 (CV_16S + 0*8)
-#define CV_16SC2 (CV_16S + 1*8)
-#define CV_16SC3 (CV_16S + 2*8)
-#define CV_16SC4 (CV_16S + 3*8)
-
-#define CV_32SC1 (CV_32S + 0*8)
-#define CV_32SC2 (CV_32S + 1*8)
-#define CV_32SC3 (CV_32S + 2*8)
-#define CV_32SC4 (CV_32S + 3*8)
-
-#define CV_32FC1 (CV_32F + 0*8)
-#define CV_32FC2 (CV_32F + 1*8)
-#define CV_32FC3 (CV_32F + 2*8)
-#define CV_32FC4 (CV_32F + 3*8)
-
-#define CV_64FC1 (CV_64F + 0*8)
-#define CV_64FC2 (CV_64F + 1*8)
-#define CV_64FC3 (CV_64F + 2*8)
-#define CV_64FC4 (CV_64F + 3*8)
-
-#define IPL_DEPTH_64F  64
-
-#define CV_AUTO_STEP  0x7fffffff
-#define CV_WHOLE_ARR  cvSlice( 0, 0x3fffffff )
-
-#define CV_ARR_CN_MASK        (3 << 3)
-#define CV_ARR_CN(flags)      ((((flags) & CV_ARR_CN_MASK) >> 3) + 1)
-#define CV_ARR_DEPTH_MASK     7
-#define CV_ARR_DEPTH(flags)   ((flags) & CV_ARR_DEPTH_MASK)
-#define CV_ARR_TYPE_MASK      31
-#define CV_ARR_TYPE(flags)    ((flags) & CV_ARR_TYPE_MASK)
-#define CV_ARR_FMT_MASK       511
-#define CV_ARR_FMT(flags)     ((flags) & CV_ARR_FMT_MASK)
-#define CV_ARR_CONT_FLAG_SHIFT 9
-#define CV_ARR_CONT_FLAG      (1 << CV_ARR_CONT_FLAG_SHIFT)
-#define CV_IS_ARR_CONT(flags) ((flags) & CV_ARR_CONT_FLAG) 
-
-#define CV_ARR_MAGIC_MASK   0xFFFF0000 
-#define CV_ARR_MAGIC_VAL    0x42240000
-
-typedef struct CvMat
-{
-    int type;
-
-#ifdef __cplusplus
-    union
-    {
-        int rows;
-        int height;
-    };
-
-    union
-    {
-        int cols;
-        int width;
-    };
-#else
-    int rows;
-    int cols;
-#endif
-
-    int step;
-    union
-    {
-        float* fl;
-        double* db;
-        uchar* ptr;
-    } data;
-} CvMat;
-
-
-#define _CV_IS_ARR(arr) \
-    ((arr) != 0 && (((const CvMat*)(arr))->type & CV_ARR_MAGIC_MASK) == CV_ARR_MAGIC_VAL)
-
-#define _CV_IS_IMAGE(img) \
-    ((img) != 0 && ((const IplImage*)(img))->nSize == sizeof(IplImage))
-
-#define CV_IS_ARR(arr) \
-    (_CV_IS_ARR(arr) && ((const CvMat*)(arr))->data.ptr != 0)
-
-#define CV_IS_IMAGE(img) \
-    (_CV_IS_IMAGE(img) && ((IplImage*)img)->imageData != 0)
-
-#define CV_IS_MASK_ARR(arr) \
-    (((arr)->type & (CV_ARR_TYPE_MASK & ~CV_8SC1)) == 0)
-
-#define CV_ARE_TYPES_EQ(arr1, arr2) \
-    ( (((arr1)->type ^ (arr2)->type) & CV_ARR_TYPE_MASK) == 0 )
-
-#define CV_ARE_CNS_EQ(arr1, arr2) \
-    ( (((arr1)->type ^ (arr2)->type) & CV_ARR_CN_MASK) == 0 )
-
-#define CV_ARE_DEPTHS_EQ(arr1, arr2) \
-    ( (((arr1)->type ^ (arr2)->type) & CV_ARR_DEPTH_MASK) == 0 )
-
-#define CV_ARE_SIZES_EQ(arr1, arr2) \
-    ( (arr1)->height == (arr2)->height && (arr1)->width == (arr2)->width )
-
-#define CV_IS_ARR_CONST(arr)  \
-    ( ((arr)->height|(arr)->width) == 1 )
-
-typedef void CvArr;
-
-typedef struct CvRect
-{
-    int x;
-    int y;
-    int width;
-    int height;
-} CvRect;
-
-typedef struct CvPoint
-{
-    int x;
-    int y;
-} CvPoint;
-
-typedef struct {
-    int width;
-    int height;
-} CvSize;
-
-
-#define CV_TERMCRIT_ITER    1
-#define CV_TERMCRIT_NUMB    CV_TERMCRIT_ITER
-#define CV_TERMCRIT_EPS     2
-
-typedef struct CvTermCriteria
-{
-    int   type;  /* may be combination of
-                 CV_TERMCRIT_ITER
-                 CV_TERMCRIT_EPS */
-    int   maxIter;
-    float epsilon;
-} CvTermCriteria;
-
-
-typedef struct CvPoint2D32f
-{
-    float x;
-    float y;
-} CvPoint2D32f;
-
-typedef struct CvPoint3D32f
-{
-    float x;
-    float y;
-    float z;
-} CvPoint3D32f;
-
-typedef struct CvPoint2D64d
-{
-    double x;
-    double y;
-} CvPoint2D64d;
-
-typedef struct CvPoint3D64d
-{
-    double x;
-    double y;
-    double z;
-} CvPoint3D64d;
-
-typedef struct CvSize2D32f
-{
-    float width;
-    float height;
-} CvSize2D32f;
-
-typedef struct CvBox2D
-{
-    CvPoint2D32f center;
-    CvSize2D32f  size;
-    float angle;
-} CvBox2D;
-
-typedef enum CvCoeffType
-{
-    CV_VALUE = 1,
-    CV_ARRAY = 2
-} CvCoeffType;
-
-typedef struct CvSlice
-{
-    int  startIndex, endIndex;
-} CvSlice;
-
-typedef struct CvScalar
-{
-    double val[4];
-}
-CvScalar;
-
-CV_INLINE  int  cvPixSize( int matType );
-CV_INLINE  int  cvPixSize( int matType )
-{
-    return (((0733100 >> CV_ARR_DEPTH( matType )*3) & 7) + 1)*CV_ARR_CN( matType );
-}
-
-CV_INLINE  CvMat  cvMat( int rows, int cols, int type, void* data CV_DEFAULT(0));
-CV_INLINE  CvMat  cvMat( int rows, int cols, int type, void* data )
-{
-    CvMat m;
-
-    assert( (unsigned)CV_ARR_DEPTH(type) <= CV_64F );
-    m.type = CV_ARR_MAGIC_VAL | CV_ARR_CONT_FLAG | CV_ARR_TYPE(type);
-    m.cols = cols;
-    m.rows = rows;
-    m.step = m.cols*cvPixSize( CV_ARR_TYPE(type) );
-    m.data.ptr = (uchar*)data;
-
-    return m; 
-}
-
-
-CV_INLINE  double  cvmGet( const CvMat* mat, int i, int j );
-CV_INLINE  double  cvmGet( const CvMat* mat, int i, int j )
-{
-    int type;
-
-    assert( (unsigned)i < (unsigned)(mat->rows) &&
-            (unsigned)j < (unsigned)(mat->cols) );
-
-    type = CV_ARR_TYPE(mat->type);
-    if( type == CV_32FC1 )
-        return ((float*)(mat->data.ptr + mat->step*i))[j];
-    else
-    {
-        assert( type == CV_64FC1 );
-        return ((double*)(mat->data.ptr + mat->step*i))[j];
-    }
-}
-
-
-CV_INLINE  void  cvmSet( CvMat* mat, int i, int j, double val );
-CV_INLINE  void  cvmSet( CvMat* mat, int i, int j, double val )
-{
-    int type;
-    assert( (unsigned)i < (unsigned)(mat->rows) &&
-            (unsigned)j < (unsigned)(mat->cols) );
-
-    type = CV_ARR_TYPE(mat->type);
-    if( type == CV_32FC1 )
-        ((float*)(mat->data.ptr + mat->step*i))[j] = (float)val;
-    else
-    {
-        assert( type == CV_64FC1 );
-        ((double*)(mat->data.ptr + mat->step*i))[j] = val;
-    }
-}
-
-
-CV_INLINE  CvRect  cvRect( int x, int y, int width, int height );
-CV_INLINE  CvRect  cvRect( int x, int y, int width, int height )
-{
-    CvRect r;
-
-    r.x = x;
-    r.y = y;
-    r.width = width;
-    r.height = height;
-
-    return r;
-}
-
-
-CV_INLINE  IplROI  cvRectToROI( CvRect rect, int coi CV_DEFAULT(0));
-CV_INLINE  IplROI  cvRectToROI( CvRect rect, int coi )
-{
-    IplROI roi;
-    roi.xOffset = rect.x;
-    roi.yOffset = rect.y;
-    roi.width = rect.width;
-    roi.height = rect.height;
-    roi.coi = coi;
-
-    return roi;
-}
-
-
-CV_INLINE  CvRect  cvROIToRect( IplROI roi );
-CV_INLINE  CvRect  cvROIToRect( IplROI roi )
-{
-    return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
-}
-
-
-CV_INLINE  CvSize  cvSize( int width, int height );
-CV_INLINE  CvSize  cvSize( int width, int height )
-{
-    CvSize s;
-
-    s.width = width;
-    s.height = height;
-
-    return s;
-}
-
-
-CV_INLINE  CvPoint  cvPoint( int x, int y );
-CV_INLINE  CvPoint  cvPoint( int x, int y )
-{
-    CvPoint p;
-
-    p.x = x;
-    p.y = y;
-
-    return p;
-}
-
-
-CV_INLINE  CvPoint2D32f  cvPoint2D32f( double x, double y );
-CV_INLINE  CvPoint2D32f  cvPoint2D32f( double x, double y )
-{
-    CvPoint2D32f p;
-
-    p.x = (float)x;
-    p.y = (float)y;
-
-    return p;
-}
-
-CV_INLINE  CvPoint3D32f  cvPoint3D32f( double x, double y, double z );
-CV_INLINE  CvPoint3D32f  cvPoint3D32f( double x, double y, double z )
-{
-    CvPoint3D32f p;
-
-    p.x = (float)x;
-    p.y = (float)y;
-    p.z = (float)z;
-
-    return p;
-}           
-
-CV_INLINE  CvTermCriteria  cvTermCriteria( int type, int maxIter, double epsilon );
-CV_INLINE  CvTermCriteria  cvTermCriteria( int type, int maxIter, double epsilon )
-{
-    CvTermCriteria t;
-
-    t.type = type;
-    t.maxIter = maxIter;
-    t.epsilon = (float)epsilon;
-
-    return t;
-}
-
-
-CV_INLINE  CvSlice  cvSlice( int start, int end );
-CV_INLINE  CvSlice  cvSlice( int start, int end )
-{
-    CvSlice slice;
-    slice.startIndex = start;
-    slice.endIndex = end;
-
-    return slice;
-}
-
-CV_INLINE  CvScalar  cvScalar( double a, double b CV_DEFAULT(0),
-                               double c CV_DEFAULT(0), double d CV_DEFAULT(0));
-CV_INLINE  CvScalar  cvScalar( double a, double b, double c, double d )
-{
-    CvScalar scalar;
-    scalar.val[0] = a; scalar.val[1] = b;
-    scalar.val[2] = c; scalar.val[3] = d;
-    return scalar;
-}
-
-
-CV_INLINE  CvScalar  cvRealScalar( double a );
-CV_INLINE  CvScalar  cvRealScalar( double a )
-{
-    CvScalar scalar;
-    scalar.val[0] = a;
-    scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
-    return scalar;
-}
-
-CV_INLINE  CvScalar  cvScalarAll( double a );
-CV_INLINE  CvScalar  cvScalarAll( double a )
-{
-    CvScalar scalar;
-    scalar.val[0] = scalar.val[1] = scalar.val[2] = scalar.val[3] = a;
-    return scalar;
-}
-
-
-#define CV_WHOLE_SEQ  cvSlice(0, 0x3fffffff)
-
-/* ************************************************************* *\
-   substitutions for round(x), floor(x), ceil(x):
-   the algorithm was taken from Agner Fog's optimization guide
-   at http://www.agner.org/assem
-\* ************************************************************* */
-CV_INLINE  int  cvRound( double val );
-CV_INLINE  int  cvRound( double val )
-{
-    double temp = val + 6755399441055744.0;
-    return (int)*((uint64*)&temp);
-}
-
-
-CV_INLINE  int  cvFloor( double val );
-CV_INLINE  int  cvFloor( double val )
-{
-    double temp = val + 6755399441055744.0;
-    float diff = (float)(val - (int)*((uint64*)&temp));
-
-    return (int)*((uint64*)&temp) - (*(int*)&diff < 0);
-}
-
-
-CV_INLINE  int  cvCeil( double val );
-CV_INLINE  int  cvCeil( double val )
-{
-    double temp = val + 6755399441055744.0;
-    float diff = (float)((int)*((uint64*)&temp) - val);
-
-    return (int)*((uint64*)&temp) + (*(int*)&diff < 0);
-}
-
-
-/* ************************************************************************** *\
-   Fast square root and inverse square root by
-   Bruce W. Holloway, Jeremy M., James Van Buskirk, Vesa Karvonen and others.
-   Taken from Paul Hsieh's site http://www.azillionmonkeys.com/qed/sqroot.html.
-\* ************************************************************************** */
-#define CV_SQRT_MAGIC  0xbe6f0000
-
-CV_INLINE  float  cvInvSqrt( float arg );
-CV_INLINE  float  cvInvSqrt( float arg )
-{
-    float x, y;
-    unsigned iarg = *((unsigned*)&arg);
-    *((unsigned*)&x) = (CV_SQRT_MAGIC - iarg)>>1;
-
-    y = arg*0.5f;
-    x*= 1.5f - y*x*x;
-    x*= 1.5f - y*x*x;
-
-    return x;
-}
-
-
-CV_INLINE  float  cvSqrt( float arg );
-CV_INLINE  float  cvSqrt( float arg )
-{
-    float x, y;
-    unsigned iarg = *((unsigned*)&arg);
-    *((unsigned*)&x) = (CV_SQRT_MAGIC - iarg)>>1;
-
-    y = arg*0.5f;
-    x*= 1.5f - y*x*x;
-    x*= 1.5f - y*x*x;
-
-    return x*arg;
-}
-
-
-/* Defines for Distance Transform */
-typedef enum CvDisType
-{
-    CV_DIST_USER         = -1, /* User defined distance */
-    CV_DIST_L1           = 1, /* distance = |x1-x2| + |y1-y2| */
-    CV_DIST_L2           = 2, /* the simple euclidean distance */
-    CV_DIST_C            = 3, /* distance = max(|x1-x2|,|y1-y2|) */
-    CV_DIST_L12          = 4, /* L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */
-    CV_DIST_FAIR         = 5, /* distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */
-    CV_DIST_WELSCH       = 6 /* distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */
-} CvDisType;
-
-
-/* Filters used in pyramid decomposition */
-typedef enum CvFilter
-{
-    CV_GAUSSIAN_5x5 = 7
-} CvFilter;
-
-#define CV_RGB( r, g, b )  (int)((uchar)(b) + ((uchar)(g) << 8) + ((uchar)(r) << 16))
-#define CV_FILLED -1
-
-/****************  segmented component's structure  *************************************/
-typedef struct CvConnectedComp
-{
-    double area;          /*  area of the segmented component  */
-    double value;          /*  gray scale value of the segmented component  */
-    CvRect rect;        /*  ROI of the segmented component  */
-} CvConnectedComp;
-
-/****************************************************************************************\
-*                         Histogram structures & defines                                 *
-\****************************************************************************************/
-#define CV_HIST_MAX_DIM 16
-
-typedef enum CvHistType {
-    CV_HIST_ARRAY = 0,
-    CV_HIST_TREE  = 1
-} CvHistType;
-
-typedef enum CvCompareMethod {
-    CV_COMP_CORREL = 0,
-    CV_COMP_CHISQR = 1,
-    CV_COMP_INTERSECT  = 2
-} CvCompareMethod;
-
-typedef enum CvHistFlag {
-    CV_HIST_MEMALLOCATED    = 1,
-    CV_HIST_HEADERALLOCATED = 2,
-    CV_HIST_UNIFORM         = 4,
-    CV_HIST_THRESHALLOCATED = 8
-} CvHistFlag;
-
-typedef struct CvHistogram
-{
-    int     header_size;    /* header's size */
-    CvHistType type;           /* type of histogram */
-    int     flags;
-    int     c_dims;
-    int     dims[CV_HIST_MAX_DIM];
-    int     mdims[CV_HIST_MAX_DIM]; /* coefficients for fast calculation of number of element   */
-                            /* &m[a,b,c] = m + a*mdims[0] + b*mdims[1] + c*mdims[2] */
-    float*  thresh[CV_HIST_MAX_DIM];
-    float*  array; /* all the histogram data, expanded into the single row */
-
-    struct  CvNode* root;
-    struct  CvSet*  set;
-    int*    chdims[CV_HIST_MAX_DIM];
-} CvHistogram;
-
-/****************************************************************************************/
-/*                                   Data structures                                    */
-/****************************************************************************************/
-
-/******************************** Memory storage ****************************************/
-
-typedef struct CvMemBlock
-{
-    struct CvMemBlock*  prev;
-    struct CvMemBlock*  next;
-} CvMemBlock;
-
-typedef struct CvMemStorage
-{
-    CvMemBlock* bottom;/* first allocated block */
-    CvMemBlock* top;   /* current memory block - top of the stack */
-    struct  CvMemStorage* parent; /* borrows new blocks from */
-    int     block_size;  /* block size */
-    int     free_space;  /* free space in the current block */
-} CvMemStorage;
-
-
-typedef struct CvMemStoragePos
-{
-    CvMemBlock* top;
-    int  free_space;
-}
-CvMemStoragePos;
-
-
-/*********************************** Sequence *******************************************/
-
-typedef struct CvSeqBlock
-{
-    struct CvSeqBlock*  prev; /* previous sequence block */
-    struct CvSeqBlock*  next; /* next sequence block */
-    int    start_index;       /* index of the first element in the block +
-                                 sequence->first->start_index */
-    int    count;             /* number of elements in the block */
-    char*  data;              /* pointer to the first element of the block */
-} CvSeqBlock;
-
-
-/*
-   Read/Write sequence.
-   Elements can be dynamically inserted to or deleted from the sequence.
-*/
-#define CV_SEQUENCE_FIELDS()                                    \
-    int       header_size;   /* size of sequence header */      \
-    struct    CvSeq* h_prev; /* previous sequence */            \
-    struct    CvSeq* h_next; /* next sequence */                \
-    struct    CvSeq* v_prev; /* 2nd previous sequence */        \
-    struct    CvSeq* v_next; /* 2nd next sequence */            \
-    int       flags;          /* micsellaneous flags */                \
-    int       total;          /* total number of elements */           \
-    int       elem_size;      /* size of sequence element in bytes */  \
-    char*     block_max;      /* maximal bound of the last block */    \
-    char*     ptr;            /* current write pointer */              \
-    int       delta_elems;    /* how many elements allocated when the seq grows */  \
-    CvMemStorage* storage;  /* where the seq is stored */       \
-    CvSeqBlock* free_blocks;  /* free blocks list */       \
-    CvSeqBlock* first; /* pointer to the first sequence block */
-
-
-typedef struct CvSeq
-{
-    CV_SEQUENCE_FIELDS()
-} CvSeq;
-
-
-/*************************************** Set ********************************************/
-/*
-  Set.
-  Order isn't keeped. There can be gaps between sequence elements.
-  After the element has been inserted it stays on the same place all the time.
-  The LSB(least-significant bit) of the first field is 0 iff the element exists.
-*/
-#define CV_SET_ELEM_FIELDS()    \
-    int*  aligned_ptr;
-
-typedef struct CvSetElem
-{
-    CV_SET_ELEM_FIELDS()
-}
-CvSetElem;
-
-#define CV_SET_FIELDS()      \
-    CV_SEQUENCE_FIELDS()     \
-    CvMemBlock* free_elems;
-
-typedef struct CvSet
-{
-    CV_SET_FIELDS()
-}
-CvSet;
-
-/************************************* Graph ********************************************/
-
-/*
-  Graph is represented as a set of vertices.
-  Vertices contain their adjacency lists (more exactly, pointers to first incoming or
-  outcoming edge (or 0 if isolated vertex)). Edges are stored in another set.
-  There is a single-linked list of incoming/outcoming edges for each vertex.
-
-  Each edge consists of:
-    two pointers to the starting and the ending vertices (vtx[0] and vtx[1],
-    respectively). Graph may be oriented or not. In the second case, edges between
-    vertex i to vertex j are not distingueshed (during the search operations).
-
-    two pointers to next edges for the starting and the ending vertices.
-    next[0] points to the next edge in the vtx[0] adjacency list and
-    next[1] points to the next edge in the vtx[1] adjacency list.
-*/
-#define CV_GRAPH_EDGE_FIELDS()    \
-    int flags;                    \
-    struct CvGraphEdge* next[2];  \
-    struct CvGraphVtx* vtx[2];
-    
-
-#define CV_GRAPH_VERTEX_FIELDS()  \
-    int flags;                    \
-    struct CvGraphEdge* first;
-    
-
-typedef struct CvGraphEdge
-{
-    CV_GRAPH_EDGE_FIELDS()
-}
-CvGraphEdge;
-
-typedef struct CvGraphVtx
-{
-    CV_GRAPH_VERTEX_FIELDS()
-}
-CvGraphVtx;
-
-typedef struct CvGraphVtx2D
-{
-    CV_GRAPH_VERTEX_FIELDS()
-    CvPoint2D32f* ptr;
-}
-CvGraphVtx2D;
-
-/*
-   Graph is "derived" from the set (this is set a of vertices)
-   and includes another set (edges)
-*/
-#define  CV_GRAPH_FIELDS()   \
-    CV_SET_FIELDS()          \
-    CvSet* edges;
-
-typedef struct CvGraph
-{
-    CV_GRAPH_FIELDS()
-}
-CvGraph;
-
-/*********************************** Chain/Countour *************************************/
-
-typedef struct CvChain
-{
-    CV_SEQUENCE_FIELDS()
-    CvPoint  origin;
-} CvChain;
-
-#define CV_CONTOUR_FIELDS()  \
-    CV_SEQUENCE_FIELDS()     \
-    CvRect rect;
-
-typedef struct CvContour
-{
-    CV_CONTOUR_FIELDS()
-} CvContour;
-
-/****************************************************************************************\
-*                                    Sequence types                                      *
-\****************************************************************************************/
-
-#define CV_SEQ_ELTYPE_BITS         5
-#define CV_SEQ_ELTYPE_MASK         ((1 << CV_SEQ_ELTYPE_BITS) - 1)
-
-#define CV_SEQ_ELTYPE_POINT          1  /* (x,y) */
-#define CV_SEQ_ELTYPE_CODE           2  /* freeman code: 0..7 */
-#define CV_SEQ_ELTYPE_PPOINT         3  /* &(x,y) */
-#define CV_SEQ_ELTYPE_INDEX          4  /* #(x,y) */
-#define CV_SEQ_ELTYPE_GRAPH_EDGE     5  /* &next_o, &next_d, &vtx_o, &vtx_d */
-#define CV_SEQ_ELTYPE_GRAPH_VERTEX   6  /* first_edge, &(x,y) */
-#define CV_SEQ_ELTYPE_TRIAN_ATR      7  /* vertex of the binary tree   */
-#define CV_SEQ_ELTYPE_CONNECTED_COMP 8  /* connected component  */
-#define CV_SEQ_ELTYPE_POINT3D        9  /* (x,y,z)  */
-
-#define CV_SEQ_KIND_BITS      5
-#define CV_SEQ_KIND_MASK       (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)
-
-#define CV_SEQ_KIND_SET        (0 << CV_SEQ_ELTYPE_BITS)
-#define CV_SEQ_KIND_CURVE      (1 << CV_SEQ_ELTYPE_BITS)
-#define CV_SEQ_KIND_BIN_TREE   (2 << CV_SEQ_ELTYPE_BITS)
-#define CV_SEQ_KIND_GRAPH      (3 << CV_SEQ_ELTYPE_BITS)
-#define CV_SEQ_KIND_SUBDIV2D   (4 << CV_SEQ_ELTYPE_BITS)
-
-#define CV_SEQ_FLAG_SHIFT      (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)
-
-/* flags for curves */
-#define CV_SEQ_FLAG_CLOSED     (1 << CV_SEQ_FLAG_SHIFT)
-#define CV_SEQ_FLAG_SIMPLE     (2 << CV_SEQ_FLAG_SHIFT)
-#define CV_SEQ_FLAG_CONVEX     (4 << CV_SEQ_FLAG_SHIFT)
-#define CV_SEQ_FLAG_HOLE       (8 << CV_SEQ_FLAG_SHIFT)
-
-/* flags for graphs */
-#define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)
-
-/* flags for graph vertices and edges */
-#define  CV_GRAPH_ITEM_VISITED_FLAG  (1 << 31)
-#define  CV_IS_GRAPH_VERTEX_VISITED(vtx) \
-    (((CvGraphVtx*)(vtx))->flags & CV_GRAPH_ITEM_VISITED_FLAG)
-#define  CV_IS_GRAPH_EDGE_VISITED(edge) \
-    (((CvGraphEdge*)(edge))->flags & CV_GRAPH_ITEM_VISITED_FLAG)
-
-/* point sets */
-#define CV_SEQ_POINT_SET       (CV_SEQ_KIND_SET    | CV_SEQ_ELTYPE_POINT)
-#define CV_SEQ_POINT3D_SET     (CV_SEQ_KIND_SET    | CV_SEQ_ELTYPE_POINT3D)
-#define CV_SEQ_POLYLINE        (CV_SEQ_KIND_CURVE  | CV_SEQ_ELTYPE_POINT)
-#define CV_SEQ_POLYGON         (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )
-#define CV_SEQ_CONTOUR         CV_SEQ_POLYGON
-#define CV_SEQ_SIMPLE_POLYGON  (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON  )
-
-/* chain-coded curves */
-#define CV_SEQ_CHAIN           (CV_SEQ_KIND_CURVE  | CV_SEQ_ELTYPE_CODE)
-#define CV_SEQ_CHAIN_CONTOUR   (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)
-
-/* binary tree for the contour */
-#define CV_SEQ_POLYGON_TREE    (CV_SEQ_KIND_BIN_TREE  | CV_SEQ_ELTYPE_TRIAN_ATR)
-
-/* sequence of the connected components */
-#define CV_SEQ_CONNECTED_COMP  (CV_SEQ_KIND_SET  | CV_SEQ_ELTYPE_CONNECTED_COMP)
-
-/* sequence of the integer numbers */
-#define CV_SEQ_INDEX  (CV_SEQ_KIND_SET  | CV_SEQ_ELTYPE_INDEX)
-
-/* type retrieving macros */
-#define CV_SEQ_TYPE_BITS       CV_SEQ_FLAG_SHIFT
-#define CV_SEQ_TYPE_MASK       ((1 << CV_SEQ_TYPE_BITS) - 1)
-
-#define CV_SEQ_SUBTYPE_BITS    (CV_SEQ_TYPE_BITS + 10)
-#define CV_SEQ_SUBTYPE_MASK    ((1 << (CV_SEQ_SUBTYPE_BITS) - 1)
-
-#define CV_GET_SEQ_ELTYPE( seq )    ((seq)->flags & CV_SEQ_ELTYPE_MASK)
-#define CV_GET_SEQ_KIND( seq )      ((seq)->flags & CV_SEQ_KIND_MASK )
-#define CV_GET_SEQ_TYPE( seq )      ((seq)->flags & CV_SEQ_TYPE_MASK )
-#define CV_GET_SEQ_SUBTYPE( seq )   ((seq)->flags & CV_SEQ_SUBTYPE_MASK )
-
-/* flag checking */
-#define CV_IS_SEQ_INDEX( seq )      ((CV_GET_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \
-                                       (CV_GET_SEQ_KIND(seq) == CV_SEQ_KIND_SET))
-
-#define CV_IS_SEQ_CURVE( seq )      (CV_GET_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)
-#define CV_IS_SEQ_CLOSED( seq )     (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)
-#define CV_IS_SEQ_CONVEX( seq )     (((seq)->flags & CV_SEQ_FLAG_CONVEX) != 0)
-#define CV_IS_SEQ_HOLE( seq )       (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)
-#define CV_IS_SEQ_SIMPLE( seq )     ((((seq)->flags & CV_SEQ_FLAG_SIMPLE) != 0) || \
-                                         CV_IS_CONVEX(seq)
-
-/* type checking macros */
-#define CV_IS_SEQ_POINT_SET( seq ) \
-(CV_GET_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_POINT)
-
-#define CV_IS_SEQ_POINT_SUBSET( seq ) \
-(CV_GET_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)
-
-#define CV_IS_SEQ_POLYLINE( seq )   \
-(CV_GET_SEQ_TYPE(seq) == CV_SEQ_POLYLINE)
-
-#define CV_IS_SEQ_POLYGON( seq )   \
-(CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))
-
-#define CV_IS_SEQ_CHAIN( seq )   \
-(CV_GET_SEQ_TYPE(seq) == CV_SEQ_CHAIN)
-
-#define CV_IS_SEQ_CONTOUR( seq )   \
-(CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))
-
-#define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \
-(CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))
-
-#define CV_IS_SEQ_POLYGON_TREE( seq ) \
-    (CV_GET_SEQ_ELTYPE (seq) ==  CV_SEQ_ELTYPE_TRIAN_ATR &&    \
-    CV_GET_SEQ_KIND( seq ) ==  CV_SEQ_KIND_BIN_TREE )
-
-#define CV_IS_GRAPH( seq )    \
-    ( CV_GET_SEQ_KIND(seq) == CV_SEQ_KIND_GRAPH )
-
-#define CV_IS_GRAPH_ORIENTED( seq )   \
-    ( CV_IS_GRAPH( seq ) && ((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0 )
-
-#define CV_IS_SUBDIV2D( seq )  \
-    ( CV_GET_SEQ_KIND(seq) == CV_SEQ_KIND_SUBDIV2D )
-
-/****************************************************************************************/
-/*                            Sequence writer & reader                                  */
-/****************************************************************************************/
-
-#define CV_SEQ_WRITER_FIELDS()                                     \
-    int          header_size;                                      \
-    CvSeq*       seq;        /* sequence, beign written */         \
-    CvSeqBlock*  block;      /* current block */                   \
-    char*        ptr;        /* pointer to free space */           \
-    char*        block_min;  /* address of end of block */         \
-    char*        block_max;  /* address of end of block */
-
-typedef struct CvSeqWriter
-{
-    CV_SEQ_WRITER_FIELDS()
-    int  reserved[7]; /* some reserved fields */
-} CvSeqWriter;
-
-
-#define CV_SEQ_READER_FIELDS()                                      \
-    int          header_size;                                       \
-    CvSeq*       seq;        /* sequence, beign read */             \
-    CvSeqBlock*  block;      /* current block */                    \
-    char*        ptr;        /* pointer to element be read next */  \
-    char*        block_max;  /* upper boundary of the block */      \
-    char*        block_min;  /* lower boundary of the block */      \
-    int          delta_index;/* = seq->first->start_index   */      \
-    char*        prev_elem;  /* pointer to previous element */
-
-
-typedef struct CvSeqReader
-{
-    CV_SEQ_READER_FIELDS()
-    int  reserved[9];
-} CvSeqReader;
-
-/****************************************************************************************/
-/*                                Operations on sequences                               */
-/****************************************************************************************/
-
-#define  CV_GET_SEQ_ELEM( elem_type, seq, index )                \
-/* assert gives some guarantee that <seq> parameter is valid */  \
-(   assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) &&      \
-    (seq)->elem_size == sizeof(elem_type)),                      \
-    (elem_type*)((seq)->first && (unsigned)index <               \
-    (unsigned)((seq)->first->count) ?                            \
-    (seq)->first->data + (index) * sizeof(elem_type) :           \
-    cvGetSeqElem( (CvSeq*)(seq), (index), 0 )))
-
-
-/* macro that adds element to sequence */
-#define CV_WRITE_SEQ_ELEM( elem, writer )             \
-{                                                     \
-    assert( (writer).seq->elem_size == sizeof(elem)); \
-    if( (writer).ptr >= (writer).block_max )          \
-    {                                                 \
-        cvCreateSeqBlock( &writer);                   \
-    }                                                 \
-    assert( (writer).ptr <= (writer).block_max - sizeof(elem));\
-    memcpy((writer).ptr, &elem, sizeof(elem));        \
-    (writer).ptr += sizeof(elem);                     \
-}
-
-
-/* move reader position forward */
-#define CV_NEXT_SEQ_ELEM( elem_size, reader )                 \
-{                                                             \
-    if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \
-    {                                                         \
-        cvChangeSeqBlock( &(reader), 1 );                     \
-    }                                                         \
-}
-
-
-/* move reader position backward */
-#define CV_PREV_SEQ_ELEM( elem_size, reader )                \
-{                                                            \
-    if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \
-    {                                                        \
-        cvChangeSeqBlock( &(reader), -1 );                   \
-    }                                                        \
-}
-
-/* read element and move read position forward */
-#define CV_READ_SEQ_ELEM( elem, reader )                       \
-{                                                              \
-    assert( (reader).seq->elem_size == sizeof(elem));          \
-    memcpy( &(elem), (reader).ptr, sizeof((elem)));            \
-    CV_NEXT_SEQ_ELEM( sizeof(elem), reader )                   \
-}
-
-/* read element and move read position backward */
-#define CV_REV_READ_SEQ_ELEM( elem, reader )                     \
-{                                                                \
-    assert( (reader).seq->elem_size == sizeof(elem));            \
-    memcpy(&(elem), (reader).ptr, sizeof((elem)));               \
-    CV_PREV_SEQ_ELEM( sizeof(elem), reader )                     \
-}
-
-
-#define CV_READ_CHAIN_POINT( _pt, reader )                              \
-{                                                                       \
-    (_pt) = (reader).pt;                                                \
-    if( (reader).ptr )                                                  \
-    {                                                                   \
-        CV_READ_SEQ_ELEM( (reader).code, (*((CvSeqReader*)&(reader)))); \
-        assert( ((reader).code & ~7) == 0 );                            \
-        (reader).pt.x += (reader).deltas[(reader).code][0];             \
-        (reader).pt.y += (reader).deltas[(reader).code][1];             \
-    }                                                                   \
-}
-
-#define CV_CURRENT_POINT( reader )  (*((CvPoint*)((reader).ptr)))
-#define CV_PREV_POINT( reader )     (*((CvPoint*)((reader).prev_elem)))
-
-#define CV_READ_EDGE( pt1, pt2, reader )               \
-{                                                      \
-    assert( sizeof(pt1) == sizeof(CvPoint) &&          \
-            sizeof(pt2) == sizeof(CvPoint) &&          \
-            reader.seq->elem_size == sizeof(CvPoint)); \
-    (pt1) = CV_PREV_POINT( reader );                   \
-    (pt2) = CV_CURRENT_POINT( reader );                \
-    (reader).prev_elem = (reader).ptr;                 \
-    CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader));      \
-}
-
-/************ Set macros **************/
-#define CV_IS_SET_ELEM_EXISTS( ptr )  (((*(long*)(ptr)) & 1) == 0)
-
-#define CV_REMOVE_SET_ELEM( set, index, elem )                                 \
-    (((CvMemBlock*)(elem))->prev = (CvMemBlock*)((long)((set)->free_elems)|1), \
-    ((CvMemBlock*)(elem))->next = (CvMemBlock*)(index),                        \
-    (set)->free_elems = (CvMemBlock*)(elem))
-
-/************ Graph macros ************/
-
-/* returns next graph edge for given vertex */
-#define  CV_NEXT_GRAPH_EDGE( edge, vertex )                              \
-     (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)),  \
-      (edge)->next[(edge)->vtx[1] == (vertex)])
-
-/****************************************************************************************/
-/*                                  Planar subdivisions                                 */
-/****************************************************************************************/
-
-typedef struct
-{
-    const char* file;
-    int         line;
-}CvStackRecord;                               
-
-
-/****************************************************************************************/
-/*                                    Older definitions                                 */
-/****************************************************************************************/
-
-typedef float*   CvVect32f;
-typedef float*   CvMatr32f;
-typedef double*  CvVect64d;
-typedef double*  CvMatr64d;
-
-typedef struct CvMatrix3
-{
-    float m[3][3];
-}
-CvMatrix3;
-
-typedef enum CvStatus
-{         
-    CV_INPLACE_NOT_SUPPORTED_ERR= -112,
-    CV_UNMATCHED_ROI_ERR        = -111,
-    CV_NOTFOUND_ERR             = -110,
-    CV_BADCONVERGENCE_ERR       = -109,
-
-    CV_BADDEPTH_ERR             = -107,
-    CV_BADROI_ERR               = -106,
-    CV_BADHEADER_ERR            = -105,
-    CV_UNMATCHED_FORMATS_ERR    = -104,
-    CV_UNSUPPORTED_COI_ERR      = -103,
-    CV_UNSUPPORTED_CHANNELS_ERR = -102,
-    CV_UNSUPPORTED_DEPTH_ERR    = -101,
-    CV_UNSUPPORTED_FORMAT_ERR   = -100,
-
-                       
-    CV_BADARG_ERR      = -49,  //ipp comp
-    CV_NOTDEFINED_ERR  = -48,  //ipp comp
-
-    CV_BADCHANNELS_ERR = -47,  //ipp comp
-    CV_BADRANGE_ERR    = -44,  //ipp comp
-    CV_BADSTEP_ERR     = -29,  //ipp comp
-
-    CV_BADFLAG_ERR     =  -12,
-    CV_DIV_BY_ZERO_ERR =  -11, //ipp comp
-    CV_BADCOEF_ERR     =  -10,
-
-    CV_BADFACTOR_ERR   =  -7,
-    CV_BADPOINT_ERR    =  -6,
-    CV_BADSCALE_ERR    =  -4,
-    CV_OUTOFMEM_ERR    =  -3,
-    CV_NULLPTR_ERR     =  -2,
-    CV_BADSIZE_ERR     =  -1,
-    CV_NO_ERR          =   0,
-    CV_OK              =   CV_NO_ERR
-} CvStatus;
-
-
-
-#endif /*_CVTYPES_H_*/
-
-/* End of file. */
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+#ifndef _CVTYPES_H_\r
+#define _CVTYPES_H_\r
+\r
+#include <assert.h>\r
+#include <stdlib.h>\r
+\r
+#ifndef WIN32\r
+    #define CV_CDECL\r
+    #define CV_STDCALL\r
+#else\r
+    #define CV_CDECL __cdecl\r
+    #define CV_STDCALL __stdcall\r
+#endif\r
+\r
+#ifndef CV_EXTERN_C\r
+    #ifdef __cplusplus\r
+        #define CV_EXTERN_C extern "C"\r
+        #define CV_DEFAULT(val) = val\r
+    #else\r
+        #define CV_EXTERN_C\r
+        #define CV_DEFAULT(val)\r
+    #endif\r
+#endif\r
+\r
+#ifndef CV_EXTERN_C_FUNCPTR\r
+    #ifdef __cplusplus\r
+        #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }\r
+    #else\r
+        #define CV_EXTERN_C_FUNCPTR(x) typedef x\r
+    #endif\r
+#endif\r
+\r
+#if defined WIN32 && defined CV_DLL\r
+    #define CV_DLL_ENTRY __declspec(dllexport)\r
+#else\r
+    #define CV_DLL_ENTRY\r
+#endif\r
+\r
+#ifndef OPENCVAPI\r
+    #define OPENCVAPI CV_EXTERN_C CV_DLL_ENTRY\r
+#endif\r
+\r
+#ifndef CV_INLINE\r
+#ifdef WIN32\r
+    #define CV_INLINE __inline\r
+#elif defined __cplusplus\r
+    #define CV_INLINE inline\r
+#else\r
+    #define CV_INLINE static\r
+#endif\r
+#endif /* CV_INLINE */\r
+\r
+#if defined _MSC_VER || defined __BORLANDC__\r
+typedef __int64 int64;\r
+typedef unsigned __int64 uint64;\r
+#else\r
+typedef long long int64;\r
+typedef unsigned long long uint64;\r
+#endif\r
+\r
+#ifndef __IPL_H__\r
+typedef unsigned char uchar;\r
+#endif\r
+\r
+\r
+/* CvArr is used to pass arbitrary array-like data structures\r
+   into the functions and where the particular\r
+   array type is recognized at runtime */ \r
+typedef void CvArr;\r
+\r
+\r
+/****************************************************************************************\\r
+*                                  Image type (IplImage)                                 *\r
+\****************************************************************************************/\r
+\r
+#ifndef HAVE_IPL\r
+\r
+/*\r
+ * The following definitions (until #endif)\r
+ * is an extract from IPL headers.\r
+ * Copyright (c) 1995 Intel Corporation.\r
+ */\r
+#define IPL_DEPTH_SIGN 0x80000000\r
+\r
+#define IPL_DEPTH_1U     1\r
+#define IPL_DEPTH_8U     8\r
+#define IPL_DEPTH_16U   16\r
+#define IPL_DEPTH_32F   32\r
+\r
+#define IPL_DEPTH_8S  (IPL_DEPTH_SIGN| 8)\r
+#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)\r
+#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)\r
+\r
+#define IPL_DATA_ORDER_PIXEL  0\r
+#define IPL_DATA_ORDER_PLANE  1\r
+\r
+#define IPL_ORIGIN_TL 0\r
+#define IPL_ORIGIN_BL 1\r
+\r
+#define IPL_ALIGN_4BYTES   4\r
+#define IPL_ALIGN_8BYTES   8\r
+#define IPL_ALIGN_16BYTES 16\r
+#define IPL_ALIGN_32BYTES 32\r
+\r
+#define IPL_ALIGN_DWORD   IPL_ALIGN_4BYTES\r
+#define IPL_ALIGN_QWORD   IPL_ALIGN_8BYTES\r
+\r
+typedef struct _IplImage {\r
+    int  nSize;         /* sizeof(IplImage) */\r
+    int  ID;            /* version (=0)*/\r
+    int  nChannels;     /* Most of OpenCV functions support 1,2,3 or 4 channels */\r
+    int  alphaChannel;  /* ignored by OpenCV */\r
+    int  depth;         /* pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,\r
+                           IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported */\r
+    char colorModel[4]; /* ignored by OpenCV */\r
+    char channelSeq[4]; /* ditto */\r
+    int  dataOrder;     /* 0 - interleaved color channels, 1 - separate color channels.\r
+                           cvCreateImage can only create interleaved images */\r
+    int  origin;        /* 0 - top-left origin,\r
+                           1 - bottom-left origin (Windows bitmaps style) */\r
+    int  align;         /* Alignment of image rows (4 or 8).\r
+                           OpenCV ignores it and uses widthStep instead */\r
+    int  width;         /* image width in pixels */\r
+    int  height;        /* image height in pixels */\r
+    struct _IplROI *roi;/* image ROI. if NULL, the whole image is selected */\r
+    struct _IplImage *maskROI; /* must be NULL */\r
+    void  *imageId;     /* ditto */\r
+    struct _IplTileInfo *tileInfo; /* ditto */\r
+    int  imageSize;     /* image data size in bytes\r
+                           (==image->height*image->widthStep\r
+                           in case of interleaved data)*/\r
+    char *imageData;  /* pointer to aligned image data */\r
+    int  widthStep;   /* size of aligned image row in bytes */\r
+    int  BorderMode[4]; /* ignored by OpenCV */\r
+    int  BorderConst[4]; /* ditto */\r
+    char *imageDataOrigin; /* pointer to very origin of image data\r
+                              (not necessarily aligned) -\r
+                              needed for correct deallocation */\r
+}\r
+IplImage;\r
+\r
+typedef struct _IplTileInfo IplTileInfo;\r
+\r
+typedef struct _IplROI {\r
+    int  coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/\r
+    int  xOffset;\r
+    int  yOffset;\r
+    int  width;\r
+    int  height;\r
+}\r
+IplROI;\r
+\r
+typedef struct _IplConvKernel\r
+{\r
+    int  nCols;\r
+    int  nRows;\r
+    int  anchorX;\r
+    int  anchorY;\r
+    int *values;\r
+    int  nShiftR;\r
+}\r
+IplConvKernel;\r
+\r
+typedef struct _IplConvKernelFP\r
+{\r
+    int  nCols;\r
+    int  nRows;\r
+    int  anchorX;\r
+    int  anchorY;\r
+    float *values;\r
+}\r
+IplConvKernelFP;\r
+\r
+#define IPL_IMAGE_HEADER 1\r
+#define IPL_IMAGE_DATA   2\r
+#define IPL_IMAGE_ROI    4\r
+\r
+#endif/*HAVE_IPL*/\r
+\r
+#define IPL_IMAGE_MAGIC_VAL  ((int)sizeof(IplImage))\r
+\r
+/* for file storages make the value independent from arch */\r
+#define IPL_IMAGE_FILE_MAGIC_VAL  112\r
+\r
+#define CV_IS_IMAGE_HDR(img) \\r
+    ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))\r
+\r
+#define CV_IS_IMAGE(img) \\r
+    (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)\r
+\r
+#define IPL_DEPTH_64F  64 /* for storing double-precision\r
+                             floating point data in IplImage's */\r
+\r
+/* get pointer to pixel at (col,row),\r
+   for multi-channel images (col) should be multiplied by number of channels */\r
+#define CV_IMAGE_ELEM( image, elemtype, row, col )       \\r
+    (((elemtype*)((image)->imageData + (image)->widthStep*(row))[(col)])\r
+\r
+\r
+/****************************************************************************************\\r
+*                                  Matrix type (CvMat)                                   *\r
+\****************************************************************************************/\r
+\r
+#define CV_8U   0\r
+#define CV_8S   1\r
+#define CV_16S  2\r
+#define CV_32S  3\r
+#define CV_32F  4\r
+#define CV_64F  5\r
+#define CV_USRTYPE1 6\r
+#define CV_USRTYPE2 7\r
+\r
+#define CV_8UC1 (CV_8U + 0*8)\r
+#define CV_8UC2 (CV_8U + 1*8)\r
+#define CV_8UC3 (CV_8U + 2*8)\r
+#define CV_8UC4 (CV_8U + 3*8)\r
+\r
+#define CV_8SC1 (CV_8S + 0*8)\r
+#define CV_8SC2 (CV_8S + 1*8)\r
+#define CV_8SC3 (CV_8S + 2*8)\r
+#define CV_8SC4 (CV_8S + 3*8)\r
+\r
+#define CV_16SC1 (CV_16S + 0*8)\r
+#define CV_16SC2 (CV_16S + 1*8)\r
+#define CV_16SC3 (CV_16S + 2*8)\r
+#define CV_16SC4 (CV_16S + 3*8)\r
+\r
+#define CV_32SC1 (CV_32S + 0*8)\r
+#define CV_32SC2 (CV_32S + 1*8)\r
+#define CV_32SC3 (CV_32S + 2*8)\r
+#define CV_32SC4 (CV_32S + 3*8)\r
+\r
+#define CV_32FC1 (CV_32F + 0*8)\r
+#define CV_32FC2 (CV_32F + 1*8)\r
+#define CV_32FC3 (CV_32F + 2*8)\r
+#define CV_32FC4 (CV_32F + 3*8)\r
+\r
+#define CV_64FC1 (CV_64F + 0*8)\r
+#define CV_64FC2 (CV_64F + 1*8)\r
+#define CV_64FC3 (CV_64F + 2*8)\r
+#define CV_64FC4 (CV_64F + 3*8)\r
+\r
+#define CV_AUTO_STEP  0x7fffffff\r
+#define CV_WHOLE_ARR  cvSlice( 0, 0x3fffffff )\r
+\r
+#define CV_MAT_CN_MASK          (3 << 3)\r
+#define CV_MAT_CN(flags)        ((((flags) & CV_MAT_CN_MASK) >> 3) + 1)\r
+#define CV_MAT_DEPTH_MASK       7\r
+#define CV_MAT_DEPTH(flags)     ((flags) & CV_MAT_DEPTH_MASK)\r
+#define CV_MAT_TYPE_MASK        31\r
+#define CV_MAT_TYPE(flags)      ((flags) & CV_MAT_TYPE_MASK)\r
+#define CV_MAT_FMT_MASK         511\r
+#define CV_MAT_FMT(flags)       ((flags) & CV_MAT_FMT_MASK)\r
+#define CV_MAT_CONT_FLAG_SHIFT  9\r
+#define CV_MAT_CONT_FLAG        (1 << CV_MAT_CONT_FLAG_SHIFT)\r
+#define CV_IS_MAT_CONT(flags)   ((flags) & CV_MAT_CONT_FLAG) \r
+#define CV_IS_CONT_MAT          CV_IS_MAT_CONT\r
+#define CV_MAT_TEMP_FLAG_SHIFT  10\r
+#define CV_MAT_TEMP_FLAG        (1 << CV_MAT_TEMP_FLAG_SHIFT)\r
+#define CV_IS_TEMP_MAT(flags)   ((flags) & CV_MAT_TEMP_FLAG)\r
+\r
+#define CV_MAGIC_MASK       0xFFFF0000\r
+#define CV_MAT_MAGIC_VAL    0x42420000\r
+\r
+typedef struct CvMat\r
+{\r
+    int type;\r
+    int step;\r
+\r
+    /* for internal use only */\r
+    int* refcount;\r
+\r
+    union\r
+    {\r
+        uchar* ptr;\r
+        short* s;\r
+        int* i;\r
+        float* fl;\r
+        double* db;\r
+    } data;\r
+\r
+#ifdef __cplusplus\r
+    union\r
+    {\r
+        int rows;\r
+        int height;\r
+    };\r
+\r
+    union\r
+    {\r
+        int cols;\r
+        int width;\r
+    };\r
+#else\r
+    int rows;\r
+    int cols;\r
+#endif\r
+\r
+} CvMat;\r
+\r
+\r
+#define CV_IS_MAT_HDR(mat) \\r
+    ((mat) != NULL && (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL)\r
+\r
+#define CV_IS_MAT(mat) \\r
+    (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)\r
+\r
+#define CV_IS_MASK_ARR(mat) \\r
+    (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)\r
+\r
+#define CV_ARE_TYPES_EQ(mat1, mat2) \\r
+    ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)\r
+\r
+#define CV_ARE_CNS_EQ(mat1, mat2) \\r
+    ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)\r
+\r
+#define CV_ARE_DEPTHS_EQ(mat1, mat2) \\r
+    ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)\r
+\r
+#define CV_ARE_SIZES_EQ(mat1, mat2) \\r
+    ((mat1)->height == (mat2)->height && (mat1)->width == (mat2)->width)\r
+\r
+#define CV_IS_MAT_CONST(mat)  \\r
+    (((mat)->height|(mat)->width) == 1)\r
+\r
+#define CV_ELEM_SIZE(type) \\r
+    (CV_MAT_CN(type) << ((0xe90 >> CV_MAT_DEPTH(type)*2) & 3))\r
+\r
+/* inline constructor. No data is allocated internally!!!\r
+   (use together with cvCreateData, or use cvCreateMat instead to\r
+   get a matrix with allocated data */\r
+CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL));\r
+CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data )\r
+{\r
+    CvMat m;\r
+\r
+    assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );\r
+    type = CV_MAT_TYPE(type);\r
+    m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;\r
+    m.cols = cols;\r
+    m.rows = rows;\r
+    m.step = m.cols*CV_ELEM_SIZE(type);\r
+    m.data.ptr = (uchar*)data;\r
+    m.refcount = NULL;\r
+\r
+    return m; \r
+}\r
+\r
+\r
+#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size )  \\r
+    (assert( (unsigned)(row) < (unsigned)(mat).rows &&   \\r
+             (unsigned)(col) < (unsigned)(mat).cols ),   \\r
+     (mat).data.ptr + (mat).step*(row) + (pix_size)*(col))\r
+\r
+#define CV_MAT_ELEM_PTR( mat, row, col )                 \\r
+    CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )\r
+\r
+#define CV_MAT_ELEM( mat, elemtype, row, col )           \\r
+    (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))\r
+\r
+\r
+CV_INLINE  double  cvmGet( const CvMat* mat, int i, int j );\r
+CV_INLINE  double  cvmGet( const CvMat* mat, int i, int j )\r
+{\r
+    int type;\r
+\r
+    type = CV_MAT_TYPE(mat->type);\r
+    assert( (unsigned)i < (unsigned)mat->rows &&\r
+            (unsigned)j < (unsigned)mat->cols );\r
+\r
+    if( type == CV_32FC1 )\r
+        return ((float*)(mat->data.ptr + i*mat->step))[j];\r
+    else\r
+    {\r
+        assert( type == CV_64FC1 );\r
+        return ((double*)(mat->data.ptr + i*mat->step))[j];\r
+    }\r
+}\r
+\r
+\r
+CV_INLINE  void  cvmSet( CvMat* mat, int i, int j, double val );\r
+CV_INLINE  void  cvmSet( CvMat* mat, int i, int j, double val )\r
+{\r
+    int type;\r
+    type = CV_MAT_TYPE(mat->type);\r
+    assert( (unsigned)i < (unsigned)mat->rows &&\r
+            (unsigned)j < (unsigned)mat->cols );\r
+\r
+    if( type == CV_32FC1 )\r
+        ((float*)(mat->data.ptr + i*mat->step))[j] = (float)val;\r
+    else\r
+    {\r
+        assert( type == CV_64FC1 );\r
+        ((double*)(mat->data.ptr + i*mat->step))[j] = (double)val;\r
+    }\r
+}\r
+\r
+/****************************************************************************************\\r
+*                       Multi-dimensional dense array (CvMatND)                          *\r
+\****************************************************************************************/\r
+\r
+#define CV_MATND_MAGIC_VAL    0x42430000\r
+#define CV_MAX_DIM 16\r
+\r
+#define CV_MAT_LIKE_FLAG_SHIFT  11\r
+#define CV_MAT_LIKE_FLAG        (1 << CV_MAT_LIKE_FLAG_SHIFT)\r
+\r
+typedef struct CvMatND\r
+{\r
+    int type;\r
+    int dims;\r
+\r
+    int* refcount;\r
+    union\r
+    {\r
+        uchar* ptr;\r
+        float* fl;\r
+        double* db;\r
+        int* i;\r
+        short* s;\r
+    } data;\r
+\r
+    struct\r
+    {\r
+        int size;\r
+        int step;\r
+    }\r
+    dim[CV_MAX_DIM];\r
+}\r
+CvMatND;\r
+\r
+#define CV_IS_MATND_HDR(mat) \\r
+    ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)\r
+\r
+#define CV_IS_MATND(mat) \\r
+    (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)\r
+\r
+\r
+/****************************************************************************************\\r
+*                      Multi-dimensional sparse array (CvSparseMat)                      *\r
+\****************************************************************************************/\r
+\r
+#define CV_SPARSE_MAT_MAGIC_VAL    0x42440000\r
+\r
+struct CvSet;\r
+\r
+typedef struct CvSparseMat\r
+{\r
+    int type;\r
+    int dims;\r
+    int* refcount;\r
+    struct CvSet* heap;\r
+    void** hashtable;\r
+    int hashsize;\r
+    int total;\r
+    int valoffset;\r
+    int idxoffset;\r
+    int size[CV_MAX_DIM];   \r
+}\r
+CvSparseMat;\r
+\r
+#define CV_IS_SPARSE_MAT_HDR(mat) \\r
+    ((mat) != NULL && \\r
+    (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)\r
+\r
+#define CV_IS_SPARSE_MAT(mat) \\r
+    CV_IS_SPARSE_MAT_HDR(mat)\r
+\r
+/**************** iteration through a sparse array *****************/\r
+\r
+typedef struct CvSparseNode\r
+{\r
+    unsigned hashval;\r
+    struct CvSparseNode* next;\r
+}\r
+CvSparseNode;\r
+\r
+typedef struct CvSparseMatIterator\r
+{\r
+    CvSparseMat* mat;\r
+    CvSparseNode* node;\r
+    int curidx;\r
+}\r
+CvSparseMatIterator;\r
+\r
+#define CV_NODE_VAL(mat,node)   ((void*)((uchar*)(node) + (mat)->valoffset))\r
+#define CV_NODE_IDX(mat,node)   ((int*)((uchar*)(node) + (mat)->idxoffset))\r
+\r
+/****************************************************************************************\\r
+*                                         Histogram                                      *\r
+\****************************************************************************************/\r
+\r
+typedef int CvHistType;\r
+\r
+#define CV_HIST_MAGIC_VAL     0x42450000\r
+#define CV_HIST_UNIFORM_FLAG  (1 << 10)\r
+\r
+/* indicates whether bin ranges are set already or not */\r
+#define CV_HIST_RANGES_FLAG   (1 << 11)\r
+\r
+#define CV_HIST_ARRAY         0\r
+#define CV_HIST_SPARSE        1\r
+#define CV_HIST_TREE          CV_HIST_SPARSE\r
+\r
+#define CV_HIST_UNIFORM       1 /* should be used as a parameter only,\r
+                                   it turns to CV_HIST_UNIFORM_FLAG of hist->type */\r
+\r
+typedef struct CvHistogram\r
+{\r
+    int     type;\r
+    CvArr*  bins;\r
+    float   thresh[CV_MAX_DIM][2]; /* for uniform histograms */\r
+    float** thresh2; /* for non-uniform histograms */\r
+    CvMatND mat; /* embedded matrix header for array histograms */\r
+}\r
+CvHistogram;\r
+\r
+#define CV_IS_HIST( hist ) \\r
+    ((hist) != NULL  && \\r
+     (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \\r
+     (hist)->bins != NULL)\r
+\r
+#define CV_IS_UNIFORM_HIST( hist ) \\r
+    (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)\r
+\r
+#define CV_IS_SPARSE_HIST( hist ) \\r
+    CV_IS_SPARSE_MAT((hist)->bins)\r
+\r
+#define CV_HIST_HAS_RANGES( hist ) \\r
+    (((hist)->type & CV_HIST_RANGES_FLAG) != 0) \r
+\r
+/****************************************************************************************\\r
+*                      Other supplementary data type definitions                         *\r
+\****************************************************************************************/\r
+\r
+/* ************************************************************* *\\r
+   substitutions for round(x), floor(x), ceil(x):\r
+   the algorithm was taken from Agner Fog's optimization guide\r
+   at http://www.agner.org/assem\r
+\* ************************************************************* */\r
+CV_INLINE  int  cvRound( double val );\r
+CV_INLINE  int  cvRound( double val )\r
+{\r
+    double temp = val + 6755399441055744.0;\r
+    return (int)*((uint64*)&temp);\r
+}\r
+\r
+\r
+CV_INLINE  int  cvFloor( double val );\r
+CV_INLINE  int  cvFloor( double val )\r
+{\r
+    double temp = val + 6755399441055744.0;\r
+    float diff = (float)(val - (int)*((uint64*)&temp));\r
+\r
+    return (int)*((uint64*)&temp) - (*(int*)&diff < 0);\r
+}\r
+\r
+\r
+CV_INLINE  int  cvCeil( double val );\r
+CV_INLINE  int  cvCeil( double val )\r
+{\r
+    double temp = val + 6755399441055744.0;\r
+    float diff = (float)((int)*((uint64*)&temp) - val);\r
+\r
+    return (int)*((uint64*)&temp) + (*(int*)&diff < 0);\r
+}\r
+\r
+/*************************************** CvRect *****************************************/\r
+\r
+typedef struct CvRect\r
+{\r
+    int x;\r
+    int y;\r
+    int width;\r
+    int height;\r
+}\r
+CvRect;\r
+\r
+CV_INLINE  CvRect  cvRect( int x, int y, int width, int height );\r
+CV_INLINE  CvRect  cvRect( int x, int y, int width, int height )\r
+{\r
+    CvRect r;\r
+\r
+    r.x = x;\r
+    r.y = y;\r
+    r.width = width;\r
+    r.height = height;\r
+\r
+    return r;\r
+}\r
+\r
+\r
+CV_INLINE  IplROI  cvRectToROI( CvRect rect, int coi CV_DEFAULT(0));\r
+CV_INLINE  IplROI  cvRectToROI( CvRect rect, int coi )\r
+{\r
+    IplROI roi;\r
+    roi.xOffset = rect.x;\r
+    roi.yOffset = rect.y;\r
+    roi.width = rect.width;\r
+    roi.height = rect.height;\r
+    roi.coi = coi;\r
+\r
+    return roi;\r
+}\r
+\r
+\r
+CV_INLINE  CvRect  cvROIToRect( IplROI roi );\r
+CV_INLINE  CvRect  cvROIToRect( IplROI roi )\r
+{\r
+    return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );\r
+}\r
+\r
+/*********************************** CvTermCriteria *************************************/\r
+\r
+#define CV_TERMCRIT_ITER    1\r
+#define CV_TERMCRIT_NUMB    CV_TERMCRIT_ITER\r
+#define CV_TERMCRIT_EPS     2\r
+\r
+typedef struct CvTermCriteria\r
+{\r
+    int    type;  /* may be combination of\r
+                     CV_TERMCRIT_ITER\r
+                     CV_TERMCRIT_EPS */\r
+    int    maxIter;\r
+    double epsilon;\r
+}\r
+CvTermCriteria;\r
+\r
+CV_INLINE  CvTermCriteria  cvTermCriteria( int type, int maxIter, double epsilon );\r
+CV_INLINE  CvTermCriteria  cvTermCriteria( int type, int maxIter, double epsilon )\r
+{\r
+    CvTermCriteria t;\r
+\r
+    t.type = type;\r
+    t.maxIter = maxIter;\r
+    t.epsilon = (float)epsilon;\r
+\r
+    return t;\r
+}\r
+\r
+\r
+/******************************* CvPoint and variants ***********************************/\r
+\r
+typedef struct CvPoint\r
+{\r
+    int x;\r
+    int y;\r
+}\r
+CvPoint;\r
+\r
+\r
+CV_INLINE  CvPoint  cvPoint( int x, int y );\r
+CV_INLINE  CvPoint  cvPoint( int x, int y )\r
+{\r
+    CvPoint p;\r
+\r
+    p.x = x;\r
+    p.y = y;\r
+\r
+    return p;\r
+}\r
+\r
+\r
+typedef struct CvPoint2D32f\r
+{\r
+    float x;\r
+    float y;\r
+}\r
+CvPoint2D32f;\r
+\r
+\r
+CV_INLINE  CvPoint2D32f  cvPoint2D32f( double x, double y );\r
+CV_INLINE  CvPoint2D32f  cvPoint2D32f( double x, double y )\r
+{\r
+    CvPoint2D32f p;\r
+\r
+    p.x = (float)x;\r
+    p.y = (float)y;\r
+\r
+    return p;\r
+}\r
+\r
+\r
+CV_INLINE  CvPoint2D32f  cvPointTo32f( CvPoint pt );\r
+CV_INLINE  CvPoint2D32f  cvPointTo32f( CvPoint pt )\r
+{\r
+    return cvPoint2D32f( (float)pt.x, (float)pt.y );    \r
+}\r
+\r
+\r
+CV_INLINE  CvPoint  cvPointFrom32f( CvPoint2D32f pt );\r
+CV_INLINE  CvPoint  cvPointFrom32f( CvPoint2D32f pt )\r
+{\r
+    return cvPoint( cvRound(pt.x), cvRound(pt.y) );    \r
+}\r
+\r
+\r
+typedef struct CvPoint3D32f\r
+{\r
+    float x;\r
+    float y;\r
+    float z;\r
+}\r
+CvPoint3D32f;\r
+\r
+\r
+CV_INLINE  CvPoint3D32f  cvPoint3D32f( double x, double y, double z );\r
+CV_INLINE  CvPoint3D32f  cvPoint3D32f( double x, double y, double z )\r
+{\r
+    CvPoint3D32f p;\r
+\r
+    p.x = (float)x;\r
+    p.y = (float)y;\r
+    p.z = (float)z;\r
+\r
+    return p;\r
+}           \r
+\r
+\r
+typedef struct CvPoint2D64d\r
+{\r
+    double x;\r
+    double y;\r
+}\r
+CvPoint2D64d;\r
+\r
+\r
+typedef struct CvPoint3D64d\r
+{\r
+    double x;\r
+    double y;\r
+    double z;\r
+}\r
+CvPoint3D64d;\r
+\r
+\r
+/******************************** CvSize's & CvBox **************************************/\r
+\r
+typedef struct\r
+{\r
+    int width;\r
+    int height;\r
+}\r
+CvSize;\r
+\r
+CV_INLINE  CvSize  cvSize( int width, int height );\r
+CV_INLINE  CvSize  cvSize( int width, int height )\r
+{\r
+    CvSize s;\r
+\r
+    s.width = width;\r
+    s.height = height;\r
+\r
+    return s;\r
+}\r
+\r
+typedef struct CvSize2D32f\r
+{\r
+    float width;\r
+    float height;\r
+}\r
+CvSize2D32f;\r
+\r
+\r
+CV_INLINE  CvSize2D32f  cvSize2D32f( double width, double height );\r
+CV_INLINE  CvSize2D32f  cvSize2D32f( double width, double height )\r
+{\r
+    CvSize2D32f s;\r
+\r
+    s.width = (float)width;\r
+    s.height = (float)height;\r
+\r
+    return s;\r
+}\r
+\r
+typedef struct CvBox2D\r
+{\r
+    CvPoint2D32f center;  /* center of the box */\r
+    CvSize2D32f  size;    /* box width and length */\r
+    float angle;          /* angle between the horizontal axis\r
+                             and the first side (i.e. length) in radians */\r
+}\r
+CvBox2D;\r
+\r
+/************************************* CvSlice ******************************************/\r
+\r
+typedef struct CvSlice\r
+{\r
+    int  startIndex, endIndex;\r
+} CvSlice;\r
+\r
+CV_INLINE  CvSlice  cvSlice( int start, int end );\r
+CV_INLINE  CvSlice  cvSlice( int start, int end )\r
+{\r
+    CvSlice slice;\r
+    slice.startIndex = start;\r
+    slice.endIndex = end;\r
+\r
+    return slice;\r
+}\r
+\r
+#define CV_WHOLE_SEQ  cvSlice(0, 0x3fffffff)\r
+\r
+\r
+/************************************* CvScalar *****************************************/\r
+\r
+typedef struct CvScalar\r
+{\r
+    double val[4];\r
+}\r
+CvScalar;\r
+\r
+\r
+CV_INLINE  CvScalar  cvScalar( double a, double b CV_DEFAULT(0),\r
+                               double c CV_DEFAULT(0), double d CV_DEFAULT(0));\r
+CV_INLINE  CvScalar  cvScalar( double a, double b, double c, double d )\r
+{\r
+    CvScalar scalar;\r
+    scalar.val[0] = a; scalar.val[1] = b;\r
+    scalar.val[2] = c; scalar.val[3] = d;\r
+    return scalar;\r
+}\r
+\r
+\r
+CV_INLINE  CvScalar  cvRealScalar( double a );\r
+CV_INLINE  CvScalar  cvRealScalar( double a )\r
+{\r
+    CvScalar scalar;\r
+    scalar.val[0] = a;\r
+    scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;\r
+    return scalar;\r
+}\r
+\r
+CV_INLINE  CvScalar  cvScalarAll( double a );\r
+CV_INLINE  CvScalar  cvScalarAll( double a )\r
+{\r
+    CvScalar scalar;\r
+    scalar.val[0] = scalar.val[1] = scalar.val[2] = scalar.val[3] = a;\r
+    return scalar;\r
+}\r
+\r
+\r
+/**************************** Connected Component  **************************************/\r
+\r
+struct CvSeq;\r
+\r
+typedef struct CvConnectedComp\r
+{\r
+    double area;  /* area of the connected component  */\r
+    double value; /* average brightness of the connected component\r
+                     (or packed RGB color) */\r
+    CvRect rect;  /* ROI of the component  */\r
+    struct CvSeq* contour; /* optional component boundary\r
+                     (the contour might have child contours corresponding to the holes)*/\r
+}\r
+CvConnectedComp;\r
+\r
+\r
+/*************** Utility definitions, macros and inline functions ***********************/\r
+\r
+#define CV_PI   3.1415926535897932384626433832795\r
+\r
+#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))\r
+\r
+#ifndef MIN\r
+#define MIN(a,b)  ((a) > (b) ? (b) : (a))\r
+#endif\r
+\r
+#ifndef MAX\r
+#define MAX(a,b)  ((a) < (b) ? (b) : (a))\r
+#endif\r
+\r
+/* min & max without jumps */\r
+#define  CV_IMIN(a, b)  ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))\r
+\r
+#define  CV_IMAX(a, b)  ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))\r
+\r
+/* absolute value without jumps */\r
+#define  CV_IABS(a)     (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))\r
+#define  CV_SIGN(a)     (((a) < 0 ? -1 : 0) | ((a) > 0))\r
+\r
+/* initializes 8-element array for fast access to 3x3 neighborhood of a pixel */\r
+#define  CV_INIT_3X3_DELTAS( deltas, step, nch )            \\r
+    ((deltas)[0] =  (nch),  (deltas)[1] = -(step) + (nch),  \\r
+     (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch),  \\r
+     (deltas)[4] = -(nch),  (deltas)[5] =  (step) - (nch),  \\r
+     (deltas)[6] =  (step), (deltas)[7] =  (step) + (nch))\r
+\r
+/* ************************************************************************** *\\r
+   Fast square root and inverse square root by\r
+   Bruce W. Holloway, Jeremy M., James Van Buskirk, Vesa Karvonen and others.\r
+   Taken from Paul Hsieh's site http://www.azillionmonkeys.com/qed/sqroot.html.\r
+\* ************************************************************************** */\r
+#define CV_SQRT_MAGIC  0xbe6f0000\r
+\r
+CV_INLINE  float  cvInvSqrt( float arg );\r
+CV_INLINE  float  cvInvSqrt( float arg )\r
+{\r
+    float x, y;\r
+    unsigned iarg = *((unsigned*)&arg);\r
+    *((unsigned*)&x) = (CV_SQRT_MAGIC - iarg)>>1;\r
+\r
+    y = arg*0.5f;\r
+    x*= 1.5f - y*x*x;\r
+    x*= 1.5f - y*x*x;\r
+\r
+    return x;\r
+}\r
+\r
+\r
+CV_INLINE  float  cvSqrt( float arg );\r
+CV_INLINE  float  cvSqrt( float arg )\r
+{\r
+    float x, y;\r
+    unsigned iarg = *((unsigned*)&arg);\r
+    *((unsigned*)&x) = (CV_SQRT_MAGIC - iarg)>>1;\r
+\r
+    y = arg*0.5f;\r
+    x*= 1.5f - y*x*x;\r
+    x*= 1.5f - y*x*x;\r
+\r
+    return x*arg;\r
+}\r
+\r
+\r
+/* Defines for Distance Transform */\r
+typedef enum CvDisType\r
+{\r
+    CV_DIST_USER         = -1, /* User defined distance */\r
+    CV_DIST_L1           = 1, /* distance = |x1-x2| + |y1-y2| */\r
+    CV_DIST_L2           = 2, /* the simple euclidean distance */\r
+    CV_DIST_C            = 3, /* distance = max(|x1-x2|,|y1-y2|) */\r
+    CV_DIST_L12          = 4, /* L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */\r
+    CV_DIST_FAIR         = 5, /* distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */\r
+    CV_DIST_WELSCH       = 6, /* distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */\r
+    CV_DIST_HUBER        = 7  /* distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 */\r
+}\r
+CvDisType;\r
+\r
+\r
+/* Filters used in pyramid decomposition */\r
+typedef enum CvFilter\r
+{\r
+    CV_GAUSSIAN_5x5 = 7\r
+}\r
+CvFilter;\r
+\r
+/****************************************************************************************/\r
+/*                                   Data structures                                    */\r
+/****************************************************************************************/\r
+\r
+/******************************** Memory storage ****************************************/\r
+\r
+typedef struct CvMemBlock\r
+{\r
+    struct CvMemBlock*  prev;\r
+    struct CvMemBlock*  next;\r
+}\r
+CvMemBlock;\r
+\r
+#define CV_STORAGE_MAGIC_VAL    0x42890000\r
+\r
+typedef struct CvMemStorage\r
+{\r
+    int     signature;\r
+    CvMemBlock* bottom;/* first allocated block */\r
+    CvMemBlock* top;   /* current memory block - top of the stack */\r
+    struct  CvMemStorage* parent; /* borrows new blocks from */\r
+    int     block_size;  /* block size */\r
+    int     free_space;  /* free space in the current block */\r
+}\r
+CvMemStorage;\r
+\r
+#define CV_IS_STORAGE(storage)  \\r
+    ((storage) != NULL &&       \\r
+    (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL)\r
+\r
+\r
+typedef struct CvMemStoragePos\r
+{\r
+    CvMemBlock* top;\r
+    int  free_space;\r
+}\r
+CvMemStoragePos;\r
+\r
+\r
+/*********************************** Sequence *******************************************/\r
+\r
+typedef struct CvSeqBlock\r
+{\r
+    struct CvSeqBlock*  prev; /* previous sequence block */\r
+    struct CvSeqBlock*  next; /* next sequence block */\r
+    int    start_index;       /* index of the first element in the block +\r
+                                 sequence->first->start_index */\r
+    int    count;             /* number of elements in the block */\r
+    char*  data;              /* pointer to the first element of the block */\r
+}\r
+CvSeqBlock;\r
+\r
+\r
+#define CV_TREE_NODE_FIELDS(node_type)                          \\r
+    int       flags;         /* micsellaneous flags */          \\r
+    int       header_size;   /* size of sequence header */      \\r
+    struct    node_type* h_prev; /* previous sequence */        \\r
+    struct    node_type* h_next; /* next sequence */            \\r
+    struct    node_type* v_prev; /* 2nd previous sequence */    \\r
+    struct    node_type* v_next; /* 2nd next sequence */\r
+\r
+/*\r
+   Read/Write sequence.\r
+   Elements can be dynamically inserted to or deleted from the sequence.\r
+*/\r
+#define CV_SEQUENCE_FIELDS()                                            \\r
+    CV_TREE_NODE_FIELDS(CvSeq)                                          \\r
+    int       total;          /* total number of elements */            \\r
+    int       elem_size;      /* size of sequence element in bytes */   \\r
+    char*     block_max;      /* maximal bound of the last block */     \\r
+    char*     ptr;            /* current write pointer */               \\r
+    int       delta_elems;    /* how many elements allocated when the seq grows */  \\r
+    CvMemStorage* storage;    /* where the seq is stored */             \\r
+    CvSeqBlock* free_blocks;  /* free blocks list */                    \\r
+    CvSeqBlock* first; /* pointer to the first sequence block */\r
+\r
+\r
+typedef struct CvSeq\r
+{\r
+    CV_SEQUENCE_FIELDS()\r
+}\r
+CvSeq;\r
+\r
+\r
+/*************************************** Set ********************************************/\r
+/*\r
+  Set.\r
+  Order isn't keeped. There can be gaps between sequence elements.\r
+  After the element has been inserted it stays on the same place all the time.\r
+  The MSB(most-significant or sign bit) of the first field is 0 iff the element exists.\r
+*/\r
+#define CV_SET_ELEM_FIELDS(elem_type)   \\r
+    int  flags;                         \\r
+    struct elem_type* next_free;\r
+\r
+typedef struct CvSetElem\r
+{\r
+    CV_SET_ELEM_FIELDS(CvSetElem)\r
+}\r
+CvSetElem;\r
+\r
+#define CV_SET_FIELDS()      \\r
+    CV_SEQUENCE_FIELDS()     \\r
+    CvSetElem* free_elems;\r
+\r
+typedef struct CvSet\r
+{\r
+    CV_SET_FIELDS()\r
+}\r
+CvSet;\r
+\r
+\r
+#define CV_SET_ELEM_IDX_MASK   ((1 << 24) - 1)\r
+#define CV_SET_ELEM_FREE_FLAG  (1 << (sizeof(int)*8-1))\r
+\r
+/* Checks whether the element pointed by ptr belongs to a set or not */\r
+#define CV_IS_SET_ELEM( ptr )  (((CvSetElem*)(ptr))->flags >= 0)\r
+\r
+/************************************* Graph ********************************************/\r
+\r
+/*\r
+  Graph is represented as a set of vertices.\r
+  Vertices contain their adjacency lists (more exactly, pointers to first incoming or\r
+  outcoming edge (or 0 if isolated vertex)). Edges are stored in another set.\r
+  There is a single-linked list of incoming/outcoming edges for each vertex.\r
+\r
+  Each edge consists of:\r
+    two pointers to the starting and the ending vertices (vtx[0] and vtx[1],\r
+    respectively). Graph may be oriented or not. In the second case, edges between\r
+    vertex i to vertex j are not distingueshed (during the search operations).\r
+\r
+    two pointers to next edges for the starting and the ending vertices.\r
+    next[0] points to the next edge in the vtx[0] adjacency list and\r
+    next[1] points to the next edge in the vtx[1] adjacency list.\r
+*/\r
+#define CV_GRAPH_EDGE_FIELDS()      \\r
+    int flags;                      \\r
+    float weight;                   \\r
+    struct CvGraphEdge* next[2];    \\r
+    struct CvGraphVtx* vtx[2];\r
+    \r
+\r
+#define CV_GRAPH_VERTEX_FIELDS()    \\r
+    int flags;                      \\r
+    struct CvGraphEdge* first;\r
+    \r
+\r
+typedef struct CvGraphEdge\r
+{\r
+    CV_GRAPH_EDGE_FIELDS()\r
+}\r
+CvGraphEdge;\r
+\r
+typedef struct CvGraphVtx\r
+{\r
+    CV_GRAPH_VERTEX_FIELDS()\r
+}\r
+CvGraphVtx;\r
+\r
+typedef struct CvGraphVtx2D\r
+{\r
+    CV_GRAPH_VERTEX_FIELDS()\r
+    CvPoint2D32f* ptr;\r
+}\r
+CvGraphVtx2D;\r
+\r
+/*\r
+   Graph is "derived" from the set (this is set a of vertices)\r
+   and includes another set (edges)\r
+*/\r
+#define  CV_GRAPH_FIELDS()   \\r
+    CV_SET_FIELDS()          \\r
+    CvSet* edges;\r
+\r
+typedef struct CvGraph\r
+{\r
+    CV_GRAPH_FIELDS()\r
+}\r
+CvGraph;\r
+\r
+/*********************************** Chain/Countour *************************************/\r
+\r
+typedef struct CvChain\r
+{\r
+    CV_SEQUENCE_FIELDS()\r
+    CvPoint  origin;\r
+}\r
+CvChain;\r
+\r
+#define CV_CONTOUR_FIELDS()  \\r
+    CV_SEQUENCE_FIELDS()     \\r
+    CvRect rect;             \\r
+    int color;               \\r
+    int reserved[3];\r
+\r
+typedef struct CvContour\r
+{\r
+    CV_CONTOUR_FIELDS()\r
+}\r
+CvContour;\r
+\r
+typedef CvContour CvPoint2DSeq;\r
+\r
+/****************************************************************************************\\r
+*                                    Sequence types                                      *\r
+\****************************************************************************************/\r
+\r
+#define CV_SEQ_MAGIC_VAL             0x42990000\r
+#define CV_IS_SEQ(seq) \\r
+    ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL)\r
+\r
+#define CV_SET_MAGIC_VAL             0x42980000\r
+#define CV_IS_SET(set) \\r
+    ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL)\r
+\r
+#define CV_SEQ_ELTYPE_BITS           5\r
+#define CV_SEQ_ELTYPE_MASK           ((1 << CV_SEQ_ELTYPE_BITS) - 1)\r
+\r
+#define CV_SEQ_ELTYPE_POINT          CV_32SC2  /* (x,y) */\r
+#define CV_SEQ_ELTYPE_CODE           CV_8UC1   /* freeman code: 0..7 */\r
+#define CV_SEQ_ELTYPE_GENERIC        0\r
+#define CV_SEQ_ELTYPE_PTR            CV_USRTYPE1 \r
+#define CV_SEQ_ELTYPE_PPOINT         CV_SEQ_ELTYPE_PTR  /* &(x,y) */\r
+#define CV_SEQ_ELTYPE_INDEX          CV_32SC1  /* #(x,y) */\r
+#define CV_SEQ_ELTYPE_GRAPH_EDGE     0  /* &next_o, &next_d, &vtx_o, &vtx_d */\r
+#define CV_SEQ_ELTYPE_GRAPH_VERTEX   0  /* first_edge, &(x,y) */\r
+#define CV_SEQ_ELTYPE_TRIAN_ATR      0  /* vertex of the binary tree   */\r
+#define CV_SEQ_ELTYPE_CONNECTED_COMP 0  /* connected component  */\r
+#define CV_SEQ_ELTYPE_POINT3D        CV_32FC3  /* (x,y,z)  */\r
+\r
+#define CV_SEQ_KIND_BITS        5\r
+#define CV_SEQ_KIND_MASK        (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)\r
+\r
+/* types of sequences */\r
+#define CV_SEQ_KIND_GENERIC     (0 << CV_SEQ_ELTYPE_BITS)\r
+#define CV_SEQ_KIND_CURVE       (1 << CV_SEQ_ELTYPE_BITS)\r
+#define CV_SEQ_KIND_BIN_TREE    (2 << CV_SEQ_ELTYPE_BITS)\r
+\r
+/* types of sparse sequences (sets) */\r
+#define CV_SEQ_KIND_GRAPH       (3 << CV_SEQ_ELTYPE_BITS)\r
+#define CV_SEQ_KIND_SUBDIV2D    (4 << CV_SEQ_ELTYPE_BITS)\r
+\r
+#define CV_SEQ_FLAG_SHIFT       (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)\r
+\r
+/* flags for curves */\r
+#define CV_SEQ_FLAG_CLOSED     (1 << CV_SEQ_FLAG_SHIFT)\r
+#define CV_SEQ_FLAG_SIMPLE     (2 << CV_SEQ_FLAG_SHIFT)\r
+#define CV_SEQ_FLAG_CONVEX     (4 << CV_SEQ_FLAG_SHIFT)\r
+#define CV_SEQ_FLAG_HOLE       (8 << CV_SEQ_FLAG_SHIFT)\r
+\r
+/* flags for graphs */\r
+#define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)\r
+\r
+#define CV_GRAPH               CV_SEQ_KIND_GRAPH\r
+#define CV_ORIENTED_GRAPH      (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED)\r
+\r
+/* point sets */\r
+#define CV_SEQ_POINT_SET       (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT)\r
+#define CV_SEQ_POINT3D_SET     (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D)\r
+#define CV_SEQ_POLYLINE        (CV_SEQ_KIND_CURVE  | CV_SEQ_ELTYPE_POINT)\r
+#define CV_SEQ_POLYGON         (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )\r
+#define CV_SEQ_CONTOUR         CV_SEQ_POLYGON\r
+#define CV_SEQ_SIMPLE_POLYGON  (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON  )\r
+\r
+/* chain-coded curves */\r
+#define CV_SEQ_CHAIN           (CV_SEQ_KIND_CURVE  | CV_SEQ_ELTYPE_CODE)\r
+#define CV_SEQ_CHAIN_CONTOUR   (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)\r
+\r
+/* binary tree for the contour */\r
+#define CV_SEQ_POLYGON_TREE    (CV_SEQ_KIND_BIN_TREE  | CV_SEQ_ELTYPE_TRIAN_ATR)\r
+\r
+/* sequence of the connected components */\r
+#define CV_SEQ_CONNECTED_COMP  (CV_SEQ_KIND_GENERIC  | CV_SEQ_ELTYPE_CONNECTED_COMP)\r
+\r
+/* sequence of the integer numbers */\r
+#define CV_SEQ_INDEX           (CV_SEQ_KIND_GENERIC  | CV_SEQ_ELTYPE_INDEX)\r
+\r
+#define CV_SEQ_ELTYPE( seq )   ((seq)->flags & CV_SEQ_ELTYPE_MASK)\r
+#define CV_SEQ_KIND( seq )     ((seq)->flags & CV_SEQ_KIND_MASK )\r
+\r
+/* flag checking */\r
+#define CV_IS_SEQ_INDEX( seq )      ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \\r
+                                     (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC))\r
+\r
+#define CV_IS_SEQ_CURVE( seq )      (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)\r
+#define CV_IS_SEQ_CLOSED( seq )     (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)\r
+#define CV_IS_SEQ_CONVEX( seq )     (((seq)->flags & CV_SEQ_FLAG_CONVEX) != 0)\r
+#define CV_IS_SEQ_HOLE( seq )       (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)\r
+#define CV_IS_SEQ_SIMPLE( seq )     (((seq)->flags & CV_SEQ_FLAG_SIMPLE) != 0) || \\r
+                                    CV_IS_SEQ_CONVEX(seq))\r
+\r
+/* type checking macros */\r
+#define CV_IS_SEQ_POINT_SET( seq ) \\r
+    ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2))\r
+\r
+#define CV_IS_SEQ_POINT_SUBSET( seq ) \\r
+    (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)\r
+\r
+#define CV_IS_SEQ_POLYLINE( seq )   \\r
+    (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq))\r
+\r
+#define CV_IS_SEQ_POLYGON( seq )   \\r
+    (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))\r
+\r
+#define CV_IS_SEQ_CHAIN( seq )   \\r
+    (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1)\r
+\r
+#define CV_IS_SEQ_CONTOUR( seq )   \\r
+    (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))\r
+\r
+#define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \\r
+    (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))\r
+\r
+#define CV_IS_SEQ_POLYGON_TREE( seq ) \\r
+    (CV_SEQ_ELTYPE (seq) ==  CV_SEQ_ELTYPE_TRIAN_ATR &&    \\r
+    CV_SEQ_KIND( seq ) ==  CV_SEQ_KIND_BIN_TREE )\r
+\r
+#define CV_IS_GRAPH( seq )    \\r
+    (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH)\r
+\r
+#define CV_IS_GRAPH_ORIENTED( seq )   \\r
+    (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0)\r
+\r
+#define CV_IS_SUBDIV2D( seq )  \\r
+    (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D)\r
+\r
+/****************************************************************************************/\r
+/*                            Sequence writer & reader                                  */\r
+/****************************************************************************************/\r
+\r
+#define CV_SEQ_WRITER_FIELDS()                                     \\r
+    int          header_size;                                      \\r
+    CvSeq*       seq;        /* the sequence written */            \\r
+    CvSeqBlock*  block;      /* current block */                   \\r
+    char*        ptr;        /* pointer to free space */           \\r
+    char*        block_min;  /* pointer to the beginning of block*/\\r
+    char*        block_max;  /* pointer to the end of block */\r
+\r
+typedef struct CvSeqWriter\r
+{\r
+    CV_SEQ_WRITER_FIELDS()\r
+    int  reserved[4]; /* some reserved fields */\r
+}\r
+CvSeqWriter;\r
+\r
+\r
+#define CV_SEQ_READER_FIELDS()                                      \\r
+    int          header_size;                                       \\r
+    CvSeq*       seq;        /* sequence, beign read */             \\r
+    CvSeqBlock*  block;      /* current block */                    \\r
+    char*        ptr;        /* pointer to element be read next */  \\r
+    char*        block_min;  /* pointer to the beginning of block */\\r
+    char*        block_max;  /* pointer to the end of block */      \\r
+    int          delta_index;/* = seq->first->start_index   */      \\r
+    char*        prev_elem;  /* pointer to previous element */\r
+\r
+\r
+typedef struct CvSeqReader\r
+{\r
+    CV_SEQ_READER_FIELDS()\r
+    int  reserved[4];\r
+}\r
+CvSeqReader;\r
+\r
+/****************************************************************************************/\r
+/*                                Operations on sequences                               */\r
+/****************************************************************************************/\r
+\r
+#define  CV_GET_SEQ_ELEM( elem_type, seq, index )                \\r
+/* assert gives some guarantee that <seq> parameter is valid */  \\r
+(   assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) &&      \\r
+    (seq)->elem_size == sizeof(elem_type)),                      \\r
+    (elem_type*)((seq)->first && (unsigned)index <               \\r
+    (unsigned)((seq)->first->count) ?                            \\r
+    (seq)->first->data + (index) * sizeof(elem_type) :           \\r
+    cvGetSeqElem( (CvSeq*)(seq), (index), NULL )))\r
+\r
+\r
+/* macro that adds element to sequence */\r
+#define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer )     \\r
+{                                                     \\r
+    if( (writer).ptr >= (writer).block_max )          \\r
+    {                                                 \\r
+        cvCreateSeqBlock( &writer);                   \\r
+    }                                                 \\r
+    memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\\r
+    (writer).ptr += (writer).seq->elem_size;          \\r
+}\r
+\r
+#define CV_WRITE_SEQ_ELEM( elem, writer )             \\r
+{                                                     \\r
+    assert( (writer).seq->elem_size == sizeof(elem)); \\r
+    if( (writer).ptr >= (writer).block_max )          \\r
+    {                                                 \\r
+        cvCreateSeqBlock( &writer);                   \\r
+    }                                                 \\r
+    assert( (writer).ptr <= (writer).block_max - sizeof(elem));\\r
+    memcpy((writer).ptr, &elem, sizeof(elem));        \\r
+    (writer).ptr += sizeof(elem);                     \\r
+}\r
+\r
+\r
+/* move reader position forward */\r
+#define CV_NEXT_SEQ_ELEM( elem_size, reader )                 \\r
+{                                                             \\r
+    if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \\r
+    {                                                         \\r
+        cvChangeSeqBlock( &(reader), 1 );                     \\r
+    }                                                         \\r
+}\r
+\r
+\r
+/* move reader position backward */\r
+#define CV_PREV_SEQ_ELEM( elem_size, reader )                \\r
+{                                                            \\r
+    if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \\r
+    {                                                        \\r
+        cvChangeSeqBlock( &(reader), -1 );                   \\r
+    }                                                        \\r
+}\r
+\r
+/* read element and move read position forward */\r
+#define CV_READ_SEQ_ELEM( elem, reader )                       \\r
+{                                                              \\r
+    assert( (reader).seq->elem_size == sizeof(elem));          \\r
+    memcpy( &(elem), (reader).ptr, sizeof((elem)));            \\r
+    CV_NEXT_SEQ_ELEM( sizeof(elem), reader )                   \\r
+}\r
+\r
+/* read element and move read position backward */\r
+#define CV_REV_READ_SEQ_ELEM( elem, reader )                     \\r
+{                                                                \\r
+    assert( (reader).seq->elem_size == sizeof(elem));            \\r
+    memcpy(&(elem), (reader).ptr, sizeof((elem)));               \\r
+    CV_PREV_SEQ_ELEM( sizeof(elem), reader )                     \\r
+}\r
+\r
+\r
+#define CV_READ_CHAIN_POINT( _pt, reader )                              \\r
+{                                                                       \\r
+    (_pt) = (reader).pt;                                                \\r
+    if( (reader).ptr )                                                  \\r
+    {                                                                   \\r
+        CV_READ_SEQ_ELEM( (reader).code, (*((CvSeqReader*)&(reader)))); \\r
+        assert( ((reader).code & ~7) == 0 );                            \\r
+        (reader).pt.x += (reader).deltas[(reader).code][0];             \\r
+        (reader).pt.y += (reader).deltas[(reader).code][1];             \\r
+    }                                                                   \\r
+}\r
+\r
+#define CV_CURRENT_POINT( reader )  (*((CvPoint*)((reader).ptr)))\r
+#define CV_PREV_POINT( reader )     (*((CvPoint*)((reader).prev_elem)))\r
+\r
+#define CV_READ_EDGE( pt1, pt2, reader )               \\r
+{                                                      \\r
+    assert( sizeof(pt1) == sizeof(CvPoint) &&          \\r
+            sizeof(pt2) == sizeof(CvPoint) &&          \\r
+            reader.seq->elem_size == sizeof(CvPoint)); \\r
+    (pt1) = CV_PREV_POINT( reader );                   \\r
+    (pt2) = CV_CURRENT_POINT( reader );                \\r
+    (reader).prev_elem = (reader).ptr;                 \\r
+    CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader));      \\r
+}\r
+\r
+/************ Graph macros ************/\r
+\r
+/* returns next graph edge for given vertex */\r
+#define  CV_NEXT_GRAPH_EDGE( edge, vertex )                              \\r
+     (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)),  \\r
+      (edge)->next[(edge)->vtx[1] == (vertex)])\r
+\r
+/****************************************************************************************/\r
+\r
+/**** For error processing and debugging purposes ******/ \r
+typedef struct\r
+{\r
+    const char* file;\r
+    int         line;\r
+}\r
+CvStackRecord;                               \r
+\r
+\r
+/****************************************************************************************/\r
+/*                                    Older definitions                                 */\r
+/****************************************************************************************/\r
+\r
+typedef float*   CvVect32f;\r
+typedef float*   CvMatr32f;\r
+typedef double*  CvVect64d;\r
+typedef double*  CvMatr64d;\r
+\r
+typedef struct CvMatrix3\r
+{\r
+    float m[3][3];\r
+}\r
+CvMatrix3;\r
+\r
+typedef enum CvStatus\r
+{         \r
+    CV_INPLACE_NOT_SUPPORTED_ERR= -112,\r
+    CV_UNMATCHED_ROI_ERR        = -111,\r
+    CV_NOTFOUND_ERR             = -110,\r
+    CV_BADCONVERGENCE_ERR       = -109,\r
+\r
+    CV_BADDEPTH_ERR             = -107,\r
+    CV_BADROI_ERR               = -106,\r
+    CV_BADHEADER_ERR            = -105,\r
+    CV_UNMATCHED_FORMATS_ERR    = -104,\r
+    CV_UNSUPPORTED_COI_ERR      = -103,\r
+    CV_UNSUPPORTED_CHANNELS_ERR = -102,\r
+    CV_UNSUPPORTED_DEPTH_ERR    = -101,\r
+    CV_UNSUPPORTED_FORMAT_ERR   = -100,\r
+\r
+                       \r
+    CV_BADARG_ERR      = -49,  //ipp comp\r
+    CV_NOTDEFINED_ERR  = -48,  //ipp comp\r
+\r
+    CV_BADCHANNELS_ERR = -47,  //ipp comp\r
+    CV_BADRANGE_ERR    = -44,  //ipp comp\r
+    CV_BADSTEP_ERR     = -29,  //ipp comp\r
+\r
+    CV_BADFLAG_ERR     =  -12,\r
+    CV_DIV_BY_ZERO_ERR =  -11, //ipp comp\r
+    CV_BADCOEF_ERR     =  -10,\r
+\r
+    CV_BADFACTOR_ERR   =  -7,\r
+    CV_BADPOINT_ERR    =  -6,\r
+    CV_BADSCALE_ERR    =  -4,\r
+    CV_OUTOFMEM_ERR    =  -3,\r
+    CV_NULLPTR_ERR     =  -2,\r
+    CV_BADSIZE_ERR     =  -1,\r
+    CV_NO_ERR          =   0,\r
+    CV_OK              =   CV_NO_ERR\r
+}\r
+CvStatus;\r
+\r
+#endif /*_CVTYPES_H_*/\r
+\r
+/* End of file. */\r
index 05a51b5e1392047279b0dfac1a8408f3a1512140..2a3964a3e135f613dcff741800126eda8fd77229 100644 (file)
@@ -1,35 +1,43 @@
-lib_LTLIBRARIES = libopencv.la
-
-libopencv_la_SOURCES = camshift.cpp cvabsdiff.cpp cvaccum.cpp cvadapthresh.cpp cvaffine.cpp cvalloc.cpp cvapprox.cpp cvarithm.cpp cvarray.cpp cvblur.cpp cvcalccontrasthistogram.cpp cvcalccovarmatrix.cpp cvcalccovarmatrixex.cpp cvcalceigenobjects.cpp cvcalcimagehomography.cpp cvcalcprobdensity.cpp cvcalibinit.cpp cvcalibration.cpp cvcamshift.cpp cvcanny.cpp cvcolor.cpp cvcondens.cpp cvcontourarea.cpp cvcontours.cpp cvcontoursmoments.cpp cvcontourtree.cpp cvconvert.cpp cvconvgen.cpp cvconvhull.cpp cvcopy.cpp cvcorner.cpp cvcornersubpix.cpp cvcorrespond.cpp cvcreatehandmask.cpp cvdatastructs.cpp cvdetectwr.cpp cvdistransform.cpp cvdominants.cpp cvdrawing.cpp cveigendecomposite.cpp cveigenobjectswrap.cpp cveigenprojection.cpp cvellipsefit.cpp cvemd.cpp cverror.cpp cvfeatureselect.cpp cvfilterwr.cpp cvfindhandregion.cpp cvfindhandregiona.cpp cvfloodfill.cpp cvfundam.cpp cvgeometry.cpp cvgeometrywrap.cpp cvgesturerecognition.cpp cvhistogram.cpp cvhmm.cpp cvhmmobs.cpp cvhmmwrap.cpp cvhough.cpp cvhoughdiv.cpp cvhoughp.cpp cvhoughwrap.cpp cvimage.cpp cvinitconvol.cpp cvjacobieigens.cpp cvkalman.cpp cvlaplace.cpp cvlinefit.cpp cvlines.cpp cvlkpyramid.cpp cvlmeds.cpp cvlogic.cpp cvmatchcontours.cpp cvmathfuncs.cpp cvmatmul.cpp cvmatrix.cpp cvmatrix64d.cpp cvmaxrect.cpp cvmean.cpp cvmeansdv.cpp cvmineval.cpp cvminmaxloc.cpp cvmoments.cpp cvmorph.cpp cvmorphing.cpp cvmorphwrap.cpp cvmotempl.cpp cvmotseg.cpp cvnorm.cpp cvoptflowbm.cpp cvoptflowhs.cpp cvoptflowlk.cpp cvouttext.cpp cvpgh.cpp cvposit.cpp cvprecomp.cpp cvprecorner.cpp cvprewarp.cpp cvprint.cpp cvproject.cpp cvpyramids.cpp cvpyrsegmentation.cpp cvrand.cpp cvrotcalipers.cpp cvsamplers.cpp cvscanlines.cpp cvscharr.cpp cvshapedescr.cpp cvsnakes.cpp cvsubdivision2d.cpp cvsumpixels.cpp cvsvd.cpp cvswitcher.cpp cvtables.cpp cvtemplmatch.cpp cvthresh.cpp cvundistort.cpp cvutilitieswrap.cpp cvutils.cpp
-
-SOMAJOR = @MMAJOR@
-SOMINOR = @MMINOR@
-SOSUBMINOR = @MSUBMINOR@
-
-# here you should add all header files, which contains the functionality
-# of your shared lib (published for the users)
-include_HEADERS =
-
-# here you should add all header files, which shouldn't be installed
-noinst_HEADERS = _cv.h _cvarr.h _cvdatastructs.h _cverror.h _cvfuncn.h _cvgeom.h _cvlist.h _cvmatrix.h _cvmorphology.h _cvoptions.h _cvtables.h _cvutils.h _cvvm.h _cvwrap.h _ipcv.h _optcv.h
-
-libopencv_la_LDFLAGS = $(all_libraries) -no-undefined -version-info $(SOMAJOR):$(SOMINOR):$(SOSUBMINOR) $(LDFLAGS)
-
-# add here the libraries which have to be include
-# for building the shared lib
-#
-#  please consider also the usage of the make environment variables
-#  like
-#  $(LIB_KDEUI), $(LIB_QT), $(LIB_HTML), etc.
-#  instead of the hardcoded entries, which have placed
-#  in here.
-#  The following line is only a suggestion!
-#
-libopencv_la_LIBADD = 
-
-LIBS += -ldl -lpthread -lm
-
-INCLUDES += -I../include -I../_include
-CFLAGS += -Wall @DEBUG@
-CXXFLAGS += -Wall @DEBUG@
-
+lib_LTLIBRARIES = libopencv.la\r
+\r
+libopencv_la_SOURCES = camshift.cpp cvabsdiff.cpp cvaccum.cpp cvadapthresh.cpp cvaffine.cpp cvalloc.cpp cvapprox.cpp cvarithm.cpp cvarray.cpp cvblur.cpp cvcalccontrasthistogram.cpp cvcalccovarmatrix.cpp cvcalccovarmatrixex.cpp cvcalceigenobjects.cpp cvcalcimagehomography.cpp cvcalcprobdensity.cpp cvcalibinit.cpp cvcalibration.cpp cvcamshift.cpp cvcanny.cpp cvcmp.cpp cvcolor.cpp cvcondens.cpp cvcontourarea.cpp cvcontours.cpp cvcontoursmoments.cpp cvcontourtree.cpp cvconvert.cpp cvconvgen.cpp cvconvhull.cpp cvcopy.cpp cvcorner.cpp cvcornersubpix.cpp cvcorrespond.cpp cvcreatehandmask.cpp cvdatastructs.cpp cvdetectwr.cpp cvdistransform.cpp cvdominants.cpp cvdrawing.cpp cveigendecomposite.cpp cveigenobjectswrap.cpp cveigenprojection.cpp cvellipsefit.cpp cvemd.cpp cverror.cpp cvfeatureselect.cpp cvfilterwr.cpp cvfindhandregion.cpp cvfloodfill.cpp cvfundam.cpp cvgeometry.cpp cvgeometrywrap.cpp cvgesturerecognition.cpp cvhistogram.cpp cvhmm.cpp cvhmmobs.cpp cvhmmwrap.cpp cvhough.cpp cvhoughdiv.cpp cvhoughp.cpp cvhoughwrap.cpp cvimage.cpp cvinitconvol.cpp cvjacobieigens.cpp cvkalman.cpp cvlaplace.cpp cvlinefit.cpp cvlines.cpp cvlkpyramid.cpp cvlmeds.cpp cvlogic.cpp cvmatchcontours.cpp cvmathfuncs.cpp cvmatmul.cpp cvmatrix64d.cpp cvmatrix.cpp cvmaxrect.cpp cvmean.cpp cvmeansdv.cpp cvmineval.cpp cvminmaxloc.cpp cvmoments.cpp cvmorph.cpp cvmorphing.cpp cvmotempl.cpp cvmotseg.cpp cvnorm.cpp cvoptflowbm.cpp cvoptflowhs.cpp cvoptflowlk.cpp cvouttext.cpp cvpgh.cpp cvposit.cpp cvprecomp.cpp cvprecorner.cpp cvprewarp.cpp cvprint.cpp cvproject.cpp cvpyramids.cpp cvpyrsegmentation.cpp cvrand.cpp cvrotcalipers.cpp cvsamplers.cpp cvscanlines.cpp cvscharr.cpp cvshapedescr.cpp cvsmooth.cpp cvsnakes.cpp cvsubdivision2d.cpp cvsumpixels.cpp cvsvd.cpp cvswitcher.cpp cvtables.cpp cvtemplmatch.cpp cvthresh.cpp cvundistort.cpp cvutils.cpp\r
+# camshift.cpp cvabsdiff.cpp cvaccum.cpp cvadapthresh.cpp cvaffine.cpp cvalloc.cpp cvapprox.cpp cvarithm.cpp cvarray.cpp cvblur.cpp cvcalccontrasthistogram.cpp cvcalccovarmatrix.cpp cvcalccovarmatrixex.cpp cvcalceigenobjects.cpp cvcalcimagehomography.cpp cvcalcprobdensity.cpp cvcalibinit.cpp cvcalibration.cpp cvcamshift.cpp cvcanny.cpp cvcolor.cpp cvcondens.cpp cvcontourarea.cpp cvcontours.cpp cvcontoursmoments.cpp cvcontourtree.cpp cvconvert.cpp cvconvgen.cpp cvconvhull.cpp cvcopy.cpp cvcorner.cpp cvcornersubpix.cpp cvcorrespond.cpp cvcreatehandmask.cpp cvdatastructs.cpp cvdetectwr.cpp cvdistransform.cpp cvdominants.cpp cvdrawing.cpp cveigendecomposite.cpp cveigenobjectswrap.cpp cveigenprojection.cpp cvellipsefit.cpp cvemd.cpp cverror.cpp cvfeatureselect.cpp cvfilterwr.cpp cvfindhandregion.cpp cvfloodfill.cpp cvfundam.cpp cvgeometry.cpp cvgeometrywrap.cpp cvgesturerecognition.cpp cvhistogram.cpp cvhmm.cpp cvhmmobs.cpp cvhmmwrap.cpp cvhough.cpp cvhoughdiv.cpp cvhoughp.cpp cvhoughwrap.cpp cvimage.cpp cvinitconvol.cpp cvjacobieigens.cpp cvkalman.cpp cvlaplace.cpp cvlinefit.cpp cvlines.cpp cvlkpyramid.cpp cvlmeds.cpp cvlogic.cpp cvmatchcontours.cpp cvmathfuncs.cpp cvmatmul.cpp cvmatrix.cpp cvmatrix64d.cpp cvmaxrect.cpp cvmean.cpp cvmeansdv.cpp cvmineval.cpp cvminmaxloc.cpp cvmoments.cpp cvmorph.cpp cvmorphing.cpp cvmotempl.cpp cvmotseg.cpp cvnorm.cpp cvoptflowbm.cpp cvoptflowhs.cpp cvoptflowlk.cpp cvouttext.cpp cvpgh.cpp cvposit.cpp cvprecomp.cpp cvprecorner.cpp cvprewarp.cpp cvprint.cpp cvproject.cpp cvpyramids.cpp cvpyrsegmentation.cpp cvrand.cpp cvrotcalipers.cpp cvsamplers.cpp cvscanlines.cpp cvscharr.cpp cvshapedescr.cpp cvsnakes.cpp cvsubdivision2d.cpp cvsumpixels.cpp cvsvd.cpp cvswitcher.cpp cvtables.cpp cvtemplmatch.cpp cvthresh.cpp cvundistort.cpp cvutils.cpp\r
+\r
+SOMAJOR = @MMAJOR@\r
+SOMINOR = @MMINOR@\r
+SOSUBMINOR = @MSUBMINOR@\r
+\r
+# here you should add all header files, which contains the functionality\r
+# of your shared lib (published for the users)\r
+include_HEADERS =\r
+\r
+# here you should add all header files, which shouldn't be installed\r
+noinst_HEADERS = _cv.h _cvarr.h _cvdatastructs.h _cverror.h _cvfuncn.h _cvgeom.h _cvlist.h _cvmatrix.h _cvmorphology.h _cvoptions.h _cvtables.h _cvutils.h _cvvm.h _cvwrap.h _ipcv.h _optcv.h\r
+\r
+libopencv_la_LDFLAGS = $(all_libraries) -no-undefined -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -release $(LT_RELEASE) $(LDFLAGS)\r
+\r
+# add here the libraries which have to be include\r
+# for building the shared lib\r
+#\r
+#  please consider also the usage of the make environment variables\r
+#  like\r
+#  $(LIB_KDEUI), $(LIB_QT), $(LIB_HTML), etc.\r
+#  instead of the hardcoded entries, which have placed\r
+#  in here.\r
+#  The following line is only a suggestion!\r
+#\r
+libopencv_la_LIBADD = \r
+\r
+#              ../../bin/ippcv/a6/libippcva6.la \\r
+#              ../../bin/ippcv/m6/libippcvm6.la \\r
+#              ../../bin/ippcv/w7/libippcvw7.la \\r
+#              ../../bin/optcv/a6/liboptcva6.la \\r
+#              ../../bin/optcv/m6/liboptcvm6.la \\r
+#              ../../bin/optcv/w7/liboptcvw7.la \r
+\r
+LIBS += -ldl -lpthread -lm\r
+\r
+INCLUDES += -I../include -I../_include\r
+CFLAGS += -Wall @DEBUG@\r
+CXXFLAGS += -Wall @DEBUG@\r
+\r
index 7a60c712a0190fb54269932d502fabcdaa86972f..6294e8bf814c3b304775c9ef2202de7dfcdbda1b 100644 (file)
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-//  By downloading, copying, installing or using the software you agree to this license.
-//  If you do not agree to this license, do not download, install,
-//  copy or use the software.
-//
-//
-//                        Intel License Agreement
-//                For Open Source Computer Vision Library
-//
-// Copyright (C) 2000, Intel Corporation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-//   * Redistribution's of source code must retain the above copyright notice,
-//     this list of conditions and the following disclaimer.
-//
-//   * Redistribution's in binary form must reproduce the above copyright notice,
-//     this list of conditions and the following disclaimer in the documentation
-//     and/or other materials provided with the distribution.
-//
-//   * The name of Intel Corporation may not be used to endorse or promote products
-//     derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-// (including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort (including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-#include "_cv.h"
-#include "_cvwrap.h"
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    icvThreshold8uC1R
-//    Purpose: Thresholding the source array
-//    Context:
-//    Parameters:
-//      Src     - source array
-//      roi     - size of picture in elements
-//      srcStep - length of string
-//      Thresh  - threshold parameter
-//      Type    - thresholding type, must be one of
-//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)
-//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)
-//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)
-//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)
-//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)
-//    Returns:
-//    Notes:
-//      The MAX constant for uchar is 255, for char is 127
-//F*/
-IPCVAPI_IMPL( CvStatus, icvThresh_8u_C1R, (const uchar * src,
-                                           int src_step,
-                                           uchar * dst,
-                                           int dst_step,
-                                           CvSize roi,
-                                           int thresh, uchar maxval, CvThreshType type) )
-{
-    /* Some variables */
-    int i, j;
-
-    /* Check for bad arguments */
-    assert( src && dst );
-    if( thresh & ~255 )
-        return CV_BADFACTOR_ERR;
-    if( roi.width <= 0 || roi.height <= 0 )
-        return CV_BADSIZE_ERR;
-    if( roi.width > src_step )
-        return CV_BADSIZE_ERR;
-    if( roi.width > dst_step )
-        return CV_BADSIZE_ERR;
-
-    if( roi.width == src_step && roi.width == dst_step )
-    {
-        roi.width *= roi.height;
-        roi.height = 1;
-    }
-
-    /* Calculating */
-    switch (type)
-    {
-    case CV_THRESH_BINARY:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-                dst[j] = (uchar) (((thresh - src[j]) >> 8) & maxval);
-        break;
-    case CV_THRESH_BINARY_INV:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-                dst[j] = (uchar) (((src[j] - thresh - 1) >> 8) & maxval);
-        break;
-    case CV_THRESH_TRUNC:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j] - thresh;
-
-                dst[j] = (uchar) ((temp & (temp >> 31)) + thresh);
-            }
-        break;
-    case CV_THRESH_TOZERO:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j];
-
-                dst[j] = (uchar) (((thresh - temp) >> 31) & temp);
-            }
-        break;
-    case CV_THRESH_TOZERO_INV:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j];
-
-                dst[j] = (uchar) (((temp - thresh - 1) >> 31) & temp);
-            }
-        break;
-    default:
-        return CV_BADFLAG_ERR;
-    }
-    return CV_NO_ERR;
-}
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    icvThreshold8sC1R
-//    Purpose: Thresholding the source array
-//    Context:
-//    Parameters:
-//      Src     - source array
-//      roi     - size of picture in elements
-//      srcStep - length of string
-//      Thresh  - threshold parameter
-//      Type    - thresholding type, must be one of
-//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)
-//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)
-//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)
-//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)
-//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)
-//    Returns:
-//    Notes:
-//      The MAX constant for uchar is 255, for char is 127
-//F*/
-IPCVAPI_IMPL( CvStatus, icvThresh_8s_C1R, (const char *src,
-                                           int src_step,
-                                           char *dst,
-                                           int dst_step,
-                                           CvSize roi,
-                                           int thresh, char maxval, CvThreshType type) )
-{
-    /* Some variables */
-    int i, j;
-
-    /* Check for bad arguments */
-    if( !src || !dst )
-        return CV_NULLPTR_ERR;
-    if( thresh < -128 || thresh > 127 )
-        return CV_BADFACTOR_ERR;
-    if( roi.width <= 0 || roi.height <= 0 )
-        return CV_BADSIZE_ERR;
-    if( roi.width > src_step )
-        return CV_BADSIZE_ERR;
-    if( roi.width > dst_step )
-        return CV_BADSIZE_ERR;
-
-    if( roi.width == src_step && roi.width == dst_step )
-    {
-        roi.width *= roi.height;
-        roi.height = 1;
-    }
-
-    /* Calculating */
-    switch (type)
-    {
-    case CV_THRESH_BINARY:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-                dst[j] = (char) (((thresh - src[j]) >> 8) & maxval);
-        break;
-    case CV_THRESH_BINARY_INV:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-                dst[j] = (char) (((src[j] - thresh - 1) >> 8) & maxval);
-        break;
-    case CV_THRESH_TRUNC:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j] - thresh;
-
-                dst[j] = (char) ((temp & (temp >> 31)) + thresh);
-            }
-        break;
-    case CV_THRESH_TOZERO:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j];
-
-                dst[j] = (char) (((thresh - temp) >> 31) & temp);
-            }
-        break;
-    case CV_THRESH_TOZERO_INV:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = src[j];
-
-                dst[j] = (char) (((temp - thresh - 1) >> 31) & temp);
-            }
-        break;
-    default:
-        return CV_BADFLAG_ERR;
-    }
-    return CV_NO_ERR;
-}
-
-
-/*F///////////////////////////////////////////////////////////////////////////////////////
-//    Name:    icvThreshold32fC1R
-//    Purpose: Thresholding the source array
-//    Context:
-//    Parameters:
-//      Src     - source array
-//      roi     - size of picture in elements
-//      srcStep - length of string
-//      Thresh  - threshold parameter
-//      Type    - thresholding type, must be one of
-//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)
-//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)
-//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)
-//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)
-//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)
-//    Returns:
-//    Notes:
-//      The MAX constant for uchar is 255, for char is 127
-//F*/
-IPCVAPI_IMPL( CvStatus, icvThresh_32f_C1R, (const float *src,
-                                            int src_step,
-                                            float *dst,
-                                            int dst_step,
-                                            CvSize roi,
-                                            float thresh, float maxval, CvThreshType type) )
-{
-    /* Some variables */
-    int i, j;
-    int iThresh = CV_TOGGLE_FLT( (int &) thresh );
-    int iMax = (int &) maxval;
-    int *isrc = (int *) src;
-    int *idst = (int *) dst;
-
-    assert( sizeof( int ) == sizeof( float ));
-
-    /* Check for bad arguments */
-    if( !src || !dst )
-        return CV_NULLPTR_ERR;
-    if( roi.width < 0 || roi.height < 0 )
-        return CV_BADSIZE_ERR;
-    if( roi.width * sizeof_float > src_step )
-        return CV_BADSIZE_ERR;
-    if( roi.width * sizeof_float > dst_step )
-        return CV_BADSIZE_ERR;
-    if( (src_step & (sizeof_float - 1)) != 0 || (dst_step & (sizeof_float - 1)) != 0 )
-        return CV_BADSIZE_ERR;
-
-    src_step /= sizeof_float;
-    dst_step /= sizeof_float;
-
-    if( roi.width == src_step && roi.width == dst_step )
-    {
-        roi.width *= roi.height;
-        roi.height = 1;
-    }
-
-    /* Calculating */
-    switch (type)
-    {
-    case CV_THRESH_BINARY:
-        for( i = 0; i < roi.height; i++, isrc += src_step, idst += dst_step )
-        {
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = isrc[j];
-
-                idst[j] = ((CV_TOGGLE_FLT( temp ) <= iThresh) - 1) & iMax;
-            }
-        }
-        break;
-
-    case CV_THRESH_BINARY_INV:
-        for( i = 0; i < roi.height; i++, isrc += src_step, idst += dst_step )
-        {
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = isrc[j];
-
-                idst[j] = CV_TOGGLE_FLT( temp ) > iThresh ? 0 : iMax;
-            }
-        }
-        break;
-
-    case CV_THRESH_TRUNC:
-        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
-        {
-            for( j = 0; j < roi.width; j++ )
-            {
-                float temp = src[j];
-
-                if( temp > thresh )
-                    temp = thresh;
-                dst[j] = temp;
-            }
-        }
-        break;
-
-    case CV_THRESH_TOZERO:
-        for( i = 0; i < roi.height; i++, isrc += src_step, idst += dst_step )
-        {
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = isrc[j];
-
-                idst[j] = ((CV_TOGGLE_FLT( temp ) <= iThresh) - 1) & temp;
-            }
-        }
-        break;
-
-    case CV_THRESH_TOZERO_INV:
-        for( i = 0; i < roi.height; i++, isrc += src_step, idst += dst_step )
-        {
-            for( j = 0; j < roi.width; j++ )
-            {
-                int temp = isrc[j];
-
-                idst[j] = CV_TOGGLE_FLT( temp ) > iThresh ? 0 : temp;
-            }
-        }
-        break;
-
-    default:
-        return CV_BADFLAG_ERR;
-    }
-
-    return CV_OK;
-}
-
-
-CV_IMPL void
-cvThreshold( const void* srcIm, void* dstIm, double thresh, double maxval, CvThreshType type )
-{
-    CvSize roi;
-    CvSize roi_dst;
-    int step;
-    int step_dst;
-    uchar *src_data = 0;
-    uchar *dst_data = 0;
-    CvMat src_stub, dst_stub;
-    CvMat *src = 0, *dst = 0;
-
-    CV_FUNCNAME( "cvThreshold" );
-
-    __BEGIN__;
-
-    CV_CALL( src = cvGetMat( srcIm, &src_stub ));
-    CV_CALL( dst = cvGetMat( dstIm, &dst_stub ));
-
-    if( !CV_ARE_DEPTHS_EQ( src, dst ))
-        CV_ERROR( IPL_BadDepth, "inconsistent depths" );
-
-    if( !CV_ARE_CNS_EQ( src, dst ) || CV_ARR_CN(src->type) != 1 )
-        CV_ERROR( IPL_BadNumChannels, "bad channels numbers" );
-
-    if( !CV_ARE_SIZES_EQ( src, dst ) )
-    {
-        CV_ERROR( IPL_BadImageSize, "unequal ROI's" );
-    }
-
-    cvGetRawData( src, &src_data, &step, &roi );
-    cvGetRawData( dst, &dst_data, &step_dst, &roi_dst );
-
-    switch( CV_ARR_DEPTH(src->type) )
-    {
-    case CV_8U:
-        IPPI_CALL( icvThresh_8u_C1R( src_data, step, dst_data, step_dst, roi,
-                                     cvRound(thresh), (uchar)cvRound( maxval ), type ));
-        break;
-    case CV_8S:
-        IPPI_CALL( icvThresh_8s_C1R( (char*)src_data, step, (char*)dst_data, step_dst, roi,
-                                     cvRound( thresh ), (char)cvRound( maxval ), type ));
-        break;
-    case CV_32F:
-        IPPI_CALL( icvThresh_32f_C1R( (float*) src_data, step,
-                                      (float*) dst_data, step_dst, roi,
-                                      (float)thresh, (float)maxval, type ));
-        break;
-    default:
-        CV_ERROR( IPL_BadDepth, icvUnsupportedFormat );
-    }
-
-    __END__;
-}
-
-
-/* End of file. */
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+#include "_cv.h"\r
+\r
+/*F///////////////////////////////////////////////////////////////////////////////////////\r
+//    Name:    icvThreshold8uC1R\r
+//    Purpose: Thresholding the source array\r
+//    Context:\r
+//    Parameters:\r
+//      Src     - source array\r
+//      roi     - size of picture in elements\r
+//      srcStep - length of string\r
+//      Thresh  - threshold parameter\r
+//      Type    - thresholding type, must be one of\r
+//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)\r
+//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)\r
+//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)\r
+//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)\r
+//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)\r
+//    Returns:\r
+//    Notes:\r
+//      The MAX constant for uchar is 255, for char is 127\r
+//F*/\r
+IPCVAPI_IMPL( CvStatus, icvThresh_8u_C1R, (const uchar * src,\r
+                                           int src_step,\r
+                                           uchar * dst,\r
+                                           int dst_step,\r
+                                           CvSize roi,\r
+                                           int thresh, uchar maxval, CvThreshType type) )\r
+{\r
+    /* Some variables */\r
+    int i, j;\r
+\r
+    /* Check for bad arguments */\r
+    assert( src && dst );\r
+    if( thresh & ~255 )\r
+        return CV_BADFACTOR_ERR;\r
+    if( roi.width <= 0 || roi.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+    if( roi.width > src_step )\r
+        return CV_BADSIZE_ERR;\r
+    if( roi.width > dst_step )\r
+        return CV_BADSIZE_ERR;\r
+\r
+    if( roi.width == src_step && roi.width == dst_step )\r
+    {\r
+        roi.width *= roi.height;\r
+        roi.height = 1;\r
+    }\r
+\r
+    /* Calculating */\r
+    switch (type)\r
+    {\r
+    case CV_THRESH_BINARY:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+                dst[j] = (uchar) (((thresh - src[j]) >> 8) & maxval);\r
+        break;\r
+    case CV_THRESH_BINARY_INV:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+                dst[j] = (uchar) (((src[j] - thresh - 1) >> 8) & maxval);\r
+        break;\r
+    case CV_THRESH_TRUNC:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = src[j] - thresh;\r
+\r
+                dst[j] = (uchar) ((temp & (temp >> 31)) + thresh);\r
+            }\r
+        break;\r
+    case CV_THRESH_TOZERO:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = src[j];\r
+\r
+                dst[j] = (uchar) (((thresh - temp) >> 31) & temp);\r
+            }\r
+        break;\r
+    case CV_THRESH_TOZERO_INV:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = src[j];\r
+\r
+                dst[j] = (uchar) (((temp - thresh - 1) >> 31) & temp);\r
+            }\r
+        break;\r
+    default:\r
+        return CV_BADFLAG_ERR;\r
+    }\r
+    return CV_NO_ERR;\r
+}\r
+\r
+\r
+/*F///////////////////////////////////////////////////////////////////////////////////////\r
+//    Name:    icvThreshold8sC1R\r
+//    Purpose: Thresholding the source array\r
+//    Context:\r
+//    Parameters:\r
+//      Src     - source array\r
+//      roi     - size of picture in elements\r
+//      srcStep - length of string\r
+//      Thresh  - threshold parameter\r
+//      Type    - thresholding type, must be one of\r
+//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)\r
+//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)\r
+//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)\r
+//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)\r
+//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)\r
+//    Returns:\r
+//    Notes:\r
+//      The MAX constant for uchar is 255, for char is 127\r
+//F*/\r
+IPCVAPI_IMPL( CvStatus, icvThresh_8s_C1R, (const char *src,\r
+                                           int src_step,\r
+                                           char *dst,\r
+                                           int dst_step,\r
+                                           CvSize roi,\r
+                                           int thresh, char maxval, CvThreshType type) )\r
+{\r
+    /* Some variables */\r
+    int i, j;\r
+\r
+    /* Check for bad arguments */\r
+    if( !src || !dst )\r
+        return CV_NULLPTR_ERR;\r
+    if( thresh < -128 || thresh > 127 )\r
+        return CV_BADFACTOR_ERR;\r
+    if( roi.width <= 0 || roi.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+    if( roi.width > src_step )\r
+        return CV_BADSIZE_ERR;\r
+    if( roi.width > dst_step )\r
+        return CV_BADSIZE_ERR;\r
+\r
+    if( roi.width == src_step && roi.width == dst_step )\r
+    {\r
+        roi.width *= roi.height;\r
+        roi.height = 1;\r
+    }\r
+\r
+    /* Calculating */\r
+    switch (type)\r
+    {\r
+    case CV_THRESH_BINARY:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+                dst[j] = (char) (((thresh - src[j]) >> 8) & maxval);\r
+        break;\r
+    case CV_THRESH_BINARY_INV:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+                dst[j] = (char) (((src[j] - thresh - 1) >> 8) & maxval);\r
+        break;\r
+    case CV_THRESH_TRUNC:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = src[j] - thresh;\r
+\r
+                dst[j] = (char) ((temp & (temp >> 31)) + thresh);\r
+            }\r
+        break;\r
+    case CV_THRESH_TOZERO:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = src[j];\r
+\r
+                dst[j] = (char) (((thresh - temp) >> 31) & temp);\r
+            }\r
+        break;\r
+    case CV_THRESH_TOZERO_INV:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = src[j];\r
+\r
+                dst[j] = (char) (((temp - thresh - 1) >> 31) & temp);\r
+            }\r
+        break;\r
+    default:\r
+        return CV_BADFLAG_ERR;\r
+    }\r
+    return CV_NO_ERR;\r
+}\r
+\r
+\r
+/*F///////////////////////////////////////////////////////////////////////////////////////\r
+//    Name:    icvThreshold32fC1R\r
+//    Purpose: Thresholding the source array\r
+//    Context:\r
+//    Parameters:\r
+//      Src     - source array\r
+//      roi     - size of picture in elements\r
+//      srcStep - length of string\r
+//      Thresh  - threshold parameter\r
+//      Type    - thresholding type, must be one of\r
+//                  CV_THRESH_BINARY       - val = (val > Thresh ? MAX    : 0)\r
+//                  CV_THRESH_BINARY_INV   - val = (val > Thresh ? 0      : MAX)\r
+//                  CV_THRESH_TRUNC        - val = (val > Thresh ? Thresh : val)\r
+//                  CV_THRESH_TOZERO       - val = (val > Thresh ? val    : 0)\r
+//                  CV_THRESH_TOZERO_INV   - val = (val > Thresh ? 0      : val)\r
+//    Returns:\r
+//    Notes:\r
+//      The MAX constant for uchar is 255, for char is 127\r
+//F*/\r
+IPCVAPI_IMPL( CvStatus, icvThresh_32f_C1R, (const float *src,\r
+                                            int src_step,\r
+                                            float *dst,\r
+                                            int dst_step,\r
+                                            CvSize roi,\r
+                                            float thresh, float maxval, CvThreshType type) )\r
+{\r
+    /* Some variables */\r
+    int i, j;\r
+    int iThresh = CV_TOGGLE_FLT( (int &) thresh );\r
+    int iMax = (int &) maxval;\r
+    int *isrc = (int *) src;\r
+    int *idst = (int *) dst;\r
+\r
+    assert( sizeof( int ) == sizeof( float ));\r
+\r
+    /* Check for bad arguments */\r
+    if( !src || !dst )\r
+        return CV_NULLPTR_ERR;\r
+    if( roi.width < 0 || roi.height < 0 )\r
+        return CV_BADSIZE_ERR;\r
+    if( roi.width * sizeof_float > src_step )\r
+        return CV_BADSIZE_ERR;\r
+    if( roi.width * sizeof_float > dst_step )\r
+        return CV_BADSIZE_ERR;\r
+    if( (src_step & (sizeof_float - 1)) != 0 || (dst_step & (sizeof_float - 1)) != 0 )\r
+        return CV_BADSIZE_ERR;\r
+\r
+    src_step /= sizeof_float;\r
+    dst_step /= sizeof_float;\r
+\r
+    if( roi.width == src_step && roi.width == dst_step )\r
+    {\r
+        roi.width *= roi.height;\r
+        roi.height = 1;\r
+    }\r
+\r
+    /* Calculating */\r
+    switch (type)\r
+    {\r
+    case CV_THRESH_BINARY:\r
+        for( i = 0; i < roi.height; i++, isrc += src_step, idst += dst_step )\r
+        {\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = isrc[j];\r
+\r
+                idst[j] = ((CV_TOGGLE_FLT( temp ) <= iThresh) - 1) & iMax;\r
+            }\r
+        }\r
+        break;\r
+\r
+    case CV_THRESH_BINARY_INV:\r
+        for( i = 0; i < roi.height; i++, isrc += src_step, idst += dst_step )\r
+        {\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = isrc[j];\r
+\r
+                idst[j] = CV_TOGGLE_FLT( temp ) > iThresh ? 0 : iMax;\r
+            }\r
+        }\r
+        break;\r
+\r
+    case CV_THRESH_TRUNC:\r
+        for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )\r
+        {\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                float temp = src[j];\r
+\r
+                if( temp > thresh )\r
+                    temp = thresh;\r
+                dst[j] = temp;\r
+            }\r
+        }\r
+        break;\r
+\r
+    case CV_THRESH_TOZERO:\r
+        for( i = 0; i < roi.height; i++, isrc += src_step, idst += dst_step )\r
+        {\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = isrc[j];\r
+\r
+                idst[j] = ((CV_TOGGLE_FLT( temp ) <= iThresh) - 1) & temp;\r
+            }\r
+        }\r
+        break;\r
+\r
+    case CV_THRESH_TOZERO_INV:\r
+        for( i = 0; i < roi.height; i++, isrc += src_step, idst += dst_step )\r
+        {\r
+            for( j = 0; j < roi.width; j++ )\r
+            {\r
+                int temp = isrc[j];\r
+\r
+                idst[j] = CV_TOGGLE_FLT( temp ) > iThresh ? 0 : temp;\r
+            }\r
+        }\r
+        break;\r
+\r
+    default:\r
+        return CV_BADFLAG_ERR;\r
+    }\r
+\r
+    return CV_OK;\r
+}\r
+\r
+\r
+CV_IMPL void\r
+cvThreshold( const void* srcarr, void* dstarr, double thresh, double maxval, CvThreshType type )\r
+{\r
+    CV_FUNCNAME( "cvThreshold" );\r
+\r
+    __BEGIN__;\r
+\r
+    CvSize roi;\r
+    int src_step, dst_step;\r
+    CvMat src_stub, *src = (CvMat*)srcarr;\r
+    CvMat dst_stub, *dst = (CvMat*)dstarr;\r
+    int coi1 = 0, coi2 = 0;\r
+    int ival = 0;\r
+\r
+    CV_CALL( src = cvGetMat( src, &src_stub, &coi1 ));\r
+    CV_CALL( dst = cvGetMat( dst, &dst_stub, &coi2 ));\r
+\r
+    if( coi1 + coi2 )\r
+        CV_ERROR( CV_BadCOI, "COI is not supported by the function" );\r
+\r
+    if( !CV_ARE_CNS_EQ( src, dst ) || CV_MAT_CN(dst->type) != 1 )\r
+        CV_ERROR( CV_StsUnmatchedFormats, "Both arrays must be single-channel" );\r
+\r
+    if( !CV_ARE_DEPTHS_EQ( src, dst ) )\r
+    {\r
+        if( CV_MAT_DEPTH(dst->type) != CV_8U )\r
+            CV_ERROR( CV_StsUnsupportedFormat, "In case of different types destination should be 8uC1" );\r
+\r
+        if( type != CV_THRESH_BINARY && type != CV_THRESH_BINARY_INV )\r
+            CV_ERROR( CV_StsBadArg,\r
+            "In case of different types only CV_THRESH_BINARY "\r
+            "and CV_THRESH_BINARY_INV thresholding types are supported" );\r
+\r
+        if( maxval < 0 )\r
+        {\r
+            CV_CALL( cvSetZero( dst ));\r
+        }\r
+        else\r
+        {\r
+            CV_CALL( cvCmpS( src, thresh, dst, type == CV_THRESH_BINARY ? CV_CMP_GT : CV_CMP_LE ));\r
+            if( maxval < 255 )\r
+                CV_CALL( cvAndS( dst, cvScalarAll( maxval ), dst ));\r
+        }\r
+        EXIT;\r
+    }\r
+\r
+    if( !CV_ARE_SIZES_EQ( src, dst ) )\r
+        CV_ERROR( CV_StsUnmatchedSizes, "" );\r
+\r
+    roi = icvGetMatSize( src );\r
+    roi.width *= CV_MAT_CN(src->type);\r
+    if( CV_IS_MAT_CONT( src->type & dst->type ))\r
+    {\r
+        roi.width *= roi.height;\r
+        roi.height = 1;\r
+        src_step = dst_step = CV_STUB_STEP;\r
+    }\r
+    else\r
+    {\r
+        src_step = src->step;\r
+        dst_step = dst->step;\r
+    }\r
+\r
+    switch( CV_MAT_DEPTH(src->type) )\r
+    {\r
+    case CV_8U:\r
+        ival = cvRound(maxval);\r
+        IPPI_CALL( icvThresh_8u_C1R( (uchar*)src->data.ptr, src_step,\r
+                                     (uchar*)dst->data.ptr, dst_step, roi,\r
+                                     cvRound(thresh), CV_CAST_8U(ival), type ));\r
+        break;\r
+    case CV_8S:\r
+        ival = cvRound(maxval);\r
+        IPPI_CALL( icvThresh_8s_C1R( (char*)src->data.ptr, src_step,\r
+                                     (char*)dst->data.ptr, dst_step, roi,\r
+                                     cvRound(thresh), CV_CAST_8S(ival), type ));\r
+        break;\r
+    case CV_32F:\r
+        IPPI_CALL( icvThresh_32f_C1R( src->data.fl, src_step,\r
+                                      dst->data.fl, dst_step, roi,\r
+                                      (float)thresh, (float)maxval, type ));\r
+        break;\r
+    default:\r
+        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );\r
+    }\r
+\r
+    __END__;\r
+}\r
+\r
+\r
+/* End of file. */\r
index e2b4c232d8396b246b8b911e34314b2c6aa1e831..389749e6e75b51b0ac57a8fc09d14e3694114243 100644 (file)
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-//  By downloading, copying, installing or using the software you agree to this license.
-//  If you do not agree to this license, do not download, install,
-//  copy or use the software.
-//
-//
-//                        Intel License Agreement
-//                For Open Source Computer Vision Library
-//
-// Copyright (C) 2000, Intel Corporation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-//   * Redistribution's of source code must retain the above copyright notice,
-//     this list of conditions and the following disclaimer.
-//
-//   * Redistribution's in binary form must reproduce the above copyright notice,
-//     this list of conditions and the following disclaimer in the documentation
-//     and/or other materials provided with the distribution.
-//
-//   * The name of Intel Corporation may not be used to endorse or promote products
-//     derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-// (including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort (including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-#include "_cv.h"
-
-typedef struct CvUnDistortData
-{
-    int ind;
-    ushort a0;
-    ushort a1;
-    ushort a2;
-    ushort a3;
-}
-CvUnDistortData;
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Names: icvUnDistortInit_8uC1R, icvUnDistortInit_8uC3R, 
-//    Purpose: The functions calculate arrays of distorted points indices and
-//             interpolation coefficients for cvUnDistort function
-//    Context:
-//    Parameters:  size        - size of each image or of its ROI
-//                 step        - full width of each image in bytes
-//                 intrMatrix  - matrix of the camera intrinsic parameters
-//                 distCoeffs  - vector of the distortion coefficients (k1, k2, p1 and p2)
-//                 interToggle - interpolation toggle
-//                 data        - distortion data array
-//
-//    Returns: CV_NO_ERR or error code
-//
-//    Notes:  1. If interToggle=0, interpolation disabled;
-//               else bilinear interpolation is used.
-//            2. Array data must be allocated before. If interToggle = 0, its length
-//               must be size.width*size.height elements; else 3*size.width*size.height.
-//F*/
-/*______________________________________________________________________________________*/
-
-IPCVAPI_IMPL( CvStatus, icvUnDistortInit, ( int srcStep, int* data,
-                                            int mapStep, CvSize size,
-                                            const float *intrMatrix,
-                                            const float *distCoeffs,
-                                            int interToggle, int pixSize ))
-{
-    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
-        u0 = intrMatrix[2], v0 = intrMatrix[5],
-        k1 = distCoeffs[0], k2 = distCoeffs[1], p1 = distCoeffs[2], p2 = distCoeffs[3];
-    int u, v;
-    float p22 = 2.f * p2;
-
-    if( size.width <= 0 || size.height <= 0 )
-        return CV_BADSIZE_ERR;
-
-    if( !intrMatrix || !distCoeffs || !data )
-        return CV_NULLPTR_ERR;
-
-    if( !interToggle )
-    {
-        for( v = 0; v < size.height; v++, (char*&)data += mapStep )
-        {
-            float dv = v - v0;
-            float y = b1 * dv;
-            float y1 = p1 / y;
-            float y2 = y * y;
-            float y3 = 2.f * p1 * y;
-
-            for( u = 0; u < size.width; u++ )
-            {
-                float du = u - u0;
-                float x = a1 * du;
-                float x1 = p2 / x;
-                float x2 = x * x;
-                float x3 = p22 * x;
-                float r2 = x2 + y2;
-                float bx = r2 * (k1 + r2 * k2) + x3 + y3;
-                float by = bx + r2 * y1;
-                int ud = u, vd = v;
-
-                bx += r2 * x1;
-                ud += cvRound( bx * du );
-                vd += cvRound( by * dv );
-                data[u] = ud < 0 || ud >= size.width || vd < 0 || vd >= size.height ?
-                    0 : vd * srcStep + ud*pixSize;
-            }
-        }
-    }
-    else                        /* interpolation */
-    {
-        const int sizex = size.width - 2, sizey = size.height - 2;
-        CvUnDistortData *uData = (CvUnDistortData *) data;
-
-        const float s15 = 32768.f;
-        const int bmax = 32767;
-
-        for( v = 0; v < size.height; v++, (char*&)uData += mapStep )
-        {
-            float dv = v - v0;
-            float y = b1 * dv;
-            float y1 = p1 / y;
-            float y2 = y * y;
-            float y3 = 2.f * p1 * y;
-
-            for( u = 0; u < size.width; u++ )
-            {
-                float du = u - u0;
-                float x = a1 * du;
-                float x1 = p2 / x;
-                float x2 = x * x;
-                float x3 = p22 * x;
-                float r2 = x2 + y2;
-                float bx = r2 * (k1 + r2 * k2) + x3 + y3;
-                float by = bx + r2 * y1;
-                float uf = (float) u, vf = (float) v;
-                int ud, vd;
-
-                bx += r2 * x1;
-                uf += bx * du;
-                vf += by * dv;
-                ud = cvFloor( uf );
-                vd = cvFloor( vf );
-                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )
-                {
-                    (uData + u)->ind = 0;
-                    (uData + u)->a0 = (uData + u)->a1 = (uData + u)->a2 = (uData + u)->a3 =
-                    (ushort) 0;
-                }
-                else
-                {
-                    float uf1, vf1;
-                    int b0, b1, b2, b3;
-
-                    (uData + u)->ind = vd * srcStep + ud*pixSize;
-                    uf -= (float) ud;
-                    vf -= (float) vd;
-                    uf1 = 1.f - uf;
-                    vf1 = 1.f - vf;
-                    b0 = (int) (s15 * uf1 * vf1);
-                    b1 = (int) (s15 * uf * vf1);
-                    b2 = (int) (s15 * uf1 * vf);
-                    b3 = (int) (s15 * uf * vf);
-                    if( b0 < 0 )
-                        b0 = 0;
-                    if( b1 < 0 )
-                        b1 = 0;
-                    if( b2 < 0 )
-                        b2 = 0;
-                    if( b3 < 0 )
-                        b3 = 0;
-                    if( b0 > bmax )
-                        b0 = bmax;
-                    if( b1 > bmax )
-                        b1 = bmax;
-                    if( b2 > bmax )
-                        b2 = bmax;
-                    if( b3 > bmax )
-                        b3 = bmax;
-                    (uData + u)->a0 = (ushort) b0;
-                    (uData + u)->a1 = (ushort) b1;
-                    (uData + u)->a2 = (ushort) b2;
-                    (uData + u)->a3 = (ushort) b3;
-                }
-            }                   /* u */
-        }                       /* v */
-    }                           /* else */
-
-    return CV_NO_ERR;
-}
-
-/*======================================================================================*/
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Names: icvUnDistort_8u_C1R, icvUnDistort_8u_C3R
-//    Purpose: The functions correct radial and tangential distortion in the frame
-//             using previousely calculated arrays of distorted points indices and
-//             undistortion coefficients
-//    Context:
-//    Parameters:  src    - source (distorted) image
-//                 dst    - output (undistorted) image
-//                 step        - full width of each image in bytes
-//                 size        - size of each image or of its ROI
-//                 interToggle - interpolation toggle
-//                 data        - distortion data array
-//
-//    Returns: CV_NO_ERR or error code
-//
-//    Notes:  1. Either icvUnDistortInit_8u_C1R or icvUnDistortInit_8u_C3R function
-//               must be used previously
-//            2. See Notes to the icvUnDistortInit_8u_C1R, icvUnDistortInit_8u_C3R
-//               functions
-//F*/
-/*______________________________________________________________________________________*/
-
-IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C1R, ( const uchar* src, int srcStep,
-                                               const int* data, int mapStep,
-                                               uchar* dst, int dstStep,
-                                               CvSize size, int interToggle ))
-{
-    int u, v;
-    uchar buf;
-
-    if( size.width <= 0 || size.height <= 0 )
-        return CV_BADSIZE_ERR;
-
-    if( !src || !dst || !data )
-        return CV_NULLPTR_ERR;
-
-    buf = *src;
-    *(uchar*&)src = (uchar)0;
-
-    if( !interToggle )          /* Interpolation disabled */
-    {
-        for( v = 0; v < size.height; v++, dst += dstStep, (char*&)data += mapStep )
-        {
-            for( u = 0; u <= size.width - 4; u += 4 )
-            {
-                uchar t0 = src[data[u]];
-                uchar t1 = src[data[u+1]];
-
-                dst[u] = t0;
-                dst[u + 1] = t1;
-
-                t0 = src[data[u+2]];
-                t1 = src[data[u+3]];
-
-                dst[u + 2] = t0;
-                dst[u + 3] = t1;
-            }
-
-            for( ; u < size.width; u++ )
-            {
-                dst[u] = src[data[u]];
-            }
-        }
-    }
-    else /* Interpolation enabled */
-    {
-        CvUnDistortData *uData = (CvUnDistortData *) data;
-
-        for( v = 0; v < size.height; v++, dst += dstStep, (char*&)uData += mapStep )
-        {
-            for( u = 0; u < size.width; u++ )
-            {
-                CvUnDistortData d = uData[u];
-                const uchar* s = src + d.ind;
-
-                dst[u] = (uchar)((s[0]*d.a0 + s[1]*d.a1 +
-                        s[srcStep]*d.a2 + s[srcStep+1]*d.a3) >> 15);
-            }
-        }
-    }
-
-    *(uchar*&)src = buf;
-    return CV_NO_ERR;
-}
-
-
-#define ICV_COPY_C3( src_ptr, dst_ptr ) \
-    (dst_ptr)[0] = (src_ptr)[0];        \
-    t0 = (src_ptr)[1];                  \
-    t1 = (src_ptr)[2];                  \
-    (dst_ptr)[1] = t0;                  \
-    (dst_ptr)[2] = t1
-   
-
-/*_____________________________ 3-CHANNEL IMAGES _______________________________*/
-
-IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C3R, ( const uchar* src, int srcStep,
-                                               const int* data, int mapStep,
-                                               uchar* dst, int dstStep,
-                                               CvSize size, int interToggle ))
-{
-    int u, v;
-    uchar buf[3];
-
-    if( size.width <= 0 || size.height <= 0 )
-        return CV_BADSIZE_ERR;
-
-    if( !src || !dst || !data )
-        return CV_NULLPTR_ERR;
-
-    memcpy( buf, src, 3 );
-    memset( (void*)src, 0, 3 );
-
-    if( !interToggle )          /* Interpolation disabled */
-    {
-        for( v = 0; v < size.height; v++, dst += dstStep, (char*&)data += mapStep )
-        {
-            for( u = 0; u <= size.width - 4; u += 4, dst += 12 )
-            {
-                uchar t0, t1;
-
-                int v3 = data[u];
-                ICV_COPY_C3( src + v3, dst );
-
-                v3 = data[u + 1];
-                ICV_COPY_C3( src + v3, dst + 3 );
-
-                v3 = data[u + 2];
-                ICV_COPY_C3( src + v3, dst + 6 );
-
-                v3 = data[u + 3];
-                ICV_COPY_C3( src + v3, dst + 9 );
-            }
-
-            for( ; u < size.width; u++, dst += 3 )
-            {
-                int v3 = data[u];
-                uchar t0, t1;
-
-                ICV_COPY_C3( src + v3, dst );
-            }
-
-            dst -= size.width * 3;
-        }
-    }
-    else  /* Interpolation enabled */
-    {
-        CvUnDistortData *uData = (CvUnDistortData *) data;
-
-        for( v = 0; v < size.height; v++, dst += dstStep, (char*&)uData += mapStep )
-        {
-            for( u = 0; u < size.width; u++, dst += 3 )
-            {
-                CvUnDistortData d = uData[u];
-                const uchar* s = src + d.ind;
-
-                dst[0] = (uchar) ((s[0] * d.a0 + s[3] * d.a1 +
-                                   s[srcStep] * d.a2 + s[srcStep + 3] * d.a3) >> 15);
-
-                dst[1] = (uchar) ((s[1] * d.a0 + s[4] * d.a1 +
-                                   s[srcStep + 1] * d.a2 + s[srcStep + 4] * d.a3) >> 15);
-
-                dst[2] = (uchar) ((s[2] * d.a0 + s[5] * d.a1 +
-                                   s[srcStep + 2] * d.a2 + s[srcStep + 5] * d.a3) >> 15);
-            }
-
-            dst -= size.width * 3;
-        }
-    }
-
-    memcpy( (void*)src, buf, 3 );
-    return CV_NO_ERR;
-}
-
-/*======================================================================================*/
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Names: icvUnDistort1_8uC1R, icvUnDistort1_8uC3R
-//    Purpose: The functions correct radial image distortion using known matrix of the
-//             camera intrinsic parameters and distortion coefficients
-//    Context:
-//    Parameters:  src    - source (distorted) image
-//                 dst    - output (undistorted) image
-//                 step        - full width of each image in bytes
-//                 size        - ROI size of each image
-//                 intrMatrix  - matrix of the camera intrinsic parameters
-//                 distCoeffs  - vector of two distortion coefficients (k1 and k2)
-//                 interToggle - interpolation toggle
-//
-//    Returns: CV_NO_ERR or error code
-//
-//    Notes:   If interToggle=0, interpolation disabled;
-//             else bilinear interpolation is used.
-//F*/
-/*______________________________________________________________________________________*/
-
-#define S  22
-#define S2 11
-#define FM (float)0x400000
-
-IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C1R, ( const uchar* src, int srcStep,
-                                                uchar* dst, int dstStep, CvSize size,
-                                                const float *intrMatrix,
-                                                const float *distCoeffs,
-                                                int interToggle ))
-{
-    const float fm = FM;
-    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
-        u0 = intrMatrix[2], v0 = intrMatrix[5], k1 = distCoeffs[0], k2 = distCoeffs[1];
-    float *x2;
-    float *du;
-    int u, v;
-    uchar buf[1];
-
-    if( size.width <= 0 || size.height <= 0 )
-        return CV_BADSIZE_ERR;
-    if( !src || !dst || !intrMatrix || !distCoeffs )
-        return CV_NULLPTR_ERR;
-
-    x2 = (float *) icvAlloc( sizeof( float ) * size.width );
-
-    if( x2 == NULL )
-        return CV_OUTOFMEM_ERR;
-    du = (float *) icvAlloc( sizeof( float ) * size.width );
-
-    if( du == NULL )
-    {
-        icvFree( (void **) &x2 );
-        return CV_OUTOFMEM_ERR;
-    }
-
-    memcpy( buf, src, 1 );
-    memset( (void*)src, 0, 1 );
-
-    if( !interToggle )
-    {
-        for( u = 0; u < size.width; u++ )
-        {
-            float w = u - u0;
-            float x = a1 * w;
-
-            x2[u] = x * x;
-            du[u] = w;
-        }
-        for( v = 0; v < size.height; v++, dst += dstStep )
-        {
-            float y = b1 * (v - v0);
-            float y2 = y * y;
-            float dv = v - v0;
-
-            for( u = 0; u < size.width; u++ )
-            {
-                float r2 = x2[u] + y2;
-                float dist = r2 * (k1 + r2 * k2);
-                int ud = u + cvRound( du[u] * dist );
-                int vd = v + cvRound( dv * dist );
-
-                dst[u] = (uchar) (ud < 0 || ud >= size.width || vd < 0 ||
-                                       vd >= size.height ? 0 : src[vd * srcStep + ud]);
-            }
-        }
-    }
-    else
-    {
-        int sizex = size.width - 2, sizey = size.height - 2;
-
-        for( u = 0; u < size.width; u++ )
-        {
-            float w = u - u0;
-            float x = a1 * w;
-
-            x2[u] = x * x;
-            du[u] = fm * w;
-        }
-        for( v = 0; v < size.height; v++, dst += dstStep )
-        {
-            float y = b1 * (v - v0);
-            float y2 = y * y;
-            float dv = fm * (v - v0);
-
-            for( u = 0; u < size.width; u++ )
-            {
-                float r2 = x2[u] + y2;
-                float dist = r2 * (k1 + r2 * k2);
-                int iu = cvRound( du[u] * dist );
-                int iv = cvRound( dv * dist );
-                int ud = iu >> S;
-                int vd = iv >> S;
-
-                iu -= ud << S;
-                iv -= vd << S;
-                ud += u;
-                vd += v;
-
-                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )
-                    dst[u] = 0;
-                else
-                {
-                    int iuv = (iu >> S2) * (iv >> S2);
-                    int uv = vd * srcStep + ud;
-                    int a0 = src[uv];
-                    int a = src[uv + 1] - a0;
-                    int b = src[uv + srcStep] - a0;
-                    int c = src[uv + srcStep + 1] - a0 - a - b;
-                    int d = ((a * iu + b * iv + c * iuv) >> S) + a0;
-
-                    d = !(d & ~255) ? d : d < 0 ? 0 : 255;
-                    dst[u] = (uchar) d;
-                }
-            }
-        }
-    }
-
-    memcpy( (void*)src, buf, 1 );
-
-    icvFree( (void **) &x2 );
-    icvFree( (void **) &du );
-    return CV_NO_ERR;
-}
-/*______________________________________________________ 3-CHANNEL IMAGES ______________*/
-
-IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C3R, ( const uchar* src, int srcStep,
-                                                uchar* dst, int dstStep, CvSize size,
-                                                const float *intrMatrix,
-                                                const float *distCoeffs,
-                                                int interToggle ))
-{
-    const float fm = FM;
-    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
-        u0 = intrMatrix[2], v0 = intrMatrix[5], k1 = distCoeffs[0], k2 = distCoeffs[1];
-    const int p = 0xFFFFFF;
-    float *x2;
-    float *du;
-    int u, v;
-    uchar buf[3];
-
-    if( size.width <= 0 || size.height <= 0 )
-        return CV_BADSIZE_ERR;
-    if( !src || !dst || !intrMatrix || !distCoeffs )
-        return CV_NULLPTR_ERR;
-
-    x2 = (float *) icvAlloc( sizeof( float ) * size.width );
-
-    if( x2 == NULL )
-        return CV_OUTOFMEM_ERR;
-    du = (float *) icvAlloc( sizeof( float ) * size.width );
-
-    if( du == NULL )
-    {
-        icvFree( (void **) &x2 );
-        return CV_OUTOFMEM_ERR;
-    }
-
-    memcpy( buf, src, 3 );
-    memset( (void*)src, 0, 3 );
-
-    if( !interToggle )
-    {
-        for( u = 0; u < size.width; u++ )
-        {
-            float w = u - u0;
-            float x = a1 * w;
-
-            x2[u] = x * x;
-            du[u] = w;
-        }
-
-        for( v = 0; v < size.height; v++, dst += dstStep )
-        {
-            float y = b1 * (v - v0);
-            float y2 = y * y;
-            float dv = v - v0;
-
-            if( v == size.height - 1 )
-                size.width--;
-            for( u = 0; u < size.width; u++ )
-            {
-                float r2 = x2[u] + y2;
-                float dist = r2 * (k1 + r2 * k2);
-                int ud = u + cvRound( du[u] * dist );
-                int vd = v + cvRound( dv * dist );
-                int u3 = u + u + u;
-
-                if( ud < 0 || ud >= size.width || vd < 0 || vd >= size.height )
-                    *(int *) (dst + u3) = 0;
-                else
-                {
-                    int uv = vd * srcStep + ud + ud + ud;
-
-                    *(int *) (dst + u3) = *(int *) (src + uv) & p;
-                }
-            }
-            if( v == size.height - 1 )
-            {
-                float r2 = x2[u] + y2;
-                float dist = r2 * (k1 + r2 * k2);
-                int ud = u + cvRound( du[u] * dist );
-                int vd = v + cvRound( dv * dist );
-                int u3 = u + u + u;
-
-                size.width++;
-                if( ud < 0 || ud >= size.width || vd < 0 || vd >= size.height )
-                    dst[u3] = dst[u3 + 1] = dst[u3 + 2] = 0;
-                else
-                {
-                    int uv = vd * srcStep + ud + ud + ud;
-
-                    dst[u3] = src[uv];
-                    dst[u3 + 1] = src[uv + 1];
-                    dst[u3 + 2] = src[uv + 2];
-                }
-            }
-        }
-    }
-    else                        /* interpolation */
-    {
-        int sizex = size.width - 2, sizey = size.height - 2;
-
-        for( u = 0; u < size.width; u++ )
-        {
-            float w = u - u0;
-            float x = a1 * w;
-
-            x2[u] = x * x;
-            du[u] = fm * w;
-        }
-
-        for( v = 0; v < size.height; v++, dst += dstStep )
-        {
-            float y = b1 * (v - v0);
-            float y2 = y * y;
-            float dv = fm * (v - v0);
-
-            if( v == size.height - 1 )
-                size.width--;
-            for( u = 0; u < size.width; u++ )
-            {
-                float r2 = x2[u] + y2;
-                float dist = r2 * (k1 + r2 * k2);
-                int iu = cvRound( du[u] * dist );
-                int iv = cvRound( dv * dist );
-                int ud = iu >> S;
-                int vd = iv >> S;
-                int u3 = u + u + u;
-
-                iu -= ud << S;
-                iv -= vd << S;
-                ud += u;
-                vd += v;
-
-                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )
-                    *(int *) (dst + u3) = 0;
-                else
-                {
-                    int iuv = (iu >> S2) * (iv >> S2);
-                    int uv = vd * srcStep + ud + ud + ud;
-                    int uvs = uv + srcStep;
-                    int a01 = src[uv];
-                    int a02 = src[uv + 1];
-                    int a03 = src[uv + 2];
-                    int a1 = src[uv + 3];
-                    int a2 = src[uv + 4];
-                    int a3 = src[uv + 5];
-                    int b1 = src[uvs];
-                    int b2 = src[uvs + 1];
-                    int b3 = src[uvs + 2];
-                    int c1 = src[uvs + 3];
-                    int c2 = src[uvs + 4];
-                    int c3 = src[uvs + 5];
-                    int d1, d2, d3;
-
-                    a1 -= a01;
-                    a2 -= a02;
-                    a3 -= a03;
-                    b1 -= a01;
-                    b2 -= a02;
-                    b3 -= a03;
-                    c1 -= a01 + a1 + b1;
-                    c2 -= a02 + a2 + b2;
-                    c3 -= a03 + a3 + b3;
-                    d1 = ((a1 * iu + b1 * iv + c1 * iuv) >> S) + a01;
-                    d2 = ((a2 * iu + b2 * iv + c2 * iuv) >> S) + a02;
-                    d3 = ((a3 * iu + b3 * iv + c3 * iuv) >> S) + a03;
-                    d1 = !(d1 & ~255) ? d1 : d1 < 0 ? 0 : 255;
-                    d2 = !(d2 & ~255) ? d2 : d2 < 0 ? 0 : 255;
-                    d3 = !(d3 & ~255) ? d3 : d3 < 0 ? 0 : 255;
-                    d1 |= (d2 << 8) | (d3 << 16);
-                    *(int *) (dst + u3) = d1;
-                }
-            }
-            if( v == size.height - 1 )
-            {
-                float r2 = x2[u] + y2;
-                float dist = r2 * (k1 + r2 * k2);
-                int iu = cvRound( du[u] * dist );
-                int iv = cvRound( dv * dist );
-                int ud = iu >> S;
-                int vd = iv >> S;
-                int u3 = u + u + u;
-
-                size.width++;
-                iu -= ud << S;
-                iv -= vd << S;
-                ud += u;
-                vd += v;
-
-                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )
-                    dst[u3] = dst[u3 + 1] = dst[u3 + 2] = 0;
-                else
-                {
-                    int iuv = (iu >> S2) * (iv >> S2);
-                    int uv = vd * srcStep + ud + ud + ud;
-                    int uvs = uv + srcStep;
-                    int a01 = src[uv];
-                    int a02 = src[uv + 1];
-                    int a03 = src[uv + 2];
-                    int a1 = src[uv + 3];
-                    int a2 = src[uv + 4];
-                    int a3 = src[uv + 5];
-                    int b1 = src[uvs];
-                    int b2 = src[uvs + 1];
-                    int b3 = src[uvs + 2];
-                    int c1 = src[uvs + 3];
-                    int c2 = src[uvs + 4];
-                    int c3 = src[uvs + 5];
-                    int d1, d2, d3;
-
-                    a1 -= a01;
-                    a2 -= a02;
-                    a3 -= a03;
-                    b1 -= a01;
-                    b2 -= a02;
-                    b3 -= a03;
-                    c1 -= a01 + a1 + b1;
-                    c2 -= a02 + a2 + b2;
-                    c3 -= a03 + a3 + b3;
-                    d1 = ((a1 * iu + b1 * iv + c1 * iuv) >> S) + a01;
-                    d2 = ((a2 * iu + b2 * iv + c2 * iuv) >> S) + a02;
-                    d3 = ((a3 * iu + b3 * iv + c3 * iuv) >> S) + a03;
-                    dst[u3] = (uchar) d1;
-                    dst[u3 + 1] = (uchar) d2;
-                    dst[u3 + 2] = (uchar) d3;
-                }
-            }
-        }
-    }
-
-    memcpy( (void*)src, buf, 1 );
-
-    icvFree( (void **) &x2 );
-    icvFree( (void **) &du );
-    return CV_NO_ERR;
-}
-
-/*======================================================================================*/
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Names: icvUnDistortEx_8uC1R, icvUnDistortEx_8uC3R
-//    Purpose: The functions correct radial and tangential image distortions using known
-//             matrix of the camera intrinsic parameters and distortion coefficients
-//    Context:
-//    Parameters:  src    - source (distorted) image
-//                 dst    - output (undistorted) image
-//                 step        - full width of each image in bytes
-//                 size        - ROI size of each image
-//                 intrMatrix  - matrix of the camera intrinsic parameters
-//                 distCoeffs  - vector of the distortion coefficients
-//                               (k1, k2, p1, p2)
-//                 interToggle - interpolation toggle
-//
-//    Returns: CV_NO_ERR or error code
-//
-//    Notes:   If interToggle=0, interpolation disabled;
-//             else bilinear interpolation is used.
-//F*/
-/*______________________________________________________________________________________*/
-
-IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,
-                                                 uchar* dst, int dstStep, CvSize size,
-                                                 const float *intrMatrix,
-                                                 const float *distCoeffs,
-                                                 int interToggle ))
-{
-    const float fm = FM;
-    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
-        u0 = intrMatrix[2], v0 = intrMatrix[5],
-        k1 = distCoeffs[0], k2 = distCoeffs[1], p1 = distCoeffs[2], p2 = distCoeffs[3];
-    float *x1;
-    float *x2;
-    float *x3;
-    float *du;
-    int u, v;
-    uchar buf[1];
-
-    if( size.width <= 0 || size.height <= 0 )
-        return CV_BADSIZE_ERR;
-    if( !src || !dst || !intrMatrix || !distCoeffs )
-        return CV_NULLPTR_ERR;
-
-    /*if ( !p1 && !p2 ) return icvUnDistort1_8uC1R ( src, dst, step, size,
-       intrMatrix, distCoeffs, interToggle ); */
-
-    x1 = (float *) icvAlloc( sizeof( float ) * size.width );
-    x2 = (float *) icvAlloc( sizeof( float ) * size.width );
-    x3 = (float *) icvAlloc( sizeof( float ) * size.width );
-    du = (float *) icvAlloc( sizeof( float ) * size.width );
-
-    if( x1 == NULL || x2 == NULL || x3 == NULL || du == NULL )
-    {
-        if( x1 )
-            icvFree( (void **) &x1 );
-        if( x2 )
-            icvFree( (void **) &x2 );
-        if( x3 )
-            icvFree( (void **) &x3 );
-        if( du )
-            icvFree( (void **) &du );
-        return CV_OUTOFMEM_ERR;
-    }
-
-    memcpy( buf, src, 1 );
-    memset( (void*)src, 0, 1 );
-
-    if( !interToggle )
-    {
-        for( u = 0; u < size.width; u++ )
-        {
-            float w = u - u0;
-            float x = a1 * w;
-
-            x1[u] = p2 / x;
-            x2[u] = x * x;
-            x3[u] = 2.f * p2 * x;
-            du[u] = w;
-        }
-
-        for( v = 0; v < size.height; v++, dst += dstStep )
-        {
-            float dv = v - v0;
-            float y = b1 * dv;
-            float y1 = p1 / y;
-            float y2 = y * y;
-            float y3 = 2.f * p1 * y;
-
-            for( u = 0; u < size.width; u++ )
-            {
-                float r2 = x2[u] + y2;
-                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;
-                float by = bx + r2 * y1;
-                int ud = u, vd = v;
-
-                bx += r2 * x1[u];
-                ud += cvRound( bx * du[u] );
-                vd += cvRound( by * dv );
-                dst[u] = (uchar) (ud < 0 || ud >= size.width || vd < 0 ||
-                                       vd >= size.height ? 0 : src[vd * srcStep + ud]);
-            }
-        }
-    }
-    else                        /* interpolation */
-    {
-        int sizex = size.width - 2, sizey = size.height - 2;
-
-        for( u = 0; u < size.width; u++ )
-        {
-            float w = u - u0;
-            float x = a1 * w;
-
-            x1[u] = p2 / x;
-            x2[u] = x * x;
-            x3[u] = 2.f * p2 * x;
-            du[u] = fm * w;
-        }
-
-        for( v = 0; v < size.height; v++, dst += dstStep )
-        {
-            float dv = v - v0;
-            float y = b1 * dv;
-            float y1 = p1 / y;
-            float y2 = y * y;
-            float y3 = 2.f * p1 * y;
-
-            dv *= fm;
-
-            for( u = 0; u < size.width; u++ )
-            {
-                float r2 = x2[u] + y2;
-                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;
-                float by = bx + r2 * y1;
-                int iu, iv, ud, vd;
-
-                bx += r2 * x1[u];
-                iu = cvRound( bx * du[u] );
-                iv = cvRound( by * dv );
-                ud = iu >> S;
-                vd = iv >> S;
-                iu -= ud << S;
-                iv -= vd << S;
-                ud += u;
-                vd += v;
-
-                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )
-                    dst[u] = 0;
-                else
-                {
-                    int iuv = (iu >> S2) * (iv >> S2);
-                    int uv = vd * srcStep + ud;
-                    int a0 = src[uv];
-                    int a = src[uv + 1] - a0;
-                    int b = src[uv + srcStep] - a0;
-                    int c = src[uv + srcStep + 1] - a0 - a - b;
-                    int d = ((a * iu + b * iv + c * iuv) >> S) + a0;
-
-                    d = !(d & ~255) ? d : d < 0 ? 0 : 255;
-                    dst[u] = (uchar) d;
-                }
-            }
-        }
-    }
-
-    memcpy( (void*)src, buf, 1 );
-
-    icvFree( (void **) &x1 );
-    icvFree( (void **) &x2 );
-    icvFree( (void **) &x3 );
-    icvFree( (void **) &du );
-    return CV_NO_ERR;
-}
-/*______________________________________________________ 3-CHANNEL IMAGES ______________*/
-
-IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,
-                                                 uchar* dst, int dstStep, CvSize size,
-                                                 const float *intrMatrix,
-                                                 const float *distCoeffs,
-                                                 int interToggle ))
-{
-    const float fm = FM;
-    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],
-        u0 = intrMatrix[2], v0 = intrMatrix[5],
-        k1 = distCoeffs[0], k2 = distCoeffs[1], p1 = distCoeffs[2], p2 = distCoeffs[3];
-    const int p = 0xFFFFFF;
-    float *x1;
-    float *x2;
-    float *x3;
-    float *du;
-    int u, v;
-    uchar buf[3];
-
-    if( size.width <= 0 || size.height <= 0 )
-        return CV_BADSIZE_ERR;
-    if( !src || !dst || !intrMatrix || !distCoeffs )
-        return CV_NULLPTR_ERR;
-
-    /*if ( !p1 && !p2 ) return icvUnDistort1_8uC3R ( src, dst, srcStep, size,
-       intrMatrix, distCoeffs, interToggle ); */
-
-    x1 = (float *) icvAlloc( sizeof( float ) * size.width );
-    x2 = (float *) icvAlloc( sizeof( float ) * size.width );
-    x3 = (float *) icvAlloc( sizeof( float ) * size.width );
-    du = (float *) icvAlloc( sizeof( float ) * size.width );
-
-    if( x1 == NULL || x2 == NULL || x3 == NULL || du == NULL )
-    {
-        if( x1 )
-            icvFree( (void **) &x1 );
-        if( x2 )
-            icvFree( (void **) &x2 );
-        if( x3 )
-            icvFree( (void **) &x3 );
-        if( du )
-            icvFree( (void **) &du );
-        return CV_OUTOFMEM_ERR;
-    }
-
-    memcpy( buf, src, 3 );
-    memset( (void*)src, 0, 3 );
-    
-    if( !interToggle )
-    {
-        for( u = 0; u < size.width; u++ )
-        {
-            float w = u - u0;
-            float x = a1 * w;
-
-            x1[u] = p2 / x;
-            x2[u] = x * x;
-            x3[u] = 2.f * p2 * x;
-            du[u] = w;
-        }
-
-        for( v = 0; v < size.height; v++, dst += dstStep )
-        {
-            float dv = v - v0;
-            float y = b1 * dv;
-            float y1 = p1 / y;
-            float y2 = y * y;
-            float y3 = 2.f * p1 * y;
-
-            if( v == size.height - 1 )
-                size.width--;
-
-            for( u = 0; u < size.width; u++ )
-            {
-                float r2 = x2[u] + y2;
-                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;
-                float by = bx + r2 * y1;
-                int ud = u, vd = v, u3 = u + u + u;
-
-                bx += r2 * x1[u];
-                ud += cvRound( bx * du[u] );
-                vd += cvRound( by * dv );
-                if( ud < 0 || ud >= size.width || vd < 0 || vd >= size.height )
-                    *(int *) (dst + u3) = 0;
-                else
-                {
-                    int uv = vd * srcStep + ud + ud + ud;
-
-                    *(int *) (dst + u3) = *(int *) (src + uv) & p;
-                }
-            }
-
-            if( v == size.height - 1 )
-            {
-                float r2 = x2[u] + y2;
-                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;
-                float by = bx + r2 * y1;
-                int ud = u, vd = v, u3 = u + u + u;
-
-                bx += r2 * x1[u];
-                ud += cvRound( bx * du[u] );
-                vd += cvRound( by * dv );
-                size.width++;
-                if( ud < 0 || ud >= size.width || vd < 0 || vd >= size.height )
-                    dst[u3] = dst[u3 + 1] = dst[u3 + 2] = 0;
-                else
-                {
-                    int uv = vd * srcStep + ud + ud + ud;
-
-                    dst[u3] = src[uv];
-                    dst[u3 + 1] = src[uv + 1];
-                    dst[u3 + 2] = src[uv + 2];
-                }
-            }
-        }
-    }
-    else                        /* interpolation */
-    {
-        int sizex = size.width - 2, sizey = size.height - 2;
-
-        for( u = 0; u < size.width; u++ )
-        {
-            float w = u - u0;
-            float x = a1 * w;
-
-            x1[u] = p2 / x;
-            x2[u] = x * x;
-            x3[u] = 2.f * p2 * x;
-            du[u] = fm * w;
-        }
-
-        for( v = 0; v < size.height; v++, dst += dstStep )
-        {
-            float dv = v - v0;
-            float y = b1 * dv;
-            float y1 = p1 / y;
-            float y2 = y * y;
-            float y3 = 2.f * p1 * y;
-
-            dv *= fm;
-
-            if( v == size.height - 1 )
-                size.width--;
-
-            for( u = 0; u < size.width; u++ )
-            {
-                float r2 = x2[u] + y2;
-                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;
-                float by = bx + r2 * y1;
-                int iu, iv, ud, vd, u3 = u + u + u;
-
-                bx += r2 * x1[u];
-                iu = cvRound( bx * du[u] );
-                iv = cvRound( by * dv );
-                ud = iu >> S;
-                vd = iv >> S;
-                iu -= ud << S;
-                iv -= vd << S;
-                ud += u;
-                vd += v;
-
-                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )
-                    *(int *) (dst + u3) = 0;
-                else
-                {
-                    int iuv = (iu >> S2) * (iv >> S2);
-                    int uv = vd * srcStep + ud + ud + ud;
-                    int uvs = uv + srcStep;
-                    int a01 = src[uv];
-                    int a02 = src[uv + 1];
-                    int a03 = src[uv + 2];
-                    int a1 = src[uv + 3];
-                    int a2 = src[uv + 4];
-                    int a3 = src[uv + 5];
-                    int b1 = src[uvs];
-                    int b2 = src[uvs + 1];
-                    int b3 = src[uvs + 2];
-                    int c1 = src[uvs + 3];
-                    int c2 = src[uvs + 4];
-                    int c3 = src[uvs + 5];
-                    int d1, d2, d3;
-
-                    a1 -= a01;
-                    a2 -= a02;
-                    a3 -= a03;
-                    b1 -= a01;
-                    b2 -= a02;
-                    b3 -= a03;
-                    c1 -= a01 + a1 + b1;
-                    c2 -= a02 + a2 + b2;
-                    c3 -= a03 + a3 + b3;
-                    d1 = ((a1 * iu + b1 * iv + c1 * iuv) >> S) + a01;
-                    d2 = ((a2 * iu + b2 * iv + c2 * iuv) >> S) + a02;
-                    d3 = ((a3 * iu + b3 * iv + c3 * iuv) >> S) + a03;
-                    d1 = !(d1 & ~255) ? d1 : d1 < 0 ? 0 : 255;
-                    d2 = !(d2 & ~255) ? d2 : d2 < 0 ? 0 : 255;
-                    d3 = !(d3 & ~255) ? d3 : d3 < 0 ? 0 : 255;
-                    d1 |= (d2 << 8) | (d3 << 16);
-                    *(int *) (dst + u3) = d1;
-                }
-            }
-
-            if( v == size.height - 1 )
-            {
-                float r2 = x2[u] + y2;
-                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;
-                float by = bx + r2 * y1;
-                int iu, iv, ud, vd, u3 = u + u + u;
-
-                bx += r2 * x1[u];
-                iu = cvRound( bx * du[u] );
-                iv = cvRound( by * dv );
-                ud = iu >> S;
-                vd = iv >> S;
-                iu -= ud << S;
-                iv -= vd << S;
-                ud += u;
-                vd += v;
-                size.width++;
-
-                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )
-                    dst[u3] = dst[u3 + 1] = dst[u3 + 2] = 0;
-                else
-                {
-                    int iuv = (iu >> S2) * (iv >> S2);
-                    int uv = vd * srcStep + ud + ud + ud;
-                    int uvs = uv + srcStep;
-                    int a01 = src[uv];
-                    int a02 = src[uv + 1];
-                    int a03 = src[uv + 2];
-                    int a1 = src[uv + 3];
-                    int a2 = src[uv + 4];
-                    int a3 = src[uv + 5];
-                    int b1 = src[uvs];
-                    int b2 = src[uvs + 1];
-                    int b3 = src[uvs + 2];
-                    int c1 = src[uvs + 3];
-                    int c2 = src[uvs + 4];
-                    int c3 = src[uvs + 5];
-                    int d1, d2, d3;
-
-                    a1 -= a01;
-                    a2 -= a02;
-                    a3 -= a03;
-                    b1 -= a01;
-                    b2 -= a02;
-                    b3 -= a03;
-                    c1 -= a01 + a1 + b1;
-                    c2 -= a02 + a2 + b2;
-                    c3 -= a03 + a3 + b3;
-                    d1 = ((a1 * iu + b1 * iv + c1 * iuv) >> S) + a01;
-                    d2 = ((a2 * iu + b2 * iv + c2 * iuv) >> S) + a02;
-                    d3 = ((a3 * iu + b3 * iv + c3 * iuv) >> S) + a03;
-                    dst[u3] = (uchar) d1;
-                    dst[u3 + 1] = (uchar) d2;
-                    dst[u3 + 2] = (uchar) d3;
-                }
-            }
-        }
-    }
-
-    memcpy( (void*)src, buf, 3 );
-
-    icvFree( (void **) &x1 );
-    icvFree( (void **) &x2 );
-    icvFree( (void **) &x3 );
-    icvFree( (void **) &du );
-    return CV_NO_ERR;
-}
-/*______________________________________________________________________________________*/
-
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvUnDistortOnce
-//    Purpose: The function corrects radial and tangential image distortion using known
-//             matrix of the camera intrinsic parameters and distortion coefficients
-//    Context:
-//    Parameters:  srcImage    - source (distorted) image
-//                 dstImage    - output (undistorted) image
-//                 intrMatrix  - matrix of the camera intrinsic parameters
-//                 distCoeffs  - vector of the distortion coefficients (k1, k2, p1 and p2)
-//                 interpolate - interpolation toggle (optional parameter)
-//
-//    Notes:   1. If interpolate = 0, interpolation disabled;
-//                else (default) bilinear interpolation is used.
-//             2. If p1 = p2 = 0, function acts faster.
-//F*/
-
-typedef CvStatus (CV_STDCALL * CvUnDistortOnceFunc)( const void* src, int srcstep,
-                                                     void* dst, int dststep, CvSize size,
-                                                     const float* intrMatrix,
-                                                     const float* distCoeffs,
-                                                     int interToggle );
-
-
-CV_IMPL void
-cvUnDistortOnce( const void* srcImage, void* dstImage,
-                 const float* intrMatrix, const float* distCoeffs,
-                 int interpolate )
-{
-    static void* undist_tab[4];
-    static int inittab = 0;
-    
-    CV_FUNCNAME( "cvUnDistortOnce" );
-
-    __BEGIN__;
-
-    int coi1 = 0, coi2 = 0;
-    CvMat srcstub, *src = (CvMat*)srcImage;
-    CvMat dststub, *dst = (CvMat*)dstImage;
-    CvSize size;
-    CvUnDistortOnceFunc  func = 0;
-
-    if( !inittab )
-    {
-        undist_tab[0] = (void*)icvUnDistort1_8u_C1R;
-        undist_tab[1] = (void*)icvUnDistortEx_8u_C1R;
-        undist_tab[2] = (void*)icvUnDistort1_8u_C3R;
-        undist_tab[3] = (void*)icvUnDistortEx_8u_C3R;
-        inittab = 1;
-    }
-
-    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
-    CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));
-
-    if( coi1 != 0 || coi2 != 0 )
-        CV_ERROR( CV_BadCOI, "" );
-
-    if( CV_ARR_TYPE(src->type) != CV_8UC1 &&
-        CV_ARR_TYPE(src->type) != CV_8UC3 )
-        CV_ERROR( CV_StsUnsupportedFormat, "" );
-
-    if( !CV_ARE_TYPES_EQ( src, dst ))
-        CV_ERROR( CV_StsUnmatchedFormats, "" );
-
-    if( !CV_ARE_SIZES_EQ( src, dst ))
-        CV_ERROR( CV_StsUnmatchedSizes, "" );
-
-    if( !intrMatrix || !distCoeffs )
-        CV_ERROR( CV_StsNullPtr, "" );
-
-    size = icvGetMatSize( src );
-
-    func = (CvUnDistortOnceFunc)
-        (undist_tab[(CV_ARR_CN(src->type)-1)+(distCoeffs[2] != 0 || distCoeffs[3] != 0)]);
-
-    if( !func )
-        CV_ERROR( CV_StsUnsupportedFormat, "" );
-
-    IPPI_CALL( func( src->data.ptr, src->step, dst->data.ptr, dst->step, size,
-                     intrMatrix, distCoeffs, interpolate ));
-  
-    __END__;
-}
-
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvUnDistortInit
-//    Purpose: The function calculates arrays of distorted points indices and
-//             interpolation coefficients for cvUnDistort function using known
-//             matrix of the camera intrinsic parameters and distortion coefficients
-//    Context:
-//    Parameters:  srcImage    - source (distorted) image
-//                 intrMatrix  - matrix of the camera intrinsic parameters
-//                 distCoeffs  - vector of the distortion coefficients (k1, k2, p1 and p2)
-//                 data        - distortion data array
-//                 interpolate - interpolation toggle (optional parameter)
-//
-//    Notes:  1. If interpolate=0, interpolation disabled;
-//               else (default) bilinear interpolation is used.
-//            2. Array data must be allocated before. If interpolate = 0, its length
-//               must be size.width*size.height elements; else 3*size.width*size.height.
-//F*/
-CV_IMPL void
-cvUnDistortInit( const void* srcImage, void* undistMap,
-                 const float* intrMatrix, const float* distCoeffs,
-                 int  interpolate )
-{
-    CV_FUNCNAME( "cvUnDistortInit" );
-
-    __BEGIN__;
-
-    int coi1 = 0, coi2 = 0;
-    CvMat srcstub, *src = (CvMat*)srcImage;
-    CvMat mapstub, *map = (CvMat*)undistMap;
-    CvSize size;
-
-    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
-    CV_CALL( map = cvGetMat( map, &mapstub, &coi2 ));
-
-    if( coi1 != 0 || coi2 != 0 )
-        CV_ERROR( CV_BadCOI, "" );
-
-    if( CV_ARR_TYPE( map->type ) != CV_32SC1 && CV_ARR_TYPE( map->type ) != CV_32SC3 )
-        CV_ERROR( CV_StsUnsupportedFormat, "" );
-
-    if( !intrMatrix || !distCoeffs )
-        CV_ERROR( CV_StsNullPtr, "" );
-
-    if( src->height > map->height ||
-        interpolate && src->width*3 > map->width*CV_ARR_CN( map->type ) ||
-        !interpolate && src->width > map->width )
-        CV_ERROR( CV_StsUnmatchedSizes, "" );
-
-    size = icvGetMatSize( src );
-
-    IPPI_CALL( icvUnDistortInit( src->step, (int*)map->data.ptr, map->step,
-                                 size, intrMatrix, distCoeffs,
-                                 interpolate, icvPixSize[CV_ARR_TYPE(src->type)]));
-
-    __END__;
-}
-
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvUnDistort
-//    Purpose: The function corrects radial and tangential distortion in the frame
-//             using previousely calculated arrays of distorted points indices and
-//             undistortion coefficients
-//    Context:
-//    Parameters:  srcImage    - source (distorted) image
-//                 dstImage    - output (undistorted) image
-//                 data        - distortion data array
-//                 interpolate - interpolation toggle (optional parameter)
-//
-//    Notes:  1. If interpolate=0, interpolation disabled;
-//               else (default) bilinear interpolation is used.
-//            2. Array data must be allocated and calculated by the cvUnDistortInit
-//               function before. If interpolate = 0, its length must be
-//               size.width*size.height elements; else 3*size.width*size.height.
-//F*/
-CV_IMPL void
-cvUnDistort( const void* srcImage, void* dstImage,
-             const void* undistMap, int interpolate )
-{
-    CV_FUNCNAME( "cvUnDistort" );
-
-    __BEGIN__;
-
-    int coi1 = 0, coi2 = 0, coi3 = 0;
-    CvMat srcstub, *src = (CvMat*)srcImage;
-    CvMat mapstub, *map = (CvMat*)undistMap;
-    CvMat dststub, *dst = (CvMat*)dstImage;
-    CvSize size;
-
-    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
-    CV_CALL( map = cvGetMat( map, &mapstub, &coi2 ));
-    CV_CALL( dst = cvGetMat( dst, &dststub, &coi3 ));
-
-    if( coi1 != 0 || coi2 != 0 || coi3 != 0 )
-        CV_ERROR( CV_BadCOI, "" );
-
-    if( CV_ARR_TYPE(src->type) != CV_8UC1 && CV_ARR_TYPE(src->type) != CV_8UC3 )
-        CV_ERROR( CV_StsUnsupportedFormat, "" );
-
-    if( !CV_ARE_TYPES_EQ( src, dst ))
-        CV_ERROR( CV_StsUnmatchedFormats, "" );
-
-    if( CV_ARR_TYPE( map->type ) != CV_32SC1 && CV_ARR_TYPE( map->type ) != CV_32SC3 )
-        CV_ERROR( CV_StsUnsupportedFormat, "" );
-
-    if( src->height > map->height ||
-        interpolate && src->width*3 > map->width*CV_ARR_CN( map->type ) ||
-        !interpolate && src->width > map->width )
-        CV_ERROR( CV_StsUnmatchedSizes, "" );
-
-    if( !CV_ARE_SIZES_EQ( src, dst ))
-        CV_ERROR( CV_StsUnmatchedSizes, "" );
-
-    size = icvGetMatSize( src );
-
-    if( CV_ARR_TYPE( src->type ) == CV_8UC1 )
-    {
-        IPPI_CALL( icvUnDistort_8u_C1R( src->data.ptr, src->step,
-                                        (int*)map->data.ptr, map->step,
-                                        dst->data.ptr, dst->step,
-                                        size, interpolate ));
-    }
-    else if( CV_ARR_TYPE( src->type ) == CV_8UC3 )
-    {
-        IPPI_CALL( icvUnDistort_8u_C3R( src->data.ptr, src->step,
-                                        (int*)map->data.ptr, map->step, 
-                                        dst->data.ptr, dst->step,
-                                        size, interpolate ));
-    }
-    else
-    {
-        CV_ERROR( CV_StsUnsupportedFormat, "Undistorted image must have 8uC1 or 8uC3 format" );
-    }
-
-    __END__;
-}
-
-
-/*F//////////////////////////////////////////////////////////////////////////////////////
-//    Name: cvConvertMap
-//    Purpose: The function converts floating-point pixel coordinate map to
-//             faster fixed-point map, used within cvUnDistort (cvRemap)
-//    Context:
-//    Parameters:  flUndistMap - source map: (width x height x 32fC2) or
-//                                           (width*2 x height x 32fC1).
-//                               each pair are pixel coordinates (x,y) in a source image.
-//                 undistMap - resultant map: (width x height x 32sC3) or
-//                                 (width*3 x height x 32sC1) if interpolation is enabled;
-//                                 (width x height x 32sC1) if interpolation is disabled;
-//                 pixelSize - bytes per pixel in images that will be transformed
-//                             using the map. For byte-depth images it is just
-//                             a number of channels.
-//                 interpolate - interpolation flag (turned on by default)
-//F*/
-CV_IMPL void
-cvConvertMap( const CvArr* srcImage, const CvArr* flUndistMap,
-              CvArr* undistMap, int interpolate )
-{
-    CV_FUNCNAME( "cvConvertMap" );
-
-    __BEGIN__;
-
-    int coi1 = 0, coi2 = 0, coi3 = 0;
-    int i, j;
-    CvMat srcstub, *src = (CvMat*)srcImage;
-    CvMat mapstub, *map = (CvMat*)undistMap;
-    CvMat flmapstub, *flmap = (CvMat*)flUndistMap;
-    CvSize size;
-    CvPoint2D32f* flmapdata = 0;
-    int srcStep, pixSize;
-
-    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
-    CV_CALL( map = cvGetMat( map, &mapstub, &coi2 ));
-    CV_CALL( flmap = cvGetMat( flmap, &flmapstub, &coi3 ));
-
-    if( coi1 != 0 || coi2 != 0 || coi3 != 0 )
-        CV_ERROR( CV_BadCOI, "" );
-
-    size = cvGetSize( src );
-
-    if( CV_ARR_DEPTH( flmap->type ) != CV_32F )
-        CV_ERROR( CV_StsUnsupportedFormat, "Source map should have 32f depth" );
-
-    if( CV_ARR_CN( flmap->type ) > 2 ||
-        size.width*2 != flmap->width * CV_ARR_CN( flmap->type ) ||
-        size.height != flmap->height )
-        CV_ERROR( CV_StsUnmatchedSizes, "Source map and source image have unmatched sizes");
-
-    if( CV_ARR_TYPE( map->type ) != CV_32SC1 &&
-        (CV_ARR_TYPE( map->type ) != CV_32SC3 || !interpolate))
-        CV_ERROR( CV_StsUnsupportedFormat, "" );
-
-    if( map->height != size.height ||
-        interpolate && size.width*3 != map->width*CV_ARR_CN( map->type ) ||
-        !interpolate && size.width != map->width )
-        CV_ERROR( CV_StsUnmatchedSizes, "" );
-
-    flmapdata = (CvPoint2D32f*)flmap->data.ptr;
-    pixSize = icvPixSize[CV_ARR_TYPE(src->type)];
-    srcStep = src->step;
-
-    if( !interpolate )
-    {
-        int* mapdata = (int*)map->data.ptr;
-
-        for( i = 0; i < size.height; i++, (char*&)flmapdata += flmap->step,
-                                          (char*&)mapdata += map->step )
-        {
-            for( j = 0; j < size.width; j++ )
-            {
-                int ix = cvRound(flmapdata[j].x);
-                int iy = cvRound(flmapdata[j].y);
-
-                if( (unsigned)ix < (unsigned)size.width &&
-                    (unsigned)iy < (unsigned)size.height )
-                    mapdata[j] = iy*srcStep + ix*pixSize;
-                else
-                    mapdata[j] = 0;
-            }
-        }
-    }
-    else
-    {
-        CvUnDistortData* mapdata = (CvUnDistortData*)map->data.ptr;
-
-        for( i = 0; i < size.height; i++, (char*&)flmapdata += flmap->step,
-                                          (char*&)mapdata += map->step )
-        {
-            for( j = 0; j < size.width; j++ )
-            {
-                float x = flmapdata[j].x;
-                float y = flmapdata[j].y;
-                int ix = cvFloor(x);
-                int iy = cvFloor(y);
-
-                x -= ix;
-                y -= iy;
-
-                if( (unsigned)ix < (unsigned)(size.width-1) &&
-                    (unsigned)iy < (unsigned)(size.height-1) )
-                {
-                    mapdata[j].ind = iy*srcStep + ix*pixSize;
-                    mapdata[j].a0 = (ushort)cvRound((1.f - x)*(1.f - y)*(1 << 15));
-                    mapdata[j].a1 = (ushort)cvRound(x*(1.f - y)*(1 << 15));
-                    mapdata[j].a2 = (ushort)cvRound((1.f - x)*y*(1 << 15));
-                    mapdata[j].a3 = (ushort)cvRound(x*y*(1 << 15));
-                }
-                else
-                {
-                    mapdata[j].ind = 0;
-                    mapdata[j].a0 = 0;
-                    mapdata[j].a1 = 0;
-                    mapdata[j].a2 = 0;
-                    mapdata[j].a3 = 0;
-                }
-            }
-        }
-    }
-
-    __END__;
-}
-
-/*  End of file  */
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+#include "_cv.h"\r
+\r
+typedef struct CvUnDistortData\r
+{\r
+    int ind;\r
+    ushort a0;\r
+    ushort a1;\r
+    ushort a2;\r
+    ushort a3;\r
+}\r
+CvUnDistortData;\r
+\r
+/*F//////////////////////////////////////////////////////////////////////////////////////\r
+//    Names: icvUnDistortInit_8uC1R, icvUnDistortInit_8uC3R, \r
+//    Purpose: The functions calculate arrays of distorted points indices and\r
+//             interpolation coefficients for cvUnDistort function\r
+//    Context:\r
+//    Parameters:  size        - size of each image or of its ROI\r
+//                 step        - full width of each image in bytes\r
+//                 intrMatrix  - matrix of the camera intrinsic parameters\r
+//                 distCoeffs  - vector of the distortion coefficients (k1, k2, p1 and p2)\r
+//                 interToggle - interpolation toggle\r
+//                 data        - distortion data array\r
+//\r
+//    Returns: CV_NO_ERR or error code\r
+//\r
+//    Notes:  1. If interToggle=0, interpolation disabled;\r
+//               else bilinear interpolation is used.\r
+//            2. Array data must be allocated before. If interToggle = 0, its length\r
+//               must be size.width*size.height elements; else 3*size.width*size.height.\r
+//F*/\r
+/*______________________________________________________________________________________*/\r
+\r
+IPCVAPI_IMPL( CvStatus, icvUnDistortInit, ( int srcStep, int* data,\r
+                                            int mapStep, CvSize size,\r
+                                            const float *intrMatrix,\r
+                                            const float *distCoeffs,\r
+                                            int interToggle, int pixSize ))\r
+{\r
+    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],\r
+        u0 = intrMatrix[2], v0 = intrMatrix[5],\r
+        k1 = distCoeffs[0], k2 = distCoeffs[1], p1 = distCoeffs[2], p2 = distCoeffs[3];\r
+    int u, v;\r
+    float p22 = 2.f * p2;\r
+\r
+    if( size.width <= 0 || size.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+\r
+    if( !intrMatrix || !distCoeffs || !data )\r
+        return CV_NULLPTR_ERR;\r
+\r
+    if( !interToggle )\r
+    {\r
+        for( v = 0; v < size.height; v++, (char*&)data += mapStep )\r
+        {\r
+            float dv = v - v0;\r
+            float y = b1 * dv;\r
+            float y1 = p1 / y;\r
+            float y2 = y * y;\r
+            float y3 = 2.f * p1 * y;\r
+\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float du = u - u0;\r
+                float x = a1 * du;\r
+                float x1 = p2 / x;\r
+                float x2 = x * x;\r
+                float x3 = p22 * x;\r
+                float r2 = x2 + y2;\r
+                float bx = r2 * (k1 + r2 * k2) + x3 + y3;\r
+                float by = bx + r2 * y1;\r
+                int ud = u, vd = v;\r
+\r
+                bx += r2 * x1;\r
+                ud += cvRound( bx * du );\r
+                vd += cvRound( by * dv );\r
+                data[u] = ud < 0 || ud >= size.width || vd < 0 || vd >= size.height ?\r
+                    0 : vd * srcStep + ud*pixSize;\r
+            }\r
+        }\r
+    }\r
+    else                        /* interpolation */\r
+    {\r
+        const int sizex = size.width - 2, sizey = size.height - 2;\r
+        CvUnDistortData *uData = (CvUnDistortData *) data;\r
+\r
+        const float s15 = 32768.f;\r
+        const int bmax = 32767;\r
+\r
+        for( v = 0; v < size.height; v++, (char*&)uData += mapStep )\r
+        {\r
+            float dv = v - v0;\r
+            float y = b1 * dv;\r
+            float y1 = p1 / y;\r
+            float y2 = y * y;\r
+            float y3 = 2.f * p1 * y;\r
+\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float du = u - u0;\r
+                float x = a1 * du;\r
+                float x1 = p2 / x;\r
+                float x2 = x * x;\r
+                float x3 = p22 * x;\r
+                float r2 = x2 + y2;\r
+                float bx = r2 * (k1 + r2 * k2) + x3 + y3;\r
+                float by = bx + r2 * y1;\r
+                float uf = (float) u, vf = (float) v;\r
+                int ud, vd;\r
+\r
+                bx += r2 * x1;\r
+                uf += bx * du;\r
+                vf += by * dv;\r
+                ud = cvFloor( uf );\r
+                vd = cvFloor( vf );\r
+                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )\r
+                {\r
+                    (uData + u)->ind = 0;\r
+                    (uData + u)->a0 = (uData + u)->a1 = (uData + u)->a2 = (uData + u)->a3 =\r
+                    (ushort) 0;\r
+                }\r
+                else\r
+                {\r
+                    float uf1, vf1;\r
+                    int b0, b1, b2, b3;\r
+\r
+                    (uData + u)->ind = vd * srcStep + ud*pixSize;\r
+                    uf -= (float) ud;\r
+                    vf -= (float) vd;\r
+                    uf1 = 1.f - uf;\r
+                    vf1 = 1.f - vf;\r
+                    b0 = (int) (s15 * uf1 * vf1);\r
+                    b1 = (int) (s15 * uf * vf1);\r
+                    b2 = (int) (s15 * uf1 * vf);\r
+                    b3 = (int) (s15 * uf * vf);\r
+                    if( b0 < 0 )\r
+                        b0 = 0;\r
+                    if( b1 < 0 )\r
+                        b1 = 0;\r
+                    if( b2 < 0 )\r
+                        b2 = 0;\r
+                    if( b3 < 0 )\r
+                        b3 = 0;\r
+                    if( b0 > bmax )\r
+                        b0 = bmax;\r
+                    if( b1 > bmax )\r
+                        b1 = bmax;\r
+                    if( b2 > bmax )\r
+                        b2 = bmax;\r
+                    if( b3 > bmax )\r
+                        b3 = bmax;\r
+                    (uData + u)->a0 = (ushort) b0;\r
+                    (uData + u)->a1 = (ushort) b1;\r
+                    (uData + u)->a2 = (ushort) b2;\r
+                    (uData + u)->a3 = (ushort) b3;\r
+                }\r
+            }                   /* u */\r
+        }                       /* v */\r
+    }                           /* else */\r
+\r
+    return CV_NO_ERR;\r
+}\r
+\r
+/*======================================================================================*/\r
+\r
+/*F//////////////////////////////////////////////////////////////////////////////////////\r
+//    Names: icvUnDistort_8u_C1R, icvUnDistort_8u_C3R\r
+//    Purpose: The functions correct radial and tangential distortion in the frame\r
+//             using previousely calculated arrays of distorted points indices and\r
+//             undistortion coefficients\r
+//    Context:\r
+//    Parameters:  src    - source (distorted) image\r
+//                 dst    - output (undistorted) image\r
+//                 step        - full width of each image in bytes\r
+//                 size        - size of each image or of its ROI\r
+//                 interToggle - interpolation toggle\r
+//                 data        - distortion data array\r
+//\r
+//    Returns: CV_NO_ERR or error code\r
+//\r
+//    Notes:  1. Either icvUnDistortInit_8u_C1R or icvUnDistortInit_8u_C3R function\r
+//               must be used previously\r
+//            2. See Notes to the icvUnDistortInit_8u_C1R, icvUnDistortInit_8u_C3R\r
+//               functions\r
+//F*/\r
+/*______________________________________________________________________________________*/\r
+\r
+IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C1R, ( const uchar* src, int srcStep,\r
+                                               const int* data, int mapStep,\r
+                                               uchar* dst, int dstStep,\r
+                                               CvSize size, int interToggle ))\r
+{\r
+    int u, v;\r
+    uchar buf;\r
+\r
+    if( size.width <= 0 || size.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+\r
+    if( !src || !dst || !data )\r
+        return CV_NULLPTR_ERR;\r
+\r
+    buf = *src;\r
+    *(uchar*&)src = (uchar)0;\r
+\r
+    if( !interToggle )          /* Interpolation disabled */\r
+    {\r
+        for( v = 0; v < size.height; v++, dst += dstStep, (char*&)data += mapStep )\r
+        {\r
+            for( u = 0; u <= size.width - 4; u += 4 )\r
+            {\r
+                uchar t0 = src[data[u]];\r
+                uchar t1 = src[data[u+1]];\r
+\r
+                dst[u] = t0;\r
+                dst[u + 1] = t1;\r
+\r
+                t0 = src[data[u+2]];\r
+                t1 = src[data[u+3]];\r
+\r
+                dst[u + 2] = t0;\r
+                dst[u + 3] = t1;\r
+            }\r
+\r
+            for( ; u < size.width; u++ )\r
+            {\r
+                dst[u] = src[data[u]];\r
+            }\r
+        }\r
+    }\r
+    else /* Interpolation enabled */\r
+    {\r
+        CvUnDistortData *uData = (CvUnDistortData *) data;\r
+\r
+        for( v = 0; v < size.height; v++, dst += dstStep, (char*&)uData += mapStep )\r
+        {\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                CvUnDistortData d = uData[u];\r
+                const uchar* s = src + d.ind;\r
+\r
+                dst[u] = (uchar)((s[0]*d.a0 + s[1]*d.a1 +\r
+                        s[srcStep]*d.a2 + s[srcStep+1]*d.a3) >> 15);\r
+            }\r
+        }\r
+    }\r
+\r
+    *(uchar*&)src = buf;\r
+    return CV_NO_ERR;\r
+}\r
+\r
+\r
+#define ICV_COPY_C3( src_ptr, dst_ptr ) \\r
+    (dst_ptr)[0] = (src_ptr)[0];        \\r
+    t0 = (src_ptr)[1];                  \\r
+    t1 = (src_ptr)[2];                  \\r
+    (dst_ptr)[1] = t0;                  \\r
+    (dst_ptr)[2] = t1\r
+   \r
+\r
+/*_____________________________ 3-CHANNEL IMAGES _______________________________*/\r
+\r
+IPCVAPI_IMPL( CvStatus, icvUnDistort_8u_C3R, ( const uchar* src, int srcStep,\r
+                                               const int* data, int mapStep,\r
+                                               uchar* dst, int dstStep,\r
+                                               CvSize size, int interToggle ))\r
+{\r
+    int u, v;\r
+    uchar buf[3];\r
+\r
+    if( size.width <= 0 || size.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+\r
+    if( !src || !dst || !data )\r
+        return CV_NULLPTR_ERR;\r
+\r
+    memcpy( buf, src, 3 );\r
+    memset( (void*)src, 0, 3 );\r
+\r
+    if( !interToggle )          /* Interpolation disabled */\r
+    {\r
+        for( v = 0; v < size.height; v++, dst += dstStep, (char*&)data += mapStep )\r
+        {\r
+            for( u = 0; u <= size.width - 4; u += 4, dst += 12 )\r
+            {\r
+                uchar t0, t1;\r
+\r
+                int v3 = data[u];\r
+                ICV_COPY_C3( src + v3, dst );\r
+\r
+                v3 = data[u + 1];\r
+                ICV_COPY_C3( src + v3, dst + 3 );\r
+\r
+                v3 = data[u + 2];\r
+                ICV_COPY_C3( src + v3, dst + 6 );\r
+\r
+                v3 = data[u + 3];\r
+                ICV_COPY_C3( src + v3, dst + 9 );\r
+            }\r
+\r
+            for( ; u < size.width; u++, dst += 3 )\r
+            {\r
+                int v3 = data[u];\r
+                uchar t0, t1;\r
+\r
+                ICV_COPY_C3( src + v3, dst );\r
+            }\r
+\r
+            dst -= size.width * 3;\r
+        }\r
+    }\r
+    else  /* Interpolation enabled */\r
+    {\r
+        CvUnDistortData *uData = (CvUnDistortData *) data;\r
+\r
+        for( v = 0; v < size.height; v++, dst += dstStep, (char*&)uData += mapStep )\r
+        {\r
+            for( u = 0; u < size.width; u++, dst += 3 )\r
+            {\r
+                CvUnDistortData d = uData[u];\r
+                const uchar* s = src + d.ind;\r
+\r
+                dst[0] = (uchar) ((s[0] * d.a0 + s[3] * d.a1 +\r
+                                   s[srcStep] * d.a2 + s[srcStep + 3] * d.a3) >> 15);\r
+\r
+                dst[1] = (uchar) ((s[1] * d.a0 + s[4] * d.a1 +\r
+                                   s[srcStep + 1] * d.a2 + s[srcStep + 4] * d.a3) >> 15);\r
+\r
+                dst[2] = (uchar) ((s[2] * d.a0 + s[5] * d.a1 +\r
+                                   s[srcStep + 2] * d.a2 + s[srcStep + 5] * d.a3) >> 15);\r
+            }\r
+\r
+            dst -= size.width * 3;\r
+        }\r
+    }\r
+\r
+    memcpy( (void*)src, buf, 3 );\r
+    return CV_NO_ERR;\r
+}\r
+\r
+/*======================================================================================*/\r
+\r
+/*F//////////////////////////////////////////////////////////////////////////////////////\r
+//    Names: icvUnDistort1_8uC1R, icvUnDistort1_8uC3R\r
+//    Purpose: The functions correct radial image distortion using known matrix of the\r
+//             camera intrinsic parameters and distortion coefficients\r
+//    Context:\r
+//    Parameters:  src    - source (distorted) image\r
+//                 dst    - output (undistorted) image\r
+//                 step        - full width of each image in bytes\r
+//                 size        - ROI size of each image\r
+//                 intrMatrix  - matrix of the camera intrinsic parameters\r
+//                 distCoeffs  - vector of two distortion coefficients (k1 and k2)\r
+//                 interToggle - interpolation toggle\r
+//\r
+//    Returns: CV_NO_ERR or error code\r
+//\r
+//    Notes:   If interToggle=0, interpolation disabled;\r
+//             else bilinear interpolation is used.\r
+//F*/\r
+/*______________________________________________________________________________________*/\r
+\r
+#define S  22\r
+#define S2 11\r
+#define FM (float)0x400000\r
+\r
+IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C1R, ( const uchar* src, int srcStep,\r
+                                                uchar* dst, int dstStep, CvSize size,\r
+                                                const float *intrMatrix,\r
+                                                const float *distCoeffs,\r
+                                                int interToggle ))\r
+{\r
+    const float fm = FM;\r
+    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],\r
+        u0 = intrMatrix[2], v0 = intrMatrix[5], k1 = distCoeffs[0], k2 = distCoeffs[1];\r
+    float *x2;\r
+    float *du;\r
+    int u, v;\r
+    uchar buf[1];\r
+\r
+    if( size.width <= 0 || size.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+    if( !src || !dst || !intrMatrix || !distCoeffs )\r
+        return CV_NULLPTR_ERR;\r
+\r
+    x2 = (float *) icvAlloc( sizeof( float ) * size.width );\r
+\r
+    if( x2 == NULL )\r
+        return CV_OUTOFMEM_ERR;\r
+    du = (float *) icvAlloc( sizeof( float ) * size.width );\r
+\r
+    if( du == NULL )\r
+    {\r
+        icvFree( (void **) &x2 );\r
+        return CV_OUTOFMEM_ERR;\r
+    }\r
+\r
+    memcpy( buf, src, 1 );\r
+    memset( (void*)src, 0, 1 );\r
+\r
+    if( !interToggle )\r
+    {\r
+        for( u = 0; u < size.width; u++ )\r
+        {\r
+            float w = u - u0;\r
+            float x = a1 * w;\r
+\r
+            x2[u] = x * x;\r
+            du[u] = w;\r
+        }\r
+        for( v = 0; v < size.height; v++, dst += dstStep )\r
+        {\r
+            float y = b1 * (v - v0);\r
+            float y2 = y * y;\r
+            float dv = v - v0;\r
+\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float dist = r2 * (k1 + r2 * k2);\r
+                int ud = u + cvRound( du[u] * dist );\r
+                int vd = v + cvRound( dv * dist );\r
+\r
+                dst[u] = (uchar) (ud < 0 || ud >= size.width || vd < 0 ||\r
+                                       vd >= size.height ? 0 : src[vd * srcStep + ud]);\r
+            }\r
+        }\r
+    }\r
+    else\r
+    {\r
+        int sizex = size.width - 2, sizey = size.height - 2;\r
+\r
+        for( u = 0; u < size.width; u++ )\r
+        {\r
+            float w = u - u0;\r
+            float x = a1 * w;\r
+\r
+            x2[u] = x * x;\r
+            du[u] = fm * w;\r
+        }\r
+        for( v = 0; v < size.height; v++, dst += dstStep )\r
+        {\r
+            float y = b1 * (v - v0);\r
+            float y2 = y * y;\r
+            float dv = fm * (v - v0);\r
+\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float dist = r2 * (k1 + r2 * k2);\r
+                int iu = cvRound( du[u] * dist );\r
+                int iv = cvRound( dv * dist );\r
+                int ud = iu >> S;\r
+                int vd = iv >> S;\r
+\r
+                iu -= ud << S;\r
+                iv -= vd << S;\r
+                ud += u;\r
+                vd += v;\r
+\r
+                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )\r
+                    dst[u] = 0;\r
+                else\r
+                {\r
+                    int iuv = (iu >> S2) * (iv >> S2);\r
+                    int uv = vd * srcStep + ud;\r
+                    int a0 = src[uv];\r
+                    int a = src[uv + 1] - a0;\r
+                    int b = src[uv + srcStep] - a0;\r
+                    int c = src[uv + srcStep + 1] - a0 - a - b;\r
+                    int d = ((a * iu + b * iv + c * iuv) >> S) + a0;\r
+\r
+                    d = !(d & ~255) ? d : d < 0 ? 0 : 255;\r
+                    dst[u] = (uchar) d;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    memcpy( (void*)src, buf, 1 );\r
+\r
+    icvFree( (void **) &x2 );\r
+    icvFree( (void **) &du );\r
+    return CV_NO_ERR;\r
+}\r
+/*______________________________________________________ 3-CHANNEL IMAGES ______________*/\r
+\r
+IPCVAPI_IMPL( CvStatus, icvUnDistort1_8u_C3R, ( const uchar* src, int srcStep,\r
+                                                uchar* dst, int dstStep, CvSize size,\r
+                                                const float *intrMatrix,\r
+                                                const float *distCoeffs,\r
+                                                int interToggle ))\r
+{\r
+    const float fm = FM;\r
+    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],\r
+        u0 = intrMatrix[2], v0 = intrMatrix[5], k1 = distCoeffs[0], k2 = distCoeffs[1];\r
+    const int p = 0xFFFFFF;\r
+    float *x2;\r
+    float *du;\r
+    int u, v;\r
+    uchar buf[3];\r
+\r
+    if( size.width <= 0 || size.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+    if( !src || !dst || !intrMatrix || !distCoeffs )\r
+        return CV_NULLPTR_ERR;\r
+\r
+    x2 = (float *) icvAlloc( sizeof( float ) * size.width );\r
+\r
+    if( x2 == NULL )\r
+        return CV_OUTOFMEM_ERR;\r
+    du = (float *) icvAlloc( sizeof( float ) * size.width );\r
+\r
+    if( du == NULL )\r
+    {\r
+        icvFree( (void **) &x2 );\r
+        return CV_OUTOFMEM_ERR;\r
+    }\r
+\r
+    memcpy( buf, src, 3 );\r
+    memset( (void*)src, 0, 3 );\r
+\r
+    if( !interToggle )\r
+    {\r
+        for( u = 0; u < size.width; u++ )\r
+        {\r
+            float w = u - u0;\r
+            float x = a1 * w;\r
+\r
+            x2[u] = x * x;\r
+            du[u] = w;\r
+        }\r
+\r
+        for( v = 0; v < size.height; v++, dst += dstStep )\r
+        {\r
+            float y = b1 * (v - v0);\r
+            float y2 = y * y;\r
+            float dv = v - v0;\r
+\r
+            if( v == size.height - 1 )\r
+                size.width--;\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float dist = r2 * (k1 + r2 * k2);\r
+                int ud = u + cvRound( du[u] * dist );\r
+                int vd = v + cvRound( dv * dist );\r
+                int u3 = u + u + u;\r
+\r
+                if( ud < 0 || ud >= size.width || vd < 0 || vd >= size.height )\r
+                    *(int *) (dst + u3) = 0;\r
+                else\r
+                {\r
+                    int uv = vd * srcStep + ud + ud + ud;\r
+\r
+                    *(int *) (dst + u3) = *(int *) (src + uv) & p;\r
+                }\r
+            }\r
+            if( v == size.height - 1 )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float dist = r2 * (k1 + r2 * k2);\r
+                int ud = u + cvRound( du[u] * dist );\r
+                int vd = v + cvRound( dv * dist );\r
+                int u3 = u + u + u;\r
+\r
+                size.width++;\r
+                if( ud < 0 || ud >= size.width || vd < 0 || vd >= size.height )\r
+                    dst[u3] = dst[u3 + 1] = dst[u3 + 2] = 0;\r
+                else\r
+                {\r
+                    int uv = vd * srcStep + ud + ud + ud;\r
+\r
+                    dst[u3] = src[uv];\r
+                    dst[u3 + 1] = src[uv + 1];\r
+                    dst[u3 + 2] = src[uv + 2];\r
+                }\r
+            }\r
+        }\r
+    }\r
+    else                        /* interpolation */\r
+    {\r
+        int sizex = size.width - 2, sizey = size.height - 2;\r
+\r
+        for( u = 0; u < size.width; u++ )\r
+        {\r
+            float w = u - u0;\r
+            float x = a1 * w;\r
+\r
+            x2[u] = x * x;\r
+            du[u] = fm * w;\r
+        }\r
+\r
+        for( v = 0; v < size.height; v++, dst += dstStep )\r
+        {\r
+            float y = b1 * (v - v0);\r
+            float y2 = y * y;\r
+            float dv = fm * (v - v0);\r
+\r
+            if( v == size.height - 1 )\r
+                size.width--;\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float dist = r2 * (k1 + r2 * k2);\r
+                int iu = cvRound( du[u] * dist );\r
+                int iv = cvRound( dv * dist );\r
+                int ud = iu >> S;\r
+                int vd = iv >> S;\r
+                int u3 = u + u + u;\r
+\r
+                iu -= ud << S;\r
+                iv -= vd << S;\r
+                ud += u;\r
+                vd += v;\r
+\r
+                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )\r
+                    *(int *) (dst + u3) = 0;\r
+                else\r
+                {\r
+                    int iuv = (iu >> S2) * (iv >> S2);\r
+                    int uv = vd * srcStep + ud + ud + ud;\r
+                    int uvs = uv + srcStep;\r
+                    int a01 = src[uv];\r
+                    int a02 = src[uv + 1];\r
+                    int a03 = src[uv + 2];\r
+                    int a1 = src[uv + 3];\r
+                    int a2 = src[uv + 4];\r
+                    int a3 = src[uv + 5];\r
+                    int b1 = src[uvs];\r
+                    int b2 = src[uvs + 1];\r
+                    int b3 = src[uvs + 2];\r
+                    int c1 = src[uvs + 3];\r
+                    int c2 = src[uvs + 4];\r
+                    int c3 = src[uvs + 5];\r
+                    int d1, d2, d3;\r
+\r
+                    a1 -= a01;\r
+                    a2 -= a02;\r
+                    a3 -= a03;\r
+                    b1 -= a01;\r
+                    b2 -= a02;\r
+                    b3 -= a03;\r
+                    c1 -= a01 + a1 + b1;\r
+                    c2 -= a02 + a2 + b2;\r
+                    c3 -= a03 + a3 + b3;\r
+                    d1 = ((a1 * iu + b1 * iv + c1 * iuv) >> S) + a01;\r
+                    d2 = ((a2 * iu + b2 * iv + c2 * iuv) >> S) + a02;\r
+                    d3 = ((a3 * iu + b3 * iv + c3 * iuv) >> S) + a03;\r
+                    d1 = !(d1 & ~255) ? d1 : d1 < 0 ? 0 : 255;\r
+                    d2 = !(d2 & ~255) ? d2 : d2 < 0 ? 0 : 255;\r
+                    d3 = !(d3 & ~255) ? d3 : d3 < 0 ? 0 : 255;\r
+                    d1 |= (d2 << 8) | (d3 << 16);\r
+                    *(int *) (dst + u3) = d1;\r
+                }\r
+            }\r
+            if( v == size.height - 1 )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float dist = r2 * (k1 + r2 * k2);\r
+                int iu = cvRound( du[u] * dist );\r
+                int iv = cvRound( dv * dist );\r
+                int ud = iu >> S;\r
+                int vd = iv >> S;\r
+                int u3 = u + u + u;\r
+\r
+                size.width++;\r
+                iu -= ud << S;\r
+                iv -= vd << S;\r
+                ud += u;\r
+                vd += v;\r
+\r
+                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )\r
+                    dst[u3] = dst[u3 + 1] = dst[u3 + 2] = 0;\r
+                else\r
+                {\r
+                    int iuv = (iu >> S2) * (iv >> S2);\r
+                    int uv = vd * srcStep + ud + ud + ud;\r
+                    int uvs = uv + srcStep;\r
+                    int a01 = src[uv];\r
+                    int a02 = src[uv + 1];\r
+                    int a03 = src[uv + 2];\r
+                    int a1 = src[uv + 3];\r
+                    int a2 = src[uv + 4];\r
+                    int a3 = src[uv + 5];\r
+                    int b1 = src[uvs];\r
+                    int b2 = src[uvs + 1];\r
+                    int b3 = src[uvs + 2];\r
+                    int c1 = src[uvs + 3];\r
+                    int c2 = src[uvs + 4];\r
+                    int c3 = src[uvs + 5];\r
+                    int d1, d2, d3;\r
+\r
+                    a1 -= a01;\r
+                    a2 -= a02;\r
+                    a3 -= a03;\r
+                    b1 -= a01;\r
+                    b2 -= a02;\r
+                    b3 -= a03;\r
+                    c1 -= a01 + a1 + b1;\r
+                    c2 -= a02 + a2 + b2;\r
+                    c3 -= a03 + a3 + b3;\r
+                    d1 = ((a1 * iu + b1 * iv + c1 * iuv) >> S) + a01;\r
+                    d2 = ((a2 * iu + b2 * iv + c2 * iuv) >> S) + a02;\r
+                    d3 = ((a3 * iu + b3 * iv + c3 * iuv) >> S) + a03;\r
+                    dst[u3] = (uchar) d1;\r
+                    dst[u3 + 1] = (uchar) d2;\r
+                    dst[u3 + 2] = (uchar) d3;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    memcpy( (void*)src, buf, 1 );\r
+\r
+    icvFree( (void **) &x2 );\r
+    icvFree( (void **) &du );\r
+    return CV_NO_ERR;\r
+}\r
+\r
+/*======================================================================================*/\r
+\r
+/*F//////////////////////////////////////////////////////////////////////////////////////\r
+//    Names: icvUnDistortEx_8uC1R, icvUnDistortEx_8uC3R\r
+//    Purpose: The functions correct radial and tangential image distortions using known\r
+//             matrix of the camera intrinsic parameters and distortion coefficients\r
+//    Context:\r
+//    Parameters:  src    - source (distorted) image\r
+//                 dst    - output (undistorted) image\r
+//                 step        - full width of each image in bytes\r
+//                 size        - ROI size of each image\r
+//                 intrMatrix  - matrix of the camera intrinsic parameters\r
+//                 distCoeffs  - vector of the distortion coefficients\r
+//                               (k1, k2, p1, p2)\r
+//                 interToggle - interpolation toggle\r
+//\r
+//    Returns: CV_NO_ERR or error code\r
+//\r
+//    Notes:   If interToggle=0, interpolation disabled;\r
+//             else bilinear interpolation is used.\r
+//F*/\r
+/*______________________________________________________________________________________*/\r
+\r
+IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C1R, ( const uchar* src, int srcStep,\r
+                                                 uchar* dst, int dstStep, CvSize size,\r
+                                                 const float *intrMatrix,\r
+                                                 const float *distCoeffs,\r
+                                                 int interToggle ))\r
+{\r
+    const float fm = FM;\r
+    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],\r
+        u0 = intrMatrix[2], v0 = intrMatrix[5],\r
+        k1 = distCoeffs[0], k2 = distCoeffs[1], p1 = distCoeffs[2], p2 = distCoeffs[3];\r
+    float *x1;\r
+    float *x2;\r
+    float *x3;\r
+    float *du;\r
+    int u, v;\r
+    uchar buf[1];\r
+\r
+    if( size.width <= 0 || size.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+    if( !src || !dst || !intrMatrix || !distCoeffs )\r
+        return CV_NULLPTR_ERR;\r
+\r
+    /*if ( !p1 && !p2 ) return icvUnDistort1_8uC1R ( src, dst, step, size,\r
+       intrMatrix, distCoeffs, interToggle ); */\r
+\r
+    x1 = (float *) icvAlloc( sizeof( float ) * size.width );\r
+    x2 = (float *) icvAlloc( sizeof( float ) * size.width );\r
+    x3 = (float *) icvAlloc( sizeof( float ) * size.width );\r
+    du = (float *) icvAlloc( sizeof( float ) * size.width );\r
+\r
+    if( x1 == NULL || x2 == NULL || x3 == NULL || du == NULL )\r
+    {\r
+        if( x1 )\r
+            icvFree( (void **) &x1 );\r
+        if( x2 )\r
+            icvFree( (void **) &x2 );\r
+        if( x3 )\r
+            icvFree( (void **) &x3 );\r
+        if( du )\r
+            icvFree( (void **) &du );\r
+        return CV_OUTOFMEM_ERR;\r
+    }\r
+\r
+    memcpy( buf, src, 1 );\r
+    memset( (void*)src, 0, 1 );\r
+\r
+    if( !interToggle )\r
+    {\r
+        for( u = 0; u < size.width; u++ )\r
+        {\r
+            float w = u - u0;\r
+            float x = a1 * w;\r
+\r
+            x1[u] = p2 / x;\r
+            x2[u] = x * x;\r
+            x3[u] = 2.f * p2 * x;\r
+            du[u] = w;\r
+        }\r
+\r
+        for( v = 0; v < size.height; v++, dst += dstStep )\r
+        {\r
+            float dv = v - v0;\r
+            float y = b1 * dv;\r
+            float y1 = p1 / y;\r
+            float y2 = y * y;\r
+            float y3 = 2.f * p1 * y;\r
+\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;\r
+                float by = bx + r2 * y1;\r
+                int ud = u, vd = v;\r
+\r
+                bx += r2 * x1[u];\r
+                ud += cvRound( bx * du[u] );\r
+                vd += cvRound( by * dv );\r
+                dst[u] = (uchar) (ud < 0 || ud >= size.width || vd < 0 ||\r
+                                       vd >= size.height ? 0 : src[vd * srcStep + ud]);\r
+            }\r
+        }\r
+    }\r
+    else                        /* interpolation */\r
+    {\r
+        int sizex = size.width - 2, sizey = size.height - 2;\r
+\r
+        for( u = 0; u < size.width; u++ )\r
+        {\r
+            float w = u - u0;\r
+            float x = a1 * w;\r
+\r
+            x1[u] = p2 / x;\r
+            x2[u] = x * x;\r
+            x3[u] = 2.f * p2 * x;\r
+            du[u] = fm * w;\r
+        }\r
+\r
+        for( v = 0; v < size.height; v++, dst += dstStep )\r
+        {\r
+            float dv = v - v0;\r
+            float y = b1 * dv;\r
+            float y1 = p1 / y;\r
+            float y2 = y * y;\r
+            float y3 = 2.f * p1 * y;\r
+\r
+            dv *= fm;\r
+\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;\r
+                float by = bx + r2 * y1;\r
+                int iu, iv, ud, vd;\r
+\r
+                bx += r2 * x1[u];\r
+                iu = cvRound( bx * du[u] );\r
+                iv = cvRound( by * dv );\r
+                ud = iu >> S;\r
+                vd = iv >> S;\r
+                iu -= ud << S;\r
+                iv -= vd << S;\r
+                ud += u;\r
+                vd += v;\r
+\r
+                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )\r
+                    dst[u] = 0;\r
+                else\r
+                {\r
+                    int iuv = (iu >> S2) * (iv >> S2);\r
+                    int uv = vd * srcStep + ud;\r
+                    int a0 = src[uv];\r
+                    int a = src[uv + 1] - a0;\r
+                    int b = src[uv + srcStep] - a0;\r
+                    int c = src[uv + srcStep + 1] - a0 - a - b;\r
+                    int d = ((a * iu + b * iv + c * iuv) >> S) + a0;\r
+\r
+                    d = !(d & ~255) ? d : d < 0 ? 0 : 255;\r
+                    dst[u] = (uchar) d;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    memcpy( (void*)src, buf, 1 );\r
+\r
+    icvFree( (void **) &x1 );\r
+    icvFree( (void **) &x2 );\r
+    icvFree( (void **) &x3 );\r
+    icvFree( (void **) &du );\r
+    return CV_NO_ERR;\r
+}\r
+/*______________________________________________________ 3-CHANNEL IMAGES ______________*/\r
+\r
+IPCVAPI_IMPL( CvStatus, icvUnDistortEx_8u_C3R, ( const uchar* src, int srcStep,\r
+                                                 uchar* dst, int dstStep, CvSize size,\r
+                                                 const float *intrMatrix,\r
+                                                 const float *distCoeffs,\r
+                                                 int interToggle ))\r
+{\r
+    const float fm = FM;\r
+    const float a1 = 1.f / intrMatrix[0], b1 = 1.f / intrMatrix[4],\r
+        u0 = intrMatrix[2], v0 = intrMatrix[5],\r
+        k1 = distCoeffs[0], k2 = distCoeffs[1], p1 = distCoeffs[2], p2 = distCoeffs[3];\r
+    const int p = 0xFFFFFF;\r
+    float *x1;\r
+    float *x2;\r
+    float *x3;\r
+    float *du;\r
+    int u, v;\r
+    uchar buf[3];\r
+\r
+    if( size.width <= 0 || size.height <= 0 )\r
+        return CV_BADSIZE_ERR;\r
+    if( !src || !dst || !intrMatrix || !distCoeffs )\r
+        return CV_NULLPTR_ERR;\r
+\r
+    /*if ( !p1 && !p2 ) return icvUnDistort1_8uC3R ( src, dst, srcStep, size,\r
+       intrMatrix, distCoeffs, interToggle ); */\r
+\r
+    x1 = (float *) icvAlloc( sizeof( float ) * size.width );\r
+    x2 = (float *) icvAlloc( sizeof( float ) * size.width );\r
+    x3 = (float *) icvAlloc( sizeof( float ) * size.width );\r
+    du = (float *) icvAlloc( sizeof( float ) * size.width );\r
+\r
+    if( x1 == NULL || x2 == NULL || x3 == NULL || du == NULL )\r
+    {\r
+        if( x1 )\r
+            icvFree( (void **) &x1 );\r
+        if( x2 )\r
+            icvFree( (void **) &x2 );\r
+        if( x3 )\r
+            icvFree( (void **) &x3 );\r
+        if( du )\r
+            icvFree( (void **) &du );\r
+        return CV_OUTOFMEM_ERR;\r
+    }\r
+\r
+    memcpy( buf, src, 3 );\r
+    memset( (void*)src, 0, 3 );\r
+    \r
+    if( !interToggle )\r
+    {\r
+        for( u = 0; u < size.width; u++ )\r
+        {\r
+            float w = u - u0;\r
+            float x = a1 * w;\r
+\r
+            x1[u] = p2 / x;\r
+            x2[u] = x * x;\r
+            x3[u] = 2.f * p2 * x;\r
+            du[u] = w;\r
+        }\r
+\r
+        for( v = 0; v < size.height; v++, dst += dstStep )\r
+        {\r
+            float dv = v - v0;\r
+            float y = b1 * dv;\r
+            float y1 = p1 / y;\r
+            float y2 = y * y;\r
+            float y3 = 2.f * p1 * y;\r
+\r
+            if( v == size.height - 1 )\r
+                size.width--;\r
+\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;\r
+                float by = bx + r2 * y1;\r
+                int ud = u, vd = v, u3 = u + u + u;\r
+\r
+                bx += r2 * x1[u];\r
+                ud += cvRound( bx * du[u] );\r
+                vd += cvRound( by * dv );\r
+                if( ud < 0 || ud >= size.width || vd < 0 || vd >= size.height )\r
+                    *(int *) (dst + u3) = 0;\r
+                else\r
+                {\r
+                    int uv = vd * srcStep + ud + ud + ud;\r
+\r
+                    *(int *) (dst + u3) = *(int *) (src + uv) & p;\r
+                }\r
+            }\r
+\r
+            if( v == size.height - 1 )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;\r
+                float by = bx + r2 * y1;\r
+                int ud = u, vd = v, u3 = u + u + u;\r
+\r
+                bx += r2 * x1[u];\r
+                ud += cvRound( bx * du[u] );\r
+                vd += cvRound( by * dv );\r
+                size.width++;\r
+                if( ud < 0 || ud >= size.width || vd < 0 || vd >= size.height )\r
+                    dst[u3] = dst[u3 + 1] = dst[u3 + 2] = 0;\r
+                else\r
+                {\r
+                    int uv = vd * srcStep + ud + ud + ud;\r
+\r
+                    dst[u3] = src[uv];\r
+                    dst[u3 + 1] = src[uv + 1];\r
+                    dst[u3 + 2] = src[uv + 2];\r
+                }\r
+            }\r
+        }\r
+    }\r
+    else                        /* interpolation */\r
+    {\r
+        int sizex = size.width - 2, sizey = size.height - 2;\r
+\r
+        for( u = 0; u < size.width; u++ )\r
+        {\r
+            float w = u - u0;\r
+            float x = a1 * w;\r
+\r
+            x1[u] = p2 / x;\r
+            x2[u] = x * x;\r
+            x3[u] = 2.f * p2 * x;\r
+            du[u] = fm * w;\r
+        }\r
+\r
+        for( v = 0; v < size.height; v++, dst += dstStep )\r
+        {\r
+            float dv = v - v0;\r
+            float y = b1 * dv;\r
+            float y1 = p1 / y;\r
+            float y2 = y * y;\r
+            float y3 = 2.f * p1 * y;\r
+\r
+            dv *= fm;\r
+\r
+            if( v == size.height - 1 )\r
+                size.width--;\r
+\r
+            for( u = 0; u < size.width; u++ )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;\r
+                float by = bx + r2 * y1;\r
+                int iu, iv, ud, vd, u3 = u + u + u;\r
+\r
+                bx += r2 * x1[u];\r
+                iu = cvRound( bx * du[u] );\r
+                iv = cvRound( by * dv );\r
+                ud = iu >> S;\r
+                vd = iv >> S;\r
+                iu -= ud << S;\r
+                iv -= vd << S;\r
+                ud += u;\r
+                vd += v;\r
+\r
+                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )\r
+                    *(int *) (dst + u3) = 0;\r
+                else\r
+                {\r
+                    int iuv = (iu >> S2) * (iv >> S2);\r
+                    int uv = vd * srcStep + ud + ud + ud;\r
+                    int uvs = uv + srcStep;\r
+                    int a01 = src[uv];\r
+                    int a02 = src[uv + 1];\r
+                    int a03 = src[uv + 2];\r
+                    int a1 = src[uv + 3];\r
+                    int a2 = src[uv + 4];\r
+                    int a3 = src[uv + 5];\r
+                    int b1 = src[uvs];\r
+                    int b2 = src[uvs + 1];\r
+                    int b3 = src[uvs + 2];\r
+                    int c1 = src[uvs + 3];\r
+                    int c2 = src[uvs + 4];\r
+                    int c3 = src[uvs + 5];\r
+                    int d1, d2, d3;\r
+\r
+                    a1 -= a01;\r
+                    a2 -= a02;\r
+                    a3 -= a03;\r
+                    b1 -= a01;\r
+                    b2 -= a02;\r
+                    b3 -= a03;\r
+                    c1 -= a01 + a1 + b1;\r
+                    c2 -= a02 + a2 + b2;\r
+                    c3 -= a03 + a3 + b3;\r
+                    d1 = ((a1 * iu + b1 * iv + c1 * iuv) >> S) + a01;\r
+                    d2 = ((a2 * iu + b2 * iv + c2 * iuv) >> S) + a02;\r
+                    d3 = ((a3 * iu + b3 * iv + c3 * iuv) >> S) + a03;\r
+                    d1 = !(d1 & ~255) ? d1 : d1 < 0 ? 0 : 255;\r
+                    d2 = !(d2 & ~255) ? d2 : d2 < 0 ? 0 : 255;\r
+                    d3 = !(d3 & ~255) ? d3 : d3 < 0 ? 0 : 255;\r
+                    d1 |= (d2 << 8) | (d3 << 16);\r
+                    *(int *) (dst + u3) = d1;\r
+                }\r
+            }\r
+\r
+            if( v == size.height - 1 )\r
+            {\r
+                float r2 = x2[u] + y2;\r
+                float bx = r2 * (k1 + r2 * k2) + x3[u] + y3;\r
+                float by = bx + r2 * y1;\r
+                int iu, iv, ud, vd, u3 = u + u + u;\r
+\r
+                bx += r2 * x1[u];\r
+                iu = cvRound( bx * du[u] );\r
+                iv = cvRound( by * dv );\r
+                ud = iu >> S;\r
+                vd = iv >> S;\r
+                iu -= ud << S;\r
+                iv -= vd << S;\r
+                ud += u;\r
+                vd += v;\r
+                size.width++;\r
+\r
+                if( ud < 0 || ud > sizex || vd < 0 || vd > sizey )\r
+                    dst[u3] = dst[u3 + 1] = dst[u3 + 2] = 0;\r
+                else\r
+                {\r
+                    int iuv = (iu >> S2) * (iv >> S2);\r
+                    int uv = vd * srcStep + ud + ud + ud;\r
+                    int uvs = uv + srcStep;\r
+                    int a01 = src[uv];\r
+                    int a02 = src[uv + 1];\r
+                    int a03 = src[uv + 2];\r
+                    int a1 = src[uv + 3];\r
+                    int a2 = src[uv + 4];\r
+                    int a3 = src[uv + 5];\r
+                    int b1 = src[uvs];\r
+                    int b2 = src[uvs + 1];\r
+                    int b3 = src[uvs + 2];\r
+                    int c1 = src[uvs + 3];\r
+                    int c2 = src[uvs + 4];\r
+                    int c3 = src[uvs + 5];\r
+                    int d1, d2, d3;\r
+\r
+                    a1 -= a01;\r
+                    a2 -= a02;\r
+                    a3 -= a03;\r
+                    b1 -= a01;\r
+                    b2 -= a02;\r
+                    b3 -= a03;\r
+                    c1 -= a01 + a1 + b1;\r
+                    c2 -= a02 + a2 + b2;\r
+                    c3 -= a03 + a3 + b3;\r
+                    d1 = ((a1 * iu + b1 * iv + c1 * iuv) >> S) + a01;\r
+                    d2 = ((a2 * iu + b2 * iv + c2 * iuv) >> S) + a02;\r
+                    d3 = ((a3 * iu + b3 * iv + c3 * iuv) >> S) + a03;\r
+                    dst[u3] = (uchar) d1;\r
+                    dst[u3 + 1] = (uchar) d2;\r
+                    dst[u3 + 2] = (uchar) d3;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    memcpy( (void*)src, buf, 3 );\r
+\r
+    icvFree( (void **) &x1 );\r
+    icvFree( (void **) &x2 );\r
+    icvFree( (void **) &x3 );\r
+    icvFree( (void **) &du );\r
+    return CV_NO_ERR;\r
+}\r
+/*______________________________________________________________________________________*/\r
+\r
+\r
+/*F//////////////////////////////////////////////////////////////////////////////////////\r
+//    Name: cvUnDistortOnce\r
+//    Purpose: The function corrects radial and tangential image distortion using known\r
+//             matrix of the camera intrinsic parameters and distortion coefficients\r
+//    Context:\r
+//    Parameters:  srcImage    - source (distorted) image\r
+//                 dstImage    - output (undistorted) image\r
+//                 intrMatrix  - matrix of the camera intrinsic parameters\r
+//                 distCoeffs  - vector of the distortion coefficients (k1, k2, p1 and p2)\r
+//                 interpolate - interpolation toggle (optional parameter)\r
+//\r
+//    Notes:   1. If interpolate = 0, interpolation disabled;\r
+//                else (default) bilinear interpolation is used.\r
+//             2. If p1 = p2 = 0, function acts faster.\r
+//F*/\r
+\r
+typedef CvStatus (CV_STDCALL * CvUnDistortOnceFunc)( const void* src, int srcstep,\r
+                                                     void* dst, int dststep, CvSize size,\r
+                                                     const float* intrMatrix,\r
+                                                     const float* distCoeffs,\r
+                                                     int interToggle );\r
+\r
+\r
+CV_IMPL void\r
+cvUnDistortOnce( const void* srcImage, void* dstImage,\r
+                 const float* intrMatrix, const float* distCoeffs,\r
+                 int interpolate )\r
+{\r
+    static void* undist_tab[4];\r
+    static int inittab = 0;\r
+    \r
+    CV_FUNCNAME( "cvUnDistortOnce" );\r
+\r
+    __BEGIN__;\r
+\r
+    int coi1 = 0, coi2 = 0;\r
+    CvMat srcstub, *src = (CvMat*)srcImage;\r
+    CvMat dststub, *dst = (CvMat*)dstImage;\r
+    CvSize size;\r
+    CvUnDistortOnceFunc  func = 0;\r
+\r
+    if( !inittab )\r
+    {\r
+        undist_tab[0] = (void*)icvUnDistort1_8u_C1R;\r
+        undist_tab[1] = (void*)icvUnDistortEx_8u_C1R;\r
+        undist_tab[2] = (void*)icvUnDistort1_8u_C3R;\r
+        undist_tab[3] = (void*)icvUnDistortEx_8u_C3R;\r
+        inittab = 1;\r
+    }\r
+\r
+    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));\r
+    CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));\r
+\r
+    if( coi1 != 0 || coi2 != 0 )\r
+        CV_ERROR( CV_BadCOI, "" );\r
+\r
+    if( CV_MAT_TYPE(src->type) != CV_8UC1 &&\r
+        CV_MAT_TYPE(src->type) != CV_8UC3 )\r
+        CV_ERROR( CV_StsUnsupportedFormat, "" );\r
+\r
+    if( !CV_ARE_TYPES_EQ( src, dst ))\r
+        CV_ERROR( CV_StsUnmatchedFormats, "" );\r
+\r
+    if( !CV_ARE_SIZES_EQ( src, dst ))\r
+        CV_ERROR( CV_StsUnmatchedSizes, "" );\r
+\r
+    if( !intrMatrix || !distCoeffs )\r
+        CV_ERROR( CV_StsNullPtr, "" );\r
+\r
+    size = icvGetMatSize( src );\r
+\r
+    func = (CvUnDistortOnceFunc)\r
+        (undist_tab[(CV_MAT_CN(src->type)-1)+(distCoeffs[2] != 0 || distCoeffs[3] != 0)]);\r
+\r
+    if( !func )\r
+        CV_ERROR( CV_StsUnsupportedFormat, "" );\r
+\r
+    IPPI_CALL( func( src->data.ptr, src->step, dst->data.ptr, dst->step, size,\r
+                     intrMatrix, distCoeffs, interpolate ));\r
+  \r
+    __END__;\r
+}\r
+\r
+\r
+/*F//////////////////////////////////////////////////////////////////////////////////////\r
+//    Name: cvUnDistortInit\r
+//    Purpose: The function calculates arrays of distorted points indices and\r
+//             interpolation coefficients for cvUnDistort function using known\r
+//             matrix of the camera intrinsic parameters and distortion coefficients\r
+//    Context:\r
+//    Parameters:  srcImage    - source (distorted) image\r
+//                 intrMatrix  - matrix of the camera intrinsic parameters\r
+//                 distCoeffs  - vector of the distortion coefficients (k1, k2, p1 and p2)\r
+//                 data        - distortion data array\r
+//                 interpolate - interpolation toggle (optional parameter)\r
+//\r
+//    Notes:  1. If interpolate=0, interpolation disabled;\r
+//               else (default) bilinear interpolation is used.\r
+//            2. Array data must be allocated before. If interpolate = 0, its length\r
+//               must be size.width*size.height elements; else 3*size.width*size.height.\r
+//F*/\r
+CV_IMPL void\r
+cvUnDistortInit( const void* srcImage, void* undistMap,\r
+                 const float* intrMatrix, const float* distCoeffs,\r
+                 int  interpolate )\r
+{\r
+    CV_FUNCNAME( "cvUnDistortInit" );\r
+\r
+    __BEGIN__;\r
+\r
+    int coi1 = 0, coi2 = 0;\r
+    CvMat srcstub, *src = (CvMat*)srcImage;\r
+    CvMat mapstub, *map = (CvMat*)undistMap;\r
+    CvSize size;\r
+\r
+    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));\r
+    CV_CALL( map = cvGetMat( map, &mapstub, &coi2 ));\r
+\r
+    if( coi1 != 0 || coi2 != 0 )\r
+        CV_ERROR( CV_BadCOI, "" );\r
+\r
+    if( CV_MAT_TYPE( map->type ) != CV_32SC1 && CV_MAT_TYPE( map->type ) != CV_32SC3 )\r
+        CV_ERROR( CV_StsUnsupportedFormat, "" );\r
+\r
+    if( !intrMatrix || !distCoeffs )\r
+        CV_ERROR( CV_StsNullPtr, "" );\r
+\r
+    if( src->height > map->height ||\r
+        interpolate && src->width*3 > map->width*CV_MAT_CN( map->type ) ||\r
+        !interpolate && src->width > map->width )\r
+        CV_ERROR( CV_StsUnmatchedSizes, "" );\r
+\r
+    size = icvGetMatSize( src );\r
+\r
+    IPPI_CALL( icvUnDistortInit( src->step, (int*)map->data.ptr, map->step,\r
+                                 size, intrMatrix, distCoeffs,\r
+                                 interpolate, icvPixSize[CV_MAT_TYPE(src->type)]));\r
+\r
+    __END__;\r
+}\r
+\r
+\r
+/*F//////////////////////////////////////////////////////////////////////////////////////\r
+//    Name: cvUnDistort\r
+//    Purpose: The function corrects radial and tangential distortion in the frame\r
+//             using previousely calculated arrays of distorted points indices and\r
+//             undistortion coefficients\r
+//    Context:\r
+//    Parameters:  srcImage    - source (distorted) image\r
+//                 dstImage    - output (undistorted) image\r
+//                 data        - distortion data array\r
+//                 interpolate - interpolation toggle (optional parameter)\r
+//\r
+//    Notes:  1. If interpolate=0, interpolation disabled;\r
+//               else (default) bilinear interpolation is used.\r
+//            2. Array data must be allocated and calculated by the cvUnDistortInit\r
+//               function before. If interpolate = 0, its length must be\r
+//               size.width*size.height elements; else 3*size.width*size.height.\r
+//F*/\r
+CV_IMPL void\r
+cvUnDistort( const void* srcImage, void* dstImage,\r
+             const void* undistMap, int interpolate )\r
+{\r
+    CV_FUNCNAME( "cvUnDistort" );\r
+\r
+    __BEGIN__;\r
+\r
+    int coi1 = 0, coi2 = 0, coi3 = 0;\r
+    CvMat srcstub, *src = (CvMat*)srcImage;\r
+    CvMat mapstub, *map = (CvMat*)undistMap;\r
+    CvMat dststub, *dst = (CvMat*)dstImage;\r
+    CvSize size;\r
+\r
+    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));\r
+    CV_CALL( map = cvGetMat( map, &mapstub, &coi2 ));\r
+    CV_CALL( dst = cvGetMat( dst, &dststub, &coi3 ));\r
+\r
+    if( coi1 != 0 || coi2 != 0 || coi3 != 0 )\r
+        CV_ERROR( CV_BadCOI, "" );\r
+\r
+    if( CV_MAT_TYPE(src->type) != CV_8UC1 && CV_MAT_TYPE(src->type) != CV_8UC3 )\r
+        CV_ERROR( CV_StsUnsupportedFormat, "" );\r
+\r
+    if( !CV_ARE_TYPES_EQ( src, dst ))\r
+        CV_ERROR( CV_StsUnmatchedFormats, "" );\r
+\r
+    if( CV_MAT_TYPE( map->type ) != CV_32SC1 && CV_MAT_TYPE( map->type ) != CV_32SC3 )\r
+        CV_ERROR( CV_StsUnsupportedFormat, "" );\r
+\r
+    if( src->height > map->height ||\r
+        interpolate && src->width*3 > map->width*CV_MAT_CN( map->type ) ||\r
+        !interpolate && src->width > map->width )\r
+        CV_ERROR( CV_StsUnmatchedSizes, "" );\r
+\r
+    if( !CV_ARE_SIZES_EQ( src, dst ))\r
+        CV_ERROR( CV_StsUnmatchedSizes, "" );\r
+\r
+    size = icvGetMatSize( src );\r
+\r
+    if( CV_MAT_TYPE( src->type ) == CV_8UC1 )\r
+    {\r
+        IPPI_CALL( icvUnDistort_8u_C1R( src->data.ptr, src->step,\r
+                                        (int*)map->data.ptr, map->step,\r
+                                        dst->data.ptr, dst->step,\r
+                                        size, interpolate ));\r
+    }\r
+    else if( CV_MAT_TYPE( src->type ) == CV_8UC3 )\r
+    {\r
+        IPPI_CALL( icvUnDistort_8u_C3R( src->data.ptr, src->step,\r
+                                        (int*)map->data.ptr, map->step, \r
+                                        dst->data.ptr, dst->step,\r
+                                        size, interpolate ));\r
+    }\r
+    else\r
+    {\r
+        CV_ERROR( CV_StsUnsupportedFormat, "Undistorted image must have 8uC1 or 8uC3 format" );\r
+    }\r
+\r
+    __END__;\r
+}\r
+\r
+\r
+/*F//////////////////////////////////////////////////////////////////////////////////////\r
+//    Name: cvConvertMap\r
+//    Purpose: The function converts floating-point pixel coordinate map to\r
+//             faster fixed-point map, used within cvUnDistort (cvRemap)\r
+//    Context:\r
+//    Parameters:  flUndistMap - source map: (width x height x 32fC2) or\r
+//                                           (width*2 x height x 32fC1).\r
+//                               each pair are pixel coordinates (x,y) in a source image.\r
+//                 undistMap - resultant map: (width x height x 32sC3) or\r
+//                                 (width*3 x height x 32sC1) if interpolation is enabled;\r
+//                                 (width x height x 32sC1) if interpolation is disabled;\r
+//                 pixelSize - bytes per pixel in images that will be transformed\r
+//                             using the map. For byte-depth images it is just\r
+//                             a number of channels.\r
+//                 interpolate - interpolation flag (turned on by default)\r
+//F*/\r
+CV_IMPL void\r
+cvConvertMap( const CvArr* srcImage, const CvArr* flUndistMap,\r
+              CvArr* undistMap, int interpolate )\r
+{\r
+    CV_FUNCNAME( "cvConvertMap" );\r
+\r
+    __BEGIN__;\r
+\r
+    int coi1 = 0, coi2 = 0, coi3 = 0;\r
+    int i, j;\r
+    CvMat srcstub, *src = (CvMat*)srcImage;\r
+    CvMat mapstub, *map = (CvMat*)undistMap;\r
+    CvMat flmapstub, *flmap = (CvMat*)flUndistMap;\r
+    CvSize size;\r
+    CvPoint2D32f* flmapdata = 0;\r
+    int srcStep, pixSize;\r
+\r
+    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));\r
+    CV_CALL( map = cvGetMat( map, &mapstub, &coi2 ));\r
+    CV_CALL( flmap = cvGetMat( flmap, &flmapstub, &coi3 ));\r
+\r
+    if( coi1 != 0 || coi2 != 0 || coi3 != 0 )\r
+        CV_ERROR( CV_BadCOI, "" );\r
+\r
+    size = cvGetSize( src );\r
+\r
+    if( CV_MAT_DEPTH( flmap->type ) != CV_32F )\r
+        CV_ERROR( CV_StsUnsupportedFormat, "Source map should have 32f depth" );\r
+\r
+    if( CV_MAT_CN( flmap->type ) > 2 ||\r
+        size.width*2 != flmap->width * CV_MAT_CN( flmap->type ) ||\r
+        size.height != flmap->height )\r
+        CV_ERROR( CV_StsUnmatchedSizes, "Source map and source image have unmatched sizes");\r
+\r
+    if( CV_MAT_TYPE( map->type ) != CV_32SC1 &&\r
+        (CV_MAT_TYPE( map->type ) != CV_32SC3 || !interpolate))\r
+        CV_ERROR( CV_StsUnsupportedFormat, "" );\r
+\r
+    if( map->height != size.height ||\r
+        interpolate && size.width*3 != map->width*CV_MAT_CN( map->type ) ||\r
+        !interpolate && size.width != map->width )\r
+        CV_ERROR( CV_StsUnmatchedSizes, "" );\r
+\r
+    flmapdata = (CvPoint2D32f*)flmap->data.ptr;\r
+    pixSize = icvPixSize[CV_MAT_TYPE(src->type)];\r
+    srcStep = src->step;\r
+\r
+    if( !interpolate )\r
+    {\r
+        int* mapdata = (int*)map->data.ptr;\r
+\r
+        for( i = 0; i < size.height; i++, (char*&)flmapdata += flmap->step,\r
+                                          (char*&)mapdata += map->step )\r
+        {\r
+            for( j = 0; j < size.width; j++ )\r
+            {\r
+                int ix = cvRound(flmapdata[j].x);\r
+                int iy = cvRound(flmapdata[j].y);\r
+\r
+                if( (unsigned)ix < (unsigned)size.width &&\r
+                    (unsigned)iy < (unsigned)size.height )\r
+                    mapdata[j] = iy*srcStep + ix*pixSize;\r
+                else\r
+                    mapdata[j] = 0;\r
+            }\r
+        }\r
+    }\r
+    else\r
+    {\r
+        CvUnDistortData* mapdata = (CvUnDistortData*)map->data.ptr;\r
+\r
+        for( i = 0; i < size.height; i++, (char*&)flmapdata += flmap->step,\r
+                                          (char*&)mapdata += map->step )\r
+        {\r
+            for( j = 0; j < size.width; j++ )\r
+            {\r
+                float x = flmapdata[j].x;\r
+                float y = flmapdata[j].y;\r
+                int ix = cvFloor(x);\r
+                int iy = cvFloor(y);\r
+\r
+                x -= ix;\r
+                y -= iy;\r
+\r
+                if( (unsigned)ix < (unsigned)(size.width-1) &&\r
+                    (unsigned)iy < (unsigned)(size.height-1) )\r
+                {\r
+                    mapdata[j].ind = iy*srcStep + ix*pixSize;\r
+                    mapdata[j].a0 = (ushort)cvRound((1.f - x)*(1.f - y)*(1 << 15));\r
+                    mapdata[j].a1 = (ushort)cvRound(x*(1.f - y)*(1 << 15));\r
+                    mapdata[j].a2 = (ushort)cvRound((1.f - x)*y*(1 << 15));\r
+                    mapdata[j].a3 = (ushort)cvRound(x*y*(1 << 15));\r
+                }\r
+                else\r
+                {\r
+                    mapdata[j].ind = 0;\r
+                    mapdata[j].a0 = 0;\r
+                    mapdata[j].a1 = 0;\r
+                    mapdata[j].a2 = 0;\r
+                    mapdata[j].a3 = 0;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    __END__;\r
+}\r
+\r
+/*  End of file  */\r
index 86880478485dfaceb111e61043ceca0687030f4f..18bc9cf5b68b52e3835ee19f9a78bbfed8862c4b 100644 (file)
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-//  By downloading, copying, installing or using the software you agree to this license.
-//  If you do not agree to this license, do not download, install,
-//  copy or use the software.
-//
-//
-//                        Intel License Agreement
-//                For Open Source Computer Vision Library
-//
-// Copyright (C) 2000, Intel Corporation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-//   * Redistribution's of source code must retain the above copyright notice,
-//     this list of conditions and the following disclaimer.
-//
-//   * Redistribution's in binary form must reproduce the above copyright notice,
-//     this list of conditions and the following disclaimer in the documentation
-//     and/or other materials provided with the distribution.
-//
-//   * The name of Intel Corporation may not be used to endorse or promote products
-//     derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-// (including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort (including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-#include "_cv.h"
-#include <ctype.h>
-
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <dlfcn.h>
-#include <string.h>
-#endif
-
-/*
-   determine processor type
-*/
-CvProcessorType
-icvGetProcessorType( void )
-{
-    CvProcessorType proc_type = CV_PROC_GENERIC;
-
-#ifdef  WIN32
-
-    SYSTEM_INFO sys;
-    GetSystemInfo( &sys );
-
-    if( sys.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL &&
-        sys.dwProcessorType == PROCESSOR_INTEL_PENTIUM )
-    {
-        int version = 0, features = 0, family = 0;
-        int id = 0;
-
-    #if _MSC_VER >= 1200 || defined __ICL || defined __BORLANDC__
-
-        __asm
-        {
-            push ebx
-            push esi
-            push edi
-            mov  eax, 1
-
-    #ifndef __BORLANDC__
-            _emit 0x0f
-            _emit 0xa2
-    #else
-            db 0fh
-            db 0a2h
-    #endif
-            pop edi
-            pop esi
-            pop ebx
-            mov version, eax
-            mov features, edx
-        }
-
-    #elif defined __GNUC__
-
-        __asm__ __volatile__
-        (
-            "push %%ebx\n\t"    
-            "push %%esi\n\t"
-            "push %%edi\n\t"
-            "movl $1, %%eax\n\t"
-            "cpuid\n\t"
-            "movl %%eax, %0\n\t"
-            "movl %%edx, %1\n\t"
-            "pop %%edi\n\t"
-            "pop %%esi\n\t"
-            "pop %%ebx\n\t"
-            : "=a" (version),
-              "=d" (features)
-            :
-        );
-
-    #endif
-
-        #define ICV_CPUID_M6     ((1<<15)|(1<<23)|6)  /* cmov + mmx */
-        #define ICV_CPUID_A6     ((1<<25)|ICV_CPUID_M6) /* <all above> + xmm */
-        #define ICV_CPUID_W7     ((1<<26)|ICV_CPUID_A6|(1<<3)|1) /* <all above> + emm */
-
-        family = (version >> 8) & 15;
-        if( family >= 6 && (features & (ICV_CPUID_M6 & ~6)) != 0 ) /* Pentium II or higher */
-        {
-            id = (features & ICV_CPUID_W7 & -256) | family;
-        }
-
-        switch( id )
-        {
-        case ICV_CPUID_W7:
-            proc_type = CV_PROC_IA32_P4;
-            break;
-        case ICV_CPUID_A6:
-            proc_type = CV_PROC_IA32_PIII;
-            break;
-        case ICV_CPUID_M6:
-            proc_type = CV_PROC_IA32_PII;
-            break;
-        }
-    }
-
-#else
-    char buffer[1000] = "";
-
-    //reading /proc/cpuinfo file (proc file system must be supported)
-    FILE *file = fopen( "/proc/cpuinfo", "r" );
-
-    memset( buffer, 0, sizeof(buffer));
-
-    if( file && fread( buffer, 1, 1000, file ))
-    {
-        if( strstr( buffer, "mmx" ) && strstr( buffer, "cmov" ))
-        {
-            proc_type = CV_PROC_IA32_PII;
-
-            if( strstr( buffer, "xmm" ) || strstr( buffer, "sse" ))
-            {
-                proc_type = CV_PROC_IA32_PIII;
-
-                if( strstr( buffer, "emm" ))
-                    proc_type = CV_PROC_IA32_P4;
-            }
-        }
-    }
-#endif
-
-    return proc_type;
-}
-
-
-CvProcessorType icvPreviousProcessor( const char* proc_type )
-{
-    char signature[100];
-    int i;
-
-    if( strlen( proc_type ) >= sizeof(signature))
-        return CV_PROC_GENERIC;
-
-    for( i = 0; proc_type[i]; i++ )
-        signature[i] = (char)tolower( proc_type[i] );
-
-    signature[i++] = '\0';
-
-    if( !strcmp( signature, CV_PROC_IA32_P4 ))
-        proc_type = CV_PROC_IA32_PIII;
-    else if( !strcmp( signature, CV_PROC_IA32_PIII ))
-        proc_type = CV_PROC_IA32_PII;
-    else
-        proc_type = CV_PROC_GENERIC;
-
-    return proc_type;
-}
-
-/* End of file. */
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+#include "_cv.h"\r
+\r
+\r
+CV_IMPL CvRect\r
+cvMaxRect( const CvRect* rect1, const CvRect* rect2 )\r
+{\r
+    if( rect1 && rect2 )\r
+    {\r
+        CvRect max_rect;\r
+        int a, b;\r
+\r
+        max_rect.x = a = rect1->x;\r
+        b = rect2->x;\r
+        if( max_rect.x > b )\r
+            max_rect.x = b;\r
+\r
+        max_rect.width = a += rect1->width;\r
+        b += rect2->width;\r
+\r
+        if( max_rect.width < b )\r
+            max_rect.width = b;\r
+        max_rect.width -= max_rect.x;\r
+\r
+        max_rect.y = a = rect1->y;\r
+        b = rect2->y;\r
+        if( max_rect.y > b )\r
+            max_rect.y = b;\r
+\r
+        max_rect.height = a += rect1->height;\r
+        b += rect2->height;\r
+\r
+        if( max_rect.height < b )\r
+            max_rect.height = b;\r
+        max_rect.height -= max_rect.y;\r
+        return max_rect;\r
+    }\r
+    else if( rect1 )\r
+        return *rect1;\r
+    else if( rect2 )\r
+        return *rect2;\r
+    else\r
+        return cvRect(0,0,0,0);\r
+}\r
+\r
+\r
+CV_IMPL void\r
+cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] )\r
+{\r
+    CV_FUNCNAME( "cvBoxPoints" );\r
+\r
+    __BEGIN__;\r
+    \r
+    float a = (float)cos(box.angle)*0.5f;\r
+    float b = (float)sin(box.angle)*0.5f;\r
+\r
+    if( !pt )\r
+        CV_ERROR( CV_StsNullPtr, "NULL vertex array pointer" );\r
+\r
+    pt[0].x = box.center.x - a*box.size.height - b*box.size.width;\r
+    pt[0].y = box.center.y + b*box.size.height - a*box.size.width;\r
+    pt[1].x = box.center.x + a*box.size.height - b*box.size.width;\r
+    pt[1].y = box.center.y - b*box.size.height - a*box.size.width;\r
+    pt[2].x = 2*box.center.x - pt[0].x;\r
+    pt[2].y = 2*box.center.y - pt[0].y;\r
+    pt[3].x = 2*box.center.x - pt[1].x;\r
+    pt[3].y = 2*box.center.y - pt[1].y;\r
+\r
+    __END__;\r
+}\r
+\r
+\r
+/* End of file. */\r