;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "opencv/cv-config")



#? *** feature

;; dummy function that adds OpenCV C header files in C file
(eval `(de dummy_feature () ,cv-cpheader-cmd ()))

;; #? * (dummy_feature)
;; #? * (cvcanny <src> <dst> <lowt> <hight> <asize>)
;; #? * (cvprecornerdetect <src> <dst> <asize>)
;; #? * (cvcornereigenvalsandvecs <src> <eigenvv> <bsize> <asize>)
;; #? * (cvcornermineigenval <src> <eigenval> <bsize> <asize>)
;; #? * (cvfindcornersubpix <src> <corners> <count> <win> <zerozone> <criteria>)
;; #? * (cvgoodfeaturestotrack <image> <eigimage> <tempimage> <corners> <ccount> <qual> <mindist> <mask>)

;; ********************************************************

;;  /****************************************************************************************\
;;  *                                  Feature detection                                     *
;;  \****************************************************************************************/

#? (cvCanny  <src> <dst> <lowt> <hight> <asize>)
;;.VP
;;  /*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) );

(de cvCanny (src dst lowt hight asize)
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvArr *") dst)
    ((-double-) lowt hight)
    ((-int-) asize)
    #{ cvCanny($src, $dst, $lowt, $hight, $asize); #}
    ())

#? (cvPreCornerDetect <src> <dst> <asize>)
;;.VP
;;  /*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) );

(de cvPreCornerDetect( src dst asize)
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvArr *") dst)
    ((-int-) asize)
    #{ cvPreCornerDetect($src, $dst, $asize); #}
    ())

#? (cvCornerEigenValsAndVecs  <src> <eigenvv> <bsize> <asize>)
;;.VP
;;  /*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) );

(de cvCornerEigenValsAndVecs( src eigenvv bsize asize)
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvArr *") eigenvv)
    ((-int-) bsize asize)
    #{ cvCornerEigenValsAndVecs($src, $eigenvv, $bsize, $asize); #}
    ())

#? (cvCornerMinEigenVal  <src> <eigenval> <bsize> <asize>)
;;.VP
;;  /*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) );

(de cvCornerMinEigenVal( src eigenval bsize asize)
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvArr *") eigenval)
    ((-int-) bsize asize)
    #{ cvCornerMinEigenVal($src, $eigenval, $bsize, $asize); #}
    ())

#? (cvFindCornerSubPix <src> <corners> <count> <win> <zerozone> <criteria>)
;;.VP
;;  /*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 );

(de cvFindCornerSubPix(src corners count win zerozone criteria)
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvPoint2D32f *") corners)
    ((-int-) count)
    ((-gptr- "CvSize *") win zerozone)
    ((-gptr- "CvTermCriteria *") criteria)
    #{ cvFindCornerSubPix($src, $corners, $count, *$win, *$zerozone, *$criteria); #}
    ())
    
#? (cvGoodFeaturesToTrack <image> <eigimage> <tempimage> <corners> <ccount> <qual> <mindist> <mask>)
;;.VP
;;  /*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));
(de cvGoodFeaturesToTrack(image eigimage tempimage corners ccount qual mindist mask)
    ((-gptr- "const CvArr *") image mask)
    ((-gptr- "CvArr *") eigimage tempimage)
    ((-gptr- "CvPoint2D32f *") corners)
    ((-gptr- "int *") ccount)
    ((-double-) qual mindist)
    #{ cvGoodFeaturesToTrack($image, $eigimage, $tempimage, $corners, $ccount, $qual, $mindist, $mask); #}
    ())

;; ********************************************************

(dhc-make ()
  dummy_feature
  cvcanny
  cvprecornerdetect
  cvcornereigenvalsandvecs
  cvcornermineigenval
  cvfindcornersubpix
  cvgoodfeaturestotrack
)
