;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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")



#? *** gesture

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

;; #? * (dummy_gesture)

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

;;  /****************************************************************************************\
;;  *                              Gesture recognition                                      *
;;  \****************************************************************************************/
;;  /*F///////////////////////////////////////////////////////////////////////////////////////

#? * (cvfindhandregion <points> <count> <indexs> <line> <size> <flag> <center> <storage> <numbers>)
;;.PRE
;;  //    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);

(de cvFindHandRegion( points count  indexs  line  size flag center  storage  numbers )
    ((-gptr- "CvPoint3D32f *") points)
    ((-int-) count  flag)
    ((-gptr- "CvSeq *") indexs)
    ((-gptr- "float *") line)
    ((-gptr- "CvSize2D32f *") size)
    ((-gptr- "CvPoint3D32f *") center)
    ((-gptr- "CvMemStorage *") storage)
    ((-gptr- "CvSeq **") numbers)
    #{ cvFindHandRegion($points, $count, $indexs, $line, *$size, $flag,$center, $storage, $numbers); #}
    ())

;;  /*F///////////////////////////////////////////////////////////////////////////////////////
#? * (cvfindhandregiona <points> <count> <indexs> <line> <size> <jc> <center> <storage> <numbers>)
;;.PRE
;;  //    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);

(de cvFindHandRegionA( points count  indexs  line  size   jc  center  storage  numbers )
    ((-gptr- "CvPoint3D32f *") points)
    ((-int-) count  jc)
    ((-gptr- "CvSeq *") indexs)
    ((-gptr- "float *") line)
    ((-gptr- "CvSize2D32f *") size)
    ((-gptr- "CvPoint3D32f *") center)
    ((-gptr- "CvMemStorage *") storage)
    ((-gptr- "CvSeq **") numbers)
    #{ cvFindHandRegion($points, $count, $indexs, $line, *$size, $jc, $center, $storage, $numbers); #}
    ())

;;  /*F///////////////////////////////////////////////////////////////////////////////////////
#? * (cvcalcimagehomography <line> <center> <intrinsic> <homography>)
;;.PRE
;;  //    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]);

(de cvCalcImageHomography(line center intrinsic  homography)
    ((-gptr- "float *") line)
    ((-gptr- "CvPoint3D32f *") center)
    ((-gptr-) intrinsic  homography)
    #{ cvCalcImageHomography($line, $center, $intrinsic, $homography); #}
    ())

;;  /*F///////////////////////////////////////////////////////////////////////////////////////
#? * (cvcreatehandmask <numbers> <img_mask> <roi>)
;;.PRE
;;  //    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);

(de cvCreateHandMask( numbers img_mask roi)
    ((-gptr- "CvSeq *") numbers)
    ((-gptr- "IplImage *") img_mask)
    ((-gptr- "CvRect *") roi)
    #{ cvCreateHandMask($numbers, $img_mask, $roi); #}
    ())

;;  /*F///////////////////////////////////////////////////////////////////////////////////////
#? * (cvcalcprobdensity <hist1> <hist2> <dst-hist> <scale>)
;;.PRE
;;  //    Name:     cvCalcProbDensity
;;  //    Purpose:  calculates hand mask probability density
;;  //    Context:
;;  //    Parameters:
;;  //      hist1     - pointer to first input image histogram
;;  //      hist2     - pointer to second input image histogram
;;  //      dest_hist - pointer to output density histogram
;;  //      scale     - scale factor
;;  //
;;  //    Notes:
;;  //F*/
;;  OPENCVAPI  void  cvCalcProbDensity(const CvHistogram* hist1,const CvHistogram* hist2,
;;                                     CvHistogram* dest_hist, double scale);
(de cvCalcProbDensity (hist1  hist2 dst-hist scale)
    ((-gptr- "CvHistogram *") hist1 hist2 dst-hist)
    ((-double-) scale)
    #{ cvCalcProbDensity($hist1, $hist2, $dst_hist, $scale); #}
    ())
    
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
#? * (cvmaxrect <rect1> <rect2>)
;;.PRE
;;  //    Name:     cvMaxRect
;;  //    Purpose:  calculates maximum rectangle
;;  //    Context:
;;  //    Parameters:
;;  //      rect1      - pointer to the first input rectangle
;;  //      rect2      - pointer to the second input rectangle
;;  //
;;  //    Notes:
;;  //F*/
;;  OPENCVAPI  CvRect cvMaxRect( CvRect *rect1, CvRect *rect2);

(de cvMaxRect (rect1 rect2)
    ((-gptr- "CvRect *") rect1)
    ((-gptr- "CvRect *") rect2)
    (let ((max-rect (new CvRect 0 0 0 0)))
      ((-obj- (CvRect)) max_rect)
      #{ *(CvRect *)$(==> max-rect getp) = cvMaxRect($rect1, $rect2); #}
      max-rect))

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

(dhc-make ()
  dummy_gesture
  cvfindhandregion
  cvfindhandregiona
  cvcalcimagehomography
  cvcreatehandmask
  cvcalcprobdensity
  cvmaxrect
)
