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



#? *** hough

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

;; #? * (dummy_hough)
;; #? * (cvhoughlines <image> <rho> <theta> <threshold> <lines> <linenum>)
;; #? * (cvhoughlinesp <image> <rho> <theta> <threshold> <linelen> <linegap> <lines> <linenum>)
;; #? * (cvhoughlinessdiv <image> <rho> <srn> <theta> <stn> <threshold> <lines> <linenum>)

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

;;  /****************************************************************************************\
;;  *                                     Hough Transform                                    *
;;  \****************************************************************************************/

#? (cvHoughLines <image> <rho> <theta> <threshold> <lines> <linenum>)
;;.VP
;;  /*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 );


(de cvHoughLines (image rho theta threshold lines linenum)
    ((-gptr- "IplImage *") image)
    ((-double-) rho theta)
    ((-int-) threshold linenum)
    ((-gptr- "float *") lines)
    (let ((s 0))
      ((-int-) s)
      #{ $s = cvHoughLines($image, $rho, $theta, $threshold, $lines, $linenum); #}
      s))

#? (cvHoughLinesP  <image> <rho> <theta> <threshold> <linelen> <linegap> <lines> <linenum>)
;;.VP
;;  /*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 );

(de cvHoughLinesP (image rho theta threshold linelen linegap lines linenum)
    ((-gptr- "IplImage *") image)
    ((-double-) rho theta)
    ((-int-) threshold linelen linegap linenum)
    ((-gptr- "int *") lines)		;why here lines is of type "int *"?
    (let ((s 0))
      ((-int-) s)
      #{ $s = cvHoughLinesP($image, $rho, $theta, $threshold,$linelen, $linegap,  $lines, $linenum); #}
      s))

#? (cvHoughLinesSDiv  <image> <rho> <srn> <theta> <stn> <threshold> <lines> <linenum>)
;;.VP
;;  /*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 );

(de cvHoughLinesSDiv (image rho srn theta stn threshold lines linenum)
    ((-gptr- "IplImage *") image)
    ((-double-) rho theta)
    ((-int-) srn stn threshold linenum)
    ((-gptr- "float *") lines)
    (let ((s 0))
      ((-int-) s)
      #{ $s = cvHoughLinesSDiv($image, $rho,$srn,  $theta, $stn, $threshold, $lines, $linenum); #}
      s))


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

(dhc-make ()
  dummy_hough
  cvhoughlines
  cvhoughlinesp
  cvhoughlinessdiv
)
