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


#? *** matrix

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

;; #? * (dummy_matrix)
;; #? * (cvadd <srca> <srcb> <dst> <mask>)
;; #? * (cvadds <src> <value> <dst> <mask>)
;; #? * (cvsub <srca> <srcb> <dst> <mask>)
;; #? * (cvsubs <src> <value> <dst> <mask>)
;; #? * (cvsubrs <src> <value> <dst> <mask>)
;; #? * (cvmul <srca> <srcb> <dst>)
;; #? * (cvscaleadd <src1> <scale> <src2> <dst>)
;; #? * (cvmuladds <src1> <scale> <src2> <dst>)
;; #? * (cvdotproduct <srca> <srcb>)
;; #? * (cvcrossproduct <srca> <srcb> <dst>)
;; #? * (cvmatmuladd <srca> <srcb> <srcc> <dst>)
;; #? * (cvmultransposed <srcarr> <dstarr> <order>)
;; #? * (cvtranspose <src> <dst>)
;; #? * (cvt <src> <dst>)
;; #? * (cvflip <src> <dst> <flipmode>)
;; #? * (cvinvert <src> <dst>)
;; #? * (cvsolve <a> <b> <x>)
;; #? * (cvdet <mat>)
;; #? * (cvtrace <mat> <s>)
;; #? * (cvsvd <a> <w> <u> <v> <flag>)
;; #? * (cvpseudoinverse <a> <b> <flags>)
;; #? * (cveigenvv <src> <evects> <evals> <eps>)
;; #? * (cvsetzero <mat>)
;; #? * (cvsetidentity <mat>)
;; #? * (cvmahalonobis <srca> <srcb> <mat>)
;; #? * (cvperspectivetransform <src> <dst> <mat>)

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

;;  /****************************************************************************************\
;;  *                                      Matrix Functions                                  *
;;  \****************************************************************************************/

#? (cvAdd <srca> <srcb> <dst> <mask>)
;;.VP
;;  /*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));

(de cvAdd (srca srcb dst mask)
    ((-gptr- "const CvArr *") srca srcb mask)
    ((-gptr- "CvArr *") dst)
    #{ cvAdd($srca, $srcb, $dst, $mask);  #}
    ())

#? (cvAddS <src> <value> <dst> <mask>)
;;.VP
;;  /*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));

(de cvAddS (src value dst mask)
    ((-gptr- "const CvArr *") src mask)
    ((-gptr- "CvScalar *") value)
    ((-gptr- "CvArr *") dst)
    #{ cvAddS($src, *$value, $dst, $mask);  #}
    ())

#? (cvSub <srca> <srcb> <dst> <mask>)
;;.VP
;;  /*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));

(de cvSub (srca srcb dst mask)
    ((-gptr- "const CvArr *") srca srcb mask)
    ((-gptr- "CvArr *") dst)
    #{ cvSub($srca, $srcb, $dst, $mask);  #}
    ())

#? (cvSubS <src> <value> <dst> <mask>)
;;.VP
;;  /*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 );
;;  }

(de cvSubS (src value dst mask)
    ((-gptr- "const CvArr *") src mask)
    ((-gptr- "CvScalar *") value)
    ((-gptr- "CvArr *") dst)
    #{ cvSubS($src, *$value, $dst, $mask);  #}
    ())

#? (cvSubRS <src> <value> <dst> <mask>)
;;.VP
;;  /*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));

(de cvSubRS (src value dst mask)
    ((-gptr- "const CvArr *") src mask)
    ((-gptr- "CvScalar *") value)
    ((-gptr- "CvArr *") dst)
    #{ cvSubRS($src, *$value, $dst, $mask);  #}
    ())

#? (cvMul <src1> <src2> <dst> <scale>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //    Name:       cvMul
;;  //    Purpose:    Multiplies two arrays
;;  //    Context:
;;  //    Parameters:
;;  //      src1 - first source array
;;  //      src2 - second source array
;;  //      dst  - destination array: dst(x,y) = srcA(x,y) * srcB(x,y)
;;  //      scale- scale factor
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvMul( const CvArr* srcA, const CvArr* srcB, CvArr* dst, double scale);

(de cvMul (srca srcb dst scale)
    ((-gptr- "const CvArr *") srca srcb)
    ((-gptr- "CvArr *") dst)
    ((-double-) scale)
    #{ cvMul($srca, $srcb, $dst, $scale);  #}
    ())


#? * (cvinrange <src> <lower> <upper> <dst>)
;;.PRE
;;  /* dst(idx) = lower(idx) <= src(idx) < upper(idx) */
;;  OPENCVAPI void cvInRange( const CvArr* src, const CvArr* lower,
;;                            const CvArr* upper, CvArr* dst );

