(* ************************************************************************************************** Project Delphi-OpenCV ************************************************************************************************** Contributor: Laentir Valetov email:laex@bk.ru Mikhail Grigorev email:sleuthound@gmail.com ************************************************************************************************** You may retrieve the latest version of this file at the GitHub, located at git://github.com/Laex/Delphi-OpenCV.git ************************************************************************************************** License: The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Alternatively, the contents of this file may be used under the terms of the GNU Lesser General Public License (the "LGPL License"), in which case the provisions of the LGPL License are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the LGPL License and not to allow others to use your version of this file under the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the LGPL License. If you do not delete the provisions above, a recipient may use your version of this file under either the MPL or the LGPL License. For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html ************************************************************************************************** Warning: Using Delphi XE3 syntax! ************************************************************************************************** The Initial Developer of the Original Code: OpenCV: open source computer vision library Homepage: http://ocv.org Online docs: http://docs.ocv.org Q&A forum: http://answers.ocv.org Dev zone: http://code.ocv.org ************************************************************************************************** Original file: opencv\modules\imgproc\include\opencv2\imgproc\imgproc_c.h ************************************************************************************************* *) // {$I OpenCV.inc} // {$IFDEF DEBUG} {$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q+,R+,S-,T-,U-,V+,W+,X+,Y+,Z1} {$ELSE} {$A8,B-,C-,D-,E-,F-,G+,H+,I+,J-,K-,L-,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1} {$ENDIF} {$WARN SYMBOL_DEPRECATED OFF} {$WARN SYMBOL_PLATFORM OFF} {$WARN UNIT_PLATFORM OFF} {$WARN UNSAFE_TYPE OFF} {$WARN UNSAFE_CODE OFF} {$WARN UNSAFE_CAST OFF} unit ocv.imgproc_c; interface uses ocv.core.types_c, ocv.imgproc.types_c; (* ********************** Background statistics accumulation **************************** *) (* Adds image to accumulator *) // CVAPI(procedure)cvAcc(var Adds squared image to accumulator * ) // CVAPI(procedure)cvSquareAcc(CvArr * image: v1: 0)): CvArr; (var sqsum: CvArr; var Adds a product of two images to accumulator * ) // CVAPI(procedure)cvMultiplyAcc(CvArr * image1: unction mask CV_DEFAULT(v1: 0)): CvArr; (; // var image2: CvArr; var acc: CvArr; var Adds image to accumulator with weights: acc = acc * (1 - alpha) + image * alpha * ) // CVAPI(procedure)cvRunningAvg(CvArr * image: unction mask CV_DEFAULT(v1: 0)): CvArr; (; // var acc: CvArr;alpha: Double; // ******************************* image Processing ******************************* { /* Copies source 2D array inside of the larger destination array and makes a border of the specified type (IPL_BORDER_*) around the copied area. */ CVAPI(void) cvCopyMakeBorder( const CvArr* src, CvArr* dst, CvPoint offset, int bordertype, CvScalar value CV_DEFAULT(cvScalarAll(0))); } procedure cvCopyMakeBorder( { } const src: pIplImage; { } dst: pIplImage; { } offset: TCvPoint; { } bordertype: Integer; { } value: TCvScalar { * cvScalarAll(0) * } ); cdecl; { // Smoothes array (removes noise) CVAPI(void) cvSmooth( const CvArr* src, CvArr* dst, int smoothtype CV_DEFAULT(CV_GAUSSIAN), int size1 CV_DEFAULT(3), int size2 CV_DEFAULT(0), double sigma1 CV_DEFAULT(0), double sigma2 CV_DEFAULT(0)); } procedure cvSmooth( { } const src: pIplImage; { } dst: pIplImage; { } smoothtype: Integer = CV_GAUSSIAN; { } size1: Integer = 3; { } size2: Integer = 0; { } sigma1: double = 0; { } sigma2: double = 0); cdecl; // (* Convolves the image with the kernel *) // CVAPI( // procedure)cvFilter2D(v1: CvPoint(-1; // { Finds integral image: SUM(X,Y) = sum(x histograms *) // CVAPI(procedure) cvCalcBayesianProb( // src: array of CvHistogram; // number: Integer; // dst: array of CvHistogram); { /* Calculates array histogram */ CVAPI(void) cvCalcArrHist( CvArr** arr, CvHistogram* hist, int accumulate CV_DEFAULT(0), const CvArr* mask CV_DEFAULT(NULL) ); } procedure cvCalcArrHist(var arr: pIplImage; hist: pCvHistogram; accumulate: Integer = 0; const mask: pIplImage = nil); cdecl; // CV_INLINE void cvCalcHist( // IplImage** image, // CvHistogram* hist, // int accumulate CV_DEFAULT(0), // const CvArr* mask CV_DEFAULT(NULL) ) // { // cvCalcArrHist( (CvArr**)image, hist, accumulate, mask ); // } procedure cvCalcHist(var image: pIplImage; hist: pCvHistogram; accumulate: Integer = 0; const mask: pIplImage = nil); {$IFDEF USE_INLINE}inline; {$ENDIF} // var mask CV_DEFAULT(0) )begin cvCalcArrHist( (CvArr*)image: vArr; // v5: hist; // v6: accumulate; // var Calculates back project *) { /* Calculates back project */ CVAPI(void) cvCalcArrBackProject( CvArr** image, CvArr* dst, const CvHistogram* hist ); #define cvCalcBackProject(image, dst, hist) cvCalcArrBackProject((CvArr**)image, dst, hist) } procedure cvCalcArrBackProject(var image: pCvArr; dst: pCvArr; const hist: pCvHistogram); cdecl; procedure cvCalcBackProject(var image: pIplImage; dst: pIplImage; const hist: pCvHistogram); cdecl; // (* Does some sort of template matching but compares histograms of // template and each window location *) // CVAPI(procedure) cvCalcArrBackProjectPatch( // image: array of CvArr; // var dst: CvArr; // range: CvSize; // var hist: CvHistogram; // method: Integer; // factor: Double); /// / >> Following declaration is a macro definition! // const cvCalcBackProjectPatch( image, dst, range, hist, method, factor ) cvCalcArrBackProjectPatch( (CvArr; // // (* calculates probabilistic density (divides one histogram by another) *) // CVAPI(procedure) cvCalcProbDensity( { /* equalizes histogram of 8-bit single-channel image */ CVAPI(void) cvEqualizeHist( const CvArr* src, CvArr* dst ); } procedure cvEqualizeHist(const src, dst: pIplImage); cdecl; // // // (* Applies distance transform to binary image *) // CVAPI(procedure) cvDistTransform( // 3: v1:); // mask CV_DEFAULT(0): unction; // labels CV_DEFAULT(0): function; // labelType CV_DEFAULT(CV_DIST_LABEL_CCOMP): Integer): Integer; // // // (* Applies fixed-level threshold to grayscale image. // This is a basic operation applied before retrieving contours *) // CVAPI(double) cvThreshold( const CvArr* src, CvArr* dst, double threshold, double max_value, int threshold_type ); function cvThreshold(const src, dst: pIplImage; threshold, max_value: double; threshold_type: Integer): double; cdecl; { /* Applies adaptive threshold to grayscale image. The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and CV_ADAPTIVE_THRESH_GAUSSIAN_C are: neighborhood size (3, 5, 7 etc.), and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) */ CVAPI(void) cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value, int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C), int threshold_type CV_DEFAULT(CV_THRESH_BINARY), int block_size CV_DEFAULT(3), double param1 CV_DEFAULT(5)); } procedure cvAdaptiveThreshold( { } const src: pIplImage; { } dst: pIplImage; { } max_value: double; { } adaptive_method: Integer = CV_ADAPTIVE_THRESH_MEAN_C; { } threshold_type: Integer = CV_THRESH_BINARY; { } block_size: Integer = 3; { } param1: double = 5); cdecl; { /* Fills the connected component until the color difference gets large enough */ CVAPI(void) cvFloodFill( CvArr* image, CvPoint seed_point, CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)), CvScalar up_diff CV_DEFAULT(cvScalarAll(0)), CvConnectedComp* comp CV_DEFAULT(NULL), int flags CV_DEFAULT(4), CvArr* mask CV_DEFAULT(NULL)); } procedure cvFloodFill( { } image: pIplImage; { } seed_point: TCvPoint; { } new_val: TCvScalar; { } lo_diff: TCvScalar { * cvScalarAll(0) * }; { } up_diff: TCvScalar { * cvScalarAll(0) * }; { } comp: pCvConnectedComp = NIL; { } flags: Integer = 4; { } mask: pCvArr = NIL); cdecl; // **************************************************************************************** // * Feature detection * // **************************************************************************************** { /* Runs canny edge detector */ CVAPI(void) cvCanny( const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture_size CV_DEFAULT(3) ); } procedure cvCanny(const image: pIplImage; edges: pIplImage; threshold1: double; threshold2: double; aperture_size: Integer = 3); cdecl; // (* Runs canny edge detector *) CVAPI( // procedure)cvCanny(CvArr * image: array of // function flags CV_DEFAULT(v1: 0)): Integer; (; var edges: CvArr; threshold1: Double; // threshold2: Double; var Calculates constraint image for corner detection Dx xor 2 * Dyy + Dxx * // Dy xor 2 - 2 * Dx * Dy * Dxy.Applying threshold to the cResult gives coordinates of // corners * ) // CVAPI( // procedure)cvPreCornerDetect(CvArr * image: // function aperture_size CV_DEFAULT(v1: 3)): Integer; (; var corners: CvArr; // var Calculates eigen values and vectors of 2 x2 gradient covariation matrix at every image // pixel * )CVAPI( // procedure)cvCornerEigenValsAndVecs(CvArr * image: // function aperture_size CV_DEFAULT(v1: 3)): Integer; (; var eigenvv: CvArr; block_size: // function; var Calculates minimal eigenvalue for 2 x2 gradient covariation matrix at every image // pixel * )CVAPI( // procedure)cvCornerMinEigenVal(CvArr * image: Integer aperture_size CV_DEFAULT(v1: 3)): Integer; (; // var eigenval: CvArr; block_size: // function; var Harris corner detector: Calculates det(M) - k * (trace(M) xor 2) // : Integer aperture_size CV_DEFAULT(v1: 3)): Integer; (; var)CVAPI( // procedure)cvCornerHarris(CvArr * image: where M is 2 x2 gradient covariation matrix for each pixel; // var harris_responce: CvArr; block_size: { /* Adjust corner position using some sort of gradient search */ CVAPI(void) cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners, int count, CvSize win, CvSize zero_zone, CvTermCriteria criteria ); } procedure cvFindCornerSubPix(const image: pIplImage; corners: pCvPoint2D32f; count: Integer; win: TCvSize; zero_zone: TCvSize; criteria: TCvTermCriteria); cdecl; // function; var Adjust corner position using some sort of gradient search * )CVAPI( // procedure)cvFindCornerSubPix(CvArr * image: Integer aperture_size CV_DEFAULT(v1: 0.04)): Integer; (; // var corners: CvPoint2D32f; count: Integer; win: CvSize; zero_zone: CvSize; // var Finds a sparse set of points within the selected region that seem to be easy to track * ) { /* Finds a sparse set of points within the selected region that seem to be easy to track */ CVAPI(void) cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image, CvArr* temp_image, CvPoint2D32f* corners, int* corner_count, double quality_level, double min_distance, const CvArr* mask CV_DEFAULT(NULL), int block_size CV_DEFAULT(3), int use_harris CV_DEFAULT(0), double k CV_DEFAULT(0.04) ); } procedure cvGoodFeaturesToTrack(const image: pIplImage; eig_image: pIplImage; temp_image: pIplImage; corners: pCvPoint2D32f; corner_count: PInteger; quality_level: double; min_distance: double; const mask: pIplImage = nil; block_size: Integer = 3; use_harris: Integer = 0; k: double = 0.04); cdecl; // (* Finds lines on binary image using one of several methods. // line_storage is either memory storage or 1 x CvMat, its // number of columns is changed by the cFunction. // method is one of CV_HOUGH_*; // rho, theta and threshold are used for each of those methods; // param1 ~ line length, param2 ~ line gap - for probabilistic, // param1 ~ srn, param2 ~ stn - for multi-scale *) // CVAPI(CvSeq)cvHoughLines2(CvArr * image, Pointer line_storage, Integer method, Double rho, // Double theta, Integer threshold, Double param1 CV_DEFAULT(0), Double param2 CV_DEFAULT(0) // ): Double; { /* Finds lines on binary image using one of several methods. line_storage is either memory storage or 1 x CvMat, its number of columns is changed by the function. method is one of CV_HOUGH_*; rho, theta and threshold are used for each of those methods; param1 ~ line length, param2 ~ line gap - for probabilistic, param1 ~ srn, param2 ~ stn - for multi-scale */ CVAPI(CvSeq*) cvHoughLines2( CvArr* image, void* line_storage, int method, double rho, double theta, int threshold, double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0)); } function cvHoughLines2( { } image: pIplImage; { } line_storage: Pointer; { } method: Integer; { } rho: double; { } theta: double; { } threshold: Integer; { } param1: double = 0; { } param2: double = 0): pCvSeq; cdecl; { /* Finds circles in the image */ CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage, int method, double dp, double min_dist, double param1 CV_DEFAULT(100), double param2 CV_DEFAULT(100), int min_radius CV_DEFAULT(0), int max_radius CV_DEFAULT(0)); } function cvHoughCircles( { } image: pIplImage; { } circle_storage: Pointer; { } method: Integer; { } dp: double; { } min_dist: double; { } param1: double = 100; { } param2: double = 100; { } min_radius: Integer = 0; { } max_radius: Integer = 0): pCvSeq; cdecl; // (* Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) *) // CVAPI( // procedure)cvFitLine(CvArr * points, Integer dist_type, Double param, Double reps, Double aeps, // Single * line): Double; // // {$IFDEF __cplusplus} // end; // {$ENDIF} // {$ENDIF} implementation uses ocv.lib; // procedure cvCvtColor(const src: pIplImage; dst: pIplImage; code: Integer); external imgproc_lib; procedure cvCvtColor(const src: pIplImage; dst: pIplImage; code: Integer); external imgproc_lib name 'cvCvtColor'; procedure cvCvtColor(const src: pCvMat; dst: pCvMat; code: Integer); external imgproc_lib name 'cvCvtColor'; procedure cvCvtColor(const src: pIplImage; dst: pCvMat; code: Integer); external imgproc_lib name 'cvCvtColor'; function cvThreshold; external imgproc_lib; procedure cvSmooth; external imgproc_lib; procedure cvResize; external imgproc_lib; function cvCreateStructuringElementEx; external imgproc_lib; procedure cvErode; external imgproc_lib; procedure cvDilate; external imgproc_lib; procedure cvReleaseStructuringElement; external imgproc_lib; procedure cvMorphologyEx; external imgproc_lib; procedure cvFloodFill; external imgproc_lib; procedure cvAdaptiveThreshold; external imgproc_lib; procedure cvCopyMakeBorder; external imgproc_lib; procedure cvSobel; external imgproc_lib; procedure cvLaplace; external imgproc_lib; procedure cvCanny; external imgproc_lib; function cvHoughLines2; external imgproc_lib; function cvHoughCircles; external imgproc_lib; procedure cvIntegral; external imgproc_lib; function cvFindContours; external imgproc_lib; function cvApproxPoly; external imgproc_lib; procedure cvEqualizeHist; external imgproc_lib; procedure cvFindCornerSubPix; external imgproc_lib; procedure cvInitUndistortMap; external imgproc_lib; procedure cvRemap; external imgproc_lib; function cvArcLength; external imgproc_lib; function cvContourPerimeter(const contour: Pointer): double; {$IFDEF USE_INLINE}inline; {$ENDIF} begin result := cvArcLength(contour, CV_WHOLE_SEQ, 1); end; function cvMatchShapes; external imgproc_lib; function cv2DRotationMatrix; external imgproc_lib; procedure cvWarpAffine; external imgproc_lib; function cvGetPerspectiveTransform; external imgproc_lib; procedure cvWarpPerspective; external imgproc_lib; function cvBoundingRect; external imgproc_lib; function cvContourArea; external imgproc_lib; function cvConvexHull2; external imgproc_lib; function cvConvexityDefects; external imgproc_lib; procedure cvPyrDown; external imgproc_lib; procedure cvPyrUp; external imgproc_lib; function cvCheckContourConvexity; external imgproc_lib; function cvCreateHist; external imgproc_lib; procedure cvCalcHist; begin cvCalcArrHist(image, hist, accumulate, mask); end; procedure cvGetMinMaxHistValue; external imgproc_lib; procedure cvCalcArrHist; external imgproc_lib; procedure cvCalcArrBackProject; external imgproc_lib; procedure cvCalcBackProject; external imgproc_lib name 'cvCalcArrBackProject'; procedure cvGoodFeaturesToTrack; external imgproc_lib; function cvMinAreaRect2; external imgproc_lib; function cvMinEnclosingCircle; external imgproc_lib; procedure cvBoxPoints; external imgproc_lib; procedure cvLogPolar; external imgproc_lib; procedure cvLinearPolar; external imgproc_lib; procedure cvReleaseHist; external imgproc_lib; procedure cvClearHist; external imgproc_lib; procedure cvMoments; external imgproc_lib; function cvGetSpatialMoment; external imgproc_lib; procedure cvMatchTemplate; external imgproc_lib; function cvGetCentralMoment; external imgproc_lib; procedure cvUndistort2; external imgproc_lib; function cvGetAffineTransform; external imgproc_lib; procedure cvUndistortPoints; external imgproc_lib; function cvStartFindContours; external imgproc_lib; function cvFindNextContour; external imgproc_lib; procedure cvSubstituteContour; external imgproc_lib; function cvEndFindContours; external imgproc_lib; function cvCompareHist; external imgproc_lib; procedure cvAcc; external imgproc_lib; procedure cvSquareAcc; external imgproc_lib; procedure cvMultiplyAcc; external imgproc_lib; procedure cvRunningAvg; external imgproc_lib; procedure cvFilter2D; external imgproc_lib; function cvCreatePyramid; external imgproc_lib; procedure cvReleasePyramid; external imgproc_lib; procedure cvPyrMeanShiftFiltering; external imgproc_lib; procedure cvWatershed; external imgproc_lib; procedure cvConvertMaps; external imgproc_lib; procedure cvInitUndistortRectifyMap; external imgproc_lib; function cvGetNormalizedCentralMoment; external imgproc_lib; procedure cvGetHuMoments; external imgproc_lib; function cvSampleLine; external imgproc_lib; procedure cvGetRectSubPix; external imgproc_lib; procedure cvGetQuadrangleSubPix; external imgproc_lib; function cvCalcEMD2; external imgproc_lib; function cvApproxChains; external imgproc_lib; procedure cvStartReadChainPoints; external imgproc_lib; function cvReadChainPoint; external imgproc_lib; function cvFitEllipse2; external imgproc_lib; function cvMaxRect; external imgproc_lib; function cvPointSeqFromMat; external imgproc_lib; function cvPointPolygonTest; external imgproc_lib; procedure cvSetHistBinRanges; external imgproc_lib; function cvMakeHistHeaderForArray; external imgproc_lib; procedure cvNormalizeHist; external imgproc_lib; procedure cvThreshHist; external imgproc_lib; procedure cvCopyHist; external imgproc_lib; procedure cvCalcBayesianProb; external imgproc_lib; procedure cvCalcArrBackProjectPatch; external imgproc_lib; procedure cvCalcProbDensity; external imgproc_lib; procedure cvDistTransform; external imgproc_lib; procedure cvPreCornerDetect; external imgproc_lib; procedure cvCornerEigenValsAndVecs; external imgproc_lib; procedure cvCornerMinEigenVal; external imgproc_lib; procedure cvCornerHarris; external imgproc_lib; procedure cvFitLine; external imgproc_lib; end.