1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
\r
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
\r
15 // Third party copyrights are property of their respective owners.
\r
17 // Redistribution and use in source and binary forms, with or without modification,
\r
18 // are permitted provided that the following conditions are met:
\r
20 // * Redistribution's of source code must retain the above copyright notice,
\r
21 // this list of conditions and the following disclaimer.
\r
23 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
24 // this list of conditions and the following disclaimer in the documentation
\r
25 // and/or other materials provided with the distribution.
\r
27 // * The name of the copyright holders may not be used to endorse or promote products
\r
28 // derived from this software without specific prior written permission.
\r
30 // This software is provided by the copyright holders and contributors "as is" and
\r
31 // any express or implied warranties, including, but not limited to, the implied
\r
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
34 // indirect, incidental, special, exemplary, or consequential damages
\r
35 // (including, but not limited to, procurement of substitute goods or services;
\r
36 // loss of use, data, or profits; or business interruption) however caused
\r
37 // and on any theory of liability, whether in contract, strict liability,
\r
38 // or tort (including negligence or otherwise) arising in any way out of
\r
39 // the use of this software, even if advised of the possibility of such damage.
\r
51 enum { BORDER_REPLICATE=IPL_BORDER_REPLICATE, BORDER_CONSTANT=IPL_BORDER_CONSTANT,
\r
52 BORDER_REFLECT=IPL_BORDER_REFLECT, BORDER_REFLECT_101=IPL_BORDER_REFLECT_101,
\r
53 BORDER_REFLECT101=BORDER_REFLECT_101, BORDER_WRAP=IPL_BORDER_WRAP,
\r
54 BORDER_TRANSPARENT, BORDER_DEFAULT=BORDER_REFLECT_101, BORDER_ISOLATED=16 };
\r
56 CV_EXPORTS int borderInterpolate( int p, int len, int borderType );
\r
58 class CV_EXPORTS BaseRowFilter
\r
62 virtual ~BaseRowFilter();
\r
63 virtual void operator()(const uchar* src, uchar* dst,
\r
64 int width, int cn) = 0;
\r
69 class CV_EXPORTS BaseColumnFilter
\r
73 virtual ~BaseColumnFilter();
\r
74 virtual void operator()(const uchar** src, uchar* dst, int dststep,
\r
75 int dstcount, int width) = 0;
\r
76 virtual void reset();
\r
81 class CV_EXPORTS BaseFilter
\r
85 virtual ~BaseFilter();
\r
86 virtual void operator()(const uchar** src, uchar* dst, int dststep,
\r
87 int dstcount, int width, int cn) = 0;
\r
88 virtual void reset();
\r
94 class CV_EXPORTS FilterEngine
\r
98 FilterEngine(const Ptr<BaseFilter>& _filter2D,
\r
99 const Ptr<BaseRowFilter>& _rowFilter,
\r
100 const Ptr<BaseColumnFilter>& _columnFilter,
\r
101 int srcType, int dstType, int bufType,
\r
102 int _rowBorderType=BORDER_REPLICATE,
\r
103 int _columnBorderType=-1,
\r
104 const Scalar& _borderValue=Scalar());
\r
105 virtual ~FilterEngine();
\r
106 void init(const Ptr<BaseFilter>& _filter2D,
\r
107 const Ptr<BaseRowFilter>& _rowFilter,
\r
108 const Ptr<BaseColumnFilter>& _columnFilter,
\r
109 int srcType, int dstType, int bufType,
\r
110 int _rowBorderType=BORDER_REPLICATE, int _columnBorderType=-1,
\r
111 const Scalar& _borderValue=Scalar());
\r
112 virtual int start(Size wholeSize, Rect roi, int maxBufRows=-1);
\r
113 virtual int start(const Mat& src, const Rect& srcRoi=Rect(0,0,-1,-1),
\r
114 bool isolated=false, int maxBufRows=-1);
\r
115 virtual int proceed(const uchar* src, int srcStep, int srcCount,
\r
116 uchar* dst, int dstStep);
\r
117 virtual void apply( const Mat& src, Mat& dst,
\r
118 const Rect& srcRoi=Rect(0,0,-1,-1),
\r
119 Point dstOfs=Point(0,0),
\r
120 bool isolated=false);
\r
121 bool isSeparable() const { return (const BaseFilter*)filter2D == 0; }
\r
122 int remainingInputRows() const;
\r
123 int remainingOutputRows() const;
\r
125 int srcType, dstType, bufType;
\r
132 int rowBorderType, columnBorderType;
\r
133 Vector<int> borderTab;
\r
134 int borderElemSize;
\r
135 Vector<uchar> ringBuf;
\r
136 Vector<uchar> srcRow;
\r
137 Vector<uchar> constBorderValue;
\r
138 Vector<uchar> constBorderRow;
\r
139 int bufStep, startY, startY0, endY, rowCount, dstY;
\r
140 Vector<uchar*> rows;
\r
142 Ptr<BaseFilter> filter2D;
\r
143 Ptr<BaseRowFilter> rowFilter;
\r
144 Ptr<BaseColumnFilter> columnFilter;
\r
147 enum { KERNEL_GENERAL=0, KERNEL_SYMMETRICAL=1, KERNEL_ASYMMETRICAL=2,
\r
148 KERNEL_SMOOTH=4, KERNEL_INTEGER=8 };
\r
150 CV_EXPORTS int getKernelType(const Mat& kernel, Point anchor);
\r
152 CV_EXPORTS Ptr<BaseRowFilter> getLinearRowFilter(int srcType, int bufType,
\r
153 const Mat& kernel, int anchor,
\r
156 CV_EXPORTS Ptr<BaseColumnFilter> getLinearColumnFilter(int bufType, int dstType,
\r
157 const Mat& kernel, int anchor,
\r
158 int symmetryType, double delta=0,
\r
161 CV_EXPORTS Ptr<BaseFilter> getLinearFilter(int srcType, int dstType,
\r
163 Point anchor=Point(-1,-1),
\r
164 double delta=0, int bits=0);
\r
166 CV_EXPORTS Ptr<FilterEngine> createSeparableLinearFilter(int srcType, int dstType,
\r
167 const Mat& rowKernel, const Mat& columnKernel,
\r
168 Point _anchor=Point(-1,-1), double delta=0,
\r
169 int _rowBorderType=BORDER_DEFAULT,
\r
170 int _columnBorderType=-1,
\r
171 const Scalar& _borderValue=Scalar());
\r
173 CV_EXPORTS Ptr<FilterEngine> createLinearFilter(int srcType, int dstType,
\r
174 const Mat& kernel, Point _anchor=Point(-1,-1),
\r
175 double delta=0, int _rowBorderType=BORDER_DEFAULT,
\r
176 int _columnBorderType=-1, const Scalar& _borderValue=Scalar());
\r
178 CV_EXPORTS Mat getGaussianKernel( int ksize, double sigma, int ktype=CV_64F );
\r
180 CV_EXPORTS Ptr<FilterEngine> createGaussianFilter( int type, Size ksize,
\r
181 double sigma1, double sigma2=0,
\r
182 int borderType=BORDER_DEFAULT);
\r
184 CV_EXPORTS void getDerivKernels( Mat& kx, Mat& ky, int dx, int dy, int ksize,
\r
185 bool normalize=false, int ktype=CV_32F );
\r
187 CV_EXPORTS Ptr<FilterEngine> createDerivFilter( int srcType, int dstType,
\r
188 int dx, int dy, int ksize,
\r
189 int borderType=BORDER_DEFAULT );
\r
191 CV_EXPORTS Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType,
\r
192 int ksize, int anchor=-1);
\r
193 CV_EXPORTS Ptr<BaseColumnFilter> getColumnSumFilter(int sumType, int dstType,
\r
194 int ksize, int anchor=-1,
\r
196 CV_EXPORTS Ptr<FilterEngine> createBoxFilter( int srcType, int dstType, Size ksize,
\r
197 Point anchor=Point(-1,-1),
\r
198 bool normalize=true,
\r
199 int borderType=BORDER_DEFAULT);
\r
201 enum { MORPH_ERODE=0, MORPH_DILATE=1, MORPH_OPEN=2, MORPH_CLOSE=3,
\r
202 MORPH_GRADIENT=4, MORPH_TOPHAT=5, MORPH_BLACKHAT=6 };
\r
204 CV_EXPORTS Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int anchor=-1);
\r
205 CV_EXPORTS Ptr<BaseColumnFilter> getMorphologyColumnFilter(int op, int type, int ksize, int anchor=-1);
\r
206 CV_EXPORTS Ptr<BaseFilter> getMorphologyFilter(int op, int type, const Mat& kernel,
\r
207 Point anchor=Point(-1,-1));
\r
209 static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); }
\r
211 CV_EXPORTS Ptr<FilterEngine> createMorphologyFilter(int op, int type, const Mat& kernel,
\r
212 Point anchor=Point(-1,-1), int _rowBorderType=BORDER_CONSTANT,
\r
213 int _columnBorderType=-1,
\r
214 const Scalar& _borderValue=morphologyDefaultBorderValue());
\r
216 enum { MORPH_RECT=0, MORPH_CROSS=1, MORPH_ELLIPSE=2 };
\r
217 CV_EXPORTS Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1));
\r
219 CV_EXPORTS void copyMakeBorder( const Mat& src, Mat& dst,
\r
220 int top, int bottom, int left, int right,
\r
223 CV_EXPORTS void medianBlur( const Mat& src, Mat& dst, int ksize );
\r
224 CV_EXPORTS void GaussianBlur( const Mat& src, Mat& dst, Size ksize,
\r
225 double sigma1, double sigma2=0,
\r
226 int borderType=BORDER_DEFAULT );
\r
227 CV_EXPORTS void bilateralFilter( const Mat& src, Mat& dst, int d,
\r
228 double sigmaColor, double sigmaSpace,
\r
229 int borderType=BORDER_DEFAULT );
\r
230 CV_EXPORTS void boxFilter( const Mat& src, Mat& dst, int ddepth,
\r
231 Size ksize, Point anchor=Point(-1,-1),
\r
232 bool normalize=true,
\r
233 int borderType=BORDER_DEFAULT );
\r
234 static inline void blur( const Mat& src, Mat& dst,
\r
235 Size ksize, Point anchor=Point(-1,-1),
\r
236 int borderType=BORDER_DEFAULT )
\r
238 boxFilter( src, dst, -1, ksize, anchor, true, borderType );
\r
241 CV_EXPORTS void filter2D( const Mat& src, Mat& dst, int ddepth,
\r
242 const Mat& kernel, Point anchor=Point(-1,-1),
\r
243 double delta=0, int borderType=BORDER_DEFAULT );
\r
245 CV_EXPORTS void sepFilter2D( const Mat& src, Mat& dst, int ddepth,
\r
246 const Mat& kernelX, const Mat& kernelY,
\r
247 Point anchor=Point(-1,-1),
\r
248 double delta=0, int borderType=BORDER_DEFAULT );
\r
250 CV_EXPORTS void Sobel( const Mat& src, Mat& dst, int ddepth,
\r
251 int dx, int dy, int ksize=3,
\r
252 double scale=1, double delta=0,
\r
253 int borderType=BORDER_DEFAULT );
\r
255 CV_EXPORTS void Scharr( const Mat& src, Mat& dst, int ddepth,
\r
256 int dx, int dy, double scale=1, double delta=0,
\r
257 int borderType=BORDER_DEFAULT );
\r
259 CV_EXPORTS void Laplacian( const Mat& src, Mat& dst, int ddepth,
\r
260 int ksize=1, double scale=1, double delta=0,
\r
261 int borderType=BORDER_DEFAULT );
\r
263 CV_EXPORTS void Canny( const Mat& image, Mat& edges,
\r
264 double threshold1, double threshold2,
\r
265 int apertureSize=3, bool L2gradient=false );
\r
267 CV_EXPORTS void cornerMinEigenVal( const Mat& src, Mat& dst,
\r
268 int blockSize, int ksize=3,
\r
269 int borderType=BORDER_DEFAULT );
\r
271 CV_EXPORTS void cornerHarris( const Mat& src, Mat& dst, int blockSize,
\r
272 int ksize, double k,
\r
273 int borderType=BORDER_DEFAULT );
\r
275 CV_EXPORTS void cornerEigenValsAndVecs( const Mat& src, Mat& dst,
\r
276 int blockSize, int ksize,
\r
277 int borderType=BORDER_DEFAULT );
\r
279 CV_EXPORTS void preCornerDetect( const Mat& src, Mat& dst, int ksize,
\r
280 int borderType=BORDER_DEFAULT );
\r
282 CV_EXPORTS void cornerSubPix( const Mat& image, Vector<Point2f>& corners,
\r
283 Size winSize, Size zeroZone,
\r
284 TermCriteria criteria );
\r
286 CV_EXPORTS void goodFeaturesToTrack( const Mat& image, Vector<Point2f>& corners,
\r
287 int maxCorners, double qualityLevel, double minDistance,
\r
288 const Mat& mask=Mat(), int blockSize=3,
\r
289 bool useHarrisDetector=false, double k=0.04 );
\r
291 CV_EXPORTS void HoughLines( Mat& image, Vector<Vec2f>& lines,
\r
292 double rho, double theta, int threshold,
\r
293 double srn=0, double stn=0 );
\r
295 CV_EXPORTS void HoughLinesP( Mat& image, Vector<Vec4i>& lines,
\r
296 double rho, double theta, int threshold,
\r
297 double minLineLength=0, double maxLineGap=0 );
\r
299 CV_EXPORTS void HoughCircles( Mat& image, Vector<Vec3f>& circles,
\r
300 int method, double dp, double minDist,
\r
301 double param1=100, double param2=100,
\r
302 int minRadius=0, int maxRadius=0 );
\r
304 CV_EXPORTS void erode( const Mat& src, Mat& dst, const Mat& kernel,
\r
305 Point anchor=Point(-1,-1), int iterations=1,
\r
306 int borderType=BORDER_CONSTANT,
\r
307 const Scalar& borderValue=morphologyDefaultBorderValue() );
\r
308 CV_EXPORTS void dilate( const Mat& src, Mat& dst, const Mat& kernel,
\r
309 Point anchor=Point(-1,-1), int iterations=1,
\r
310 int borderType=BORDER_CONSTANT,
\r
311 const Scalar& borderValue=morphologyDefaultBorderValue() );
\r
312 CV_EXPORTS void morphologyEx( const Mat& src, Mat& dst, int op, const Mat& kernel,
\r
313 Point anchor=Point(-1,-1), int iterations=1,
\r
314 int borderType=BORDER_CONSTANT,
\r
315 const Scalar& borderValue=morphologyDefaultBorderValue() );
\r
317 enum { INTER_NEAREST=0, INTER_LINEAR=1, INTER_CUBIC=2, INTER_AREA=3,
\r
318 INTER_LANCZOS4=4, INTER_MAX=7, WARP_INVERSE_MAP=16 };
\r
320 CV_EXPORTS void resize( const Mat& src, Mat& dst,
\r
321 Size dsize=Size(), double fx=0, double fy=0,
\r
322 int interpolation=INTER_LINEAR );
\r
324 CV_EXPORTS void warpAffine( const Mat& src, Mat& dst,
\r
325 const Mat& M, Size dsize,
\r
326 int flags=INTER_LINEAR,
\r
327 int borderMode=BORDER_CONSTANT,
\r
328 const Scalar& borderValue=Scalar());
\r
329 CV_EXPORTS void warpPerspective( const Mat& src, Mat& dst,
\r
330 const Mat& M, Size dsize,
\r
331 int flags=INTER_LINEAR,
\r
332 int borderMode=BORDER_CONSTANT,
\r
333 const Scalar& borderValue=Scalar());
\r
335 CV_EXPORTS void remap( const Mat& src, Mat& dst, const Mat& map1, const Mat& map2,
\r
336 int interpolation, int borderMode=BORDER_CONSTANT,
\r
337 const Scalar& borderValue=Scalar());
\r
339 CV_EXPORTS void convertMaps( const Mat& map1, const Mat& map2, Mat& dstmap1, Mat& dstmap2,
\r
340 int dstmap1type, bool nninterpolation=false );
\r
342 CV_EXPORTS Mat getRotationMatrix2D( Point2f center, double angle, double scale );
\r
343 CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] );
\r
344 CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );
\r
346 CV_EXPORTS void getRectSubPix( const Mat& image, Size patchSize,
\r
347 Point2f center, Mat& patch, int patchType=-1 );
\r
349 CV_EXPORTS void integral( const Mat& src, Mat& sum, int sdepth=-1 );
\r
350 CV_EXPORTS void integral( const Mat& src, Mat& sum, Mat& sqsum, int sdepth=-1 );
\r
351 CV_EXPORTS void integral( const Mat& src, Mat& sum, Mat& sqsum, Mat& tilted, int sdepth=-1 );
\r
353 CV_EXPORTS void accumulate( const Mat& src, Mat& dst, const Mat& mask=Mat() );
\r
354 CV_EXPORTS void accumulateSquare( const Mat& src, Mat& dst, const Mat& mask=Mat() );
\r
355 CV_EXPORTS void accumulateProduct( const Mat& src1, const Mat& src2,
\r
356 Mat& dst, const Mat& mask=Mat() );
\r
357 CV_EXPORTS void accumulateWeighted( const Mat& src, Mat& dst,
\r
358 double alpha, const Mat& mask=Mat() );
\r
360 enum { THRESH_BINARY=0, THRESH_BINARY_INV=1, THRESH_TRUNC=2, THRESH_TOZERO=3,
\r
361 THRESH_TOZERO_INV=4, THRESH_MASK=7, THRESH_OTSU=8 };
\r
363 CV_EXPORTS double threshold( const Mat& src, Mat& dst, double thresh, double maxval, int type );
\r
365 enum { ADAPTIVE_THRESH_MEAN_C=0, ADAPTIVE_THRESH_GAUSSIAN_C=1 };
\r
367 CV_EXPORTS void adaptiveThreshold( const Mat& src, Mat& dst, double maxValue,
\r
368 int adaptiveMethod, int thresholdType,
\r
369 int blockSize, double C );
\r
371 CV_EXPORTS void pyrDown( const Mat& src, Mat& dst, const Size& dstsize=Size());
\r
372 CV_EXPORTS void pyrUp( const Mat& src, Mat& dst, const Size& dstsize=Size());
\r
373 CV_EXPORTS void buildPyramid( const Mat& src, Vector<Mat>& dst, int maxlevel );
\r
376 CV_EXPORTS void undistort( const Mat& src, Mat& dst, const Mat& cameraMatrix,
\r
377 const Mat& distCoeffs, const Mat& newCameraMatrix=Mat() );
\r
378 CV_EXPORTS void initUndistortRectifyMap( const Mat& cameraMatrix, const Mat& distCoeffs,
\r
379 const Mat& R, const Mat& newCameraMatrix,
\r
380 Size size, int m1type, Mat& map1, Mat& map2 );
\r
381 CV_EXPORTS Mat getDefaultNewCameraMatrix( const Mat& cameraMatrix, Size imgsize=Size(),
\r
382 bool centerPrincipalPoint=false );
\r
384 enum { OPTFLOW_USE_INITIAL_FLOW=4, OPTFLOW_FARNEBACK_GAUSSIAN=256 };
\r
386 CV_EXPORTS void calcOpticalFlowPyrLK( const Mat& prevImg, const Mat& nextImg,
\r
387 const Vector<Point2f>& prevPts,
\r
388 Vector<Point2f>& nextPts,
\r
389 Vector<bool>& status, Vector<float>& err,
\r
390 Size winSize=Size(15,15), int maxLevel=3,
\r
391 TermCriteria criteria=TermCriteria(
\r
392 TermCriteria::COUNT+TermCriteria::EPS,
\r
394 double derivLambda=0.5,
\r
397 CV_EXPORTS void calcOpticalFlowFarneback( const Mat& prev0, const Mat& next0,
\r
398 Mat& flow0, double pyr_scale, int levels, int winsize,
\r
399 int iterations, int poly_n, double poly_sigma, int flags );
\r
402 CV_EXPORTS void calcHist( const Vector<Mat>& images, const Vector<int>& channels,
\r
403 const Mat& mask, MatND& hist, const Vector<int>& histSize,
\r
404 const Vector<Vector<float> >& ranges,
\r
405 bool uniform=true, bool accumulate=false );
\r
407 CV_EXPORTS void calcHist( const Vector<Mat>& images, const Vector<int>& channels,
\r
408 const Mat& mask, SparseMat& hist, const Vector<int>& histSize,
\r
409 const Vector<Vector<float> >& ranges,
\r
410 bool uniform=true, bool accumulate=false );
\r
412 CV_EXPORTS void calcBackProject( const Vector<Mat>& images, const Vector<int>& channels,
\r
413 const MatND& hist, Mat& backProject,
\r
414 const Vector<Vector<float> >& ranges,
\r
415 double scale=1, bool uniform=true );
\r
417 CV_EXPORTS void calcBackProject( const Vector<Mat>& images, const Vector<int>& channels,
\r
418 const SparseMat& hist, Mat& backProject,
\r
419 const Vector<Vector<float> >& ranges,
\r
420 double scale=1, bool uniform=true );
\r
422 CV_EXPORTS double compareHist( const MatND& H1, const MatND& H2, int method );
\r
424 CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method );
\r
426 CV_EXPORTS void equalizeHist( const Mat& src, Mat& dst );
\r
428 CV_EXPORTS void watershed( const Mat& image, Mat& markers );
\r
430 enum { INPAINT_NS=CV_INPAINT_NS, INPAINT_TELEA=CV_INPAINT_TELEA };
\r
432 CV_EXPORTS void inpaint( const Mat& src, const Mat& inpaintMask,
\r
433 Mat& dst, double inpaintRange, int flags );
\r
435 CV_EXPORTS void distanceTransform( const Mat& src, Mat& dst, Mat& labels,
\r
436 int distanceType, int maskSize );
\r
438 CV_EXPORTS void distanceTransform( const Mat& src, Mat& dst,
\r
439 int distanceType, int maskSize );
\r
441 enum { FLOODFILL_FIXED_RANGE = 1 << 16,
\r
442 FLOODFILL_MASK_ONLY = 1 << 17 };
\r
444 CV_EXPORTS int floodFill( Mat& image,
\r
445 Point seedPoint, Scalar newVal, Rect* rect=0,
\r
446 Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
\r
449 CV_EXPORTS int floodFill( Mat& image, Mat& mask,
\r
450 Point seedPoint, Scalar newVal, Rect* rect=0,
\r
451 Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
\r
454 CV_EXPORTS void cvtColor( const Mat& src, Mat& dst, int code, int dstCn=0 );
\r
456 class CV_EXPORTS Moments
\r
460 Moments(double m00, double m10, double m01, double m20, double m11,
\r
461 double m02, double m30, double m21, double m12, double m03 );
\r
462 Moments( const CvMoments& moments );
\r
463 operator CvMoments() const;
\r
465 double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; // spatial moments
\r
466 double mu20, mu11, mu02, mu30, mu21, mu12, mu03; // central moments
\r
467 double nu20, nu11, nu02, nu30, nu21, nu12, nu03; // central normalized moments
\r
470 CV_EXPORTS Moments moments( const Mat& image, bool binaryImage=false );
\r
472 CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] );
\r
474 enum { TM_SQDIFF=CV_TM_SQDIFF, TM_SQDIFF_NORMED=CV_TM_SQDIFF_NORMED,
\r
475 TM_CCORR=CV_TM_CCORR, TM_CCORR_NORMED=CV_TM_CCORR_NORMED,
\r
476 TM_CCOEFF=CV_TM_CCOEFF, TM_CCOEFF_NORMED=CV_TM_CCOEFF_NORMED };
\r
478 CV_EXPORTS void matchTemplate( const Mat& image, const Mat& templ, Mat& result, int method );
\r
480 enum { RETR_EXTERNAL=CV_RETR_EXTERNAL, RETR_LIST=CV_RETR_LIST,
\r
481 RETR_CCOMP=CV_RETR_CCOMP, RETR_TREE=CV_RETR_TREE };
\r
483 enum { CHAIN_APPROX_NONE=CV_CHAIN_APPROX_NONE,
\r
484 CHAIN_APPROX_SIMPLE=CV_CHAIN_APPROX_SIMPLE,
\r
485 CHAIN_APPROX_TC89_L1=CV_CHAIN_APPROX_TC89_L1,
\r
486 CHAIN_APPROX_TC89_KCOS=CV_CHAIN_APPROX_TC89_KCOS };
\r
488 CV_EXPORTS Vector<Vector<Point> >
\r
489 findContours( const Mat& image, Vector<Vec4i>& hierarchy,
\r
490 int mode, int method, Point offset=Point());
\r
492 CV_EXPORTS Vector<Vector<Point> >
\r
493 findContours( const Mat& image, int mode, int method, Point offset=Point());
\r
496 drawContours( Mat& image, const Vector<Vector<Point> >& contours,
\r
497 const Scalar& color, int thickness=1,
\r
498 int lineType=8, const Vector<Vec4i>& hierarchy=Vector<Vec4i>(),
\r
499 int maxLevel=1, Point offset=Point() );
\r
501 CV_EXPORTS void approxPolyDP( const Vector<Point>& curve,
\r
502 Vector<Point>& approxCurve,
\r
503 double epsilon, bool closed );
\r
504 CV_EXPORTS void approxPolyDP( const Vector<Point2f>& curve,
\r
505 Vector<Point2f>& approxCurve,
\r
506 double epsilon, bool closed );
\r
508 CV_EXPORTS double arcLength( const Vector<Point>& curve, bool closed );
\r
509 CV_EXPORTS double arcLength( const Vector<Point2f>& curve, bool closed );
\r
511 CV_EXPORTS Rect boundingRect( const Vector<Point>& points );
\r
512 CV_EXPORTS Rect boundingRect( const Vector<Point2f>& points );
\r
514 CV_EXPORTS double contourArea( const Vector<Point>& contour );
\r
515 CV_EXPORTS double contourArea( const Vector<Point2f>& contour );
\r
517 CV_EXPORTS RotatedRect minAreaRect( const Vector<Point>& points );
\r
518 CV_EXPORTS RotatedRect minAreaRect( const Vector<Point2f>& points );
\r
520 CV_EXPORTS void minEnclosingCircle( const Vector<Point>& points,
\r
521 Point2f center, float& radius );
\r
522 CV_EXPORTS void minEnclosingCircle( const Vector<Point2f>& points,
\r
523 Point2f center, float& radius );
\r
525 CV_EXPORTS Moments moments( const Vector<Point>& points );
\r
526 CV_EXPORTS Moments moments( const Vector<Point2f>& points );
\r
528 CV_EXPORTS double matchShapes( const Vector<Point2f>& contour1,
\r
529 const Vector<Point2f>& contour2,
\r
530 int method, double parameter );
\r
531 CV_EXPORTS double matchShapes( const Vector<Point>& contour1,
\r
532 const Vector<Point>& contour2,
\r
533 int method, double parameter );
\r
535 CV_EXPORTS void convexHull( const Vector<Point>& points,
\r
536 Vector<int>& hull, bool clockwise=false );
\r
537 CV_EXPORTS void convexHull( const Vector<Point>& points,
\r
538 Vector<Point>& hull, bool clockwise=false );
\r
539 CV_EXPORTS void convexHull( const Vector<Point2f>& points,
\r
540 Vector<int>& hull, bool clockwise=false );
\r
541 CV_EXPORTS void convexHull( const Vector<Point2f>& points,
\r
542 Vector<Point2f>& hull, bool clockwise=false );
\r
544 CV_EXPORTS bool isContourConvex( const Vector<Point>& contour );
\r
545 CV_EXPORTS bool isContourConvex( const Vector<Point2f>& contour );
\r
547 CV_EXPORTS RotatedRect fitEllipse( const Vector<Point>& points );
\r
548 CV_EXPORTS RotatedRect fitEllipse( const Vector<Point2f>& points );
\r
550 CV_EXPORTS Vec4f fitLine( const Vector<Point> points, int distType,
\r
551 double param, double reps, double aeps );
\r
552 CV_EXPORTS Vec4f fitLine( const Vector<Point2f> points, int distType,
\r
553 double param, double reps, double aeps );
\r
554 CV_EXPORTS Vec6f fitLine( const Vector<Point3f> points, int distType,
\r
555 double param, double reps, double aeps );
\r
557 CV_EXPORTS double pointPolygonTest( const Vector<Point>& contour,
\r
558 Point2f pt, bool measureDist );
\r
559 CV_EXPORTS double pointPolygonTest( const Vector<Point2f>& contour,
\r
560 Point2f pt, bool measureDist );
\r
562 CV_EXPORTS Mat estimateRigidTransform( const Vector<Point2f>& A,
\r
563 const Vector<Point2f>& B,
\r
566 CV_EXPORTS void updateMotionHistory( const Mat& silhouette, Mat& mhi,
\r
567 double timestamp, double duration );
\r
569 CV_EXPORTS void calcMotionGradient( const Mat& mhi, Mat& mask,
\r
571 double delta1, double delta2,
\r
572 int apertureSize=3 );
\r
574 CV_EXPORTS double calcGlobalOrientation( const Mat& orientation, const Mat& mask,
\r
575 const Mat& mhi, double timestamp,
\r
577 // TODO: need good API for cvSegmentMotion
\r
579 CV_EXPORTS RotatedRect CAMShift( const Mat& probImage, Rect& window,
\r
580 TermCriteria criteria );
\r
582 CV_EXPORTS int meanShift( const Mat& probImage, Rect& window,
\r
583 TermCriteria criteria );
\r
585 class CV_EXPORTS KalmanFilter
\r
589 KalmanFilter(int dynamParams, int measureParams, int controlParams=0);
\r
590 void init(int dynamParams, int measureParams, int controlParams=0);
\r
592 const Mat& predict(const Mat& control=Mat());
\r
593 const Mat& correct(const Mat& measurement);
\r
595 Mat statePre; // predicted state (x'(k)):
\r
596 // x(k)=A*x(k-1)+B*u(k)
\r
597 Mat statePost; // corrected state (x(k)):
\r
598 // x(k)=x'(k)+K(k)*(z(k)-H*x'(k))
\r
599 Mat transitionMatrix; // state transition matrix (A)
\r
600 Mat controlMatrix; // control matrix (B)
\r
601 // (it is not used if there is no control)
\r
602 Mat measurementMatrix; // measurement matrix (H)
\r
603 Mat processNoiseCov; // process noise covariance matrix (Q)
\r
604 Mat measurementNoiseCov;// measurement noise covariance matrix (R)
\r
605 Mat errorCovPre; // priori error estimate covariance matrix (P'(k)):
\r
606 // P'(k)=A*P(k-1)*At + Q)*/
\r
607 Mat gain; // Kalman gain matrix (K(k)):
\r
608 // K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)
\r
609 Mat errorCovPost; // posteriori error estimate covariance matrix (P(k)):
\r
610 // P(k)=(I-K(k)*H)*P'(k)
\r
611 Mat temp1; // temporary matrices
\r
619 ///////////////////////////// Object Detection ////////////////////////////
\r
621 template<> inline void Ptr<CvHaarClassifierCascade>::delete_obj()
\r
622 { cvReleaseHaarClassifierCascade(&obj); }
\r
624 class CV_EXPORTS HaarClassifierCascade
\r
627 enum { DO_CANNY_PRUNING = CV_HAAR_DO_CANNY_PRUNING,
\r
628 SCALE_IMAGE = CV_HAAR_SCALE_IMAGE,
\r
629 FIND_BIGGEST_OBJECT = CV_HAAR_FIND_BIGGEST_OBJECT,
\r
630 DO_ROUGH_SEARCH = CV_HAAR_DO_ROUGH_SEARCH };
\r
632 HaarClassifierCascade();
\r
633 HaarClassifierCascade(const String& filename);
\r
634 bool load(const String& filename);
\r
636 void detectMultiScale( const Mat& image,
\r
637 Vector<Rect>& objects,
\r
638 double scaleFactor=1.1,
\r
639 int minNeighbors=3, int flags=0,
\r
640 Size minSize=Size());
\r
642 int runAt(Point pt, int startStage=0, int nstages=0) const;
\r
644 void setImages( const Mat& sum, const Mat& sqsum,
\r
645 const Mat& tiltedSum, double scale );
\r
647 Ptr<CvHaarClassifierCascade> cascade;
\r
650 CV_EXPORTS void undistortPoints( const Vector<Point2f>& src, Vector<Point2f>& dst,
\r
651 const Mat& cameraMatrix, const Mat& distCoeffs,
\r
652 const Mat& R=Mat(), const Mat& P=Mat());
\r
654 CV_EXPORTS Mat Rodrigues(const Mat& src);
\r
655 CV_EXPORTS Mat Rodrigues(const Mat& src, Mat& jacobian);
\r
657 enum { LMEDS=4, RANSAC=8 };
\r
659 CV_EXPORTS Mat findHomography( const Vector<Point2f>& srcPoints,
\r
660 const Vector<Point2f>& dstPoints,
\r
661 Vector<bool>& mask, int method=0,
\r
662 double ransacReprojThreshold=0 );
\r
664 CV_EXPORTS Mat findHomography( const Vector<Point2f>& srcPoints,
\r
665 const Vector<Point2f>& dstPoints,
\r
666 int method=0, double ransacReprojThreshold=0 );
\r
668 /* Computes RQ decomposition for 3x3 matrices */
\r
669 CV_EXPORTS void RQDecomp3x3( const Mat& M, Mat& R, Mat& Q );
\r
670 CV_EXPORTS Vec3d RQDecomp3x3( const Mat& M, Mat& R, Mat& Q,
\r
671 Mat& Qx, Mat& Qy, Mat& Qz );
\r
673 CV_EXPORTS void decomposeProjectionMatrix( const Mat& projMatrix, Mat& cameraMatrix,
\r
674 Mat& rotMatrix, Mat& transVect );
\r
675 CV_EXPORTS void decomposeProjectionMatrix( const Mat& projMatrix, Mat& cameraMatrix,
\r
676 Mat& rotMatrix, Mat& transVect,
\r
677 Mat& rotMatrixX, Mat& rotMatrixY,
\r
678 Mat& rotMatrixZ, Vec3d& eulerAngles );
\r
680 CV_EXPORTS void matMulDeriv( const Mat& A, const Mat& B, Mat& dABdA, Mat& dABdB );
\r
682 CV_EXPORTS void composeRT( const Mat& rvec1, const Mat& tvec1,
\r
683 const Mat& rvec2, const Mat& tvec2,
\r
684 Mat& rvec3, Mat& tvec3 );
\r
686 CV_EXPORTS void composeRT( const Mat& rvec1, const Mat& tvec1,
\r
687 const Mat& rvec2, const Mat& tvec2,
\r
688 Mat& rvec3, Mat& tvec3,
\r
689 Mat& dr3dr1, Mat& dr3dt1,
\r
690 Mat& dr3dr2, Mat& dr3dt2,
\r
691 Mat& dt3dr1, Mat& dt3dt1,
\r
692 Mat& dt3dr2, Mat& dt3dt2 );
\r
694 CV_EXPORTS void projectPoints( const Vector<Point3f>& objectPoints,
\r
695 const Mat& rvec, const Mat& tvec,
\r
696 const Mat& cameraMatrix,
\r
697 const Mat& distCoeffs,
\r
698 Vector<Point2f>& imagePoints );
\r
700 CV_EXPORTS void projectPoints( const Vector<Point3f>& objectPoints,
\r
701 const Mat& rvec, const Mat& tvec,
\r
702 const Mat& cameraMatrix,
\r
703 const Mat& distCoeffs,
\r
704 Vector<Point2f>& imagePoints,
\r
705 Mat& dpdrot, Mat& dpdt, Mat& dpdf,
\r
706 Mat& dpdc, Mat& dpddist,
\r
707 double aspectRatio=0 );
\r
709 CV_EXPORTS void solvePnP( const Vector<Point3f>& objectPoints,
\r
710 const Vector<Point2f>& imagePoints,
\r
711 const Mat& cameraMatrix,
\r
712 const Mat& distCoeffs,
\r
713 Mat& rvec, Mat& tvec,
\r
714 bool useExtrinsicGuess=false );
\r
716 CV_EXPORTS Mat initCameraMatrix2D( const Vector<Vector<Point3f> >& objectPoints,
\r
717 const Vector<Vector<Point2f> >& imagePoints,
\r
718 Size imageSize, double aspectRatio=1. );
\r
720 enum { CALIB_CB_ADAPTIVE_THRESH = CV_CALIB_CB_ADAPTIVE_THRESH,
\r
721 CALIB_CB_NORMALIZE_IMAGE = CV_CALIB_CB_NORMALIZE_IMAGE,
\r
722 CALIB_CB_FILTER_QUADS = CV_CALIB_CB_FILTER_QUADS };
\r
724 CV_EXPORTS bool findChessboardCorners( const Mat& image, Size patternSize,
\r
725 Vector<Point2f>& corners,
\r
726 int flags=CV_CALIB_CB_ADAPTIVE_THRESH+
\r
727 CV_CALIB_CB_NORMALIZE_IMAGE );
\r
729 CV_EXPORTS void drawChessboardCorners( Mat& image, Size patternSize,
\r
730 const Vector<Point2f>& corners,
\r
731 bool patternWasFound );
\r
735 CALIB_USE_INTRINSIC_GUESS = CV_CALIB_USE_INTRINSIC_GUESS,
\r
736 CALIB_FIX_ASPECT_RATIO = CV_CALIB_FIX_ASPECT_RATIO,
\r
737 CALIB_FIX_PRINCIPAL_POINT = CV_CALIB_FIX_PRINCIPAL_POINT,
\r
738 CALIB_ZERO_TANGENT_DIST = CV_CALIB_ZERO_TANGENT_DIST,
\r
739 CALIB_FIX_FOCAL_LENGTH = CV_CALIB_FIX_FOCAL_LENGTH,
\r
740 CALIB_FIX_K1 = CV_CALIB_FIX_K1,
\r
741 CALIB_FIX_K2 = CV_CALIB_FIX_K2,
\r
742 CALIB_FIX_K3 = CV_CALIB_FIX_K3,
\r
744 CALIB_FIX_INTRINSIC = CV_CALIB_FIX_INTRINSIC,
\r
745 CALIB_SAME_FOCAL_LENGTH = CV_CALIB_SAME_FOCAL_LENGTH,
\r
746 // for stereo rectification
\r
747 CALIB_ZERO_DISPARITY = CV_CALIB_ZERO_DISPARITY
\r
750 CV_EXPORTS void calibrateCamera( const Vector<Vector<Point3f> >& objectPoints,
\r
751 const Vector<Vector<Point2f> >& imagePoints,
\r
753 Mat& cameraMatrix, Mat& distCoeffs,
\r
754 Vector<Mat>& rvecs, Vector<Mat>& tvecs,
\r
757 CV_EXPORTS void calibrationMatrixValues( const Mat& cameraMatrix,
\r
759 double apertureWidth,
\r
760 double apertureHeight,
\r
763 double& focalLength,
\r
764 Point2d& principalPoint,
\r
765 double& aspectRatio );
\r
767 CV_EXPORTS void stereoCalibrate( const Vector<Vector<Point3f> >& objectPoints,
\r
768 const Vector<Vector<Point2f> >& imagePoints1,
\r
769 const Vector<Vector<Point2f> >& imagePoints2,
\r
770 Mat& cameraMatrix1, Mat& distCoeffs1,
\r
771 Mat& cameraMatrix2, Mat& distCoeffs2,
\r
772 Size imageSize, Mat& R, Mat& T,
\r
774 TermCriteria criteria = TermCriteria(TermCriteria::COUNT+
\r
775 TermCriteria::EPS, 30, 1e-6),
\r
776 int flags=CALIB_FIX_INTRINSIC );
\r
778 CV_EXPORTS void stereoRectify( const Mat& cameraMatrix1, const Mat& distCoeffs1,
\r
779 const Mat& cameraMatrix2, const Mat& distCoeffs2,
\r
780 Size imageSize, const Mat& R, const Mat& T,
\r
781 Mat& R1, Mat& R2, Mat& P1, Mat& P2, Mat& Q,
\r
782 int flags=CALIB_ZERO_DISPARITY );
\r
784 CV_EXPORTS bool stereoRectifyUncalibrated( const Vector<Point2f>& points1,
\r
785 const Vector<Point2f>& points2,
\r
786 const Mat& F, Size imgSize,
\r
788 double threshold=5 );
\r
790 CV_EXPORTS void convertPointsHomogeneous( const Vector<Point2f>& src,
\r
791 Vector<Point3f>& dst );
\r
792 CV_EXPORTS void convertPointsHomogeneous( const Vector<Point3f>& src,
\r
793 Vector<Point2f>& dst );
\r
797 FM_7POINT = CV_FM_7POINT,
\r
798 FM_8POINT = CV_FM_8POINT,
\r
799 FM_LMEDS = CV_FM_LMEDS,
\r
800 FM_RANSAC = CV_FM_RANSAC
\r
803 CV_EXPORTS Mat findFundamentalMat( const Vector<Point2f>& points1,
\r
804 const Vector<Point2f>& points2,
\r
805 Vector<bool>& mask,
\r
806 int method=FM_RANSAC,
\r
807 double param1=3., double param2=0.99 );
\r
809 CV_EXPORTS Mat findFundamentalMat( const Vector<Point2f>& points1,
\r
810 const Vector<Point2f>& points2,
\r
811 int method=FM_RANSAC,
\r
812 double param1=3., double param2=0.99 );
\r
814 CV_EXPORTS void computeCorrespondEpilines( const Vector<Point2f>& points1,
\r
815 int whichImage, const Mat& F,
\r
816 Vector<Vec3f>& lines );
\r
818 template<> inline void Ptr<CvStereoBMState>::delete_obj()
\r
819 { cvReleaseStereoBMState(&obj); }
\r
821 // Block matching stereo correspondence algorithm
\r
822 class CV_EXPORTS StereoBM
\r
824 enum { NORMALIZED_RESPONSE = CV_STEREO_BM_NORMALIZED_RESPONSE,
\r
825 BASIC_PRESET=CV_STEREO_BM_BASIC,
\r
826 FISH_EYE_PRESET=CV_STEREO_BM_FISH_EYE,
\r
827 NARROW_PRESET=CV_STEREO_BM_NARROW };
\r
830 StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
\r
831 void init(int preset, int ndisparities=0, int SADWindowSize=21);
\r
832 void operator()( const Mat& left, const Mat& right, Mat& disparity );
\r
834 Ptr<CvStereoBMState> state;
\r
837 CV_EXPORTS void reprojectImageTo3D( const Mat& disparity,
\r
838 Mat& _3dImage, const Mat& Q,
\r
839 bool handleMissingValues=false );
\r
841 class CV_EXPORTS SURFKeypoint : public CvSURFPoint
\r
844 SURFKeypoint() { pt=Point2f(); laplacian=size=0; dir=hessian=0; }
\r
845 SURFKeypoint(Point2f _pt, int _laplacian, int _size, float _dir=0.f, float _hessian=0.f)
\r
846 { pt = _pt; laplacian = _laplacian; size = _size; dir = _dir; hessian = _hessian; }
\r
849 class CV_EXPORTS SURF : public CvSURFParams
\r
853 SURF(double _hessianThreshold, bool _extended=false);
\r
855 int descriptorSize() const;
\r
856 void operator()(const Mat& img, const Mat& mask,
\r
857 Vector<SURFKeypoint>& keypoints) const;
\r
858 void operator()(const Mat& img, const Mat& mask,
\r
859 Vector<SURFKeypoint>& keypoints,
\r
860 Vector<float>& descriptors,
\r
861 bool useProvidedKeypoints=false) const;
\r
865 class CV_EXPORTS MSER : public CvMSERParams
\r
869 MSER( int _delta, int _min_area, int _max_area,
\r
870 float _max_variation, float _min_diversity,
\r
871 int _max_evolution, double _area_threshold,
\r
872 double _min_margin, int _edge_blur_size );
\r
873 Vector<Vector<Point> > operator()(Mat& image, const Mat& mask) const;
\r
876 class CV_EXPORTS StarKeypoint : public CvStarKeypoint
\r
879 StarKeypoint() { pt = Point(); size = 0; response = 0.f; }
\r
880 StarKeypoint(Point _pt, int _size, float _response)
\r
882 pt = _pt; size = _size; response = _response;
\r
886 class CV_EXPORTS StarDetector : CvStarDetectorParams
\r
890 StarDetector(int _maxSize, int _responseThreshold,
\r
891 int _lineThresholdProjected,
\r
892 int _lineThresholdBinarized,
\r
893 int _suppressNonmaxSize);
\r
895 void operator()(const Mat& image, Vector<StarKeypoint>& keypoints) const;
\r
900 //////////////////////////////////////////////////////////////////////////////////////////
\r
902 class CV_EXPORTS CvLevMarq
\r
906 CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
\r
907 cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
\r
908 bool completeSymmFlag=false );
\r
910 void init( int nparams, int nerrs, CvTermCriteria criteria=
\r
911 cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
\r
912 bool completeSymmFlag=false );
\r
913 bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
\r
914 bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
\r
918 enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
\r
930 double prevErrNorm, errNorm;
\r
932 CvTermCriteria criteria;
\r
935 bool completeSymmFlag;
\r
939 // 2009-01-12, Xavier Delacour <xavier.delacour@gmail.com>
\r
945 struct CvLSHOperations
\r
947 virtual ~CvLSHOperations() {}
\r
949 virtual int vector_add(const void* data) = 0;
\r
950 virtual void vector_remove(int i) = 0;
\r
951 virtual const void* vector_lookup(int i) = 0;
\r
952 virtual void vector_reserve(int n) = 0;
\r
953 virtual unsigned int vector_count() = 0;
\r
955 virtual void hash_insert(lsh_hash h, int l, int i) = 0;
\r
956 virtual void hash_remove(lsh_hash h, int l, int i) = 0;
\r
957 virtual int hash_lookup(lsh_hash h, int l, int* ret_i, int ret_i_max) = 0;
\r
961 #endif /* __cplusplus */
\r
963 #endif /* _CV_HPP_ */
\r