;; Jie's comments: (5/9/2002) 
;; are "opencvInRange" and "cvInRangeS" implemented at all?

(de cvInRange (src lower upper  dst)
    ((-gptr- "const CvArr *") src lower upper)
    ((-gptr- "CvArr *") dst)
    #{ cvInRange($src, $lower, $upper, $dst);  #}
    ())


#? * (cvinranges <src> <lower> <upper> <dst>)
;;.PRE
;;  /* dst(idx) = lower <= src(idx) < upper */
;;  OPENCVAPI void cvInRangeS( const CvArr* src, CvScalar lower,
;;                             CvScalar upper, CvArr* dst );

(de cvInRangeS (src lower upper  dst)
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvScalar *") lower upper)
    ((-gptr- "CvArr *") dst)
    #{ cvInRangeS($src, *$lower, *$upper, $dst);  #}
    ())


;;  /****************************************************************************************\
;;  *                                      Logic Operations                                  *
;;  \****************************************************************************************/

#? * (cvand <src1> <src2> <dst> <mask>)
;;.PRE
;;  /* dst(idx) = src1(idx) & src2(idx) */
;;  OPENCVAPI void cvAnd( const CvArr* src1, const CvArr* src2,
;;                        CvArr* dst, const CvArr* mask CV_DEFAULT(0));

(de cvAnd (src1 src2 dst mask)
    ((-gptr- "const CvArr *") src1 src2 mask)
    ((-gptr- "CvArr *") dst)
    #{ cvAnd($src1, $src2, $dst, $mask); #}
    ())

#? * (cvands <src> <value> <dst> <mask>)
;;.PRE
;;  /* dst(idx) = src(idx) & value */
;;  OPENCVAPI void cvAndS( const CvArr* src, CvScalar value,
;;                         CvArr* dst, const CvArr* mask CV_DEFAULT(0));

(de cvAndS (src value dst mask)
    ((-gptr- "const CvArr *") src mask)
    ((-gptr- "CvScalar *") value)
    ((-gptr- "CvArr *") dst)
    #{  cvAndS($src, *$value, $dst, $mask); #}
    ())

#? * (cvor <src1> <src2> <dst> <mask>)
;;.PRE
;;  /* dst(idx) = src1(idx) | src2(idx) */
;;  OPENCVAPI void cvOr( const CvArr* src1, const CvArr* src2,
;;                       CvArr* dst, const CvArr* mask CV_DEFAULT(0));

(de cvOr (src1 src2 dst mask)
    ((-gptr- "const CvArr *") src1 src2 mask)
    ((-gptr- "CvArr *") dst)
    #{ cvOr($src1, $src2, $dst, $mask); #}
    ())

#? * (cvors <src> <value> <dst> <mask>)
;;.PRE
;;  /* dst(idx) = src(idx) | value */
;;  OPENCVAPI void cvOrS( const CvArr* src, CvScalar value,
;;                        CvArr* dst, const CvArr* mask CV_DEFAULT(0));

(de cvOrS (src value dst mask)
    ((-gptr- "const CvArr *") src mask)
    ((-gptr- "CvScalar *") value)
    ((-gptr- "CvArr *") dst)
    #{  cvOrS($src, *$value, $dst, $mask); #}
    ())


#? * (cvxor <src1> <src2> <dst> <mask>)
;;.PRE
;;  /* dst(idx) = src1(idx) ^ src2(idx) */
;;  OPENCVAPI void cvXor( const CvArr* src1, const CvArr* src2,
;;                        CvArr* dst, const CvArr* mask CV_DEFAULT(0));

(de cvXor (src1 src2 dst mask)
    ((-gptr- "const CvArr *") src1 src2 mask)
    ((-gptr- "CvArr *") dst)
    #{ cvXor($src1, $src2, $dst, $mask); #}
    ())

#? * (cvxors <src> <value> <dst> <mask>)
;;.PRE
;;  /* dst(idx) = src(idx) ^ value */
;;  OPENCVAPI void cvXorS( const CvArr* src, CvScalar value,
;;                         CvArr* dst, const CvArr* mask CV_DEFAULT(0));

