1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #ifndef __OPENCV_CV_HPP__
44 #define __OPENCV_CV_HPP__
51 enum { BORDER_REPLICATE=IPL_BORDER_REPLICATE, BORDER_CONSTANT=IPL_BORDER_CONSTANT,
52 BORDER_REFLECT=IPL_BORDER_REFLECT, BORDER_REFLECT_101=IPL_BORDER_REFLECT_101,
53 BORDER_REFLECT101=BORDER_REFLECT_101, BORDER_WRAP=IPL_BORDER_WRAP,
54 BORDER_TRANSPARENT, BORDER_DEFAULT=BORDER_REFLECT_101, BORDER_ISOLATED=16 };
56 CV_EXPORTS int borderInterpolate( int p, int len, int borderType );
58 class CV_EXPORTS BaseRowFilter
62 virtual ~BaseRowFilter();
63 virtual void operator()(const uchar* src, uchar* dst,
64 int width, int cn) = 0;
69 class CV_EXPORTS BaseColumnFilter
73 virtual ~BaseColumnFilter();
74 virtual void operator()(const uchar** src, uchar* dst, int dststep,
75 int dstcount, int width) = 0;
81 class CV_EXPORTS BaseFilter
85 virtual ~BaseFilter();
86 virtual void operator()(const uchar** src, uchar* dst, int dststep,
87 int dstcount, int width, int cn) = 0;
94 class CV_EXPORTS FilterEngine
98 FilterEngine(const Ptr<BaseFilter>& _filter2D,
99 const Ptr<BaseRowFilter>& _rowFilter,
100 const Ptr<BaseColumnFilter>& _columnFilter,
101 int srcType, int dstType, int bufType,
102 int _rowBorderType=BORDER_REPLICATE,
103 int _columnBorderType=-1,
104 const Scalar& _borderValue=Scalar());
105 virtual ~FilterEngine();
106 void init(const Ptr<BaseFilter>& _filter2D,
107 const Ptr<BaseRowFilter>& _rowFilter,
108 const Ptr<BaseColumnFilter>& _columnFilter,
109 int srcType, int dstType, int bufType,
110 int _rowBorderType=BORDER_REPLICATE, int _columnBorderType=-1,
111 const Scalar& _borderValue=Scalar());
112 virtual int start(Size wholeSize, Rect roi, int maxBufRows=-1);
113 virtual int start(const Mat& src, const Rect& srcRoi=Rect(0,0,-1,-1),
114 bool isolated=false, int maxBufRows=-1);
115 virtual int proceed(const uchar* src, int srcStep, int srcCount,
116 uchar* dst, int dstStep);
117 virtual void apply( const Mat& src, Mat& dst,
118 const Rect& srcRoi=Rect(0,0,-1,-1),
119 Point dstOfs=Point(0,0),
120 bool isolated=false);
121 bool isSeparable() const { return (const BaseFilter*)filter2D == 0; }
122 int remainingInputRows() const;
123 int remainingOutputRows() const;
125 int srcType, dstType, bufType;
132 int rowBorderType, columnBorderType;
133 vector<int> borderTab;
135 vector<uchar> ringBuf;
136 vector<uchar> srcRow;
137 vector<uchar> constBorderValue;
138 vector<uchar> constBorderRow;
139 int bufStep, startY, startY0, endY, rowCount, dstY;
142 Ptr<BaseFilter> filter2D;
143 Ptr<BaseRowFilter> rowFilter;
144 Ptr<BaseColumnFilter> columnFilter;
147 enum { KERNEL_GENERAL=0, KERNEL_SYMMETRICAL=1, KERNEL_ASYMMETRICAL=2,
148 KERNEL_SMOOTH=4, KERNEL_INTEGER=8 };
150 CV_EXPORTS int getKernelType(const Mat& kernel, Point anchor);
152 CV_EXPORTS Ptr<BaseRowFilter> getLinearRowFilter(int srcType, int bufType,
153 const Mat& kernel, int anchor,
156 CV_EXPORTS Ptr<BaseColumnFilter> getLinearColumnFilter(int bufType, int dstType,
157 const Mat& kernel, int anchor,
158 int symmetryType, double delta=0,
161 CV_EXPORTS Ptr<BaseFilter> getLinearFilter(int srcType, int dstType,
163 Point anchor=Point(-1,-1),
164 double delta=0, int bits=0);
166 CV_EXPORTS Ptr<FilterEngine> createSeparableLinearFilter(int srcType, int dstType,
167 const Mat& rowKernel, const Mat& columnKernel,
168 Point _anchor=Point(-1,-1), double delta=0,
169 int _rowBorderType=BORDER_DEFAULT,
170 int _columnBorderType=-1,
171 const Scalar& _borderValue=Scalar());
173 CV_EXPORTS Ptr<FilterEngine> createLinearFilter(int srcType, int dstType,
174 const Mat& kernel, Point _anchor=Point(-1,-1),
175 double delta=0, int _rowBorderType=BORDER_DEFAULT,
176 int _columnBorderType=-1, const Scalar& _borderValue=Scalar());
178 CV_EXPORTS Mat getGaussianKernel( int ksize, double sigma, int ktype=CV_64F );
180 CV_EXPORTS Ptr<FilterEngine> createGaussianFilter( int type, Size ksize,
181 double sigma1, double sigma2=0,
182 int borderType=BORDER_DEFAULT);
184 CV_EXPORTS void getDerivKernels( Mat& kx, Mat& ky, int dx, int dy, int ksize,
185 bool normalize=false, int ktype=CV_32F );
187 CV_EXPORTS Ptr<FilterEngine> createDerivFilter( int srcType, int dstType,
188 int dx, int dy, int ksize,
189 int borderType=BORDER_DEFAULT );
191 CV_EXPORTS Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType,
192 int ksize, int anchor=-1);
193 CV_EXPORTS Ptr<BaseColumnFilter> getColumnSumFilter(int sumType, int dstType,
194 int ksize, int anchor=-1,
196 CV_EXPORTS Ptr<FilterEngine> createBoxFilter( int srcType, int dstType, Size ksize,
197 Point anchor=Point(-1,-1),
199 int borderType=BORDER_DEFAULT);
201 enum { MORPH_ERODE=0, MORPH_DILATE=1, MORPH_OPEN=2, MORPH_CLOSE=3,
202 MORPH_GRADIENT=4, MORPH_TOPHAT=5, MORPH_BLACKHAT=6 };
204 CV_EXPORTS Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int anchor=-1);
205 CV_EXPORTS Ptr<BaseColumnFilter> getMorphologyColumnFilter(int op, int type, int ksize, int anchor=-1);
206 CV_EXPORTS Ptr<BaseFilter> getMorphologyFilter(int op, int type, const Mat& kernel,
207 Point anchor=Point(-1,-1));
209 static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); }
211 CV_EXPORTS Ptr<FilterEngine> createMorphologyFilter(int op, int type, const Mat& kernel,
212 Point anchor=Point(-1,-1), int _rowBorderType=BORDER_CONSTANT,
213 int _columnBorderType=-1,
214 const Scalar& _borderValue=morphologyDefaultBorderValue());
216 enum { MORPH_RECT=0, MORPH_CROSS=1, MORPH_ELLIPSE=2 };
217 CV_EXPORTS Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1));
219 template<> inline void Ptr<IplConvKernel>::delete_obj()
220 { cvReleaseStructuringElement(&obj); }
223 CV_EXPORTS void copyMakeBorder( const Mat& src, Mat& dst,
224 int top, int bottom, int left, int right,
225 int borderType, const Scalar& value=Scalar() );
227 CV_EXPORTS void medianBlur( const Mat& src, Mat& dst, int ksize );
228 CV_EXPORTS void GaussianBlur( const Mat& src, Mat& dst, Size ksize,
229 double sigma1, double sigma2=0,
230 int borderType=BORDER_DEFAULT );
231 CV_EXPORTS void bilateralFilter( const Mat& src, Mat& dst, int d,
232 double sigmaColor, double sigmaSpace,
233 int borderType=BORDER_DEFAULT );
234 CV_EXPORTS void boxFilter( const Mat& src, Mat& dst, int ddepth,
235 Size ksize, Point anchor=Point(-1,-1),
237 int borderType=BORDER_DEFAULT );
238 static inline void blur( const Mat& src, Mat& dst,
239 Size ksize, Point anchor=Point(-1,-1),
240 int borderType=BORDER_DEFAULT )
242 boxFilter( src, dst, -1, ksize, anchor, true, borderType );
245 CV_EXPORTS void filter2D( const Mat& src, Mat& dst, int ddepth,
246 const Mat& kernel, Point anchor=Point(-1,-1),
247 double delta=0, int borderType=BORDER_DEFAULT );
249 CV_EXPORTS void sepFilter2D( const Mat& src, Mat& dst, int ddepth,
250 const Mat& kernelX, const Mat& kernelY,
251 Point anchor=Point(-1,-1),
252 double delta=0, int borderType=BORDER_DEFAULT );
254 CV_EXPORTS void Sobel( const Mat& src, Mat& dst, int ddepth,
255 int dx, int dy, int ksize=3,
256 double scale=1, double delta=0,
257 int borderType=BORDER_DEFAULT );
259 CV_EXPORTS void Scharr( const Mat& src, Mat& dst, int ddepth,
260 int dx, int dy, double scale=1, double delta=0,
261 int borderType=BORDER_DEFAULT );
263 CV_EXPORTS void Laplacian( const Mat& src, Mat& dst, int ddepth,
264 int ksize=1, double scale=1, double delta=0,
265 int borderType=BORDER_DEFAULT );
267 CV_EXPORTS void Canny( const Mat& image, Mat& edges,
268 double threshold1, double threshold2,
269 int apertureSize=3, bool L2gradient=false );
271 CV_EXPORTS void cornerMinEigenVal( const Mat& src, Mat& dst,
272 int blockSize, int ksize=3,
273 int borderType=BORDER_DEFAULT );
275 CV_EXPORTS void cornerHarris( const Mat& src, Mat& dst, int blockSize,
277 int borderType=BORDER_DEFAULT );
279 CV_EXPORTS void cornerEigenValsAndVecs( const Mat& src, Mat& dst,
280 int blockSize, int ksize,
281 int borderType=BORDER_DEFAULT );
283 CV_EXPORTS void preCornerDetect( const Mat& src, Mat& dst, int ksize,
284 int borderType=BORDER_DEFAULT );
286 CV_EXPORTS void cornerSubPix( const Mat& image, vector<Point2f>& corners,
287 Size winSize, Size zeroZone,
288 TermCriteria criteria );
290 CV_EXPORTS void goodFeaturesToTrack( const Mat& image, vector<Point2f>& corners,
291 int maxCorners, double qualityLevel, double minDistance,
292 const Mat& mask=Mat(), int blockSize=3,
293 bool useHarrisDetector=false, double k=0.04 );
295 CV_EXPORTS void HoughLines( const Mat& image, vector<Vec2f>& lines,
296 double rho, double theta, int threshold,
297 double srn=0, double stn=0 );
299 CV_EXPORTS void HoughLinesP( Mat& image, vector<Vec4i>& lines,
300 double rho, double theta, int threshold,
301 double minLineLength=0, double maxLineGap=0 );
303 CV_EXPORTS void HoughCircles( const Mat& image, vector<Vec3f>& circles,
304 int method, double dp, double minDist,
305 double param1=100, double param2=100,
306 int minRadius=0, int maxRadius=0 );
308 CV_EXPORTS void erode( const Mat& src, Mat& dst, const Mat& kernel,
309 Point anchor=Point(-1,-1), int iterations=1,
310 int borderType=BORDER_CONSTANT,
311 const Scalar& borderValue=morphologyDefaultBorderValue() );
312 CV_EXPORTS void dilate( const Mat& src, Mat& dst, const Mat& kernel,
313 Point anchor=Point(-1,-1), int iterations=1,
314 int borderType=BORDER_CONSTANT,
315 const Scalar& borderValue=morphologyDefaultBorderValue() );
316 CV_EXPORTS void morphologyEx( const Mat& src, Mat& dst, int op, const Mat& kernel,
317 Point anchor=Point(-1,-1), int iterations=1,
318 int borderType=BORDER_CONSTANT,
319 const Scalar& borderValue=morphologyDefaultBorderValue() );
321 enum { INTER_NEAREST=0, INTER_LINEAR=1, INTER_CUBIC=2, INTER_AREA=3,
322 INTER_LANCZOS4=4, INTER_MAX=7, WARP_INVERSE_MAP=16 };
324 CV_EXPORTS void resize( const Mat& src, Mat& dst,
325 Size dsize, double fx=0, double fy=0,
326 int interpolation=INTER_LINEAR );
328 CV_EXPORTS void warpAffine( const Mat& src, Mat& dst,
329 const Mat& M, Size dsize,
330 int flags=INTER_LINEAR,
331 int borderMode=BORDER_CONSTANT,
332 const Scalar& borderValue=Scalar());
333 CV_EXPORTS void warpPerspective( const Mat& src, Mat& dst,
334 const Mat& M, Size dsize,
335 int flags=INTER_LINEAR,
336 int borderMode=BORDER_CONSTANT,
337 const Scalar& borderValue=Scalar());
339 CV_EXPORTS void remap( const Mat& src, Mat& dst, const Mat& map1, const Mat& map2,
340 int interpolation, int borderMode=BORDER_CONSTANT,
341 const Scalar& borderValue=Scalar());
343 CV_EXPORTS void convertMaps( const Mat& map1, const Mat& map2, Mat& dstmap1, Mat& dstmap2,
344 int dstmap1type, bool nninterpolation=false );
346 CV_EXPORTS Mat getRotationMatrix2D( Point2f center, double angle, double scale );
347 CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] );
348 CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );
349 CV_EXPORTS void invertAffineTransform(const Mat& M, Mat& iM);
351 CV_EXPORTS void getRectSubPix( const Mat& image, Size patchSize,
352 Point2f center, Mat& patch, int patchType=-1 );
354 CV_EXPORTS void integral( const Mat& src, Mat& sum, int sdepth=-1 );
355 CV_EXPORTS void integral( const Mat& src, Mat& sum, Mat& sqsum, int sdepth=-1 );
356 CV_EXPORTS void integral( const Mat& src, Mat& sum, Mat& sqsum, Mat& tilted, int sdepth=-1 );
358 CV_EXPORTS void accumulate( const Mat& src, Mat& dst, const Mat& mask=Mat() );
359 CV_EXPORTS void accumulateSquare( const Mat& src, Mat& dst, const Mat& mask=Mat() );
360 CV_EXPORTS void accumulateProduct( const Mat& src1, const Mat& src2,
361 Mat& dst, const Mat& mask=Mat() );
362 CV_EXPORTS void accumulateWeighted( const Mat& src, Mat& dst,
363 double alpha, const Mat& mask=Mat() );
365 enum { THRESH_BINARY=0, THRESH_BINARY_INV=1, THRESH_TRUNC=2, THRESH_TOZERO=3,
366 THRESH_TOZERO_INV=4, THRESH_MASK=7, THRESH_OTSU=8 };
368 CV_EXPORTS double threshold( const Mat& src, Mat& dst, double thresh, double maxval, int type );
370 enum { ADAPTIVE_THRESH_MEAN_C=0, ADAPTIVE_THRESH_GAUSSIAN_C=1 };
372 CV_EXPORTS void adaptiveThreshold( const Mat& src, Mat& dst, double maxValue,
373 int adaptiveMethod, int thresholdType,
374 int blockSize, double C );
376 CV_EXPORTS void pyrDown( const Mat& src, Mat& dst, const Size& dstsize=Size());
377 CV_EXPORTS void pyrUp( const Mat& src, Mat& dst, const Size& dstsize=Size());
378 CV_EXPORTS void buildPyramid( const Mat& src, vector<Mat>& dst, int maxlevel );
381 CV_EXPORTS void undistort( const Mat& src, Mat& dst, const Mat& cameraMatrix,
382 const Mat& distCoeffs, const Mat& newCameraMatrix=Mat() );
383 CV_EXPORTS void initUndistortRectifyMap( const Mat& cameraMatrix, const Mat& distCoeffs,
384 const Mat& R, const Mat& newCameraMatrix,
385 Size size, int m1type, Mat& map1, Mat& map2 );
386 CV_EXPORTS Mat getOptimalNewCameraMatrix( const Mat& cameraMatrix, const Mat& distCoeffs,
387 Size imageSize, double alpha, Size newImgSize=Size(),
388 Rect* validPixROI=0);
389 CV_EXPORTS Mat getDefaultNewCameraMatrix( const Mat& cameraMatrix, Size imgsize=Size(),
390 bool centerPrincipalPoint=false );
392 enum { OPTFLOW_USE_INITIAL_FLOW=4, OPTFLOW_FARNEBACK_GAUSSIAN=256 };
394 CV_EXPORTS void calcOpticalFlowPyrLK( const Mat& prevImg, const Mat& nextImg,
395 const vector<Point2f>& prevPts, vector<Point2f>& nextPts,
396 vector<uchar>& status, vector<float>& err,
397 Size winSize=Size(15,15), int maxLevel=3,
398 TermCriteria criteria=TermCriteria(
399 TermCriteria::COUNT+TermCriteria::EPS,
401 double derivLambda=0.5,
404 CV_EXPORTS void calcOpticalFlowFarneback( const Mat& prev0, const Mat& next0,
405 Mat& flow0, double pyr_scale, int levels, int winsize,
406 int iterations, int poly_n, double poly_sigma, int flags );
409 template<> inline void Ptr<CvHistogram>::delete_obj()
410 { cvReleaseHist(&obj); }
412 CV_EXPORTS void calcHist( const Mat* images, int nimages,
413 const int* channels, const Mat& mask,
414 MatND& hist, int dims, const int* histSize,
415 const float** ranges, bool uniform=true,
416 bool accumulate=false );
418 CV_EXPORTS void calcHist( const Mat* images, int nimages,
419 const int* channels, const Mat& mask,
420 SparseMat& hist, int dims, const int* histSize,
421 const float** ranges, bool uniform=true,
422 bool accumulate=false );
424 CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
425 const int* channels, const MatND& hist,
426 Mat& backProject, const float** ranges,
427 double scale=1, bool uniform=true );
429 CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
430 const int* channels, const SparseMat& hist,
431 Mat& backProject, const float** ranges,
432 double scale=1, bool uniform=true );
434 CV_EXPORTS double compareHist( const MatND& H1, const MatND& H2, int method );
436 CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method );
438 CV_EXPORTS void equalizeHist( const Mat& src, Mat& dst );
440 CV_EXPORTS void watershed( const Mat& image, Mat& markers );
442 enum { GC_BGD = 0, // background
443 GC_FGD = 1, // foreground
444 GC_PR_BGD = 2, // most probably background
445 GC_PR_FGD = 3 // most probably foreground
448 enum { GC_INIT_WITH_RECT = 0,
449 GC_INIT_WITH_MASK = 1,
453 CV_EXPORTS void grabCut( const Mat& img, Mat& mask, Rect rect,
454 Mat& bgdModel, Mat& fgdModel,
455 int iterCount, int mode = GC_EVAL );
457 enum { INPAINT_NS=CV_INPAINT_NS, INPAINT_TELEA=CV_INPAINT_TELEA };
459 CV_EXPORTS void inpaint( const Mat& src, const Mat& inpaintMask,
460 Mat& dst, double inpaintRange, int flags );
462 CV_EXPORTS void distanceTransform( const Mat& src, Mat& dst, Mat& labels,
463 int distanceType, int maskSize );
465 CV_EXPORTS void distanceTransform( const Mat& src, Mat& dst,
466 int distanceType, int maskSize );
468 enum { FLOODFILL_FIXED_RANGE = 1 << 16,
469 FLOODFILL_MASK_ONLY = 1 << 17 };
471 CV_EXPORTS int floodFill( Mat& image,
472 Point seedPoint, Scalar newVal, Rect* rect=0,
473 Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
476 CV_EXPORTS int floodFill( Mat& image, Mat& mask,
477 Point seedPoint, Scalar newVal, Rect* rect=0,
478 Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
481 CV_EXPORTS void cvtColor( const Mat& src, Mat& dst, int code, int dstCn=0 );
483 class CV_EXPORTS Moments
487 Moments(double m00, double m10, double m01, double m20, double m11,
488 double m02, double m30, double m21, double m12, double m03 );
489 Moments( const CvMoments& moments );
490 operator CvMoments() const;
492 double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; // spatial moments
493 double mu20, mu11, mu02, mu30, mu21, mu12, mu03; // central moments
494 double nu20, nu11, nu02, nu30, nu21, nu12, nu03; // central normalized moments
497 CV_EXPORTS Moments moments( const Mat& array, bool binaryImage=false );
499 CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] );
501 enum { TM_SQDIFF=CV_TM_SQDIFF, TM_SQDIFF_NORMED=CV_TM_SQDIFF_NORMED,
502 TM_CCORR=CV_TM_CCORR, TM_CCORR_NORMED=CV_TM_CCORR_NORMED,
503 TM_CCOEFF=CV_TM_CCOEFF, TM_CCOEFF_NORMED=CV_TM_CCOEFF_NORMED };
505 CV_EXPORTS void matchTemplate( const Mat& image, const Mat& templ, Mat& result, int method );
507 enum { RETR_EXTERNAL=CV_RETR_EXTERNAL, RETR_LIST=CV_RETR_LIST,
508 RETR_CCOMP=CV_RETR_CCOMP, RETR_TREE=CV_RETR_TREE };
510 enum { CHAIN_APPROX_NONE=CV_CHAIN_APPROX_NONE,
511 CHAIN_APPROX_SIMPLE=CV_CHAIN_APPROX_SIMPLE,
512 CHAIN_APPROX_TC89_L1=CV_CHAIN_APPROX_TC89_L1,
513 CHAIN_APPROX_TC89_KCOS=CV_CHAIN_APPROX_TC89_KCOS };
515 CV_EXPORTS void findContours( const Mat& image, vector<vector<Point> >& contours,
516 vector<Vec4i>& hierarchy, int mode,
517 int method, Point offset=Point());
519 CV_EXPORTS void findContours( const Mat& image, vector<vector<Point> >& contours,
520 int mode, int method, Point offset=Point());
522 CV_EXPORTS void drawContours( Mat& image, const vector<vector<Point> >& contours,
523 int contourIdx, const Scalar& color,
524 int thickness=1, int lineType=8,
525 const vector<Vec4i>& hierarchy=vector<Vec4i>(),
526 int maxLevel=INT_MAX, Point offset=Point() );
528 CV_EXPORTS void approxPolyDP( const Mat& curve,
529 vector<Point>& approxCurve,
530 double epsilon, bool closed );
531 CV_EXPORTS void approxPolyDP( const Mat& curve,
532 vector<Point2f>& approxCurve,
533 double epsilon, bool closed );
535 CV_EXPORTS double arcLength( const Mat& curve, bool closed );
536 CV_EXPORTS Rect boundingRect( const Mat& points );
537 CV_EXPORTS double contourArea( const Mat& contour );
538 CV_EXPORTS RotatedRect minAreaRect( const Mat& points );
539 CV_EXPORTS void minEnclosingCircle( const Mat& points,
540 Point2f& center, float& radius );
541 CV_EXPORTS double matchShapes( const Mat& contour1,
543 int method, double parameter );
545 CV_EXPORTS void convexHull( const Mat& points, vector<int>& hull, bool clockwise=false );
546 CV_EXPORTS void convexHull( const Mat& points, vector<Point>& hull, bool clockwise=false );
547 CV_EXPORTS void convexHull( const Mat& points, vector<Point2f>& hull, bool clockwise=false );
549 CV_EXPORTS bool isContourConvex( const Mat& contour );
551 CV_EXPORTS RotatedRect fitEllipse( const Mat& points );
553 CV_EXPORTS void fitLine( const Mat& points, Vec4f& line, int distType,
554 double param, double reps, double aeps );
555 CV_EXPORTS void fitLine( const Mat& points, Vec6f& line, int distType,
556 double param, double reps, double aeps );
558 CV_EXPORTS double pointPolygonTest( const Mat& contour,
559 Point2f pt, bool measureDist );
561 CV_EXPORTS Mat estimateRigidTransform( const Mat& A, const Mat& B,
564 CV_EXPORTS void updateMotionHistory( const Mat& silhouette, Mat& mhi,
565 double timestamp, double duration );
567 CV_EXPORTS void calcMotionGradient( const Mat& mhi, Mat& mask,
569 double delta1, double delta2,
570 int apertureSize=3 );
572 CV_EXPORTS double calcGlobalOrientation( const Mat& orientation, const Mat& mask,
573 const Mat& mhi, double timestamp,
575 // TODO: need good API for cvSegmentMotion
577 CV_EXPORTS RotatedRect CamShift( const Mat& probImage, Rect& window,
578 TermCriteria criteria );
580 CV_EXPORTS int meanShift( const Mat& probImage, Rect& window,
581 TermCriteria criteria );
583 CV_EXPORTS int estimateAffine3D(const Mat& from, const Mat& to, Mat& out,
584 vector<uchar>& outliers,
585 double param1 = 3.0, double param2 = 0.99);
587 class CV_EXPORTS KalmanFilter
591 KalmanFilter(int dynamParams, int measureParams, int controlParams=0);
592 void init(int dynamParams, int measureParams, int controlParams=0);
594 const Mat& predict(const Mat& control=Mat());
595 const Mat& correct(const Mat& measurement);
597 Mat statePre; // predicted state (x'(k)):
598 // x(k)=A*x(k-1)+B*u(k)
599 Mat statePost; // corrected state (x(k)):
600 // x(k)=x'(k)+K(k)*(z(k)-H*x'(k))
601 Mat transitionMatrix; // state transition matrix (A)
602 Mat controlMatrix; // control matrix (B)
603 // (it is not used if there is no control)
604 Mat measurementMatrix; // measurement matrix (H)
605 Mat processNoiseCov; // process noise covariance matrix (Q)
606 Mat measurementNoiseCov;// measurement noise covariance matrix (R)
607 Mat errorCovPre; // priori error estimate covariance matrix (P'(k)):
608 // P'(k)=A*P(k-1)*At + Q)*/
609 Mat gain; // Kalman gain matrix (K(k)):
610 // K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)
611 Mat errorCovPost; // posteriori error estimate covariance matrix (P(k)):
612 // P(k)=(I-K(k)*H)*P'(k)
613 Mat temp1; // temporary matrices
621 ///////////////////////////// Object Detection ////////////////////////////
623 CV_EXPORTS void groupRectangles(vector<Rect>& rectList, int groupThreshold, double eps=0.2);
624 CV_EXPORTS void groupRectangles(vector<Rect>& rectList, vector<int>& weights, int groupThreshold, double eps=0.2);
626 class CV_EXPORTS FeatureEvaluator
629 enum { HAAR = 0, LBP = 1 };
630 virtual ~FeatureEvaluator();
631 virtual bool read(const FileNode& node);
632 virtual Ptr<FeatureEvaluator> clone() const;
633 virtual int getFeatureType() const;
635 virtual bool setImage(const Mat&, Size origWinSize);
636 virtual bool setWindow(Point p);
638 virtual double calcOrd(int featureIdx) const;
639 virtual int calcCat(int featureIdx) const;
641 static Ptr<FeatureEvaluator> create(int type);
644 template<> inline void Ptr<CvHaarClassifierCascade>::delete_obj()
645 { cvReleaseHaarClassifierCascade(&obj); }
647 class CV_EXPORTS CascadeClassifier
650 struct CV_EXPORTS DTreeNode
653 float threshold; // for ordered features only
658 struct CV_EXPORTS DTree
663 struct CV_EXPORTS Stage
671 enum { DO_CANNY_PRUNING = CV_HAAR_DO_CANNY_PRUNING,
672 SCALE_IMAGE = CV_HAAR_SCALE_IMAGE,
673 FIND_BIGGEST_OBJECT = CV_HAAR_FIND_BIGGEST_OBJECT,
674 DO_ROUGH_SEARCH = CV_HAAR_DO_ROUGH_SEARCH };
677 CascadeClassifier(const string& filename);
678 ~CascadeClassifier();
681 bool load(const string& filename);
682 bool read(const FileNode& node);
683 void detectMultiScale( const Mat& image,
684 vector<Rect>& objects,
685 double scaleFactor=1.1,
686 int minNeighbors=3, int flags=0,
687 Size minSize=Size());
689 bool setImage( Ptr<FeatureEvaluator>&, const Mat& );
690 int runAt( Ptr<FeatureEvaluator>&, Point );
699 vector<Stage> stages;
700 vector<DTree> classifiers;
701 vector<DTreeNode> nodes;
702 vector<float> leaves;
705 Ptr<FeatureEvaluator> feval;
706 Ptr<CvHaarClassifierCascade> oldCascade;
710 CV_EXPORTS void undistortPoints( const Mat& src, vector<Point2f>& dst,
711 const Mat& cameraMatrix, const Mat& distCoeffs,
712 const Mat& R=Mat(), const Mat& P=Mat());
713 CV_EXPORTS void undistortPoints( const Mat& src, Mat& dst,
714 const Mat& cameraMatrix, const Mat& distCoeffs,
715 const Mat& R=Mat(), const Mat& P=Mat());
717 CV_EXPORTS void Rodrigues(const Mat& src, Mat& dst);
718 CV_EXPORTS void Rodrigues(const Mat& src, Mat& dst, Mat& jacobian);
720 enum { LMEDS=4, RANSAC=8 };
722 CV_EXPORTS Mat findHomography( const Mat& srcPoints,
723 const Mat& dstPoints,
724 Mat& mask, int method=0,
725 double ransacReprojThreshold=0 );
727 CV_EXPORTS Mat findHomography( const Mat& srcPoints,
728 const Mat& dstPoints,
729 vector<uchar>& mask, int method=0,
730 double ransacReprojThreshold=0 );
732 CV_EXPORTS Mat findHomography( const Mat& srcPoints,
733 const Mat& dstPoints,
734 int method=0, double ransacReprojThreshold=0 );
736 /* Computes RQ decomposition for 3x3 matrices */
737 CV_EXPORTS void RQDecomp3x3( const Mat& M, Mat& R, Mat& Q );
738 CV_EXPORTS Vec3d RQDecomp3x3( const Mat& M, Mat& R, Mat& Q,
739 Mat& Qx, Mat& Qy, Mat& Qz );
741 CV_EXPORTS void decomposeProjectionMatrix( const Mat& projMatrix, Mat& cameraMatrix,
742 Mat& rotMatrix, Mat& transVect );
743 CV_EXPORTS void decomposeProjectionMatrix( const Mat& projMatrix, Mat& cameraMatrix,
744 Mat& rotMatrix, Mat& transVect,
745 Mat& rotMatrixX, Mat& rotMatrixY,
746 Mat& rotMatrixZ, Vec3d& eulerAngles );
748 CV_EXPORTS void matMulDeriv( const Mat& A, const Mat& B, Mat& dABdA, Mat& dABdB );
750 CV_EXPORTS void composeRT( const Mat& rvec1, const Mat& tvec1,
751 const Mat& rvec2, const Mat& tvec2,
752 Mat& rvec3, Mat& tvec3 );
754 CV_EXPORTS void composeRT( const Mat& rvec1, const Mat& tvec1,
755 const Mat& rvec2, const Mat& tvec2,
756 Mat& rvec3, Mat& tvec3,
757 Mat& dr3dr1, Mat& dr3dt1,
758 Mat& dr3dr2, Mat& dr3dt2,
759 Mat& dt3dr1, Mat& dt3dt1,
760 Mat& dt3dr2, Mat& dt3dt2 );
762 CV_EXPORTS void projectPoints( const Mat& objectPoints,
763 const Mat& rvec, const Mat& tvec,
764 const Mat& cameraMatrix,
765 const Mat& distCoeffs,
766 vector<Point2f>& imagePoints );
768 CV_EXPORTS void projectPoints( const Mat& objectPoints,
769 const Mat& rvec, const Mat& tvec,
770 const Mat& cameraMatrix,
771 const Mat& distCoeffs,
772 vector<Point2f>& imagePoints,
773 Mat& dpdrot, Mat& dpdt, Mat& dpdf,
774 Mat& dpdc, Mat& dpddist,
775 double aspectRatio=0 );
777 CV_EXPORTS void solvePnP( const Mat& objectPoints,
778 const Mat& imagePoints,
779 const Mat& cameraMatrix,
780 const Mat& distCoeffs,
781 Mat& rvec, Mat& tvec,
782 bool useExtrinsicGuess=false );
784 CV_EXPORTS Mat initCameraMatrix2D( const vector<vector<Point3f> >& objectPoints,
785 const vector<vector<Point2f> >& imagePoints,
786 Size imageSize, double aspectRatio=1. );
788 enum { CALIB_CB_ADAPTIVE_THRESH = CV_CALIB_CB_ADAPTIVE_THRESH,
789 CALIB_CB_NORMALIZE_IMAGE = CV_CALIB_CB_NORMALIZE_IMAGE,
790 CALIB_CB_FILTER_QUADS = CV_CALIB_CB_FILTER_QUADS };
792 CV_EXPORTS bool findChessboardCorners( const Mat& image, Size patternSize,
793 vector<Point2f>& corners,
794 int flags=CV_CALIB_CB_ADAPTIVE_THRESH+
795 CV_CALIB_CB_NORMALIZE_IMAGE );
797 CV_EXPORTS void drawChessboardCorners( Mat& image, Size patternSize,
799 bool patternWasFound );
803 CALIB_USE_INTRINSIC_GUESS = CV_CALIB_USE_INTRINSIC_GUESS,
804 CALIB_FIX_ASPECT_RATIO = CV_CALIB_FIX_ASPECT_RATIO,
805 CALIB_FIX_PRINCIPAL_POINT = CV_CALIB_FIX_PRINCIPAL_POINT,
806 CALIB_ZERO_TANGENT_DIST = CV_CALIB_ZERO_TANGENT_DIST,
807 CALIB_FIX_FOCAL_LENGTH = CV_CALIB_FIX_FOCAL_LENGTH,
808 CALIB_FIX_K1 = CV_CALIB_FIX_K1,
809 CALIB_FIX_K2 = CV_CALIB_FIX_K2,
810 CALIB_FIX_K3 = CV_CALIB_FIX_K3,
812 CALIB_FIX_INTRINSIC = CV_CALIB_FIX_INTRINSIC,
813 CALIB_SAME_FOCAL_LENGTH = CV_CALIB_SAME_FOCAL_LENGTH,
814 // for stereo rectification
815 CALIB_ZERO_DISPARITY = CV_CALIB_ZERO_DISPARITY
818 CV_EXPORTS double calibrateCamera( const vector<vector<Point3f> >& objectPoints,
819 const vector<vector<Point2f> >& imagePoints,
821 Mat& cameraMatrix, Mat& distCoeffs,
822 vector<Mat>& rvecs, vector<Mat>& tvecs,
825 CV_EXPORTS void calibrationMatrixValues( const Mat& cameraMatrix,
827 double apertureWidth,
828 double apertureHeight,
832 Point2d& principalPoint,
833 double& aspectRatio );
835 CV_EXPORTS double stereoCalibrate( const vector<vector<Point3f> >& objectPoints,
836 const vector<vector<Point2f> >& imagePoints1,
837 const vector<vector<Point2f> >& imagePoints2,
838 Mat& cameraMatrix1, Mat& distCoeffs1,
839 Mat& cameraMatrix2, Mat& distCoeffs2,
840 Size imageSize, Mat& R, Mat& T,
842 TermCriteria criteria = TermCriteria(TermCriteria::COUNT+
843 TermCriteria::EPS, 30, 1e-6),
844 int flags=CALIB_FIX_INTRINSIC );
846 CV_EXPORTS void stereoRectify( const Mat& cameraMatrix1, const Mat& distCoeffs1,
847 const Mat& cameraMatrix2, const Mat& distCoeffs2,
848 Size imageSize, const Mat& R, const Mat& T,
849 Mat& R1, Mat& R2, Mat& P1, Mat& P2, Mat& Q,
850 int flags=CALIB_ZERO_DISPARITY );
852 CV_EXPORTS void stereoRectify( const Mat& cameraMatrix1, const Mat& distCoeffs1,
853 const Mat& cameraMatrix2, const Mat& distCoeffs2,
854 Size imageSize, const Mat& R, const Mat& T,
855 Mat& R1, Mat& R2, Mat& P1, Mat& P2, Mat& Q,
856 double alpha, Size newImageSize=Size(),
857 Rect* validPixROI1=0, Rect* validPixROI2=0,
858 int flags=CALIB_ZERO_DISPARITY );
860 CV_EXPORTS bool stereoRectifyUncalibrated( const Mat& points1,
862 const Mat& F, Size imgSize,
864 double threshold=5 );
866 CV_EXPORTS void convertPointsHomogeneous( const Mat& src, vector<Point3f>& dst );
867 CV_EXPORTS void convertPointsHomogeneous( const Mat& src, vector<Point2f>& dst );
871 FM_7POINT = CV_FM_7POINT,
872 FM_8POINT = CV_FM_8POINT,
873 FM_LMEDS = CV_FM_LMEDS,
874 FM_RANSAC = CV_FM_RANSAC
877 CV_EXPORTS Mat findFundamentalMat( const Mat& points1, const Mat& points2,
878 vector<uchar>& mask, int method=FM_RANSAC,
879 double param1=3., double param2=0.99 );
881 CV_EXPORTS Mat findFundamentalMat( const Mat& points1, const Mat& points2,
882 int method=FM_RANSAC,
883 double param1=3., double param2=0.99 );
885 CV_EXPORTS void computeCorrespondEpilines( const Mat& points1,
886 int whichImage, const Mat& F,
887 vector<Vec3f>& lines );
889 template<> inline void Ptr<CvStereoBMState>::delete_obj()
890 { cvReleaseStereoBMState(&obj); }
892 // Block matching stereo correspondence algorithm
893 class CV_EXPORTS StereoBM
896 enum { PREFILTER_NORMALIZED_RESPONSE = CV_STEREO_BM_NORMALIZED_RESPONSE,
897 PREFILTER_XSOBEL = CV_STEREO_BM_XSOBEL,
898 BASIC_PRESET=CV_STEREO_BM_BASIC,
899 FISH_EYE_PRESET=CV_STEREO_BM_FISH_EYE,
900 NARROW_PRESET=CV_STEREO_BM_NARROW };
903 StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
904 void init(int preset, int ndisparities=0, int SADWindowSize=21);
905 void operator()( const Mat& left, const Mat& right, Mat& disparity, int disptype=CV_16S );
907 Ptr<CvStereoBMState> state;
911 class CV_EXPORTS StereoSGBM
914 enum { DISP_SHIFT=4, DISP_SCALE = (1<<DISP_SHIFT) };
917 StereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
918 int P1=0, int P2=0, int disp12MaxDiff=0,
919 int preFilterCap=0, int uniquenessRatio=0,
920 int speckleWindowSize=0, int speckleRange=0,
922 virtual ~StereoSGBM();
924 virtual void operator()(const Mat& left, const Mat& right, Mat& disp);
927 int numberOfDisparities;
932 int speckleWindowSize;
942 CV_EXPORTS void filterSpeckles( Mat& img, double newVal, int maxSpeckleSize, double maxDiff, Mat& buf );
944 CV_EXPORTS Rect getValidDisparityROI( Rect roi1, Rect roi2,
945 int minDisparity, int numberOfDisparities,
948 CV_EXPORTS void validateDisparity( Mat& disparity, const Mat& cost,
949 int minDisparity, int numberOfDisparities,
950 int disp12MaxDisp=1 );
952 CV_EXPORTS void reprojectImageTo3D( const Mat& disparity,
953 Mat& _3dImage, const Mat& Q,
954 bool handleMissingValues=false );
956 class CV_EXPORTS KeyPoint
959 KeyPoint() : pt(0,0), size(0), angle(-1), response(0), octave(0), class_id(-1) {}
960 KeyPoint(Point2f _pt, float _size, float _angle=-1,
961 float _response=0, int _octave=0, int _class_id=-1)
962 : pt(_pt), size(_size), angle(_angle),
963 response(_response), octave(_octave), class_id(_class_id) {}
964 KeyPoint(float x, float y, float _size, float _angle=-1,
965 float _response=0, int _octave=0, int _class_id=-1)
966 : pt(x, y), size(_size), angle(_angle),
967 response(_response), octave(_octave), class_id(_class_id) {}
977 CV_EXPORTS void write(FileStorage& fs, const string& name, const vector<KeyPoint>& keypoints);
978 CV_EXPORTS void read(const FileNode& node, vector<KeyPoint>& keypoints);
980 class CV_EXPORTS SURF : public CvSURFParams
984 SURF(double _hessianThreshold, int _nOctaves=4,
985 int _nOctaveLayers=2, bool _extended=false);
987 int descriptorSize() const;
988 void operator()(const Mat& img, const Mat& mask,
989 vector<KeyPoint>& keypoints) const;
990 void operator()(const Mat& img, const Mat& mask,
991 vector<KeyPoint>& keypoints,
992 vector<float>& descriptors,
993 bool useProvidedKeypoints=false) const;
997 class CV_EXPORTS MSER : public CvMSERParams
1001 MSER( int _delta, int _min_area, int _max_area,
1002 float _max_variation, float _min_diversity,
1003 int _max_evolution, double _area_threshold,
1004 double _min_margin, int _edge_blur_size );
1005 void operator()(Mat& image, vector<vector<Point> >& msers, const Mat& mask) const;
1009 class CV_EXPORTS StarDetector : public CvStarDetectorParams
1013 StarDetector(int _maxSize, int _responseThreshold,
1014 int _lineThresholdProjected,
1015 int _lineThresholdBinarized,
1016 int _suppressNonmaxSize);
1018 void operator()(const Mat& image, vector<KeyPoint>& keypoints) const;
1023 //////////////////////////////////////////////////////////////////////////////////////////
1025 class CV_EXPORTS CvLevMarq
1029 CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
1030 cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
1031 bool completeSymmFlag=false );
1033 void init( int nparams, int nerrs, CvTermCriteria criteria=
1034 cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
1035 bool completeSymmFlag=false );
1036 bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
1037 bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
1041 enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
1043 cv::Ptr<CvMat> mask;
1044 cv::Ptr<CvMat> prevParam;
1045 cv::Ptr<CvMat> param;
1049 cv::Ptr<CvMat> JtJN;
1050 cv::Ptr<CvMat> JtErr;
1051 cv::Ptr<CvMat> JtJV;
1052 cv::Ptr<CvMat> JtJW;
1053 double prevErrNorm, errNorm;
1055 CvTermCriteria criteria;
1058 bool completeSymmFlag;
1062 // 2009-01-12, Xavier Delacour <xavier.delacour@gmail.com>
1068 struct CvLSHOperations
1070 virtual ~CvLSHOperations() {}
1072 virtual int vector_add(const void* data) = 0;
1073 virtual void vector_remove(int i) = 0;
1074 virtual const void* vector_lookup(int i) = 0;
1075 virtual void vector_reserve(int n) = 0;
1076 virtual unsigned int vector_count() = 0;
1078 virtual void hash_insert(lsh_hash h, int l, int i) = 0;
1079 virtual void hash_remove(lsh_hash h, int l, int i) = 0;
1080 virtual int hash_lookup(lsh_hash h, int l, int* ret_i, int ret_i_max) = 0;
1083 #endif /* __cplusplus */