(de cvXorS (src value dst mask)
    ((-gptr- "const CvArr *") src mask)
    ((-gptr- "CvScalar *") value)
    ((-gptr- "CvArr *") dst)
    #{  cvXorS($src, *$value, $dst, $mask); #}
    ())

#? (cvScaleAdd <src1> <scale> <src2> <dst>)
;;.VP
;;  /*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 );

(de cvScaleAdd( src1 scale src2 dst)
    ((-gptr- "const CvArr *") src1 src2)
    ((-gptr- "CvScalar *") scale)
    ((-gptr- "CvArr *") dst)
    #{ cvScaleAdd($src1, *$scale, $src2, $dst); #}
    ())


#? * (cvmatmuladds <src> <dst> <transform> <shiftvec>)
;;.PRE
;;  #define cvMulAddS cvScaleAdd

(de cvMulAddS( src1 scale src2 dst)
    ((-gptr- "const CvArr *") src1 src2)
    ((-gptr- "CvScalar *") scale)
    ((-gptr- "CvArr *") dst)
    #{ cvScaleAdd($src1, *$scale, $src2, $dst); #}
    ())

#? (cvDotProduct  <srca> <srcb>)
;;.VP
;;  /*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 );

(de cvDotProduct ( srca srcb)
    ((-gptr- "const CvArr *") srca srcb)
    (let ((s 0))
      ((-double-) s)
      #{ $s = cvDotProduct($srca, $srcb); #}
      s))

#? (cvCrossProduct <srca> <srcb> <dst>)
;;.VP
;;  /*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 );

(de cvCrossProduct (srca srcb dst)
    ((-gptr- "const CvArr *") srca srcb)
    ((-gptr- "CvArr *") dst)
    #{ cvCrossProduct($srca, $srcb, $dst); #}
    ())


#? (cvMatMulAdd <srca> <srcb> <srcc> <dst>)
;;.VP
;;  /*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 );
(de cvMatMulAdd (srca srcb srcc dst)
    ((-gptr- "const CvArr *") srca srcb srcc)
    ((-gptr- "CvArr *") dst)
    #{ cvMatMulAdd($srca, $srcb, $srcc, $dst); #}
    ())


#? (cvMatMulAddS  <src> <dst> <transform> <shiftvec>)
;;.VP
;;  /*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));

(de cvMatMulAddS ( src dst transform shiftvec)
    ((-gptr- "const CvArr *") src transform shiftvec)
    ((-gptr- "CvArr *") dst)
    #{ cvMatMulAddS($src, $dst, $transform, $shiftvec); #}
    ())

#? (cvMulTransposed <srcarr> <dstarr> <order>)
;;.VP
;;  /*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 );

(de cvMulTransposed (srcarr dstarr order)
    ((-gptr- "const CvArr *") srcarr)
    ((-gptr- "CvArr *") dstarr)
    ((-int-) order)
    #{ cvMulTransposed($srcarr, $dstarr, $order, NULL, 1.); #}
    ())

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

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

;;  #define cvT cvTranspose

(de cvT (src dst)
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvArr *") dst)
    #{  cvTranspose($src, $dst); #}
    ())

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

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


#? * (cvmirror <src> <dst> <flipmode>)
;;.PRE
;;  #define cvMirror cvFlip

(de cvMirror (src dst flipmode)
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvArr *") dst)
    ((-int-) flipmode)
    #{ cvFlip ($src, $dst, $flipmode); #}
    ())

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

(de cvInvert ( src dst )
    ((-gptr- "const CvArr *") src)
    ((-gptr- "CvArr *") dst)
    (let ((s 0))
      ((-int-) s)
      #{ $s = cvInvert($src, $dst, CV_LU); #}
      s))

;(defalias cvInv cvInvert)

#? (cvSolve  <a> <b> <x>)
;;.VP
;;  /*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 );

(de cvSolve ( a b x)
    ((-gptr- "const CvArr *") a b)
    ((-gptr- "CvArr *") x)
    (let ((s 0))
      ((-int-) s)
      #{ $s = cvSolve ($a, $b, $x, CV_LU); #}
      s))

#? (cvDetmat <mat>)
;;.VP
;;  /*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 );

(de cvDet (mat)
    ((-gptr- "const CvArr *") mat)
    (let ((s 0))
      ((-double-) s)
      #{ $s = cvDet($mat); #}
      s))

#? (cvTracemat <s>)
;;.VP
;;  /*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 );

(de cvTrace(mat s)
    ((-gptr- "const CvArr *") mat)
    ((-gptr- "CvScalar *") s)
    #{ { CvScalar tmp;
    tmp = cvTrace($mat);
    memcpy($s, &tmp, sizeof(CvScalar));
    } #}
    ())

#? (cvSVD  <a> <w> <u> <v> <flag>)
;;.VP
;;  /*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*/
;;  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));
(de cvSVD ( a w u v flag)
    ((-gptr- "CvArr *") a w u v)
    ((-int-) flag)
    #{ cvSVD($a, $w, $u, $v, $flag); #}
    ())


#? (cvPseudoInverse  <a> <b>)
;;.VP
;;  /*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).
;;  //
;;  //    Return value:
;;  //       The function returns condition number or DBL_MAX if the matrix is signular.
;;  //F*/
;;  OPENCVAPI  double  cvPseudoInverse( CvArr* A, CvArr* B);

(de cvPseudoInverse ( a b)
    ((-gptr- "CvArr *") a b)
    (let ((s 0))
      ((-double-) s)
      #{ $s = cvInvert($a, $b, CV_SVD); #}
      s))

;(defalias cvPseudoInv cvPseudoInverse)


#? (cvEigenVV  <src> <evects> <evals> <eps>)
;;.VP
;;  /*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 );

(de cvEigenVV ( src evects evals eps)
    ((-gptr- "CvArr *") src evects evals)
    ((-double-) eps)
    #{ cvEigenVV($src, $evects, $evals, $eps); #}
    ())

#? (cvSetZero  <mat> )
;;.VP
;;  /*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 );

(de cvSetZero ( mat )
    ((-gptr- "CvArr *") mat)
    #{ cvSetZero($mat); #}
    ())


#? * (cvzero <mat>)
;;.PRE
;;  #define cvZero  cvSetZero

(de cvZero ( mat )
    ((-gptr- "CvArr *") mat)
    #{ cvSetZero($mat); #}
    ())

#? (cvSetIdentity  <mat> <value>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //    Name:       cvSetIdentity
;;  //    Purpose:    Fills identity matrix
;;  //    Context:
;;  //    Parameters:
;;  //      mat - matrix
;;  //    Returns:
;;  //    Notes:
;;  //F*/
;;  OPENCVAPI  void  cvSetIdentity( CvArr* mat );

(de cvSetIdentity ( mat )
    ((-gptr- "CvArr *") mat)
    #{ cvSetIdentity($mat, cvRealScalar(1)); #}
    ())

#? (cvMahalanobis  <srca> <srcb> <mat>)
;;.VP
;;  /*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 );

(de cvMahalanobis ( srca srcb mat)
     ((-gptr- "const CvArr *") srca srcb)
     ((-gptr- "CvArr *") mat)
     (let ((s 0))
       ((-double-) s )
       #{ $s = cvMahalanobis($srca, $srcb, $mat); #}
       s))

;;  #define cvMahalonobis  cvMahalanobis

(de cvMahalonobis ( srca srcb mat)
     ((-gptr- "const CvArr *") srca srcb)
     ((-gptr- "CvArr *") mat)
     (let ((s 0))
       ((-double-) s )
       #{ $s = cvMahalanobis($srca, $srcb, $mat); #}
       s))

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

(de cvPerspectiveTransform (src dst mat)
    ((-gptr- "const CvArr *") src mat)
    ((-gptr- "CvArr *") dst)
    #{ cvPerspectiveTransform ($src, $dst, $mat); #}
    ())
;; ********************************************************

(dhc-make ()
  dummy_matrix
  cvadd
  cvadds
  cvsub
  cvsubs
  cvsubrs
  cvmul
;;  cvinrange
;;  cvinranges
  cvand
  cvands
  cvor
  cvors
  cvxor
  cvxors
  cvscaleadd
  cvmuladds
  cvdotproduct
  cvcrossproduct
  cvmatmuladd
  cvmatmuladds
  cvmultransposed
  cvtranspose
  cvt
  cvflip
  cvmirror
  cvinvert
  cvsolve
  cvdet
  cvtrace
  cvsvd
  cvpseudoinverse
  cveigenvv
  cvsetzero
  cvzero
  cvsetidentity
  cvmahalanobis
  cvmahalonobis
  cvperspectivetransform
)
