From 199a35a1051d35a897a42c5812686730a9842830 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 11 Apr 2013 17:38:33 +0400 Subject: [PATCH 1/6] Move C API of opencv_video to separate file --- apps/traincascade/HOGfeatures.cpp | 1 + apps/traincascade/haarfeatures.cpp | 1 + apps/traincascade/lbpfeatures.cpp | 1 + include/opencv/cv.h | 2 +- include/opencv/cv.hpp | 1 + include/opencv/cvaux.h | 2 +- modules/contrib/src/colortracker.cpp | 4 +- modules/contrib/src/featuretracker.cpp | 8 +- .../legacy/src/blobtrackpostprockalman.cpp | 1 + modules/legacy/src/camshift.cpp | 1 + modules/legacy/test/test_optflow.cpp | 1 + modules/python/src2/cv2.cpp | 1 + modules/video/include/opencv2/video.hpp | 7 +- .../include/opencv2/video/background_segm.hpp | 8 +- .../video/include/opencv2/video/tracking.hpp | 361 ++++-------------- .../video/include/opencv2/video/tracking_c.h | 227 +++++++++++ modules/video/perf/perf_ecc.cpp | 8 +- modules/video/perf/perf_optflowpyrlk.cpp | 4 +- modules/video/src/affineflow.cpp | 3 +- modules/video/src/bgfg_gaussmix.cpp | 4 +- modules/video/src/bgfg_gaussmix2.cpp | 2 +- modules/video/src/bgfg_gmg.cpp | 2 +- modules/video/src/camshift.cpp | 2 +- modules/video/src/compat_video.cpp | 1 + modules/video/src/ecc.cpp | 12 +- modules/video/src/lkpyramid.cpp | 10 +- modules/video/src/motempl.cpp | 6 +- modules/video/src/optflowgf.cpp | 2 +- modules/video/src/precomp.hpp | 3 +- .../test/test_backgroundsubtractor_gbh.cpp | 2 +- modules/video/test/test_camshift.cpp | 1 + modules/video/test/test_ecc.cpp | 8 +- modules/video/test/test_estimaterigid.cpp | 6 +- modules/video/test/test_kalman.cpp | 1 + modules/video/test/test_motiontemplates.cpp | 12 +- modules/video/test/test_optflowpyrlk.cpp | 1 + modules/videostab/src/global_motion.cpp | 2 +- modules/videostab/src/inpainting.cpp | 4 +- samples/c/fback_c.c | 2 +- samples/c/motempl.c | 4 +- ...es_HighDynamicRange_Retina_toneMapping.cpp | 2 +- ...hDynamicRange_Retina_toneMapping_video.cpp | 2 +- samples/cpp/camshiftdemo.cpp | 12 +- samples/cpp/fabmap_sample.cpp | 2 +- samples/cpp/fback.cpp | 6 +- samples/cpp/image_alignment.cpp | 12 +- samples/cpp/kalman.cpp | 14 +- samples/cpp/lkdemo.cpp | 6 +- 48 files changed, 409 insertions(+), 376 deletions(-) create mode 100644 modules/video/include/opencv2/video/tracking_c.h diff --git a/apps/traincascade/HOGfeatures.cpp b/apps/traincascade/HOGfeatures.cpp index b4ae56d37..132e2e62e 100644 --- a/apps/traincascade/HOGfeatures.cpp +++ b/apps/traincascade/HOGfeatures.cpp @@ -1,4 +1,5 @@ #include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" #include "HOGfeatures.h" #include "cascadeclassifier.h" diff --git a/apps/traincascade/haarfeatures.cpp b/apps/traincascade/haarfeatures.cpp index 40af47d42..ceb730aaf 100644 --- a/apps/traincascade/haarfeatures.cpp +++ b/apps/traincascade/haarfeatures.cpp @@ -1,4 +1,5 @@ #include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" #include "haarfeatures.h" #include "cascadeclassifier.h" diff --git a/apps/traincascade/lbpfeatures.cpp b/apps/traincascade/lbpfeatures.cpp index eb15b5ae8..dd1659f9d 100644 --- a/apps/traincascade/lbpfeatures.cpp +++ b/apps/traincascade/lbpfeatures.cpp @@ -1,4 +1,5 @@ #include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" #include "lbpfeatures.h" #include "cascadeclassifier.h" diff --git a/include/opencv/cv.h b/include/opencv/cv.h index 87fc0f2cf..39de8507b 100644 --- a/include/opencv/cv.h +++ b/include/opencv/cv.h @@ -63,8 +63,8 @@ #include "opencv2/core/core_c.h" #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/photo/photo_c.h" +#include "opencv2/video/tracking_c.h" -#include "opencv2/video.hpp" #include "opencv2/features2d.hpp" #include "opencv2/flann.hpp" #include "opencv2/calib3d.hpp" diff --git a/include/opencv/cv.hpp b/include/opencv/cv.hpp index 6b579ff91..4f60c49a7 100644 --- a/include/opencv/cv.hpp +++ b/include/opencv/cv.hpp @@ -51,6 +51,7 @@ #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/photo.hpp" +#include "opencv2/video.hpp" #include "opencv2/highgui.hpp" #endif diff --git a/include/opencv/cvaux.h b/include/opencv/cvaux.h index 78777ac1b..12e49cc93 100644 --- a/include/opencv/cvaux.h +++ b/include/opencv/cvaux.h @@ -49,8 +49,8 @@ #include "opencv2/core/core_c.h" #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/photo/photo_c.h" +#include "opencv2/video/tracking_c.h" -#include "opencv2/video.hpp" #include "opencv2/features2d.hpp" #include "opencv2/calib3d.hpp" #include "opencv2/objdetect.hpp" diff --git a/modules/contrib/src/colortracker.cpp b/modules/contrib/src/colortracker.cpp index 5a9d9b7c4..c1d91bb9b 100644 --- a/modules/contrib/src/colortracker.cpp +++ b/modules/contrib/src/colortracker.cpp @@ -60,7 +60,7 @@ void CvMeanShiftTracker::newTrackingWindow(Mat image, Rect selection) float srange[] = { 0, 1 }; const float* ranges[] = {hrange, srange}; - cvtColor(image, hsv, CV_BGR2HSV); + cvtColor(image, hsv, COLOR_BGR2HSV); inRange(hsv, Scalar(0, 30, MIN(10, 256)), Scalar(180, 256, MAX(10, 256)), mask); hue.create(hsv.size(), CV_8UC2); @@ -83,7 +83,7 @@ RotatedRect CvMeanShiftTracker::updateTrackingWindow(Mat image) float srange[] = { 0, 1 }; const float* ranges[] = {hrange, srange}; - cvtColor(image, hsv, CV_BGR2HSV); + cvtColor(image, hsv, COLOR_BGR2HSV); inRange(hsv, Scalar(0, 30, MIN(10, 256)), Scalar(180, 256, MAX(10, 256)), mask); hue.create(hsv.size(), CV_8UC2); mixChannels(&hsv, 1, &hue, 1, channels, 2); diff --git a/modules/contrib/src/featuretracker.cpp b/modules/contrib/src/featuretracker.cpp index 575f69abf..e94450db6 100644 --- a/modules/contrib/src/featuretracker.cpp +++ b/modules/contrib/src/featuretracker.cpp @@ -80,7 +80,7 @@ CvFeatureTracker::~CvFeatureTracker() void CvFeatureTracker::newTrackingWindow(Mat image, Rect selection) { image.copyTo(prev_image); - cvtColor(prev_image, prev_image_bw, CV_BGR2GRAY); + cvtColor(prev_image, prev_image_bw, COLOR_BGR2GRAY); prev_trackwindow = selection; prev_center.x = selection.x; prev_center.y = selection.y; @@ -148,12 +148,12 @@ Rect CvFeatureTracker::updateTrackingWindowWithFlow(Mat image) ittr++; Size subPixWinSize(10,10), winSize(31,31); Mat image_bw; - TermCriteria termcrit(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03); + TermCriteria termcrit(TermCriteria::COUNT | TermCriteria::EPS, 20, 0.03); std::vector status; std::vector err; - cvtColor(image, image_bw, CV_BGR2GRAY); - cvtColor(prev_image, prev_image_bw, CV_BGR2GRAY); + cvtColor(image, image_bw, COLOR_BGR2GRAY); + cvtColor(prev_image, prev_image_bw, COLOR_BGR2GRAY); if (ittr == 1) { diff --git a/modules/legacy/src/blobtrackpostprockalman.cpp b/modules/legacy/src/blobtrackpostprockalman.cpp index debe89d3f..fb6f8dee9 100644 --- a/modules/legacy/src/blobtrackpostprockalman.cpp +++ b/modules/legacy/src/blobtrackpostprockalman.cpp @@ -39,6 +39,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/video/tracking_c.h" /*======================= KALMAN FILTER =========================*/ /* State vector is (x,y,w,h,dx,dy,dw,dh). */ diff --git a/modules/legacy/src/camshift.cpp b/modules/legacy/src/camshift.cpp index 830e19824..b3cd9974a 100644 --- a/modules/legacy/src/camshift.cpp +++ b/modules/legacy/src/camshift.cpp @@ -39,6 +39,7 @@ // //M*/ #include "precomp.hpp" +#include "opencv2/video/tracking_c.h" CvCamShiftTracker::CvCamShiftTracker() { diff --git a/modules/legacy/test/test_optflow.cpp b/modules/legacy/test/test_optflow.cpp index f72d4c36a..99645410f 100644 --- a/modules/legacy/test/test_optflow.cpp +++ b/modules/legacy/test/test_optflow.cpp @@ -42,6 +42,7 @@ #include "test_precomp.hpp" #include "opencv2/video/tracking.hpp" +#include "opencv2/video/tracking_c.h" #include #include diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 75c8c2ec0..ac409ca2f 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -25,6 +25,7 @@ #include "opencv2/highgui/highgui_c.h" #include "opencv2/photo/photo_c.h" +#include "opencv2/video/tracking_c.h" #include "opencv2/opencv_modules.hpp" diff --git a/modules/video/include/opencv2/video.hpp b/modules/video/include/opencv2/video.hpp index 1dd96f543..b429ceff9 100644 --- a/modules/video/include/opencv2/video.hpp +++ b/modules/video/include/opencv2/video.hpp @@ -7,11 +7,12 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -46,13 +47,9 @@ #include "opencv2/video/tracking.hpp" #include "opencv2/video/background_segm.hpp" -#ifdef __cplusplus namespace cv { - CV_EXPORTS bool initModule_video(void); - } -#endif #endif //__OPENCV_VIDEO_HPP__ diff --git a/modules/video/include/opencv2/video/background_segm.hpp b/modules/video/include/opencv2/video/background_segm.hpp index d43157bd2..a46dc820e 100644 --- a/modules/video/include/opencv2/video/background_segm.hpp +++ b/modules/video/include/opencv2/video/background_segm.hpp @@ -7,7 +7,7 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. @@ -45,7 +45,7 @@ #define __OPENCV_BACKGROUND_SEGM_HPP__ #include "opencv2/core.hpp" -#include + namespace cv { @@ -66,6 +66,7 @@ public: }; + /*! Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm @@ -97,6 +98,7 @@ CV_EXPORTS_W Ptr double backgroundRatio=0.7, double noiseSigma=0); + /*! The class implements the following algorithm: "Improved adaptive Gausian mixture model for background subtraction" @@ -193,6 +195,6 @@ public: CV_EXPORTS_W Ptr createBackgroundSubtractorGMG(int initializationFrames=120, double decisionThreshold=0.8); -} +} // cv #endif diff --git a/modules/video/include/opencv2/video/tracking.hpp b/modules/video/include/opencv2/video/tracking.hpp index f943bb7e5..2045b19d9 100644 --- a/modules/video/include/opencv2/video/tracking.hpp +++ b/modules/video/include/opencv2/video/tracking.hpp @@ -7,11 +7,12 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -43,218 +44,95 @@ #ifndef __OPENCV_TRACKING_HPP__ #define __OPENCV_TRACKING_HPP__ -#ifdef __cplusplus -# include "opencv2/core.hpp" -# include "opencv2/imgproc.hpp" -#endif - -#include "opencv2/imgproc/types_c.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/****************************************************************************************\ -* Motion Analysis * -\****************************************************************************************/ - -/************************************ optical flow ***************************************/ - -#define CV_LKFLOW_PYR_A_READY 1 -#define CV_LKFLOW_PYR_B_READY 2 -#define CV_LKFLOW_INITIAL_GUESSES 4 -#define CV_LKFLOW_GET_MIN_EIGENVALS 8 - -/* It is Lucas & Kanade method, modified to use pyramids. - Also it does several iterations to get optical flow for - every point at every pyramid level. - Calculates optical flow between two images for certain set of points (i.e. - it is a "sparse" optical flow, which is opposite to the previous 3 methods) */ -CVAPI(void) cvCalcOpticalFlowPyrLK( const CvArr* prev, const CvArr* curr, - CvArr* prev_pyr, CvArr* curr_pyr, - const CvPoint2D32f* prev_features, - CvPoint2D32f* curr_features, - int count, - CvSize win_size, - int level, - char* status, - float* track_error, - CvTermCriteria criteria, - int flags ); - - -/* Modification of a previous sparse optical flow algorithm to calculate - affine flow */ -CVAPI(void) cvCalcAffineFlowPyrLK( const CvArr* prev, const CvArr* curr, - CvArr* prev_pyr, CvArr* curr_pyr, - const CvPoint2D32f* prev_features, - CvPoint2D32f* curr_features, - float* matrices, int count, - CvSize win_size, int level, - char* status, float* track_error, - CvTermCriteria criteria, int flags ); - -/* Estimate rigid transformation between 2 images or 2 point sets */ -CVAPI(int) cvEstimateRigidTransform( const CvArr* A, const CvArr* B, - CvMat* M, int full_affine ); - -/* Estimate optical flow for each pixel using the two-frame G. Farneback algorithm */ -CVAPI(void) cvCalcOpticalFlowFarneback( const CvArr* prev, const CvArr* next, - CvArr* flow, double pyr_scale, int levels, - int winsize, int iterations, int poly_n, - double poly_sigma, int flags ); - -/********************************* motion templates *************************************/ - -/****************************************************************************************\ -* All the motion template functions work only with single channel images. * -* Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S * -* Motion history image must have depth IPL_DEPTH_32F, * -* Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S, * -* Motion orientation image - IPL_DEPTH_32F * -* Segmentation mask - IPL_DEPTH_32F * -* All the angles are in degrees, all the times are in milliseconds * -\****************************************************************************************/ - -/* Updates motion history image given motion silhouette */ -CVAPI(void) cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi, - double timestamp, double duration ); - -/* Calculates gradient of the motion history image and fills - a mask indicating where the gradient is valid */ -CVAPI(void) cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation, - double delta1, double delta2, - int aperture_size CV_DEFAULT(3)); - -/* Calculates average motion direction within a selected motion region - (region can be selected by setting ROIs and/or by composing a valid gradient mask - with the region mask) */ -CVAPI(double) cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask, - const CvArr* mhi, double timestamp, - double duration ); - -/* Splits a motion history image into a few parts corresponding to separate independent motions - (e.g. left hand, right hand) */ -CVAPI(CvSeq*) cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask, - CvMemStorage* storage, - double timestamp, double seg_thresh ); - -/****************************************************************************************\ -* Tracking * -\****************************************************************************************/ - -/* Implements CAMSHIFT algorithm - determines object position, size and orientation - from the object histogram back project (extension of meanshift) */ -CVAPI(int) cvCamShift( const CvArr* prob_image, CvRect window, - CvTermCriteria criteria, CvConnectedComp* comp, - CvBox2D* box CV_DEFAULT(NULL) ); - -/* Implements MeanShift algorithm - determines object position - from the object histogram back project */ -CVAPI(int) cvMeanShift( const CvArr* prob_image, CvRect window, - CvTermCriteria criteria, CvConnectedComp* comp ); - -/* -standard Kalman filter (in G. Welch' and G. Bishop's notation): - - x(k)=A*x(k-1)+B*u(k)+w(k) p(w)~N(0,Q) - z(k)=H*x(k)+v(k), p(v)~N(0,R) -*/ -typedef struct CvKalman -{ - int MP; /* number of measurement vector dimensions */ - int DP; /* number of state vector dimensions */ - int CP; /* number of control vector dimensions */ - - /* backward compatibility fields */ -#if 1 - float* PosterState; /* =state_pre->data.fl */ - float* PriorState; /* =state_post->data.fl */ - float* DynamMatr; /* =transition_matrix->data.fl */ - float* MeasurementMatr; /* =measurement_matrix->data.fl */ - float* MNCovariance; /* =measurement_noise_cov->data.fl */ - float* PNCovariance; /* =process_noise_cov->data.fl */ - float* KalmGainMatr; /* =gain->data.fl */ - float* PriorErrorCovariance;/* =error_cov_pre->data.fl */ - float* PosterErrorCovariance;/* =error_cov_post->data.fl */ - float* Temp1; /* temp1->data.fl */ - float* Temp2; /* temp2->data.fl */ -#endif - - CvMat* state_pre; /* predicted state (x'(k)): - x(k)=A*x(k-1)+B*u(k) */ - CvMat* state_post; /* corrected state (x(k)): - x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */ - CvMat* transition_matrix; /* state transition matrix (A) */ - CvMat* control_matrix; /* control matrix (B) - (it is not used if there is no control)*/ - CvMat* measurement_matrix; /* measurement matrix (H) */ - CvMat* process_noise_cov; /* process noise covariance matrix (Q) */ - CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */ - CvMat* error_cov_pre; /* priori error estimate covariance matrix (P'(k)): - P'(k)=A*P(k-1)*At + Q)*/ - CvMat* gain; /* Kalman gain matrix (K(k)): - K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/ - CvMat* error_cov_post; /* posteriori error estimate covariance matrix (P(k)): - P(k)=(I-K(k)*H)*P'(k) */ - CvMat* temp1; /* temporary matrices */ - CvMat* temp2; - CvMat* temp3; - CvMat* temp4; - CvMat* temp5; -} CvKalman; - -/* Creates Kalman filter and sets A, B, Q, R and state to some initial values */ -CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params, - int control_params CV_DEFAULT(0)); - -/* Releases Kalman filter state */ -CVAPI(void) cvReleaseKalman( CvKalman** kalman); - -/* Updates Kalman filter by time (predicts future state of the system) */ -CVAPI(const CvMat*) cvKalmanPredict( CvKalman* kalman, - const CvMat* control CV_DEFAULT(NULL)); - -/* Updates Kalman filter by measurement - (corrects state of the system and internal matrices) */ -CVAPI(const CvMat*) cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement ); - -#define cvKalmanUpdateByTime cvKalmanPredict -#define cvKalmanUpdateByMeasurement cvKalmanCorrect - - -#ifdef __cplusplus -} +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" namespace cv { +enum { OPTFLOW_USE_INITIAL_FLOW = 4, + OPTFLOW_LK_GET_MIN_EIGENVALS = 8, + OPTFLOW_FARNEBACK_GAUSSIAN = 256 + }; + +enum { MOTION_TRANSLATION = 0, + MOTION_EUCLIDEAN = 1, + MOTION_AFFINE = 2, + MOTION_HOMOGRAPHY = 3 + }; + //! updates motion history image using the current silhouette CV_EXPORTS_W void updateMotionHistory( InputArray silhouette, InputOutputArray mhi, double timestamp, double duration ); //! computes the motion gradient orientation image from the motion history image -CV_EXPORTS_W void calcMotionGradient( InputArray mhi, OutputArray mask, - OutputArray orientation, - double delta1, double delta2, - int apertureSize=3 ); +CV_EXPORTS_W void calcMotionGradient( InputArray mhi, OutputArray mask, OutputArray orientation, + double delta1, double delta2, int apertureSize = 3 ); //! computes the global orientation of the selected motion history image part -CV_EXPORTS_W double calcGlobalOrientation( InputArray orientation, InputArray mask, - InputArray mhi, double timestamp, - double duration ); +CV_EXPORTS_W double calcGlobalOrientation( InputArray orientation, InputArray mask, InputArray mhi, + double timestamp, double duration ); -CV_EXPORTS_W void segmentMotion(InputArray mhi, OutputArray segmask, - CV_OUT std::vector& boundingRects, - double timestamp, double segThresh); +CV_EXPORTS_W void segmentMotion( InputArray mhi, OutputArray segmask, + CV_OUT std::vector& boundingRects, + double timestamp, double segThresh ); //! updates the object tracking window using CAMSHIFT algorithm -CV_EXPORTS_W RotatedRect CamShift( InputArray probImage, CV_OUT CV_IN_OUT Rect& window, +CV_EXPORTS_W RotatedRect CamShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); //! updates the object tracking window using meanshift algorithm -CV_EXPORTS_W int meanShift( InputArray probImage, CV_OUT CV_IN_OUT Rect& window, - TermCriteria criteria ); +CV_EXPORTS_W int meanShift( InputArray probImage, CV_IN_OUT Rect& window, TermCriteria criteria ); + +//! constructs a pyramid which can be used as input for calcOpticalFlowPyrLK +CV_EXPORTS_W int buildOpticalFlowPyramid( InputArray img, OutputArrayOfArrays pyramid, + Size winSize, int maxLevel, bool withDerivatives = true, + int pyrBorder = BORDER_REFLECT_101, + int derivBorder = BORDER_CONSTANT, + bool tryReuseInputImage = true ); + +//! computes sparse optical flow using multi-scale Lucas-Kanade algorithm +CV_EXPORTS_W void calcOpticalFlowPyrLK( InputArray prevImg, InputArray nextImg, + InputArray prevPts, InputOutputArray nextPts, + OutputArray status, OutputArray err, + Size winSize = Size(21,21), int maxLevel = 3, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), + int flags = 0, double minEigThreshold = 1e-4 ); + +//! computes dense optical flow using Farneback algorithm +CV_EXPORTS_W void calcOpticalFlowFarneback( InputArray prev, InputArray next, InputOutputArray flow, + double pyr_scale, int levels, int winsize, + int iterations, int poly_n, double poly_sigma, + int flags ); + +//! estimates the best-fit Euqcidean, similarity, affine or perspective transformation +// that maps one 2D point set to another or one image to another. +CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine ); + +//! estimates the best-fit Translation, Euclidean, Affine or Perspective Transformation +// with respect to Enhanced Correlation Coefficient criterion that maps one image to +// another (area-based alignment) +// +// see reference: +// Evangelidis, G. E., Psarakis, E.Z., Parametric Image Alignment using +// Enhanced Correlation Coefficient Maximization, PAMI, 30(8), 2008 +CV_EXPORTS_W double findTransformECC( InputArray templateImage, InputArray inputImage, + InputOutputArray warpMatrix, int motionType = MOTION_AFFINE, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001)); + + +//! computes dense optical flow using Simple Flow algorithm +CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, + int layers, int averaging_block_size, int max_flow); + +CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, int layers, + int averaging_block_size, int max_flow, + double sigma_dist, double sigma_color, int postprocess_window, + double sigma_dist_fix, double sigma_color_fix, double occ_thr, + int upscale_averaging_radius, double upscale_sigma_dist, + double upscale_sigma_color, double speed_up_thr ); + + /*! Kalman filter. @@ -269,14 +147,14 @@ public: //! the default constructor CV_WRAP KalmanFilter(); //! the full constructor taking the dimensionality of the state, of the measurement and of the control vector - CV_WRAP KalmanFilter(int dynamParams, int measureParams, int controlParams=0, int type=CV_32F); + CV_WRAP KalmanFilter( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F ); //! re-initializes Kalman filter. The previous content is destroyed. - void init(int dynamParams, int measureParams, int controlParams=0, int type=CV_32F); + void init( int dynamParams, int measureParams, int controlParams = 0, int type = CV_32F ); //! computes predicted state - CV_WRAP const Mat& predict(const Mat& control=Mat()); + CV_WRAP const Mat& predict( const Mat& control = Mat() ); //! updates the predicted state from the measurement - CV_WRAP const Mat& correct(const Mat& measurement); + CV_WRAP const Mat& correct( const Mat& measurement ); Mat statePre; //!< predicted state (x'(k)): x(k)=A*x(k-1)+B*u(k) Mat statePost; //!< corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) @@ -297,89 +175,12 @@ public: Mat temp5; }; -enum -{ - OPTFLOW_USE_INITIAL_FLOW = CV_LKFLOW_INITIAL_GUESSES, - OPTFLOW_LK_GET_MIN_EIGENVALS = CV_LKFLOW_GET_MIN_EIGENVALS, - OPTFLOW_FARNEBACK_GAUSSIAN = 256 -}; -//! constructs a pyramid which can be used as input for calcOpticalFlowPyrLK -CV_EXPORTS_W int buildOpticalFlowPyramid(InputArray img, OutputArrayOfArrays pyramid, - Size winSize, int maxLevel, bool withDerivatives = true, - int pyrBorder = BORDER_REFLECT_101, int derivBorder = BORDER_CONSTANT, - bool tryReuseInputImage = true); - -//! computes sparse optical flow using multi-scale Lucas-Kanade algorithm -CV_EXPORTS_W void calcOpticalFlowPyrLK( InputArray prevImg, InputArray nextImg, - InputArray prevPts, InputOutputArray nextPts, - OutputArray status, OutputArray err, - Size winSize=Size(21,21), int maxLevel=3, - TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), - int flags=0, double minEigThreshold=1e-4); - -//! computes dense optical flow using Farneback algorithm -CV_EXPORTS_W void calcOpticalFlowFarneback( InputArray prev, InputArray next, - InputOutputArray flow, double pyr_scale, int levels, int winsize, - int iterations, int poly_n, double poly_sigma, int flags ); - -//! estimates the best-fit Euqcidean, similarity, affine or perspective transformation -// that maps one 2D point set to another or one image to another. -CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, - bool fullAffine); - -enum -{ - MOTION_TRANSLATION=0, - MOTION_EUCLIDEAN=1, - MOTION_AFFINE=2, - MOTION_HOMOGRAPHY=3 -}; - -//! estimates the best-fit Translation, Euclidean, Affine or Perspective Transformation -// with respect to Enhanced Correlation Coefficient criterion that maps one image to -// another (area-based alignment) -// -// see reference: -// Evangelidis, G. E., Psarakis, E.Z., Parametric Image Alignment using -// Enhanced Correlation Coefficient Maximization, PAMI, 30(8), 2008 - -CV_EXPORTS_W double findTransformECC(InputArray templateImage, - InputArray inputImage, - InputOutputArray warpMatrix, - int motionType=MOTION_AFFINE, - TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001)); - - -//! computes dense optical flow using Simple Flow algorithm -CV_EXPORTS_W void calcOpticalFlowSF(InputArray from, - InputArray to, - OutputArray flow, - int layers, - int averaging_block_size, - int max_flow); - -CV_EXPORTS_W void calcOpticalFlowSF(InputArray from, - InputArray to, - OutputArray flow, - int layers, - int averaging_block_size, - int max_flow, - double sigma_dist, - double sigma_color, - int postprocess_window, - double sigma_dist_fix, - double sigma_color_fix, - double occ_thr, - int upscale_averaging_radius, - double upscale_sigma_dist, - double upscale_sigma_color, - double speed_up_thr); class CV_EXPORTS DenseOpticalFlow : public Algorithm { public: - virtual void calc(InputArray I0, InputArray I1, InputOutputArray flow) = 0; + virtual void calc( InputArray I0, InputArray I1, InputOutputArray flow ) = 0; virtual void collectGarbage() = 0; }; @@ -390,8 +191,6 @@ public: // [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation". CV_EXPORTS Ptr createOptFlow_DualTVL1(); -} - -#endif +} // cv #endif diff --git a/modules/video/include/opencv2/video/tracking_c.h b/modules/video/include/opencv2/video/tracking_c.h new file mode 100644 index 000000000..e05a0b3ad --- /dev/null +++ b/modules/video/include/opencv2/video/tracking_c.h @@ -0,0 +1,227 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_TRACKING_C_H__ +#define __OPENCV_TRACKING_C_H__ + +#include "opencv2/imgproc/types_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************************\ +* Motion Analysis * +\****************************************************************************************/ + +/************************************ optical flow ***************************************/ + +#define CV_LKFLOW_PYR_A_READY 1 +#define CV_LKFLOW_PYR_B_READY 2 +#define CV_LKFLOW_INITIAL_GUESSES 4 +#define CV_LKFLOW_GET_MIN_EIGENVALS 8 + +/* It is Lucas & Kanade method, modified to use pyramids. + Also it does several iterations to get optical flow for + every point at every pyramid level. + Calculates optical flow between two images for certain set of points (i.e. + it is a "sparse" optical flow, which is opposite to the previous 3 methods) */ +CVAPI(void) cvCalcOpticalFlowPyrLK( const CvArr* prev, const CvArr* curr, + CvArr* prev_pyr, CvArr* curr_pyr, + const CvPoint2D32f* prev_features, + CvPoint2D32f* curr_features, + int count, + CvSize win_size, + int level, + char* status, + float* track_error, + CvTermCriteria criteria, + int flags ); + + +/* Modification of a previous sparse optical flow algorithm to calculate + affine flow */ +CVAPI(void) cvCalcAffineFlowPyrLK( const CvArr* prev, const CvArr* curr, + CvArr* prev_pyr, CvArr* curr_pyr, + const CvPoint2D32f* prev_features, + CvPoint2D32f* curr_features, + float* matrices, int count, + CvSize win_size, int level, + char* status, float* track_error, + CvTermCriteria criteria, int flags ); + +/* Estimate rigid transformation between 2 images or 2 point sets */ +CVAPI(int) cvEstimateRigidTransform( const CvArr* A, const CvArr* B, + CvMat* M, int full_affine ); + +/* Estimate optical flow for each pixel using the two-frame G. Farneback algorithm */ +CVAPI(void) cvCalcOpticalFlowFarneback( const CvArr* prev, const CvArr* next, + CvArr* flow, double pyr_scale, int levels, + int winsize, int iterations, int poly_n, + double poly_sigma, int flags ); + +/********************************* motion templates *************************************/ + +/****************************************************************************************\ +* All the motion template functions work only with single channel images. * +* Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S * +* Motion history image must have depth IPL_DEPTH_32F, * +* Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S, * +* Motion orientation image - IPL_DEPTH_32F * +* Segmentation mask - IPL_DEPTH_32F * +* All the angles are in degrees, all the times are in milliseconds * +\****************************************************************************************/ + +/* Updates motion history image given motion silhouette */ +CVAPI(void) cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi, + double timestamp, double duration ); + +/* Calculates gradient of the motion history image and fills + a mask indicating where the gradient is valid */ +CVAPI(void) cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation, + double delta1, double delta2, + int aperture_size CV_DEFAULT(3)); + +/* Calculates average motion direction within a selected motion region + (region can be selected by setting ROIs and/or by composing a valid gradient mask + with the region mask) */ +CVAPI(double) cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask, + const CvArr* mhi, double timestamp, + double duration ); + +/* Splits a motion history image into a few parts corresponding to separate independent motions + (e.g. left hand, right hand) */ +CVAPI(CvSeq*) cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask, + CvMemStorage* storage, + double timestamp, double seg_thresh ); + +/****************************************************************************************\ +* Tracking * +\****************************************************************************************/ + +/* Implements CAMSHIFT algorithm - determines object position, size and orientation + from the object histogram back project (extension of meanshift) */ +CVAPI(int) cvCamShift( const CvArr* prob_image, CvRect window, + CvTermCriteria criteria, CvConnectedComp* comp, + CvBox2D* box CV_DEFAULT(NULL) ); + +/* Implements MeanShift algorithm - determines object position + from the object histogram back project */ +CVAPI(int) cvMeanShift( const CvArr* prob_image, CvRect window, + CvTermCriteria criteria, CvConnectedComp* comp ); + +/* +standard Kalman filter (in G. Welch' and G. Bishop's notation): + + x(k)=A*x(k-1)+B*u(k)+w(k) p(w)~N(0,Q) + z(k)=H*x(k)+v(k), p(v)~N(0,R) +*/ +typedef struct CvKalman +{ + int MP; /* number of measurement vector dimensions */ + int DP; /* number of state vector dimensions */ + int CP; /* number of control vector dimensions */ + + /* backward compatibility fields */ +#if 1 + float* PosterState; /* =state_pre->data.fl */ + float* PriorState; /* =state_post->data.fl */ + float* DynamMatr; /* =transition_matrix->data.fl */ + float* MeasurementMatr; /* =measurement_matrix->data.fl */ + float* MNCovariance; /* =measurement_noise_cov->data.fl */ + float* PNCovariance; /* =process_noise_cov->data.fl */ + float* KalmGainMatr; /* =gain->data.fl */ + float* PriorErrorCovariance;/* =error_cov_pre->data.fl */ + float* PosterErrorCovariance;/* =error_cov_post->data.fl */ + float* Temp1; /* temp1->data.fl */ + float* Temp2; /* temp2->data.fl */ +#endif + + CvMat* state_pre; /* predicted state (x'(k)): + x(k)=A*x(k-1)+B*u(k) */ + CvMat* state_post; /* corrected state (x(k)): + x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */ + CvMat* transition_matrix; /* state transition matrix (A) */ + CvMat* control_matrix; /* control matrix (B) + (it is not used if there is no control)*/ + CvMat* measurement_matrix; /* measurement matrix (H) */ + CvMat* process_noise_cov; /* process noise covariance matrix (Q) */ + CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */ + CvMat* error_cov_pre; /* priori error estimate covariance matrix (P'(k)): + P'(k)=A*P(k-1)*At + Q)*/ + CvMat* gain; /* Kalman gain matrix (K(k)): + K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/ + CvMat* error_cov_post; /* posteriori error estimate covariance matrix (P(k)): + P(k)=(I-K(k)*H)*P'(k) */ + CvMat* temp1; /* temporary matrices */ + CvMat* temp2; + CvMat* temp3; + CvMat* temp4; + CvMat* temp5; +} CvKalman; + +/* Creates Kalman filter and sets A, B, Q, R and state to some initial values */ +CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params, + int control_params CV_DEFAULT(0)); + +/* Releases Kalman filter state */ +CVAPI(void) cvReleaseKalman( CvKalman** kalman); + +/* Updates Kalman filter by time (predicts future state of the system) */ +CVAPI(const CvMat*) cvKalmanPredict( CvKalman* kalman, + const CvMat* control CV_DEFAULT(NULL)); + +/* Updates Kalman filter by measurement + (corrects state of the system and internal matrices) */ +CVAPI(const CvMat*) cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement ); + +#define cvKalmanUpdateByTime cvKalmanPredict +#define cvKalmanUpdateByMeasurement cvKalmanCorrect + + +#ifdef __cplusplus +} // extern "C" +#endif + + +#endif // __OPENCV_TRACKING_C_H__ diff --git a/modules/video/perf/perf_ecc.cpp b/modules/video/perf/perf_ecc.cpp index 66fad48bb..4f0709b88 100644 --- a/modules/video/perf/perf_ecc.cpp +++ b/modules/video/perf/perf_ecc.cpp @@ -35,7 +35,7 @@ PERF_TEST_P(TransformationType, findTransformECC, /*testing::ValuesIn(MotionType 0.f, 1.f, 11.839f); warpAffine(img, templateImage, warpGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); break; case MOTION_EUCLIDEAN: angle = CV_PI/30; @@ -43,20 +43,20 @@ PERF_TEST_P(TransformationType, findTransformECC, /*testing::ValuesIn(MotionType warpGround = (Mat_(2,3) << (float)cos(angle), (float)-sin(angle), 12.123f, (float)sin(angle), (float)cos(angle), 14.789f); warpAffine(img, templateImage, warpGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); break; case MOTION_AFFINE: warpGround = (Mat_(2,3) << 0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f); warpAffine(img, templateImage, warpGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); break; case MOTION_HOMOGRAPHY: warpGround = (Mat_(3,3) << 0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f, 0.0002f, 0.0003f, 1.f); warpPerspective(img, templateImage, warpGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); break; } diff --git a/modules/video/perf/perf_optflowpyrlk.cpp b/modules/video/perf/perf_optflowpyrlk.cpp index d34bd7215..9ea3190c5 100644 --- a/modules/video/perf/perf_optflowpyrlk.cpp +++ b/modules/video/perf/perf_optflowpyrlk.cpp @@ -50,7 +50,7 @@ PERF_TEST_P(Path_Idx_Cn_NPoints_WSize, OpticalFlowPyrLK_full, testing::Combine( int winSize = get<4>(GetParam()); int maxLevel = 2; - TermCriteria criteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 7, 0.001); + TermCriteria criteria(TermCriteria::COUNT|TermCriteria::EPS, 7, 0.001); int flags = 0; double minEigThreshold = 1e-4; @@ -124,7 +124,7 @@ PERF_TEST_P(Path_Idx_Cn_NPoints_WSize_Deriv, OpticalFlowPyrLK_self, testing::Com bool withDerivatives = get<5>(GetParam()); int maxLevel = 2; - TermCriteria criteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 7, 0.001); + TermCriteria criteria(TermCriteria::COUNT|TermCriteria::EPS, 7, 0.001); int flags = 0; double minEigThreshold = 1e-4; diff --git a/modules/video/src/affineflow.cpp b/modules/video/src/affineflow.cpp index bc3fdba2f..bad9da8af 100644 --- a/modules/video/src/affineflow.cpp +++ b/modules/video/src/affineflow.cpp @@ -42,6 +42,7 @@ #include "precomp.hpp" #include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/video/tracking_c.h" // to be moved to legacy @@ -541,7 +542,7 @@ cvCalcAffineFlowPyrLK( const void* arrA, const void* arrB, if( !matrices ) CV_Error( CV_StsNullPtr, "" ); - imgSize = cvGetMatSize( imgA ); + imgSize = cv::Size(imgA->cols, imgA->rows); if( pyrA ) { diff --git a/modules/video/src/bgfg_gaussmix.cpp b/modules/video/src/bgfg_gaussmix.cpp index 2be2691c4..ebdd19bd0 100644 --- a/modules/video/src/bgfg_gaussmix.cpp +++ b/modules/video/src/bgfg_gaussmix.cpp @@ -124,7 +124,7 @@ public: virtual void getBackgroundImage(OutputArray) const { - CV_Error( CV_StsNotImplemented, "" ); + CV_Error( Error::StsNotImplemented, "" ); } virtual int getHistory() const { return history; } @@ -458,7 +458,7 @@ void BackgroundSubtractorMOGImpl::apply(InputArray _image, OutputArray _fgmask, else if( image.type() == CV_8UC3 ) process8uC3( image, fgmask, learningRate, bgmodel, nmixtures, backgroundRatio, varThreshold, noiseSigma ); else - CV_Error( CV_StsUnsupportedFormat, "Only 1- and 3-channel 8-bit images are supported in BackgroundSubtractorMOG" ); + CV_Error( Error::StsUnsupportedFormat, "Only 1- and 3-channel 8-bit images are supported in BackgroundSubtractorMOG" ); } Ptr createBackgroundSubtractorMOG(int history, int nmixtures, diff --git a/modules/video/src/bgfg_gaussmix2.cpp b/modules/video/src/bgfg_gaussmix2.cpp index 1337a1f5b..35f5d0678 100644 --- a/modules/video/src/bgfg_gaussmix2.cpp +++ b/modules/video/src/bgfg_gaussmix2.cpp @@ -761,7 +761,7 @@ void BackgroundSubtractorMOG2Impl::getBackgroundImage(OutputArray backgroundImag } default: - CV_Error(CV_StsUnsupportedFormat, ""); + CV_Error(Error::StsUnsupportedFormat, ""); } } diff --git a/modules/video/src/bgfg_gmg.cpp b/modules/video/src/bgfg_gmg.cpp index 20ddeba44..e3e423211 100644 --- a/modules/video/src/bgfg_gmg.cpp +++ b/modules/video/src/bgfg_gmg.cpp @@ -134,7 +134,7 @@ public: virtual void getBackgroundImage(OutputArray) const { - CV_Error( CV_StsNotImplemented, "" ); + CV_Error( Error::StsNotImplemented, "" ); } virtual void write(FileStorage& fs) const diff --git a/modules/video/src/camshift.cpp b/modules/video/src/camshift.cpp index 5cad1b82a..9ba02381d 100644 --- a/modules/video/src/camshift.cpp +++ b/modules/video/src/camshift.cpp @@ -49,7 +49,7 @@ int cv::meanShift( InputArray _probImage, Rect& window, TermCriteria criteria ) CV_Assert( mat.channels() == 1 ); if( window.height <= 0 || window.width <= 0 ) - CV_Error( CV_StsBadArg, "Input window has non-positive sizes" ); + CV_Error( Error::StsBadArg, "Input window has non-positive sizes" ); window = window & Rect(0, 0, mat.cols, mat.rows); diff --git a/modules/video/src/compat_video.cpp b/modules/video/src/compat_video.cpp index 5f70c893e..e6dc96030 100644 --- a/modules/video/src/compat_video.cpp +++ b/modules/video/src/compat_video.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/video/tracking_c.h" /////////////////////////// Meanshift & CAMShift /////////////////////////// diff --git a/modules/video/src/ecc.cpp b/modules/video/src/ecc.cpp index ac710d445..f56e1f24b 100644 --- a/modules/video/src/ecc.cpp +++ b/modules/video/src/ecc.cpp @@ -325,14 +325,14 @@ double cv::findTransformECC(InputArray templateImage, if( ! (src.type()==dst.type())) - CV_Error( CV_StsUnmatchedFormats, "Both input images must have the same data type" ); + CV_Error( Error::StsUnmatchedFormats, "Both input images must have the same data type" ); //accept only 1-channel images if( src.type() != CV_8UC1 && src.type()!= CV_32FC1) - CV_Error( CV_StsUnsupportedFormat, "Images must have 8uC1 or 32fC1 type"); + CV_Error( Error::StsUnsupportedFormat, "Images must have 8uC1 or 32fC1 type"); if( map.type() != CV_32FC1) - CV_Error( CV_StsUnsupportedFormat, "warpMatrix must be single-channel floating-point matrix"); + CV_Error( Error::StsUnsupportedFormat, "warpMatrix must be single-channel floating-point matrix"); CV_Assert (map.cols == 3); CV_Assert (map.rows == 2 || map.rows ==3); @@ -428,8 +428,8 @@ double cv::findTransformECC(InputArray templateImage, Mat deltaP = Mat(numberOfParameters, 1, CV_32F);//transformation parameter correction Mat error = Mat(hs, ws, CV_32F);//error as 2D matrix - const int imageFlags = CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP; - const int maskFlags = CV_INTER_NN+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP; + const int imageFlags = INTER_LINEAR + WARP_INVERSE_MAP; + const int maskFlags = INTER_NEAREST + WARP_INVERSE_MAP; // iteratively update map_matrix @@ -504,7 +504,7 @@ double cv::findTransformECC(InputArray templateImage, if (lambda_d <= 0.0) { rho = -1; - CV_Error(CV_StsNoConv, "The algorithm stopped before its convergence. The correlation is going to be minimized. Images may be uncorrelated or non-overlapped"); + CV_Error(Error::StsNoConv, "The algorithm stopped before its convergence. The correlation is going to be minimized. Images may be uncorrelated or non-overlapped"); } const double lambda = (lambda_n/lambda_d); diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index 019397f94..e46517268 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -328,7 +328,7 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const float minEig = (A22 + A11 - std::sqrt((A11-A22)*(A11-A22) + 4.f*A12*A12))/(2*winSize.width*winSize.height); - if( err && (flags & CV_LKFLOW_GET_MIN_EIGENVALS) != 0 ) + if( err && (flags & OPTFLOW_LK_GET_MIN_EIGENVALS) != 0 ) err[ptidx] = (float)minEig; if( minEig < minEigThreshold || D < FLT_EPSILON ) @@ -452,7 +452,7 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const prevDelta = delta; } - if( status[ptidx] && err && level == 0 && (flags & CV_LKFLOW_GET_MIN_EIGENVALS) == 0 ) + if( status[ptidx] && err && level == 0 && (flags & OPTFLOW_LK_GET_MIN_EIGENVALS) == 0 ) { Point2f nextPoint = nextPts[ptidx] - halfWin; Point inextPoint; @@ -864,10 +864,10 @@ cv::Mat cv::estimateRigidTransform( InputArray src1, InputArray src2, bool fullA int good_count = 0; if( A.size() != B.size() ) - CV_Error( CV_StsUnmatchedSizes, "Both input images must have the same size" ); + CV_Error( Error::StsUnmatchedSizes, "Both input images must have the same size" ); if( A.type() != B.type() ) - CV_Error( CV_StsUnmatchedFormats, "Both input images must have the same data type" ); + CV_Error( Error::StsUnmatchedFormats, "Both input images must have the same data type" ); int count = A.checkVector(2); @@ -947,7 +947,7 @@ cv::Mat cv::estimateRigidTransform( InputArray src1, InputArray src2, bool fullA pB.resize(count); } else - CV_Error( CV_StsUnsupportedFormat, "Both input images must have either 8uC1 or 8uC3 type" ); + CV_Error( Error::StsUnsupportedFormat, "Both input images must have either 8uC1 or 8uC3 type" ); good_idx.resize(count); diff --git a/modules/video/src/motempl.cpp b/modules/video/src/motempl.cpp index 7d992684b..aa6d12d8d 100644 --- a/modules/video/src/motempl.cpp +++ b/modules/video/src/motempl.cpp @@ -123,13 +123,13 @@ void cv::calcMotionGradient( InputArray _mhi, OutputArray _mask, Mat orient = _orientation.getMat(); if( aperture_size < 3 || aperture_size > 7 || (aperture_size & 1) == 0 ) - CV_Error( CV_StsOutOfRange, "aperture_size must be 3, 5 or 7" ); + CV_Error( Error::StsOutOfRange, "aperture_size must be 3, 5 or 7" ); if( delta1 <= 0 || delta2 <= 0 ) - CV_Error( CV_StsOutOfRange, "both delta's must be positive" ); + CV_Error( Error::StsOutOfRange, "both delta's must be positive" ); if( mhi.type() != CV_32FC1 ) - CV_Error( CV_StsUnsupportedFormat, + CV_Error( Error::StsUnsupportedFormat, "MHI must be single-channel floating-point images" ); if( orient.data == mhi.data ) diff --git a/modules/video/src/optflowgf.cpp b/modules/video/src/optflowgf.cpp index 6784a55cd..df2559a3e 100644 --- a/modules/video/src/optflowgf.cpp +++ b/modules/video/src/optflowgf.cpp @@ -627,7 +627,7 @@ void cv::calcOpticalFlowFarneback( InputArray _prev0, InputArray _next0, { img[i]->convertTo(fimg, CV_32F); GaussianBlur(fimg, fimg, Size(smooth_sz, smooth_sz), sigma, sigma); - resize( fimg, I, Size(width, height), CV_INTER_LINEAR ); + resize( fimg, I, Size(width, height), INTER_LINEAR ); FarnebackPolyExp( I, R[i], poly_n, poly_sigma ); } diff --git a/modules/video/src/precomp.hpp b/modules/video/src/precomp.hpp index fdbbb0ae1..5cd7ec381 100644 --- a/modules/video/src/precomp.hpp +++ b/modules/video/src/precomp.hpp @@ -44,12 +44,11 @@ #define __OPENCV_PRECOMP_H__ #include "opencv2/video.hpp" +#include "opencv2/video/tracking_c.h" #include "opencv2/core/utility.hpp" #include "opencv2/core/private.hpp" -#include - #ifdef HAVE_TEGRA_OPTIMIZATION #include "opencv2/video/video_tegra.hpp" #endif diff --git a/modules/video/test/test_backgroundsubtractor_gbh.cpp b/modules/video/test/test_backgroundsubtractor_gbh.cpp index 649a18b85..a7261516a 100644 --- a/modules/video/test/test_backgroundsubtractor_gbh.cpp +++ b/modules/video/test/test_backgroundsubtractor_gbh.cpp @@ -41,7 +41,7 @@ void CV_BackgroundSubtractorTest::run(int) Mat fgmask; if (fgbg.empty()) - CV_Error(CV_StsError,"Failed to create Algorithm\n"); + CV_Error(Error::StsError,"Failed to create Algorithm\n"); /** * Set a few parameters diff --git a/modules/video/test/test_camshift.cpp b/modules/video/test/test_camshift.cpp index 4a2ddc734..f003286d4 100644 --- a/modules/video/test/test_camshift.cpp +++ b/modules/video/test/test_camshift.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/video/tracking_c.h" using namespace cv; using namespace std; diff --git a/modules/video/test/test_ecc.cpp b/modules/video/test/test_ecc.cpp index 58389290b..4065e6182 100644 --- a/modules/video/test/test_ecc.cpp +++ b/modules/video/test/test_ecc.cpp @@ -138,7 +138,7 @@ bool CV_ECC_Test_Translation::testTranslation(int from) Mat warpedImage; warpAffine(testImg, warpedImage, translationGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); Mat mapTranslation = (Mat_(2,3) << 1, 0, 0, 0, 1, 0); @@ -213,7 +213,7 @@ bool CV_ECC_Test_Euclidean::testEuclidean(int from) Mat warpedImage; warpAffine(testImg, warpedImage, euclideanGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); Mat mapEuclidean = (Mat_(2,3) << 1, 0, 0, 0, 1, 0); @@ -288,7 +288,7 @@ bool CV_ECC_Test_Affine::testAffine(int from) Mat warpedImage; warpAffine(testImg, warpedImage, affineGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); Mat mapAffine = (Mat_(2,3) << 1, 0, 0, 0, 1, 0); @@ -363,7 +363,7 @@ bool CV_ECC_Test_Homography::testHomography(int from) Mat warpedImage; warpPerspective(testImg, warpedImage, homoGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); Mat mapHomography = Mat::eye(3, 3, CV_32F); diff --git a/modules/video/test/test_estimaterigid.cpp b/modules/video/test/test_estimaterigid.cpp index 47122fe59..5259ce7ee 100644 --- a/modules/video/test/test_estimaterigid.cpp +++ b/modules/video/test/test_estimaterigid.cpp @@ -93,18 +93,18 @@ bool CV_RigidTransform_Test::testNPoints(int from) progress = update_progress(progress, k, ntests, 0); Mat aff(2, 3, CV_64F); - rng.fill(aff, CV_RAND_UNI, Scalar(-2), Scalar(2)); + rng.fill(aff, RNG::UNIFORM, Scalar(-2), Scalar(2)); int n = (unsigned)rng % 100 + 10; Mat fpts(1, n, CV_32FC2); Mat tpts(1, n, CV_32FC2); - rng.fill(fpts, CV_RAND_UNI, Scalar(0,0), Scalar(10,10)); + rng.fill(fpts, RNG::UNIFORM, Scalar(0,0), Scalar(10,10)); transform(fpts.ptr(), fpts.ptr() + n, tpts.ptr(), WrapAff2D(aff)); Mat noise(1, n, CV_32FC2); - rng.fill(noise, CV_RAND_NORMAL, Scalar::all(0), Scalar::all(0.001*(n<=7 ? 0 : n <= 30 ? 1 : 10))); + rng.fill(noise, RNG::NORMAL, Scalar::all(0), Scalar::all(0.001*(n<=7 ? 0 : n <= 30 ? 1 : 10))); tpts += noise; Mat aff_est = estimateRigidTransform(fpts, tpts, true); diff --git a/modules/video/test/test_kalman.cpp b/modules/video/test/test_kalman.cpp index 17b3ee6a4..2aa74e1c2 100644 --- a/modules/video/test/test_kalman.cpp +++ b/modules/video/test/test_kalman.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/video/tracking_c.h" using namespace cv; diff --git a/modules/video/test/test_motiontemplates.cpp b/modules/video/test/test_motiontemplates.cpp index 082131737..7779327b1 100644 --- a/modules/video/test/test_motiontemplates.cpp +++ b/modules/video/test/test_motiontemplates.cpp @@ -169,9 +169,7 @@ double CV_UpdateMHITest::get_success_error_level( int /*test_case_idx*/, int /*i void CV_UpdateMHITest::run_func() { - CvMat m = test_mat[INPUT_OUTPUT][0]; cv::updateMotionHistory( test_mat[INPUT][0], test_mat[INPUT_OUTPUT][0], timestamp, duration); - m = test_mat[INPUT_OUTPUT][0]; } @@ -203,8 +201,7 @@ static void test_MHIGradient( const Mat& mhi, Mat& mask, Mat& orientation, if( delta1 > delta2 ) { - double t; - CV_SWAP( delta1, delta2, t ); + std::swap( delta1, delta2 ); } for( int i = 0; i < mhi.rows; i++ ) @@ -417,7 +414,7 @@ void CV_MHIGlobalOrientTest::get_test_array_types_and_sizes( int test_case_idx, { RNG& rng = ts->get_rng(); CV_MHIBaseTest::get_test_array_types_and_sizes( test_case_idx, sizes, types ); - CvSize size = sizes[INPUT][0]; + Size size = sizes[INPUT][0]; size.width = MAX( size.width, 16 ); size.height = MAX( size.height, 16 ); @@ -430,8 +427,7 @@ void CV_MHIGlobalOrientTest::get_test_array_types_and_sizes( int test_case_idx, max_angle = cvtest::randReal(rng)*359.9; if( min_angle >= max_angle ) { - double t; - CV_SWAP( min_angle, max_angle, t ); + std::swap( min_angle, max_angle); } max_angle += 0.1; duration = exp(cvtest::randReal(rng)*max_log_duration); @@ -474,7 +470,7 @@ int CV_MHIGlobalOrientTest::validate_test_results( int test_case_idx ) test_mat[INPUT][0], timestamp, duration ); double err_level = get_success_error_level( test_case_idx, 0, 0 ); int code = cvtest::TS::OK; - int nz = cvCountNonZero( test_array[INPUT][1] ); + int nz = countNonZero( test_mat[INPUT][1] ); if( nz > 32 && !(min_angle - err_level <= angle && max_angle + err_level >= angle) && diff --git a/modules/video/test/test_optflowpyrlk.cpp b/modules/video/test/test_optflowpyrlk.cpp index 309bf5e30..e4aa5e572 100644 --- a/modules/video/test/test_optflowpyrlk.cpp +++ b/modules/video/test/test_optflowpyrlk.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/video/tracking_c.h" /* ///////////////////// pyrlk_test ///////////////////////// */ diff --git a/modules/videostab/src/global_motion.cpp b/modules/videostab/src/global_motion.cpp index 0af1129a9..fcaf9932e 100644 --- a/modules/videostab/src/global_motion.cpp +++ b/modules/videostab/src/global_motion.cpp @@ -754,7 +754,7 @@ Mat KeypointBasedMotionEstimatorGpu::estimate(const gpu::GpuMat &frame0, const g grayFrame0 = frame0; else { - gpu::cvtColor(frame0, grayFrame0_, CV_BGR2GRAY); + gpu::cvtColor(frame0, grayFrame0_, COLOR_BGR2GRAY); grayFrame0 = grayFrame0_; } diff --git a/modules/videostab/src/inpainting.cpp b/modules/videostab/src/inpainting.cpp index e24281b5e..09ae1423c 100644 --- a/modules/videostab/src/inpainting.cpp +++ b/modules/videostab/src/inpainting.cpp @@ -357,7 +357,7 @@ void MotionInpainter::inpaint(int idx, Mat &frame, Mat &mask) mask1_.setTo(255); } - cvtColor(frame, grayFrame_, CV_BGR2GRAY); + cvtColor(frame, grayFrame_, COLOR_BGR2GRAY); MotionInpaintBody body; body.rad = 2; @@ -383,7 +383,7 @@ void MotionInpainter::inpaint(int idx, Mat &frame, Mat &mask) frame1_, transformedFrame1_, motion1to0, frame1_.size(), INTER_LINEAR, borderMode_); - cvtColor(transformedFrame1_, transformedGrayFrame1_, CV_BGR2GRAY); + cvtColor(transformedFrame1_, transformedGrayFrame1_, COLOR_BGR2GRAY); // warp mask diff --git a/samples/c/fback_c.c b/samples/c/fback_c.c index 0fd85688d..e0317a442 100644 --- a/samples/c/fback_c.c +++ b/samples/c/fback_c.c @@ -1,4 +1,4 @@ -#include "opencv2/video/tracking.hpp" +#include "opencv2/video/tracking_c.h" #include "opencv2/highgui/highgui_c.h" #include "opencv2/imgproc/imgproc_c.h" #include diff --git a/samples/c/motempl.c b/samples/c/motempl.c index 56ec2f104..76b69ade7 100644 --- a/samples/c/motempl.c +++ b/samples/c/motempl.c @@ -1,6 +1,6 @@ -#include "opencv2/video/tracking.hpp" -#include "opencv2/highgui/highgui_c.h" +#include "opencv2/video/tracking_c.h" #include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/highgui/highgui_c.h" #include #include #include diff --git a/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp b/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp index bfae1ebce..6a9bcb383 100644 --- a/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp +++ b/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping.cpp @@ -69,7 +69,7 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i { cv::Mat rgbIntImg; outputMat.convertTo(rgbIntImg, CV_8UC3); - cvtColor(rgbIntImg, intGrayImage, CV_BGR2GRAY); + cv::cvtColor(rgbIntImg, intGrayImage, cv::COLOR_BGR2GRAY); } // get histogram density probability in order to cut values under above edges limits (here 5-95%)... usefull for HDR pixel errors cancellation diff --git a/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping_video.cpp b/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping_video.cpp index 7c47fcf66..ee28fafda 100644 --- a/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping_video.cpp +++ b/samples/cpp/OpenEXRimages_HighDynamicRange_Retina_toneMapping_video.cpp @@ -88,7 +88,7 @@ static void rescaleGrayLevelMat(const cv::Mat &inputMat, cv::Mat &outputMat, con { cv::Mat rgbIntImg; normalisedImage.convertTo(rgbIntImg, CV_8UC3); - cvtColor(rgbIntImg, intGrayImage, CV_BGR2GRAY); + cv::cvtColor(rgbIntImg, intGrayImage, cv::COLOR_BGR2GRAY); } // get histogram density probability in order to cut values under above edges limits (here 5-95%)... usefull for HDR pixel errors cancellation diff --git a/samples/cpp/camshiftdemo.cpp b/samples/cpp/camshiftdemo.cpp index a61996e48..6439cef78 100644 --- a/samples/cpp/camshiftdemo.cpp +++ b/samples/cpp/camshiftdemo.cpp @@ -114,7 +114,7 @@ int main( int argc, const char** argv ) if( !paused ) { - cvtColor(image, hsv, CV_BGR2HSV); + cvtColor(image, hsv, COLOR_BGR2HSV); if( trackObject ) { @@ -130,7 +130,7 @@ int main( int argc, const char** argv ) { Mat roi(hue, selection), maskroi(mask, selection); calcHist(&roi, 1, 0, maskroi, hist, 1, &hsize, &phranges); - normalize(hist, hist, 0, 255, CV_MINMAX); + normalize(hist, hist, 0, 255, NORM_MINMAX); trackWindow = selection; trackObject = 1; @@ -140,7 +140,7 @@ int main( int argc, const char** argv ) Mat buf(1, hsize, CV_8UC3); for( int i = 0; i < hsize; i++ ) buf.at(i) = Vec3b(saturate_cast(i*180./hsize), 255, 255); - cvtColor(buf, buf, CV_HSV2BGR); + cvtColor(buf, buf, COLOR_HSV2BGR); for( int i = 0; i < hsize; i++ ) { @@ -154,7 +154,7 @@ int main( int argc, const char** argv ) calcBackProject(&hue, 1, 0, hist, backproj, &phranges); backproj &= mask; RotatedRect trackBox = CamShift(backproj, trackWindow, - TermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 )); + TermCriteria( TermCriteria::EPS | TermCriteria::COUNT, 10, 1 )); if( trackWindow.area() <= 1 ) { int cols = backproj.cols, rows = backproj.rows, r = (MIN(cols, rows) + 5)/6; @@ -164,8 +164,8 @@ int main( int argc, const char** argv ) } if( backprojMode ) - cvtColor( backproj, image, CV_GRAY2BGR ); - ellipse( image, trackBox, Scalar(0,0,255), 3, CV_AA ); + cvtColor( backproj, image, COLOR_GRAY2BGR ); + ellipse( image, trackBox, Scalar(0,0,255), 3, LINE_AA ); } } else if( trackObject < 0 ) diff --git a/samples/cpp/fabmap_sample.cpp b/samples/cpp/fabmap_sample.cpp index bbe5f2b4c..8fa5b5dc0 100644 --- a/samples/cpp/fabmap_sample.cpp +++ b/samples/cpp/fabmap_sample.cpp @@ -204,7 +204,7 @@ int main(int argc, char * argv[]) { } Mat result_large(100, 100, CV_8UC1); - resize(result_small, result_large, Size(500, 500), 0, 0, CV_INTER_NN); + resize(result_small, result_large, Size(500, 500), 0, 0, INTER_NEAREST); cout << endl << "Press any key to exit" << endl; imshow("Confusion Matrix", result_large); diff --git a/samples/cpp/fback.cpp b/samples/cpp/fback.cpp index 4923e8abc..5293fd1f7 100644 --- a/samples/cpp/fback.cpp +++ b/samples/cpp/fback.cpp @@ -42,13 +42,13 @@ int main(int, char**) for(;;) { cap >> frame; - cvtColor(frame, gray, CV_BGR2GRAY); + cvtColor(frame, gray, COLOR_BGR2GRAY); if( prevgray.data ) { calcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0); - cvtColor(prevgray, cflow, CV_GRAY2BGR); - drawOptFlowMap(flow, cflow, 16, 1.5, CV_RGB(0, 255, 0)); + cvtColor(prevgray, cflow, COLOR_GRAY2BGR); + drawOptFlowMap(flow, cflow, 16, 1.5, Scalar(0, 255, 0)); imshow("flow", cflow); } if(waitKey(30)>=0) diff --git a/samples/cpp/image_alignment.cpp b/samples/cpp/image_alignment.cpp index b251e7253..56e8209dd 100644 --- a/samples/cpp/image_alignment.cpp +++ b/samples/cpp/image_alignment.cpp @@ -238,7 +238,7 @@ int main (const int argc, const char * argv[]) warpGround = (Mat_(2,3) << 1, 0, (rng.uniform(10.f, 20.f)), 0, 1, (rng.uniform(10.f, 20.f))); warpAffine(target_image, template_image, warpGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); break; case MOTION_EUCLIDEAN: angle = CV_PI/30 + CV_PI*rng.uniform((double)-2.f, (double)2.f)/180; @@ -246,7 +246,7 @@ int main (const int argc, const char * argv[]) warpGround = (Mat_(2,3) << cos(angle), -sin(angle), (rng.uniform(10.f, 20.f)), sin(angle), cos(angle), (rng.uniform(10.f, 20.f))); warpAffine(target_image, template_image, warpGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); break; case MOTION_AFFINE: @@ -255,7 +255,7 @@ int main (const int argc, const char * argv[]) (rng.uniform(-0.03f, 0.03f)), (1-rng.uniform(-0.05f, 0.05f)), (rng.uniform(10.f, 20.f))); warpAffine(target_image, template_image, warpGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); break; case MOTION_HOMOGRAPHY: warpGround = (Mat_(3,3) << (1-rng.uniform(-0.05f, 0.05f)), @@ -263,7 +263,7 @@ int main (const int argc, const char * argv[]) (rng.uniform(-0.03f, 0.03f)), (1-rng.uniform(-0.05f, 0.05f)),(rng.uniform(10.f, 20.f)), (rng.uniform(0.0001f, 0.0003f)), (rng.uniform(0.0001f, 0.0003f)), 1.f); warpPerspective(target_image, template_image, warpGround, - Size(200,200), CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); break; } } @@ -333,10 +333,10 @@ int main (const int argc, const char * argv[]) Mat warped_image = Mat(template_image.rows, template_image.cols, CV_32FC1); if (warp_mode != MOTION_HOMOGRAPHY) warpAffine (target_image, warped_image, warp_matrix, warped_image.size(), - CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + INTER_LINEAR + WARP_INVERSE_MAP); else warpPerspective (target_image, warped_image, warp_matrix, warped_image.size(), - CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP); + INTER_LINEAR + WARP_INVERSE_MAP); //save the warped image imwrite(warpedImFile, warped_image); diff --git a/samples/cpp/kalman.cpp b/samples/cpp/kalman.cpp index c5bb96930..1f170d384 100644 --- a/samples/cpp/kalman.cpp +++ b/samples/cpp/kalman.cpp @@ -69,18 +69,18 @@ int main(int, char**) Point measPt = calcPoint(center, R, measAngle); // plot points - #define drawCross( center, color, d ) \ - line( img, Point( center.x - d, center.y - d ), \ - Point( center.x + d, center.y + d ), color, 1, CV_AA, 0); \ - line( img, Point( center.x + d, center.y - d ), \ - Point( center.x - d, center.y + d ), color, 1, CV_AA, 0 ) + #define drawCross( center, color, d ) \ + line( img, Point( center.x - d, center.y - d ), \ + Point( center.x + d, center.y + d ), color, 1, LINE_AA, 0); \ + line( img, Point( center.x + d, center.y - d ), \ + Point( center.x - d, center.y + d ), color, 1, LINE_AA, 0 ) img = Scalar::all(0); drawCross( statePt, Scalar(255,255,255), 3 ); drawCross( measPt, Scalar(0,0,255), 3 ); drawCross( predictPt, Scalar(0,255,0), 3 ); - line( img, statePt, measPt, Scalar(0,0,255), 3, CV_AA, 0 ); - line( img, statePt, predictPt, Scalar(0,255,255), 3, CV_AA, 0 ); + line( img, statePt, measPt, Scalar(0,0,255), 3, LINE_AA, 0 ); + line( img, statePt, predictPt, Scalar(0,255,255), 3, LINE_AA, 0 ); if(theRNG().uniform(0,4) != 0) KF.correct(measurement); diff --git a/samples/cpp/lkdemo.cpp b/samples/cpp/lkdemo.cpp index 3b7fb8bcb..3913e2c2d 100644 --- a/samples/cpp/lkdemo.cpp +++ b/samples/cpp/lkdemo.cpp @@ -38,7 +38,7 @@ static void onMouse( int event, int x, int y, int /*flags*/, void* /*param*/ ) int main( int argc, char** argv ) { VideoCapture cap; - TermCriteria termcrit(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03); + TermCriteria termcrit(TermCriteria::COUNT|TermCriteria::EPS,20,0.03); Size subPixWinSize(10,10), winSize(31,31); const int MAX_COUNT = 500; @@ -72,7 +72,7 @@ int main( int argc, char** argv ) break; frame.copyTo(image); - cvtColor(image, gray, CV_BGR2GRAY); + cvtColor(image, gray, COLOR_BGR2GRAY); if( nightMode ) image = Scalar::all(0); @@ -117,7 +117,7 @@ int main( int argc, char** argv ) { vector tmp; tmp.push_back(point); - cornerSubPix( gray, tmp, winSize, cvSize(-1,-1), termcrit); + cornerSubPix( gray, tmp, winSize, Size(-1,-1), termcrit); points[1].push_back(tmp[0]); addRemovePt = false; } From e5a33723fcabc6fc266c0ccf9b407de421da821f Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 11 Apr 2013 19:27:54 +0400 Subject: [PATCH 2/6] Move C API of opencv_calib3d to separate file --- apps/haartraining/CMakeLists.txt | 2 +- apps/haartraining/cvclassifier.h | 4 +- include/opencv/cv.h | 8 +- include/opencv/cv.hpp | 2 + include/opencv/cvaux.h | 7 +- ...mera_calibration_and_3d_reconstruction.rst | 10 +- modules/calib3d/include/opencv2/calib3d.hpp | 707 ++++-------------- .../include/opencv2/calib3d/calib3d_c.h | 413 ++++++++++ modules/calib3d/perf/perf_pnp.cpp | 6 +- modules/calib3d/src/calibinit.cpp | 1 + modules/calib3d/src/calibration.cpp | 5 +- modules/calib3d/src/checkchessboard.cpp | 1 + modules/calib3d/src/circlesgrid.cpp | 53 +- modules/calib3d/src/compat_ptsetreg.cpp | 1 + modules/calib3d/src/compat_stereo.cpp | 5 +- modules/calib3d/src/epnp.h | 1 + modules/calib3d/src/five-point.cpp | 2 +- modules/calib3d/src/fundam.cpp | 22 +- modules/calib3d/src/posit.cpp | 1 + modules/calib3d/src/ptsetreg.cpp | 2 +- modules/calib3d/src/quadsubpix.cpp | 2 +- modules/calib3d/src/solvepnp.cpp | 10 +- modules/calib3d/src/stereobm.cpp | 32 +- modules/calib3d/src/stereosgbm.cpp | 2 +- modules/calib3d/src/triangulate.cpp | 1 + .../calib3d/test/test_cameracalibration.cpp | 1 + .../test_cameracalibration_artificial.cpp | 2 +- .../test/test_cameracalibration_badarg.cpp | 1 + .../calib3d/test/test_chessboardgenerator.cpp | 8 +- modules/calib3d/test/test_chesscorners.cpp | 10 +- .../calib3d/test/test_chesscorners_badarg.cpp | 1 + .../calib3d/test/test_chesscorners_timing.cpp | 1 + modules/calib3d/test/test_fundam.cpp | 1 + modules/calib3d/test/test_homography.cpp | 26 +- modules/calib3d/test/test_posit.cpp | 1 + .../test/test_reproject_image_to_3d.cpp | 1 + modules/calib3d/test/test_solvepnp_ransac.cpp | 12 +- modules/calib3d/test/test_stereomatching.cpp | 26 +- modules/contrib/src/ba.cpp | 1 + modules/contrib/src/featuretracker.cpp | 2 +- .../features2d/include/opencv2/features2d.hpp | 6 - modules/imgproc/src/gcgraph.hpp | 6 +- .../org/opencv/test/calib3d/Calib3dTest.java | 12 +- modules/legacy/include/opencv2/legacy.hpp | 4 +- modules/legacy/src/3dtracker.cpp | 1 + modules/legacy/src/compat.cpp | 1 + modules/legacy/src/planardetect.cpp | 1 + modules/legacy/src/trifocal.cpp | 1 + modules/nonfree/test/test_features2d.cpp | 12 +- modules/ocl/test/test_hough.cpp | 2 +- .../opencv2/stitching/detail/warpers_inl.hpp | 1 + modules/stitching/src/blenders.cpp | 2 +- modules/stitching/src/exposure_compensate.cpp | 2 +- modules/stitching/src/matchers.cpp | 10 +- modules/stitching/src/motion_estimators.cpp | 1 + modules/stitching/src/seam_finders.cpp | 6 +- modules/videostab/src/global_motion.cpp | 4 +- modules/videostab/src/inpainting.cpp | 2 +- modules/videostab/src/motion_stabilizing.cpp | 2 +- samples/cpp/3calibration.cpp | 20 +- samples/cpp/build3dmodel.cpp | 4 +- samples/cpp/calibration.cpp | 34 +- samples/cpp/calibration_artificial.cpp | 8 +- samples/cpp/descriptor_extractor_matcher.cpp | 12 +- samples/cpp/generic_descriptor_match.cpp | 2 +- samples/cpp/select3dobj.cpp | 18 +- samples/cpp/stereo_calib.cpp | 20 +- .../camera_calibration/camera_calibration.cpp | 32 +- .../features2D/SURF_Homography.cpp | 6 +- samples/ocl/surf_matcher.cpp | 2 +- 70 files changed, 836 insertions(+), 792 deletions(-) create mode 100644 modules/calib3d/include/opencv2/calib3d/calib3d_c.h diff --git a/apps/haartraining/CMakeLists.txt b/apps/haartraining/CMakeLists.txt index e25f56fc0..f71cbeeaa 100644 --- a/apps/haartraining/CMakeLists.txt +++ b/apps/haartraining/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(OPENCV_HAARTRAINING_DEPS opencv_core opencv_imgproc opencv_photo opencv_highgui opencv_objdetect opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy) +SET(OPENCV_HAARTRAINING_DEPS opencv_core opencv_imgproc opencv_photo opencv_ml opencv_highgui opencv_objdetect opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy) ocv_check_dependencies(${OPENCV_HAARTRAINING_DEPS}) if(NOT OCV_DEPENDENCIES_FOUND) diff --git a/apps/haartraining/cvclassifier.h b/apps/haartraining/cvclassifier.h index df644ed17..9a4344118 100644 --- a/apps/haartraining/cvclassifier.h +++ b/apps/haartraining/cvclassifier.h @@ -112,7 +112,9 @@ CV_INLINE float cvLogRatio( float val ) /* each trainData matrix row is a sample */ #define CV_ROW_SAMPLE 1 -#define CV_IS_ROW_SAMPLE( flags ) ( ( flags ) & CV_ROW_SAMPLE ) +#ifndef CV_IS_ROW_SAMPLE +# define CV_IS_ROW_SAMPLE( flags ) ( ( flags ) & CV_ROW_SAMPLE ) +#endif /* Classifier supports tune function */ #define CV_TUNABLE (1 << 1) diff --git a/include/opencv/cv.h b/include/opencv/cv.h index 39de8507b..09a2baa31 100644 --- a/include/opencv/cv.h +++ b/include/opencv/cv.h @@ -64,13 +64,11 @@ #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/photo/photo_c.h" #include "opencv2/video/tracking_c.h" - -#include "opencv2/features2d.hpp" -#include "opencv2/flann.hpp" -#include "opencv2/calib3d.hpp" -#include "opencv2/objdetect.hpp" +#include "opencv2/legacy.hpp" #include "opencv2/legacy/compat.hpp" +#include "opencv2/objdetect.hpp" + #if !defined(CV_IMPL) #define CV_IMPL extern "C" #endif //CV_IMPL diff --git a/include/opencv/cv.hpp b/include/opencv/cv.hpp index 4f60c49a7..f9fa3aee2 100644 --- a/include/opencv/cv.hpp +++ b/include/opencv/cv.hpp @@ -53,5 +53,7 @@ #include "opencv2/photo.hpp" #include "opencv2/video.hpp" #include "opencv2/highgui.hpp" +#include "opencv2/features2d.hpp" +#include "opencv2/calib3d.hpp" #endif diff --git a/include/opencv/cvaux.h b/include/opencv/cvaux.h index 12e49cc93..345036b24 100644 --- a/include/opencv/cvaux.h +++ b/include/opencv/cvaux.h @@ -50,13 +50,12 @@ #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/photo/photo_c.h" #include "opencv2/video/tracking_c.h" - -#include "opencv2/features2d.hpp" -#include "opencv2/calib3d.hpp" -#include "opencv2/objdetect.hpp" #include "opencv2/legacy.hpp" #include "opencv2/legacy/compat.hpp" #include "opencv2/legacy/blobtrack.hpp" + + +#include "opencv2/objdetect.hpp" #include "opencv2/contrib.hpp" #endif diff --git a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst index 63305bfa4..9f4721332 100644 --- a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst +++ b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst @@ -115,7 +115,7 @@ calibrateCamera --------------- Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. -.. ocv:function:: double calibrateCamera( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags=0, TermCriteria criteria=TermCriteria( TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON) ) +.. ocv:function:: double calibrateCamera( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags=0, TermCriteria criteria=TermCriteria( TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ) .. ocv:pyfunction:: cv2.calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs[, rvecs[, tvecs[, flags[, criteria]]]]) -> retval, cameraMatrix, distCoeffs, rvecs, tvecs @@ -454,7 +454,7 @@ findChessboardCorners ------------------------- Finds the positions of internal corners of the chessboard. -.. ocv:function:: bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE ) +.. ocv:function:: bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, int flags=CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE ) .. ocv:pyfunction:: cv2.findChessboardCorners(image, patternSize[, corners[, flags]]) -> retval, corners @@ -515,7 +515,7 @@ Finds centers in the grid of circles. .. ocv:function:: bool findCirclesGrid( InputArray image, Size patternSize, OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID, const Ptr &blobDetector = new SimpleBlobDetector() ) -.. ocv:pyfunction:: cv2.findCirclesGridDefault(image, patternSize[, centers[, flags]]) -> retval, centers +.. ocv:pyfunction:: cv2.findCirclesGrid(image, patternSize[, centers[, flags[, blobDetector]]]) -> retval, centers :param image: grid view of input circles; it must be an 8-bit grayscale or color image. @@ -694,7 +694,7 @@ findEssentialMat ------------------ Calculates an essential matrix from the corresponding points in two images. -.. ocv:function:: Mat findEssentialMat( InputArray points1, InputArray points2, double focal=1.0, Point2d pp=Point2d(0, 0), int method=CV_RANSAC, double prob=0.999, double threshold=1.0, OutputArray mask=noArray() ) +.. ocv:function:: Mat findEssentialMat( InputArray points1, InputArray points2, double focal=1.0, Point2d pp=Point2d(0, 0), int method=RANSAC, double prob=0.999, double threshold=1.0, OutputArray mask=noArray() ) :param points1: Array of ``N`` ``(N >= 5)`` 2D points from the first image. The point coordinates should be floating-point (single or double precision). @@ -975,7 +975,7 @@ initCameraMatrix2D ---------------------- Finds an initial camera matrix from 3D-2D point correspondences. -.. ocv:function:: Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, double aspectRatio=1.) +.. ocv:function:: Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size imageSize, double aspectRatio=1.0 ) .. ocv:pyfunction:: cv2.initCameraMatrix2D(objectPoints, imagePoints, imageSize[, aspectRatio]) -> retval diff --git a/modules/calib3d/include/opencv2/calib3d.hpp b/modules/calib3d/include/opencv2/calib3d.hpp index f3c7e8262..64462eea8 100644 --- a/modules/calib3d/include/opencv2/calib3d.hpp +++ b/modules/calib3d/include/opencv2/calib3d.hpp @@ -7,7 +7,7 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. @@ -44,562 +44,184 @@ #ifndef __OPENCV_CALIB3D_HPP__ #define __OPENCV_CALIB3D_HPP__ -#ifdef __cplusplus -# include "opencv2/core.hpp" -#endif -#include "opencv2/core/core_c.h" +#include "opencv2/core.hpp" #include "opencv2/features2d.hpp" -#ifdef __cplusplus -extern "C" { -#endif - -/****************************************************************************************\ -* Camera Calibration, Pose Estimation and Stereo * -\****************************************************************************************/ - -typedef struct CvPOSITObject CvPOSITObject; - -/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */ -CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count ); - - -/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of - an object given its model and projection in a weak-perspective case */ -CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points, - double focal_length, CvTermCriteria criteria, - float* rotation_matrix, float* translation_vector); - -/* Releases CvPOSITObject structure */ -CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object ); - -/* updates the number of RANSAC iterations */ -CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob, - int model_points, int max_iters ); - -CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst ); - -/* Calculates fundamental matrix given a set of corresponding points */ -#define CV_FM_7POINT 1 -#define CV_FM_8POINT 2 - -#define CV_LMEDS 4 -#define CV_RANSAC 8 - -#define CV_FM_LMEDS_ONLY CV_LMEDS -#define CV_FM_RANSAC_ONLY CV_RANSAC -#define CV_FM_LMEDS CV_LMEDS -#define CV_FM_RANSAC CV_RANSAC - -enum -{ - CV_ITERATIVE = 0, - CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" - CV_P3P = 2 // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem" -}; - -CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2, - CvMat* fundamental_matrix, - int method CV_DEFAULT(CV_FM_RANSAC), - double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99), - CvMat* status CV_DEFAULT(NULL) ); - -/* For each input point on one of images - computes parameters of the corresponding - epipolar line on the other image */ -CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points, - int which_image, - const CvMat* fundamental_matrix, - CvMat* correspondent_lines ); - -/* Triangulation functions */ - -CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2, - CvMat* projPoints1, CvMat* projPoints2, - CvMat* points4D); - -CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2, - CvMat* new_points1, CvMat* new_points2); - - -/* Computes the optimal new camera matrix according to the free scaling parameter alpha: - alpha=0 - only valid pixels will be retained in the undistorted image - alpha=1 - all the source image pixels will be retained in the undistorted image -*/ -CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix, - const CvMat* dist_coeffs, - CvSize image_size, double alpha, - CvMat* new_camera_matrix, - CvSize new_imag_size CV_DEFAULT(cvSize(0,0)), - CvRect* valid_pixel_ROI CV_DEFAULT(0), - int center_principal_point CV_DEFAULT(0)); - -/* Converts rotation vector to rotation matrix or vice versa */ -CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst, - CvMat* jacobian CV_DEFAULT(0) ); - -/* Finds perspective transformation between the object plane and image (view) plane */ -CVAPI(int) cvFindHomography( const CvMat* src_points, - const CvMat* dst_points, - CvMat* homography, - int method CV_DEFAULT(0), - double ransacReprojThreshold CV_DEFAULT(3), - CvMat* mask CV_DEFAULT(0)); - -/* Computes RQ decomposition for 3x3 matrices */ -CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ, - CvMat *matrixQx CV_DEFAULT(NULL), - CvMat *matrixQy CV_DEFAULT(NULL), - CvMat *matrixQz CV_DEFAULT(NULL), - CvPoint3D64f *eulerAngles CV_DEFAULT(NULL)); - -/* Computes projection matrix decomposition */ -CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr, - CvMat *rotMatr, CvMat *posVect, - CvMat *rotMatrX CV_DEFAULT(NULL), - CvMat *rotMatrY CV_DEFAULT(NULL), - CvMat *rotMatrZ CV_DEFAULT(NULL), - CvPoint3D64f *eulerAngles CV_DEFAULT(NULL)); - -/* Computes d(AB)/dA and d(AB)/dB */ -CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB ); - -/* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)), - t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */ -CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1, - const CvMat* _rvec2, const CvMat* _tvec2, - CvMat* _rvec3, CvMat* _tvec3, - CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0), - CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0), - CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0), - CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) ); - -/* Projects object points to the view plane using - the specified extrinsic and intrinsic camera parameters */ -CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector, - const CvMat* translation_vector, const CvMat* camera_matrix, - const CvMat* distortion_coeffs, CvMat* image_points, - CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL), - CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL), - CvMat* dpddist CV_DEFAULT(NULL), - double aspect_ratio CV_DEFAULT(0)); - -/* Finds extrinsic camera parameters from - a few known corresponding point pairs and intrinsic parameters */ -CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points, - const CvMat* image_points, - const CvMat* camera_matrix, - const CvMat* distortion_coeffs, - CvMat* rotation_vector, - CvMat* translation_vector, - int use_extrinsic_guess CV_DEFAULT(0) ); - -/* Computes initial estimate of the intrinsic camera parameters - in case of planar calibration target (e.g. chessboard) */ -CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points, - const CvMat* image_points, - const CvMat* npoints, CvSize image_size, - CvMat* camera_matrix, - double aspect_ratio CV_DEFAULT(1.) ); - -#define CV_CALIB_CB_ADAPTIVE_THRESH 1 -#define CV_CALIB_CB_NORMALIZE_IMAGE 2 -#define CV_CALIB_CB_FILTER_QUADS 4 -#define CV_CALIB_CB_FAST_CHECK 8 - -// Performs a fast check if a chessboard is in the input image. This is a workaround to -// a problem of cvFindChessboardCorners being slow on images with no chessboard -// - src: input image -// - size: chessboard size -// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called, -// 0 if there is no chessboard, -1 in case of error -CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size); - - /* Detects corners on a chessboard calibration pattern */ -CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size, - CvPoint2D32f* corners, - int* corner_count CV_DEFAULT(NULL), - int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) ); - -/* Draws individual chessboard corners or the whole chessboard detected */ -CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size, - CvPoint2D32f* corners, - int count, int pattern_was_found ); - -#define CV_CALIB_USE_INTRINSIC_GUESS 1 -#define CV_CALIB_FIX_ASPECT_RATIO 2 -#define CV_CALIB_FIX_PRINCIPAL_POINT 4 -#define CV_CALIB_ZERO_TANGENT_DIST 8 -#define CV_CALIB_FIX_FOCAL_LENGTH 16 -#define CV_CALIB_FIX_K1 32 -#define CV_CALIB_FIX_K2 64 -#define CV_CALIB_FIX_K3 128 -#define CV_CALIB_FIX_K4 2048 -#define CV_CALIB_FIX_K5 4096 -#define CV_CALIB_FIX_K6 8192 -#define CV_CALIB_RATIONAL_MODEL 16384 -#define CV_CALIB_THIN_PRISM_MODEL 32768 -#define CV_CALIB_FIX_S1_S2_S3_S4 65536 - - -/* Finds intrinsic and extrinsic camera parameters - from a few views of known calibration pattern */ -CVAPI(double) cvCalibrateCamera2( const CvMat* object_points, - const CvMat* image_points, - const CvMat* point_counts, - CvSize image_size, - CvMat* camera_matrix, - CvMat* distortion_coeffs, - CvMat* rotation_vectors CV_DEFAULT(NULL), - CvMat* translation_vectors CV_DEFAULT(NULL), - int flags CV_DEFAULT(0), - CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria( - CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) ); - -/* Computes various useful characteristics of the camera from the data computed by - cvCalibrateCamera2 */ -CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix, - CvSize image_size, - double aperture_width CV_DEFAULT(0), - double aperture_height CV_DEFAULT(0), - double *fovx CV_DEFAULT(NULL), - double *fovy CV_DEFAULT(NULL), - double *focal_length CV_DEFAULT(NULL), - CvPoint2D64f *principal_point CV_DEFAULT(NULL), - double *pixel_aspect_ratio CV_DEFAULT(NULL)); - -#define CV_CALIB_FIX_INTRINSIC 256 -#define CV_CALIB_SAME_FOCAL_LENGTH 512 - -/* Computes the transformation from one camera coordinate system to another one - from a few correspondent views of the same calibration target. Optionally, calibrates - both cameras */ -CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1, - const CvMat* image_points2, const CvMat* npoints, - CvMat* camera_matrix1, CvMat* dist_coeffs1, - CvMat* camera_matrix2, CvMat* dist_coeffs2, - CvSize image_size, CvMat* R, CvMat* T, - CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0), - CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria( - CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)), - int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC)); - -#define CV_CALIB_ZERO_DISPARITY 1024 - -/* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both - views parallel (=> to make all the epipolar lines horizontal or vertical) */ -CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2, - const CvMat* dist_coeffs1, const CvMat* dist_coeffs2, - CvSize image_size, const CvMat* R, const CvMat* T, - CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2, - CvMat* Q CV_DEFAULT(0), - int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY), - double alpha CV_DEFAULT(-1), - CvSize new_image_size CV_DEFAULT(cvSize(0,0)), - CvRect* valid_pix_ROI1 CV_DEFAULT(0), - CvRect* valid_pix_ROI2 CV_DEFAULT(0)); - -/* Computes rectification transformations for uncalibrated pair of images using a set - of point correspondences */ -CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2, - const CvMat* F, CvSize img_size, - CvMat* H1, CvMat* H2, - double threshold CV_DEFAULT(5)); - - - -/* stereo correspondence parameters and functions */ - -#define CV_STEREO_BM_NORMALIZED_RESPONSE 0 -#define CV_STEREO_BM_XSOBEL 1 - -/* Block matching algorithm structure */ -typedef struct CvStereoBMState -{ - // pre-filtering (normalization of input images) - int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now - int preFilterSize; // averaging window size: ~5x5..21x21 - int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap] - - // correspondence using Sum of Absolute Difference (SAD) - int SADWindowSize; // ~5x5..21x21 - int minDisparity; // minimum disparity (can be negative) - int numberOfDisparities; // maximum disparity - minimum disparity (> 0) - - // post-filtering - int textureThreshold; // the disparity is only computed for pixels - // with textured enough neighborhood - int uniquenessRatio; // accept the computed disparity d* only if - // SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.) - // for any d != d*+/-1 within the search range. - int speckleWindowSize; // disparity variation window - int speckleRange; // acceptable range of variation in window - - int trySmallerWindows; // if 1, the results may be more accurate, - // at the expense of slower processing - CvRect roi1, roi2; - int disp12MaxDiff; - - // temporary buffers - CvMat* preFilteredImg0; - CvMat* preFilteredImg1; - CvMat* slidingSumBuf; - CvMat* cost; - CvMat* disp; -} CvStereoBMState; - -#define CV_STEREO_BM_BASIC 0 -#define CV_STEREO_BM_FISH_EYE 1 -#define CV_STEREO_BM_NARROW 2 - -CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC), - int numberOfDisparities CV_DEFAULT(0)); - -CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state ); - -CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right, - CvArr* disparity, CvStereoBMState* state ); - -CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity, - int numberOfDisparities, int SADWindowSize ); - -CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost, - int minDisparity, int numberOfDisparities, - int disp12MaxDiff CV_DEFAULT(1) ); - -/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */ -CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage, - CvArr* _3dImage, const CvMat* Q, - int handleMissingValues CV_DEFAULT(0) ); - - -#ifdef __cplusplus -} - -////////////////////////////////////////////////////////////////////////////////////////// -class CV_EXPORTS CvLevMarq -{ -public: - CvLevMarq(); - CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria= - cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), - bool completeSymmFlag=false ); - ~CvLevMarq(); - void init( int nparams, int nerrs, CvTermCriteria criteria= - cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), - bool completeSymmFlag=false ); - bool update( const CvMat*& param, CvMat*& J, CvMat*& err ); - bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm ); - - void clear(); - void step(); - enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 }; - - cv::Ptr mask; - cv::Ptr prevParam; - cv::Ptr param; - cv::Ptr J; - cv::Ptr err; - cv::Ptr JtJ; - cv::Ptr JtJN; - cv::Ptr JtErr; - cv::Ptr JtJV; - cv::Ptr JtJW; - double prevErrNorm, errNorm; - int lambdaLg10; - CvTermCriteria criteria; - int state; - int iters; - bool completeSymmFlag; -}; - namespace cv { -//! converts rotation vector to rotation matrix or vice versa using Rodrigues transformation -CV_EXPORTS_W void Rodrigues(InputArray src, OutputArray dst, OutputArray jacobian=noArray()); //! type of the robust estimation algorithm -enum -{ - LMEDS=CV_LMEDS, //!< least-median algorithm - RANSAC=CV_RANSAC //!< RANSAC algorithm -}; +enum { LMEDS = 4, //!< least-median algorithm + RANSAC = 8 //!< RANSAC algorithm + }; + +enum { ITERATIVE = 0, + EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" + P3P = 2 // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem" + }; + +enum { CALIB_CB_ADAPTIVE_THRESH = 1, + CALIB_CB_NORMALIZE_IMAGE = 2, + CALIB_CB_FILTER_QUADS = 4, + CALIB_CB_FAST_CHECK = 8 + }; + +enum { CALIB_CB_SYMMETRIC_GRID = 1, + CALIB_CB_ASYMMETRIC_GRID = 2, + CALIB_CB_CLUSTERING = 4 + }; + +enum { CALIB_USE_INTRINSIC_GUESS = 0x00001, + CALIB_FIX_ASPECT_RATIO = 0x00002, + CALIB_FIX_PRINCIPAL_POINT = 0x00004, + CALIB_ZERO_TANGENT_DIST = 0x00008, + CALIB_FIX_FOCAL_LENGTH = 0x00010, + CALIB_FIX_K1 = 0x00020, + CALIB_FIX_K2 = 0x00040, + CALIB_FIX_K3 = 0x00080, + CALIB_FIX_K4 = 0x00800, + CALIB_FIX_K5 = 0x01000, + CALIB_FIX_K6 = 0x02000, + CALIB_RATIONAL_MODEL = 0x04000, + CALIB_THIN_PRISM_MODEL = 0x08000, + CALIB_FIX_S1_S2_S3_S4 = 0x10000, + // only for stereo + CALIB_FIX_INTRINSIC = 0x00100, + CALIB_SAME_FOCAL_LENGTH = 0x00200, + // for stereo rectification + CALIB_ZERO_DISPARITY = 0x00400 + }; + +//! the algorithm for finding fundamental matrix +enum { FM_7POINT = 1, //!< 7-point algorithm + FM_8POINT = 2, //!< 8-point algorithm + FM_LMEDS = 4, //!< least-median algorithm + FM_RANSAC = 8 //!< RANSAC algorithm + }; + + + +//! converts rotation vector to rotation matrix or vice versa using Rodrigues transformation +CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() ); //! computes the best-fit perspective transformation mapping srcPoints to dstPoints. CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints, - int method=0, double ransacReprojThreshold=3, + int method = 0, double ransacReprojThreshold = 3, OutputArray mask=noArray()); //! variant of findHomography for backward compatibility CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints, - OutputArray mask, int method=0, double ransacReprojThreshold=3); + OutputArray mask, int method = 0, double ransacReprojThreshold = 3 ); //! Computes RQ decomposition of 3x3 matrix CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ, - OutputArray Qx=noArray(), - OutputArray Qy=noArray(), - OutputArray Qz=noArray()); + OutputArray Qx = noArray(), + OutputArray Qy = noArray(), + OutputArray Qz = noArray()); //! Decomposes the projection matrix into camera matrix and the rotation martix and the translation vector CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix, OutputArray rotMatrix, OutputArray transVect, - OutputArray rotMatrixX=noArray(), - OutputArray rotMatrixY=noArray(), - OutputArray rotMatrixZ=noArray(), - OutputArray eulerAngles=noArray() ); + OutputArray rotMatrixX = noArray(), + OutputArray rotMatrixY = noArray(), + OutputArray rotMatrixZ = noArray(), + OutputArray eulerAngles =noArray() ); //! computes derivatives of the matrix product w.r.t each of the multiplied matrix coefficients -CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, - OutputArray dABdA, - OutputArray dABdB ); +CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB ); //! composes 2 [R|t] transformations together. Also computes the derivatives of the result w.r.t the arguments CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1, InputArray rvec2, InputArray tvec2, OutputArray rvec3, OutputArray tvec3, - OutputArray dr3dr1=noArray(), OutputArray dr3dt1=noArray(), - OutputArray dr3dr2=noArray(), OutputArray dr3dt2=noArray(), - OutputArray dt3dr1=noArray(), OutputArray dt3dt1=noArray(), - OutputArray dt3dr2=noArray(), OutputArray dt3dt2=noArray() ); + OutputArray dr3dr1 = noArray(), OutputArray dr3dt1 = noArray(), + OutputArray dr3dr2 = noArray(), OutputArray dr3dt2 = noArray(), + OutputArray dt3dr1 = noArray(), OutputArray dt3dt1 = noArray(), + OutputArray dt3dr2 = noArray(), OutputArray dt3dt2 = noArray() ); //! projects points from the model coordinate space to the image coordinates. Also computes derivatives of the image coordinates w.r.t the intrinsic and extrinsic camera parameters CV_EXPORTS_W void projectPoints( InputArray objectPoints, InputArray rvec, InputArray tvec, InputArray cameraMatrix, InputArray distCoeffs, OutputArray imagePoints, - OutputArray jacobian=noArray(), - double aspectRatio=0 ); + OutputArray jacobian = noArray(), + double aspectRatio = 0 ); //! computes the camera pose from a few 3D points and the corresponding projections. The outliers are not handled. -enum -{ - ITERATIVE=CV_ITERATIVE, - EPNP=CV_EPNP, - P3P=CV_P3P -}; CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, - bool useExtrinsicGuess=false, int flags=ITERATIVE); + bool useExtrinsicGuess = false, int flags = ITERATIVE ); //! computes the camera pose from a few 3D points and the corresponding projections. The outliers are possible. -CV_EXPORTS_W void solvePnPRansac( InputArray objectPoints, - InputArray imagePoints, - InputArray cameraMatrix, - InputArray distCoeffs, - OutputArray rvec, - OutputArray tvec, - bool useExtrinsicGuess = false, - int iterationsCount = 100, - float reprojectionError = 8.0, - int minInliersCount = 100, - OutputArray inliers = noArray(), - int flags = ITERATIVE); +CV_EXPORTS_W void solvePnPRansac( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, + bool useExtrinsicGuess = false, int iterationsCount = 100, + float reprojectionError = 8.0, int minInliersCount = 100, + OutputArray inliers = noArray(), int flags = ITERATIVE ); //! initializes camera matrix from a few 3D points and the corresponding projections. CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, - Size imageSize, double aspectRatio=1. ); - -enum { CALIB_CB_ADAPTIVE_THRESH = 1, CALIB_CB_NORMALIZE_IMAGE = 2, - CALIB_CB_FILTER_QUADS = 4, CALIB_CB_FAST_CHECK = 8 }; + Size imageSize, double aspectRatio = 1.0 ); //! finds checkerboard pattern of the specified size in the image -CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, - OutputArray corners, - int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE ); +CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, + int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE ); //! finds subpixel-accurate positions of the chessboard corners -CV_EXPORTS bool find4QuadCornerSubpix(InputArray img, InputOutputArray corners, Size region_size); +CV_EXPORTS bool find4QuadCornerSubpix( InputArray img, InputOutputArray corners, Size region_size ); //! draws the checkerboard pattern (found or partly found) in the image CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize, InputArray corners, bool patternWasFound ); -enum { CALIB_CB_SYMMETRIC_GRID = 1, CALIB_CB_ASYMMETRIC_GRID = 2, - CALIB_CB_CLUSTERING = 4 }; - //! finds circles' grid pattern of the specified size in the image CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, - OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID, - const Ptr &blobDetector = new SimpleBlobDetector()); - -//! the deprecated function. Use findCirclesGrid() instead of it. -CV_EXPORTS_W bool findCirclesGridDefault( InputArray image, Size patternSize, - OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID ); -enum -{ - CALIB_USE_INTRINSIC_GUESS = CV_CALIB_USE_INTRINSIC_GUESS, - CALIB_FIX_ASPECT_RATIO = CV_CALIB_FIX_ASPECT_RATIO, - CALIB_FIX_PRINCIPAL_POINT = CV_CALIB_FIX_PRINCIPAL_POINT, - CALIB_ZERO_TANGENT_DIST = CV_CALIB_ZERO_TANGENT_DIST, - CALIB_FIX_FOCAL_LENGTH = CV_CALIB_FIX_FOCAL_LENGTH, - CALIB_FIX_K1 = CV_CALIB_FIX_K1, - CALIB_FIX_K2 = CV_CALIB_FIX_K2, - CALIB_FIX_K3 = CV_CALIB_FIX_K3, - CALIB_FIX_K4 = CV_CALIB_FIX_K4, - CALIB_FIX_K5 = CV_CALIB_FIX_K5, - CALIB_FIX_K6 = CV_CALIB_FIX_K6, - CALIB_RATIONAL_MODEL = CV_CALIB_RATIONAL_MODEL, - CALIB_THIN_PRISM_MODEL = CV_CALIB_THIN_PRISM_MODEL, - CALIB_FIX_S1_S2_S3_S4=CV_CALIB_FIX_S1_S2_S3_S4, - // only for stereo - CALIB_FIX_INTRINSIC = CV_CALIB_FIX_INTRINSIC, - CALIB_SAME_FOCAL_LENGTH = CV_CALIB_SAME_FOCAL_LENGTH, - // for stereo rectification - CALIB_ZERO_DISPARITY = CV_CALIB_ZERO_DISPARITY -}; + OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID, + const Ptr &blobDetector = new SimpleBlobDetector()); //! finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern. CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints, - InputArrayOfArrays imagePoints, - Size imageSize, - InputOutputArray cameraMatrix, - InputOutputArray distCoeffs, + InputArrayOfArrays imagePoints, Size imageSize, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, - int flags=0, TermCriteria criteria = TermCriteria( - TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON) ); + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); //! computes several useful camera characteristics from the camera matrix, camera frame resolution and the physical sensor size. -CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix, - Size imageSize, - double apertureWidth, - double apertureHeight, - CV_OUT double& fovx, - CV_OUT double& fovy, - CV_OUT double& focalLength, - CV_OUT Point2d& principalPoint, - CV_OUT double& aspectRatio ); +CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix, Size imageSize, + double apertureWidth, double apertureHeight, + CV_OUT double& fovx, CV_OUT double& fovy, + CV_OUT double& focalLength, CV_OUT Point2d& principalPoint, + CV_OUT double& aspectRatio ); //! finds intrinsic and extrinsic parameters of a stereo camera CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints, - InputArrayOfArrays imagePoints1, - InputArrayOfArrays imagePoints2, - InputOutputArray cameraMatrix1, - InputOutputArray distCoeffs1, - InputOutputArray cameraMatrix2, - InputOutputArray distCoeffs2, - Size imageSize, OutputArray R, - OutputArray T, OutputArray E, OutputArray F, + InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1, + InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2, + Size imageSize, OutputArray R,OutputArray T, OutputArray E, OutputArray F, TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6), - int flags=CALIB_FIX_INTRINSIC ); + int flags = CALIB_FIX_INTRINSIC ); //! computes the rectification transformation for a stereo camera from its intrinsic and extrinsic parameters CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1, - InputArray cameraMatrix2, InputArray distCoeffs2, - Size imageSize, InputArray R, InputArray T, - OutputArray R1, OutputArray R2, - OutputArray P1, OutputArray P2, - OutputArray Q, int flags=CALIB_ZERO_DISPARITY, - double alpha=-1, Size newImageSize=Size(), - CV_OUT Rect* validPixROI1=0, CV_OUT Rect* validPixROI2=0 ); + InputArray cameraMatrix2, InputArray distCoeffs2, + Size imageSize, InputArray R, InputArray T, + OutputArray R1, OutputArray R2, + OutputArray P1, OutputArray P2, + OutputArray Q, int flags = CALIB_ZERO_DISPARITY, + double alpha = -1, Size newImageSize = Size(), + CV_OUT Rect* validPixROI1 = 0, CV_OUT Rect* validPixROI2 = 0 ); //! computes the rectification transformation for an uncalibrated stereo camera (zero distortion is assumed) CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2, InputArray F, Size imgSize, OutputArray H1, OutputArray H2, - double threshold=5 ); + double threshold = 5 ); //! computes the rectification transformations for 3-head camera, where all the heads are on the same line. CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1, @@ -615,8 +237,9 @@ CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distC //! returns the optimal new camera matrix CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs, - Size imageSize, double alpha, Size newImgSize=Size(), - CV_OUT Rect* validPixROI=0, bool centerPrincipalPoint=false); + Size imageSize, double alpha, Size newImgSize = Size(), + CV_OUT Rect* validPixROI = 0, + bool centerPrincipalPoint = false); //! converts point coordinates from normal pixel coordinates to homogeneous coordinates ((x,y)->(x,y,1)) CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst ); @@ -627,44 +250,36 @@ CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst //! for backward compatibility CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst ); -//! the algorithm for finding fundamental matrix -enum -{ - FM_7POINT = CV_FM_7POINT, //!< 7-point algorithm - FM_8POINT = CV_FM_8POINT, //!< 8-point algorithm - FM_LMEDS = CV_FM_LMEDS, //!< least-median algorithm - FM_RANSAC = CV_FM_RANSAC //!< RANSAC algorithm -}; - //! finds fundamental matrix from a set of corresponding 2D points CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2, - int method=FM_RANSAC, - double param1=3., double param2=0.99, - OutputArray mask=noArray()); + int method = FM_RANSAC, + double param1 = 3., double param2 = 0.99, + OutputArray mask = noArray() ); //! variant of findFundamentalMat for backward compatibility CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2, - OutputArray mask, int method=FM_RANSAC, - double param1=3., double param2=0.99); + OutputArray mask, int method = FM_RANSAC, + double param1 = 3., double param2 = 0.99 ); //! finds essential matrix from a set of corresponding 2D points using five-point algorithm -CV_EXPORTS Mat findEssentialMat( InputArray points1, InputArray points2, double focal = 1.0, Point2d pp = Point2d(0, 0), - int method = CV_RANSAC, - double prob = 0.999, double threshold = 1.0, OutputArray mask = noArray() ); +CV_EXPORTS Mat findEssentialMat( InputArray points1, InputArray points2, + double focal = 1.0, Point2d pp = Point2d(0, 0), + int method = RANSAC, double prob = 0.999, + double threshold = 1.0, OutputArray mask = noArray() ); //! decompose essential matrix to possible rotation matrix and one translation vector CV_EXPORTS void decomposeEssentialMat( InputArray E, OutputArray R1, OutputArray R2, OutputArray t ); //! recover relative camera pose from a set of corresponding 2D points -CV_EXPORTS int recoverPose( InputArray E, InputArray points1, InputArray points2, OutputArray R, OutputArray t, +CV_EXPORTS int recoverPose( InputArray E, InputArray points1, InputArray points2, + OutputArray R, OutputArray t, double focal = 1.0, Point2d pp = Point2d(0, 0), - InputOutputArray mask = noArray()); + InputOutputArray mask = noArray() ); //! finds coordinates of epipolar lines corresponding the specified points -CV_EXPORTS void computeCorrespondEpilines( InputArray points, - int whichImage, InputArray F, - OutputArray lines ); +CV_EXPORTS void computeCorrespondEpilines( InputArray points, int whichImage, + InputArray F, OutputArray lines ); CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2, InputArray projPoints1, InputArray projPoints2, @@ -673,13 +288,39 @@ CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2, CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2, OutputArray newPoints1, OutputArray newPoints2 ); +//! filters off speckles (small regions of incorrectly computed disparity) +CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, + int maxSpeckleSize, double maxDiff, + InputOutputArray buf = noArray() ); + +//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify()) +CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2, + int minDisparity, int numberOfDisparities, + int SADWindowSize ); + +//! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm +CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost, + int minDisparity, int numberOfDisparities, + int disp12MaxDisp = 1 ); + +//! reprojects disparity image to 3D: (x,y,d)->(X,Y,Z) using the matrix Q returned by cv::stereoRectify +CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity, + OutputArray _3dImage, InputArray Q, + bool handleMissingValues = false, + int ddepth = -1 ); + +CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst, + OutputArray out, OutputArray inliers, + double ransacThreshold = 3, double confidence = 0.99); + -template<> CV_EXPORTS void Ptr::delete_obj(); class CV_EXPORTS_W StereoMatcher : public Algorithm { public: - enum { DISP_SHIFT=4, DISP_SCALE=(1 << DISP_SHIFT) }; + enum { DISP_SHIFT = 4, + DISP_SCALE = (1 << DISP_SHIFT) + }; CV_WRAP virtual void compute( InputArray left, InputArray right, OutputArray disparity ) = 0; @@ -704,10 +345,13 @@ public: }; + class CV_EXPORTS_W StereoBM : public StereoMatcher { public: - enum { PREFILTER_NORMALIZED_RESPONSE = 0, PREFILTER_XSOBEL = 1 }; + enum { PREFILTER_NORMALIZED_RESPONSE = 0, + PREFILTER_XSOBEL = 1 + }; CV_WRAP virtual int getPreFilterType() const = 0; CV_WRAP virtual void setPreFilterType(int preFilterType) = 0; @@ -734,13 +378,15 @@ public: CV_WRAP virtual void setROI2(Rect roi2) = 0; }; -CV_EXPORTS_W Ptr createStereoBM(int numDisparities=0, int blockSize=21); +CV_EXPORTS_W Ptr createStereoBM(int numDisparities = 0, int blockSize = 21); class CV_EXPORTS_W StereoSGBM : public StereoMatcher { public: - enum { MODE_SGBM=0, MODE_HH=1 }; + enum { MODE_SGBM = 0, + MODE_HH = 1 + }; CV_WRAP virtual int getPreFilterCap() const = 0; CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; @@ -760,38 +406,11 @@ public: CV_EXPORTS_W Ptr createStereoSGBM(int minDisparity, int numDisparities, int blockSize, - int P1=0, int P2=0, int disp12MaxDiff=0, - int preFilterCap=0, int uniquenessRatio=0, - int speckleWindowSize=0, int speckleRange=0, - int mode=StereoSGBM::MODE_SGBM); + int P1 = 0, int P2 = 0, int disp12MaxDiff = 0, + int preFilterCap = 0, int uniquenessRatio = 0, + int speckleWindowSize = 0, int speckleRange = 0, + int mode = StereoSGBM::MODE_SGBM); -//! filters off speckles (small regions of incorrectly computed disparity) -CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, - int maxSpeckleSize, double maxDiff, - InputOutputArray buf=noArray() ); - -//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify()) -CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2, - int minDisparity, int numberOfDisparities, - int SADWindowSize ); - -//! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm -CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost, - int minDisparity, int numberOfDisparities, - int disp12MaxDisp=1 ); - -//! reprojects disparity image to 3D: (x,y,d)->(X,Y,Z) using the matrix Q returned by cv::stereoRectify -CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity, - OutputArray _3dImage, InputArray Q, - bool handleMissingValues=false, - int ddepth=-1 ); - -CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst, - OutputArray out, OutputArray inliers, - double ransacThreshold=3, double confidence=0.99); - -} - -#endif +} // cv #endif diff --git a/modules/calib3d/include/opencv2/calib3d/calib3d_c.h b/modules/calib3d/include/opencv2/calib3d/calib3d_c.h new file mode 100644 index 000000000..a505d526d --- /dev/null +++ b/modules/calib3d/include/opencv2/calib3d/calib3d_c.h @@ -0,0 +1,413 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_CALIB3D_C_H__ +#define __OPENCV_CALIB3D_C_H__ + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************************\ +* Camera Calibration, Pose Estimation and Stereo * +\****************************************************************************************/ + +typedef struct CvPOSITObject CvPOSITObject; + +/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */ +CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count ); + + +/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of + an object given its model and projection in a weak-perspective case */ +CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points, + double focal_length, CvTermCriteria criteria, + float* rotation_matrix, float* translation_vector); + +/* Releases CvPOSITObject structure */ +CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object ); + +/* updates the number of RANSAC iterations */ +CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob, + int model_points, int max_iters ); + +CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst ); + +/* Calculates fundamental matrix given a set of corresponding points */ +#define CV_FM_7POINT 1 +#define CV_FM_8POINT 2 + +#define CV_LMEDS 4 +#define CV_RANSAC 8 + +#define CV_FM_LMEDS_ONLY CV_LMEDS +#define CV_FM_RANSAC_ONLY CV_RANSAC +#define CV_FM_LMEDS CV_LMEDS +#define CV_FM_RANSAC CV_RANSAC + +enum +{ + CV_ITERATIVE = 0, + CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" + CV_P3P = 2 // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem" +}; + +CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2, + CvMat* fundamental_matrix, + int method CV_DEFAULT(CV_FM_RANSAC), + double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99), + CvMat* status CV_DEFAULT(NULL) ); + +/* For each input point on one of images + computes parameters of the corresponding + epipolar line on the other image */ +CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points, + int which_image, + const CvMat* fundamental_matrix, + CvMat* correspondent_lines ); + +/* Triangulation functions */ + +CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2, + CvMat* projPoints1, CvMat* projPoints2, + CvMat* points4D); + +CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2, + CvMat* new_points1, CvMat* new_points2); + + +/* Computes the optimal new camera matrix according to the free scaling parameter alpha: + alpha=0 - only valid pixels will be retained in the undistorted image + alpha=1 - all the source image pixels will be retained in the undistorted image +*/ +CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix, + const CvMat* dist_coeffs, + CvSize image_size, double alpha, + CvMat* new_camera_matrix, + CvSize new_imag_size CV_DEFAULT(cvSize(0,0)), + CvRect* valid_pixel_ROI CV_DEFAULT(0), + int center_principal_point CV_DEFAULT(0)); + +/* Converts rotation vector to rotation matrix or vice versa */ +CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst, + CvMat* jacobian CV_DEFAULT(0) ); + +/* Finds perspective transformation between the object plane and image (view) plane */ +CVAPI(int) cvFindHomography( const CvMat* src_points, + const CvMat* dst_points, + CvMat* homography, + int method CV_DEFAULT(0), + double ransacReprojThreshold CV_DEFAULT(3), + CvMat* mask CV_DEFAULT(0)); + +/* Computes RQ decomposition for 3x3 matrices */ +CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ, + CvMat *matrixQx CV_DEFAULT(NULL), + CvMat *matrixQy CV_DEFAULT(NULL), + CvMat *matrixQz CV_DEFAULT(NULL), + CvPoint3D64f *eulerAngles CV_DEFAULT(NULL)); + +/* Computes projection matrix decomposition */ +CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr, + CvMat *rotMatr, CvMat *posVect, + CvMat *rotMatrX CV_DEFAULT(NULL), + CvMat *rotMatrY CV_DEFAULT(NULL), + CvMat *rotMatrZ CV_DEFAULT(NULL), + CvPoint3D64f *eulerAngles CV_DEFAULT(NULL)); + +/* Computes d(AB)/dA and d(AB)/dB */ +CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB ); + +/* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)), + t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */ +CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1, + const CvMat* _rvec2, const CvMat* _tvec2, + CvMat* _rvec3, CvMat* _tvec3, + CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0), + CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0), + CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0), + CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) ); + +/* Projects object points to the view plane using + the specified extrinsic and intrinsic camera parameters */ +CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector, + const CvMat* translation_vector, const CvMat* camera_matrix, + const CvMat* distortion_coeffs, CvMat* image_points, + CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL), + CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL), + CvMat* dpddist CV_DEFAULT(NULL), + double aspect_ratio CV_DEFAULT(0)); + +/* Finds extrinsic camera parameters from + a few known corresponding point pairs and intrinsic parameters */ +CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points, + const CvMat* image_points, + const CvMat* camera_matrix, + const CvMat* distortion_coeffs, + CvMat* rotation_vector, + CvMat* translation_vector, + int use_extrinsic_guess CV_DEFAULT(0) ); + +/* Computes initial estimate of the intrinsic camera parameters + in case of planar calibration target (e.g. chessboard) */ +CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points, + const CvMat* image_points, + const CvMat* npoints, CvSize image_size, + CvMat* camera_matrix, + double aspect_ratio CV_DEFAULT(1.) ); + +#define CV_CALIB_CB_ADAPTIVE_THRESH 1 +#define CV_CALIB_CB_NORMALIZE_IMAGE 2 +#define CV_CALIB_CB_FILTER_QUADS 4 +#define CV_CALIB_CB_FAST_CHECK 8 + +// Performs a fast check if a chessboard is in the input image. This is a workaround to +// a problem of cvFindChessboardCorners being slow on images with no chessboard +// - src: input image +// - size: chessboard size +// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called, +// 0 if there is no chessboard, -1 in case of error +CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size); + + /* Detects corners on a chessboard calibration pattern */ +CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size, + CvPoint2D32f* corners, + int* corner_count CV_DEFAULT(NULL), + int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) ); + +/* Draws individual chessboard corners or the whole chessboard detected */ +CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size, + CvPoint2D32f* corners, + int count, int pattern_was_found ); + +#define CV_CALIB_USE_INTRINSIC_GUESS 1 +#define CV_CALIB_FIX_ASPECT_RATIO 2 +#define CV_CALIB_FIX_PRINCIPAL_POINT 4 +#define CV_CALIB_ZERO_TANGENT_DIST 8 +#define CV_CALIB_FIX_FOCAL_LENGTH 16 +#define CV_CALIB_FIX_K1 32 +#define CV_CALIB_FIX_K2 64 +#define CV_CALIB_FIX_K3 128 +#define CV_CALIB_FIX_K4 2048 +#define CV_CALIB_FIX_K5 4096 +#define CV_CALIB_FIX_K6 8192 +#define CV_CALIB_RATIONAL_MODEL 16384 +#define CV_CALIB_THIN_PRISM_MODEL 32768 +#define CV_CALIB_FIX_S1_S2_S3_S4 65536 + + +/* Finds intrinsic and extrinsic camera parameters + from a few views of known calibration pattern */ +CVAPI(double) cvCalibrateCamera2( const CvMat* object_points, + const CvMat* image_points, + const CvMat* point_counts, + CvSize image_size, + CvMat* camera_matrix, + CvMat* distortion_coeffs, + CvMat* rotation_vectors CV_DEFAULT(NULL), + CvMat* translation_vectors CV_DEFAULT(NULL), + int flags CV_DEFAULT(0), + CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria( + CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) ); + +/* Computes various useful characteristics of the camera from the data computed by + cvCalibrateCamera2 */ +CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix, + CvSize image_size, + double aperture_width CV_DEFAULT(0), + double aperture_height CV_DEFAULT(0), + double *fovx CV_DEFAULT(NULL), + double *fovy CV_DEFAULT(NULL), + double *focal_length CV_DEFAULT(NULL), + CvPoint2D64f *principal_point CV_DEFAULT(NULL), + double *pixel_aspect_ratio CV_DEFAULT(NULL)); + +#define CV_CALIB_FIX_INTRINSIC 256 +#define CV_CALIB_SAME_FOCAL_LENGTH 512 + +/* Computes the transformation from one camera coordinate system to another one + from a few correspondent views of the same calibration target. Optionally, calibrates + both cameras */ +CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1, + const CvMat* image_points2, const CvMat* npoints, + CvMat* camera_matrix1, CvMat* dist_coeffs1, + CvMat* camera_matrix2, CvMat* dist_coeffs2, + CvSize image_size, CvMat* R, CvMat* T, + CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0), + CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria( + CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)), + int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC)); + +#define CV_CALIB_ZERO_DISPARITY 1024 + +/* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both + views parallel (=> to make all the epipolar lines horizontal or vertical) */ +CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2, + const CvMat* dist_coeffs1, const CvMat* dist_coeffs2, + CvSize image_size, const CvMat* R, const CvMat* T, + CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2, + CvMat* Q CV_DEFAULT(0), + int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY), + double alpha CV_DEFAULT(-1), + CvSize new_image_size CV_DEFAULT(cvSize(0,0)), + CvRect* valid_pix_ROI1 CV_DEFAULT(0), + CvRect* valid_pix_ROI2 CV_DEFAULT(0)); + +/* Computes rectification transformations for uncalibrated pair of images using a set + of point correspondences */ +CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2, + const CvMat* F, CvSize img_size, + CvMat* H1, CvMat* H2, + double threshold CV_DEFAULT(5)); + + + +/* stereo correspondence parameters and functions */ + +#define CV_STEREO_BM_NORMALIZED_RESPONSE 0 +#define CV_STEREO_BM_XSOBEL 1 + +/* Block matching algorithm structure */ +typedef struct CvStereoBMState +{ + // pre-filtering (normalization of input images) + int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now + int preFilterSize; // averaging window size: ~5x5..21x21 + int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap] + + // correspondence using Sum of Absolute Difference (SAD) + int SADWindowSize; // ~5x5..21x21 + int minDisparity; // minimum disparity (can be negative) + int numberOfDisparities; // maximum disparity - minimum disparity (> 0) + + // post-filtering + int textureThreshold; // the disparity is only computed for pixels + // with textured enough neighborhood + int uniquenessRatio; // accept the computed disparity d* only if + // SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.) + // for any d != d*+/-1 within the search range. + int speckleWindowSize; // disparity variation window + int speckleRange; // acceptable range of variation in window + + int trySmallerWindows; // if 1, the results may be more accurate, + // at the expense of slower processing + CvRect roi1, roi2; + int disp12MaxDiff; + + // temporary buffers + CvMat* preFilteredImg0; + CvMat* preFilteredImg1; + CvMat* slidingSumBuf; + CvMat* cost; + CvMat* disp; +} CvStereoBMState; + +#define CV_STEREO_BM_BASIC 0 +#define CV_STEREO_BM_FISH_EYE 1 +#define CV_STEREO_BM_NARROW 2 + +CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC), + int numberOfDisparities CV_DEFAULT(0)); + +CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state ); + +CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right, + CvArr* disparity, CvStereoBMState* state ); + +CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity, + int numberOfDisparities, int SADWindowSize ); + +CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost, + int minDisparity, int numberOfDisparities, + int disp12MaxDiff CV_DEFAULT(1) ); + +/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */ +CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage, + CvArr* _3dImage, const CvMat* Q, + int handleMissingValues CV_DEFAULT(0) ); + +#ifdef __cplusplus +} // extern "C" + +////////////////////////////////////////////////////////////////////////////////////////// +class CV_EXPORTS CvLevMarq +{ +public: + CvLevMarq(); + CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + ~CvLevMarq(); + void init( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + bool update( const CvMat*& param, CvMat*& J, CvMat*& err ); + bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm ); + + void clear(); + void step(); + enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 }; + + cv::Ptr mask; + cv::Ptr prevParam; + cv::Ptr param; + cv::Ptr J; + cv::Ptr err; + cv::Ptr JtJ; + cv::Ptr JtJN; + cv::Ptr JtErr; + cv::Ptr JtJV; + cv::Ptr JtJW; + double prevErrNorm, errNorm; + int lambdaLg10; + CvTermCriteria criteria; + int state; + int iters; + bool completeSymmFlag; +}; + +#endif + +#endif /* __OPENCV_CALIB3D_C_H__ */ diff --git a/modules/calib3d/perf/perf_pnp.cpp b/modules/calib3d/perf/perf_pnp.cpp index 02ecd2c59..e88155729 100644 --- a/modules/calib3d/perf/perf_pnp.cpp +++ b/modules/calib3d/perf/perf_pnp.cpp @@ -10,7 +10,7 @@ using namespace perf; using std::tr1::make_tuple; using std::tr1::get; -CV_ENUM(pnpAlgo, CV_ITERATIVE, CV_EPNP /*, CV_P3P*/) +CV_ENUM(pnpAlgo, ITERATIVE, EPNP /*, P3P*/) typedef std::tr1::tuple PointsNum_Algo_t; typedef perf::TestBaseWithParam PointsNum_Algo; @@ -20,7 +20,7 @@ typedef perf::TestBaseWithParam PointsNum; PERF_TEST_P(PointsNum_Algo, solvePnP, testing::Combine( testing::Values(/*4,*/ 3*9, 7*13), //TODO: find why results on 4 points are too unstable - testing::Values((int)CV_ITERATIVE, (int)CV_EPNP) + testing::Values((int)ITERATIVE, (int)EPNP) ) ) { @@ -93,7 +93,7 @@ PERF_TEST(PointsNum_Algo, solveP3P) TEST_CYCLE_N(1000) { - solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, CV_P3P); + solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, P3P); } SANITY_CHECK(rvec, 1e-6); diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index ac4c8367a..b93b4951e 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -61,6 +61,7 @@ #include "precomp.hpp" #include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/calib3d/calib3d_c.h" #include "circlesgrid.hpp" #include diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index 176503f81..bb7863575 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -42,6 +42,7 @@ #include "precomp.hpp" #include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/calib3d/calib3d_c.h" #include #include @@ -825,7 +826,7 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints, dpdk_p[dpdk_step+7] = fy*y*cdist*(-icdist2)*icdist2*r6; if( _dpdk->cols > 8 ) { - dpdk_p[8] = fx*r2; //s1 + dpdk_p[8] = fx*r2; //s1 dpdk_p[9] = fx*r4; //s2 dpdk_p[10] = 0;//s3 dpdk_p[11] = 0;//s4 @@ -1255,7 +1256,7 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints, //when the thin prism model is used the distortion coefficients matrix must have 12 parameters if((flags & CV_CALIB_THIN_PRISM_MODEL) && (distCoeffs->cols*distCoeffs->rows != 12)) CV_Error( CV_StsBadArg, "Thin prism model must have 12 parameters in the distortion matrix" ); - + nimages = npoints->rows*npoints->cols; npstep = npoints->rows == 1 ? 1 : npoints->step/CV_ELEM_SIZE(npoints->type); diff --git a/modules/calib3d/src/checkchessboard.cpp b/modules/calib3d/src/checkchessboard.cpp index 4019d564e..715fe73ef 100644 --- a/modules/calib3d/src/checkchessboard.cpp +++ b/modules/calib3d/src/checkchessboard.cpp @@ -41,6 +41,7 @@ #include "precomp.hpp" #include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/calib3d/calib3d_c.h" #include #include diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp index 3514aeb4b..db9530483 100644 --- a/modules/calib3d/src/circlesgrid.cpp +++ b/modules/calib3d/src/circlesgrid.cpp @@ -202,12 +202,12 @@ void CirclesGridClusterFinder::findCorners(const std::vector &hull2 //corners are the most sharp angles (6) Mat anglesMat = Mat(angles); Mat sortedIndices; - sortIdx(anglesMat, sortedIndices, CV_SORT_EVERY_COLUMN + CV_SORT_DESCENDING); + sortIdx(anglesMat, sortedIndices, SORT_EVERY_COLUMN + SORT_DESCENDING); CV_Assert(sortedIndices.type() == CV_32SC1); CV_Assert(sortedIndices.cols == 1); const int cornersCount = isAsymmetricGrid ? 6 : 4; Mat cornersIndices; - cv::sort(sortedIndices.rowRange(0, cornersCount), cornersIndices, CV_SORT_EVERY_COLUMN + CV_SORT_ASCENDING); + cv::sort(sortedIndices.rowRange(0, cornersCount), cornersIndices, SORT_EVERY_COLUMN + SORT_ASCENDING); corners.clear(); for(int i=0; i (id, Vertex())); } void Graph::addEdge(size_t id1, size_t id2) { - assert( doesVertexExist( id1 ) ); - assert( doesVertexExist( id2 ) ); + CV_Assert( doesVertexExist( id1 ) ); + CV_Assert( doesVertexExist( id2 ) ); vertices[id1].neighbors.insert(id2); vertices[id2].neighbors.insert(id1); @@ -454,8 +454,8 @@ void Graph::addEdge(size_t id1, size_t id2) void Graph::removeEdge(size_t id1, size_t id2) { - assert( doesVertexExist( id1 ) ); - assert( doesVertexExist( id2 ) ); + CV_Assert( doesVertexExist( id1 ) ); + CV_Assert( doesVertexExist( id2 ) ); vertices[id1].neighbors.erase(id2); vertices[id2].neighbors.erase(id1); @@ -463,8 +463,8 @@ void Graph::removeEdge(size_t id1, size_t id2) bool Graph::areVerticesAdjacent(size_t id1, size_t id2) const { - assert( doesVertexExist( id1 ) ); - assert( doesVertexExist( id2 ) ); + CV_Assert( doesVertexExist( id1 ) ); + CV_Assert( doesVertexExist( id2 ) ); Vertices::const_iterator it = vertices.find(id1); return it->second.neighbors.find(id2) != it->second.neighbors.end(); @@ -477,7 +477,7 @@ size_t Graph::getVerticesCount() const size_t Graph::getDegree(size_t id) const { - assert( doesVertexExist(id) ); + CV_Assert( doesVertexExist(id) ); Vertices::const_iterator it = vertices.find(id); return it->second.neighbors.size(); @@ -495,7 +495,7 @@ void Graph::floydWarshall(cv::Mat &distanceMatrix, int infinity) const distanceMatrix.at ((int)it1->first, (int)it1->first) = 0; for (Neighbors::const_iterator it2 = it1->second.neighbors.begin(); it2 != it1->second.neighbors.end(); it2++) { - assert( it1->first != *it2 ); + CV_Assert( it1->first != *it2 ); distanceMatrix.at ((int)it1->first, (int)*it2) = edgeWeight; } } @@ -524,7 +524,7 @@ void Graph::floydWarshall(cv::Mat &distanceMatrix, int infinity) const const Graph::Neighbors& Graph::getNeighbors(size_t id) const { - assert( doesVertexExist(id) ); + CV_Assert( doesVertexExist(id) ); Vertices::const_iterator it = vertices.find(id); return it->second.neighbors; @@ -604,7 +604,7 @@ bool CirclesGridFinder::findHoles() } default: - CV_Error(CV_StsBadArg, "Unkown pattern type"); + CV_Error(Error::StsBadArg, "Unkown pattern type"); } return (isDetectionCorrect()); //CV_Error( 0, "Detection is not correct" ); @@ -813,7 +813,7 @@ void CirclesGridFinder::findMCS(const std::vector &basis, std::vector& centers, const std::vector &keypoints, std::vector &warpedKeypoints) { - assert( !centers.empty() ); + CV_Assert( !centers.empty() ); const float edgeLength = 30; const Point2f offset(150, 150); @@ -832,7 +832,7 @@ Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector srcKeypoints; @@ -912,7 +912,7 @@ void CirclesGridFinder::findCandidateLine(std::vector &line, size_t seed } } - assert( line.size() == seeds.size() ); + CV_Assert( line.size() == seeds.size() ); } void CirclesGridFinder::findCandidateHoles(std::vector &above, std::vector &below, bool addRow, Point2f basisVec, @@ -927,9 +927,9 @@ void CirclesGridFinder::findCandidateHoles(std::vector &above, std::vect size_t lastIdx = addRow ? holes.size() - 1 : holes[0].size() - 1; findCandidateLine(below, lastIdx, addRow, basisVec, belowSeeds); - assert( below.size() == above.size() ); - assert( belowSeeds.size() == aboveSeeds.size() ); - assert( below.size() == belowSeeds.size() ); + CV_Assert( below.size() == above.size() ); + CV_Assert( belowSeeds.size() == aboveSeeds.size() ); + CV_Assert( below.size() == belowSeeds.size() ); } bool CirclesGridFinder::areCentersNew(const std::vector &newCenters, const std::vector > &holes) @@ -1000,10 +1000,10 @@ void CirclesGridFinder::insertWinner(float aboveConfidence, float belowConfidenc float CirclesGridFinder::computeGraphConfidence(const std::vector &basisGraphs, bool addRow, const std::vector &points, const std::vector &seeds) { - assert( points.size() == seeds.size() ); + CV_Assert( points.size() == seeds.size() ); float confidence = 0; const size_t vCount = basisGraphs[0].getVerticesCount(); - assert( basisGraphs[0].getVerticesCount() == basisGraphs[1].getVerticesCount() ); + CV_Assert( basisGraphs[0].getVerticesCount() == basisGraphs[1].getVerticesCount() ); for (size_t i = 0; i < seeds.size(); i++) { @@ -1087,7 +1087,7 @@ void CirclesGridFinder::findBasis(const std::vector &samples, std::vect const int clustersCount = 4; kmeans(Mat(samples).reshape(1, 0), clustersCount, bestLabels, termCriteria, parameters.kmeansAttempts, KMEANS_RANDOM_CENTERS, centers); - assert( centers.type() == CV_32FC1 ); + CV_Assert( centers.type() == CV_32FC1 ); std::vector basisIndices; //TODO: only remove duplicate @@ -1204,7 +1204,7 @@ void CirclesGridFinder::computeRNG(Graph &rng, std::vector &vectors void computePredecessorMatrix(const Mat &dm, int verticesCount, Mat &predecessorMatrix) { - assert( dm.type() == CV_32SC1 ); + CV_Assert( dm.type() == CV_32SC1 ); predecessorMatrix.create(verticesCount, verticesCount, CV_32SC1); predecessorMatrix = -1; for (int i = 0; i < predecessorMatrix.rows; i++) @@ -1253,7 +1253,6 @@ size_t CirclesGridFinder::findLongestPath(std::vector &basisGraphs, Path double maxVal; Point maxLoc; - assert (infinity < 0); minMaxLoc(distanceMatrix, 0, &maxVal, 0, &maxLoc); if (maxVal > longestPaths[0].length) @@ -1594,9 +1593,3 @@ size_t CirclesGridFinder::getFirstCorner(std::vector &largeCornerIndices, return cornerIdx; } - -bool cv::findCirclesGridDefault( InputArray image, Size patternSize, - OutputArray centers, int flags ) -{ - return findCirclesGrid(image, patternSize, centers, flags); -} diff --git a/modules/calib3d/src/compat_ptsetreg.cpp b/modules/calib3d/src/compat_ptsetreg.cpp index dca0d0dab..74c9e0012 100644 --- a/modules/calib3d/src/compat_ptsetreg.cpp +++ b/modules/calib3d/src/compat_ptsetreg.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" /************************************************************************************\ Some backward compatibility stuff, to be moved to legacy or compat module diff --git a/modules/calib3d/src/compat_stereo.cpp b/modules/calib3d/src/compat_stereo.cpp index f1d983424..16eefc684 100644 --- a/modules/calib3d/src/compat_stereo.cpp +++ b/modules/calib3d/src/compat_stereo.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" CvStereoBMState* cvCreateStereoBMState( int /*preset*/, int numberOfDisparities ) { @@ -83,10 +84,6 @@ void cvReleaseStereoBMState( CvStereoBMState** state ) cvFree( state ); } -template<> void cv::Ptr::delete_obj() -{ cvReleaseStereoBMState(&obj); } - - void cvFindStereoCorrespondenceBM( const CvArr* leftarr, const CvArr* rightarr, CvArr* disparr, CvStereoBMState* state ) { diff --git a/modules/calib3d/src/epnp.h b/modules/calib3d/src/epnp.h index 203830a6d..fe0160630 100644 --- a/modules/calib3d/src/epnp.h +++ b/modules/calib3d/src/epnp.h @@ -2,6 +2,7 @@ #define epnp_h #include "precomp.hpp" +#include "opencv2/core/core_c.h" class epnp { public: diff --git a/modules/calib3d/src/five-point.cpp b/modules/calib3d/src/five-point.cpp index 5af82bde7..7eae2ebf8 100644 --- a/modules/calib3d/src/five-point.cpp +++ b/modules/calib3d/src/five-point.cpp @@ -435,7 +435,7 @@ cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, double f threshold /= focal; Mat E; - if( method == CV_RANSAC ) + if( method == RANSAC ) createRANSACPointSetRegistrator(new EMEstimatorCallback, 5, threshold, prob)->run(points1, points2, E, _mask); else createLMeDSPointSetRegistrator(new EMEstimatorCallback, 5, prob)->run(points1, points2, E, _mask); diff --git a/modules/calib3d/src/fundam.cpp b/modules/calib3d/src/fundam.cpp index 0db8fcab9..c58e8220a 100644 --- a/modules/calib3d/src/fundam.cpp +++ b/modules/calib3d/src/fundam.cpp @@ -181,12 +181,12 @@ public: LtL[j][k] += Lx[j]*Lx[k] + Ly[j]*Ly[k]; } completeSymm( _LtL ); - + eigen( _LtL, matW, matV ); _Htemp = _invHnorm*_H0; _H0 = _Htemp*_Hnorm2; _H0.convertTo(_model, _H0.type(), 1./_H0.at(2,2) ); - + return 1; } @@ -292,7 +292,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2, { npoints = p.checkVector(3, -1, false); if( npoints < 0 ) - CV_Error(CV_StsBadArg, "The input arrays should be 2D or 3D point sets"); + CV_Error(Error::StsBadArg, "The input arrays should be 2D or 3D point sets"); if( npoints == 0 ) return Mat(); convertPointsFromHomogeneous(p, p); @@ -317,7 +317,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2, else if( method == LMEDS ) result = createLMeDSPointSetRegistrator(cb, 4, confidence, maxIters)->run(src, dst, H, tempMask); else - CV_Error(CV_StsBadArg, "Unknown estimation method"); + CV_Error(Error::StsBadArg, "Unknown estimation method"); if( result && npoints > 4 ) { @@ -475,7 +475,7 @@ static int run7Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix ) return n; } - + static int run8Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix ) { double a[9*9], w[9], v[9*9]; @@ -585,11 +585,11 @@ static int run8Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix ) gemm( T2, F0, 1., 0, 0., TF, GEMM_1_T ); F0 = Mat(3, 3, CV_64F, fmatrix); gemm( TF, T1, 1., 0, 0., F0, 0 ); - + // make F(3,3) = 1 if( fabs(F0.at(2,2)) > FLT_EPSILON ) F0 *= 1./F0.at(2,2); - + return 1; } @@ -671,7 +671,7 @@ cv::Mat cv::findFundamentalMat( InputArray _points1, InputArray _points2, { npoints = p.checkVector(3, -1, false); if( npoints < 0 ) - CV_Error(CV_StsBadArg, "The input arrays should be 2D or 3D point sets"); + CV_Error(Error::StsBadArg, "The input arrays should be 2D or 3D point sets"); if( npoints == 0 ) return Mat(); convertPointsFromHomogeneous(p, p); @@ -739,7 +739,7 @@ void cv::computeCorrespondEpilines( InputArray _points, int whichImage, { npoints = points.checkVector(3); if( npoints < 0 ) - CV_Error( CV_StsBadArg, "The input should be a 2D or 3D point set"); + CV_Error( Error::StsBadArg, "The input should be a 2D or 3D point set"); Mat temp; convertPointsFromHomogeneous(points, temp); points = temp; @@ -893,7 +893,7 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst ) } } else - CV_Error(CV_StsUnsupportedFormat, ""); + CV_Error(Error::StsUnsupportedFormat, ""); } @@ -974,7 +974,7 @@ void cv::convertPointsToHomogeneous( InputArray _src, OutputArray _dst ) } } else - CV_Error(CV_StsUnsupportedFormat, ""); + CV_Error(Error::StsUnsupportedFormat, ""); } diff --git a/modules/calib3d/src/posit.cpp b/modules/calib3d/src/posit.cpp index c8c1c2c2f..14c33e1e7 100644 --- a/modules/calib3d/src/posit.cpp +++ b/modules/calib3d/src/posit.cpp @@ -39,6 +39,7 @@ // //M*/ #include "precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" /* POSIT structure */ struct CvPOSITObject diff --git a/modules/calib3d/src/ptsetreg.cpp b/modules/calib3d/src/ptsetreg.cpp index 6c5f20f7c..c92d858dc 100644 --- a/modules/calib3d/src/ptsetreg.cpp +++ b/modules/calib3d/src/ptsetreg.cpp @@ -53,7 +53,7 @@ namespace cv int RANSACUpdateNumIters( double p, double ep, int modelPoints, int maxIters ) { if( modelPoints <= 0 ) - CV_Error( CV_StsOutOfRange, "the number of model points should be positive" ); + CV_Error( Error::StsOutOfRange, "the number of model points should be positive" ); p = MAX(p, 0.); p = MIN(p, 1.); diff --git a/modules/calib3d/src/quadsubpix.cpp b/modules/calib3d/src/quadsubpix.cpp index b2a9ab836..2e98a462b 100644 --- a/modules/calib3d/src/quadsubpix.cpp +++ b/modules/calib3d/src/quadsubpix.cpp @@ -108,7 +108,7 @@ static void findCorner(const std::vector& contour, Point2f point, Point min_idx = (int)i; } } - assert(min_idx >= 0); + CV_Assert(min_idx >= 0); // temporary solution, have to make something more precise corner = contour[min_idx]; diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index 5bcffb316..7b5b0d4d6 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -43,6 +43,8 @@ #include "precomp.hpp" #include "epnp.h" #include "p3p.h" +#include "opencv2/calib3d/calib3d_c.h" + #include using namespace cv; @@ -57,7 +59,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints, _tvec.create(3, 1, CV_64F); Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat(); - if (flags == CV_EPNP) + if (flags == EPNP) { cv::Mat undistortedPoints; cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs); @@ -68,7 +70,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints, cv::Rodrigues(R, rvec); return true; } - else if (flags == CV_P3P) + else if (flags == P3P) { CV_Assert( npoints == 4); cv::Mat undistortedPoints; @@ -81,7 +83,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints, cv::Rodrigues(R, rvec); return result; } - else if (flags == CV_ITERATIVE) + else if (flags == ITERATIVE) { CvMat c_objectPoints = opoints, c_imagePoints = ipoints; CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs; @@ -342,7 +344,7 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints, if (localInliers.size() >= (size_t)pnpransac::MIN_POINTS_COUNT) { - if (flags != CV_P3P) + if (flags != P3P) { int i, pointsCount = (int)localInliers.size(); Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2); diff --git a/modules/calib3d/src/stereobm.cpp b/modules/calib3d/src/stereobm.cpp index f073aa966..1fc193a0a 100644 --- a/modules/calib3d/src/stereobm.cpp +++ b/modules/calib3d/src/stereobm.cpp @@ -84,7 +84,7 @@ struct StereoBMParams int disp12MaxDiff; int dispType; }; - + static void prefilterNorm( const Mat& src, Mat& dst, int winsize, int ftzero, uchar* buf ) { @@ -783,46 +783,46 @@ public: { params = StereoBMParams(_numDisparities, _SADWindowSize); } - + void compute( InputArray leftarr, InputArray rightarr, OutputArray disparr ) { Mat left0 = leftarr.getMat(), right0 = rightarr.getMat(); int dtype = disparr.fixedType() ? disparr.type() : params.dispType; if (left0.size() != right0.size()) - CV_Error( CV_StsUnmatchedSizes, "All the images must have the same size" ); + CV_Error( Error::StsUnmatchedSizes, "All the images must have the same size" ); if (left0.type() != CV_8UC1 || right0.type() != CV_8UC1) - CV_Error( CV_StsUnsupportedFormat, "Both input images must have CV_8UC1" ); + CV_Error( Error::StsUnsupportedFormat, "Both input images must have CV_8UC1" ); if (dtype != CV_16SC1 && dtype != CV_32FC1) - CV_Error( CV_StsUnsupportedFormat, "Disparity image must have CV_16SC1 or CV_32FC1 format" ); + CV_Error( Error::StsUnsupportedFormat, "Disparity image must have CV_16SC1 or CV_32FC1 format" ); disparr.create(left0.size(), dtype); Mat disp0 = disparr.getMat(); if( params.preFilterType != PREFILTER_NORMALIZED_RESPONSE && params.preFilterType != PREFILTER_XSOBEL ) - CV_Error( CV_StsOutOfRange, "preFilterType must be = CV_STEREO_BM_NORMALIZED_RESPONSE" ); + CV_Error( Error::StsOutOfRange, "preFilterType must be = CV_STEREO_BM_NORMALIZED_RESPONSE" ); if( params.preFilterSize < 5 || params.preFilterSize > 255 || params.preFilterSize % 2 == 0 ) - CV_Error( CV_StsOutOfRange, "preFilterSize must be odd and be within 5..255" ); + CV_Error( Error::StsOutOfRange, "preFilterSize must be odd and be within 5..255" ); if( params.preFilterCap < 1 || params.preFilterCap > 63 ) - CV_Error( CV_StsOutOfRange, "preFilterCap must be within 1..63" ); + CV_Error( Error::StsOutOfRange, "preFilterCap must be within 1..63" ); if( params.SADWindowSize < 5 || params.SADWindowSize > 255 || params.SADWindowSize % 2 == 0 || params.SADWindowSize >= std::min(left0.cols, left0.rows) ) - CV_Error( CV_StsOutOfRange, "SADWindowSize must be odd, be within 5..255 and be not larger than image width or height" ); + CV_Error( Error::StsOutOfRange, "SADWindowSize must be odd, be within 5..255 and be not larger than image width or height" ); if( params.numDisparities <= 0 || params.numDisparities % 16 != 0 ) - CV_Error( CV_StsOutOfRange, "numDisparities must be positive and divisble by 16" ); + CV_Error( Error::StsOutOfRange, "numDisparities must be positive and divisble by 16" ); if( params.textureThreshold < 0 ) - CV_Error( CV_StsOutOfRange, "texture threshold must be non-negative" ); + CV_Error( Error::StsOutOfRange, "texture threshold must be non-negative" ); if( params.uniquenessRatio < 0 ) - CV_Error( CV_StsOutOfRange, "uniqueness ratio must be non-negative" ); + CV_Error( Error::StsOutOfRange, "uniqueness ratio must be non-negative" ); preFilteredImg0.create( left0.size(), CV_8U ); preFilteredImg1.create( left0.size(), CV_8U ); @@ -887,15 +887,15 @@ public: R2.area() > 0 ? Rect(0, 0, width, height) : validDisparityRect, params.minDisparity, params.numDisparities, params.SADWindowSize); - + parallel_for_(Range(0, nstripes), FindStereoCorrespInvoker(left, right, disp, ¶ms, nstripes, bufSize0, useShorts, validDisparityRect, slidingSumBuf, cost)); - + if( params.speckleRange >= 0 && params.speckleWindowSize > 0 ) filterSpeckles(disp, FILTERED, params.speckleWindowSize, params.speckleRange, slidingSumBuf); - + if (disp0.data != disp.data) disp.convertTo(disp0, disp0.type(), 1./(1 << DISPARITY_SHIFT), 0); } @@ -963,7 +963,7 @@ public: void read(const FileNode& fn) { FileNode n = fn["name"]; - CV_Assert( n.isString() && strcmp(n.node->data.str.ptr, name_) == 0 ); + CV_Assert( n.isString() && String(n) == name_ ); params.minDisparity = (int)fn["minDisparity"]; params.numDisparities = (int)fn["numDisparities"]; params.SADWindowSize = (int)fn["blockSize"]; diff --git a/modules/calib3d/src/stereosgbm.cpp b/modules/calib3d/src/stereosgbm.cpp index 160d92637..508eb59b1 100644 --- a/modules/calib3d/src/stereosgbm.cpp +++ b/modules/calib3d/src/stereosgbm.cpp @@ -919,7 +919,7 @@ public: void read(const FileNode& fn) { FileNode n = fn["name"]; - CV_Assert( n.isString() && strcmp(n.node->data.str.ptr, name_) == 0 ); + CV_Assert( n.isString() && String(n) == name_ ); params.minDisparity = (int)fn["minDisparity"]; params.numDisparities = (int)fn["numDisparities"]; params.SADWindowSize = (int)fn["blockSize"]; diff --git a/modules/calib3d/src/triangulate.cpp b/modules/calib3d/src/triangulate.cpp index 9f52b3716..59c7c0f2b 100644 --- a/modules/calib3d/src/triangulate.cpp +++ b/modules/calib3d/src/triangulate.cpp @@ -40,6 +40,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" // cvCorrectMatches function is Copyright (C) 2009, Jostein Austvik Jacobsen. // cvTriangulatePoints function is derived from icvReconstructPointsFor3View, originally by Valery Mosyagin. diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index e8b557094..fb8238237 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" #include diff --git a/modules/calib3d/test/test_cameracalibration_artificial.cpp b/modules/calib3d/test/test_cameracalibration_artificial.cpp index 811e7002e..1ff13c9e8 100644 --- a/modules/calib3d/test/test_cameracalibration_artificial.cpp +++ b/modules/calib3d/test/test_cameracalibration_artificial.cpp @@ -327,7 +327,7 @@ protected: Mat camMat_est = Mat::eye(3, 3, CV_64F), distCoeffs_est = Mat::zeros(1, 5, CV_64F); vector rvecs_est, tvecs_est; - int flags = /*CV_CALIB_FIX_K3|*/CV_CALIB_FIX_K4|CV_CALIB_FIX_K5|CV_CALIB_FIX_K6; //CALIB_FIX_K3; //CALIB_FIX_ASPECT_RATIO | | CALIB_ZERO_TANGENT_DIST; + int flags = /*CALIB_FIX_K3|*/CALIB_FIX_K4|CALIB_FIX_K5|CALIB_FIX_K6; //CALIB_FIX_K3; //CALIB_FIX_ASPECT_RATIO | | CALIB_ZERO_TANGENT_DIST; TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 100, DBL_EPSILON); double rep_error = calibrateCamera(objectPoints, imagePoints, imgSize, camMat_est, distCoeffs_est, rvecs_est, tvecs_est, flags, criteria); rep_error /= brdsNum * cornersSize.area(); diff --git a/modules/calib3d/test/test_cameracalibration_badarg.cpp b/modules/calib3d/test/test_cameracalibration_badarg.cpp index b805e71a4..91118e1ed 100644 --- a/modules/calib3d/test/test_cameracalibration_badarg.cpp +++ b/modules/calib3d/test/test_cameracalibration_badarg.cpp @@ -41,6 +41,7 @@ #include "test_precomp.hpp" #include "test_chessboardgenerator.hpp" +#include "opencv2/calib3d/calib3d_c.h" #include diff --git a/modules/calib3d/test/test_chessboardgenerator.cpp b/modules/calib3d/test/test_chessboardgenerator.cpp index 7c761fc57..3a5ebbc3a 100644 --- a/modules/calib3d/test/test_chessboardgenerator.cpp +++ b/modules/calib3d/test/test_chessboardgenerator.cpp @@ -161,15 +161,15 @@ Mat cv::ChessBoardGenerator::generateChessBoard(const Mat& bg, const Mat& camMat if (rendererResolutionMultiplier == 1) { result = bg.clone(); - drawContours(result, whole_contour, -1, Scalar::all(255), CV_FILLED, CV_AA); - drawContours(result, squares_black, -1, Scalar::all(0), CV_FILLED, CV_AA); + drawContours(result, whole_contour, -1, Scalar::all(255), FILLED, LINE_AA); + drawContours(result, squares_black, -1, Scalar::all(0), FILLED, LINE_AA); } else { Mat tmp; resize(bg, tmp, bg.size() * rendererResolutionMultiplier); - drawContours(tmp, whole_contour, -1, Scalar::all(255), CV_FILLED, CV_AA); - drawContours(tmp, squares_black, -1, Scalar::all(0), CV_FILLED, CV_AA); + drawContours(tmp, whole_contour, -1, Scalar::all(255), FILLED, LINE_AA); + drawContours(tmp, squares_black, -1, Scalar::all(0), FILLED, LINE_AA); resize(tmp, result, bg.size(), 0, 0, INTER_AREA); } diff --git a/modules/calib3d/test/test_chesscorners.cpp b/modules/calib3d/test/test_chesscorners.cpp index bbc792ea5..f9625d540 100644 --- a/modules/calib3d/test/test_chesscorners.cpp +++ b/modules/calib3d/test/test_chesscorners.cpp @@ -57,14 +57,14 @@ void show_points( const Mat& gray, const Mat& u, const vector& v, Size merge(vector(3, gray), rgb); for(size_t i = 0; i < v.size(); i++ ) - circle( rgb, v[i], 3, CV_RGB(255, 0, 0), CV_FILLED); + circle( rgb, v[i], 3, Scalar(255, 0, 0), FILLED); if( !u.empty() ) { const Point2f* u_data = u.ptr(); size_t count = u.cols * u.rows; for(size_t i = 0; i < count; i++ ) - circle( rgb, u_data[i], 3, CV_RGB(0, 255, 0), CV_FILLED); + circle( rgb, u_data[i], 3, Scalar(0, 255, 0), FILLED); } if (!v.empty()) { @@ -208,7 +208,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename ) } int progress = 0; - int max_idx = board_list.node->data.seq->total/2; + int max_idx = board_list.size()/2; double sum_error = 0.0; int count = 0; @@ -244,7 +244,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename ) switch( pattern ) { case CHESSBOARD: - result = findChessboardCorners(gray, pattern_size, v, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE); + result = findChessboardCorners(gray, pattern_size, v, CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE); break; case CIRCLES_GRID: result = findCirclesGrid(gray, pattern_size, v); @@ -459,7 +459,7 @@ bool CV_ChessboardDetectorTest::checkByGenerator() vector& cnt = cnts[0]; cnt.push_back(cg[ 0]); cnt.push_back(cg[0+2]); cnt.push_back(cg[7+0]); cnt.push_back(cg[7+2]); - cv::drawContours(cb, cnts, -1, Scalar::all(128), CV_FILLED); + cv::drawContours(cb, cnts, -1, Scalar::all(128), FILLED); found = findChessboardCorners(cb, cbg.cornersSize(), corners_found); if (found) diff --git a/modules/calib3d/test/test_chesscorners_badarg.cpp b/modules/calib3d/test/test_chesscorners_badarg.cpp index d7c4c4f4c..318912eeb 100644 --- a/modules/calib3d/test/test_chesscorners_badarg.cpp +++ b/modules/calib3d/test/test_chesscorners_badarg.cpp @@ -41,6 +41,7 @@ #include "test_precomp.hpp" #include "test_chessboardgenerator.hpp" +#include "opencv2/calib3d/calib3d_c.h" #include diff --git a/modules/calib3d/test/test_chesscorners_timing.cpp b/modules/calib3d/test/test_chesscorners_timing.cpp index 7dffd597e..47653f88d 100644 --- a/modules/calib3d/test/test_chesscorners_timing.cpp +++ b/modules/calib3d/test/test_chesscorners_timing.cpp @@ -41,6 +41,7 @@ #include "test_precomp.hpp" #include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/calib3d/calib3d_c.h" class CV_ChessboardDetectorTimingTest : public cvtest::BaseTest { diff --git a/modules/calib3d/test/test_fundam.cpp b/modules/calib3d/test/test_fundam.cpp index 67a8a98d5..7e6f9a8e7 100644 --- a/modules/calib3d/test/test_fundam.cpp +++ b/modules/calib3d/test/test_fundam.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" using namespace cv; using namespace std; diff --git a/modules/calib3d/test/test_homography.cpp b/modules/calib3d/test/test_homography.cpp index f68af1d7c..5bb50bb26 100644 --- a/modules/calib3d/test/test_homography.cpp +++ b/modules/calib3d/test/test_homography.cpp @@ -65,7 +65,7 @@ #define METHODS_COUNT 3 int NORM_TYPE[COUNT_NORM_TYPES] = {cv::NORM_L1, cv::NORM_L2, cv::NORM_INF}; -int METHOD[METHODS_COUNT] = {0, CV_RANSAC, CV_LMEDS}; +int METHOD[METHODS_COUNT] = {0, cv::RANSAC, cv::LMEDS}; using namespace cv; using namespace std; @@ -309,7 +309,7 @@ void CV_HomographyTest::run(int) switch (method) { case 0: - case CV_LMEDS: + case LMEDS: { Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, method), cv::findHomography(src_mat_2f, dst_vec, method), @@ -339,14 +339,14 @@ void CV_HomographyTest::run(int) continue; } - case CV_RANSAC: + case RANSAC: { cv::Mat mask [4]; double diff; - Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, CV_RANSAC, reproj_threshold, mask[0]), - cv::findHomography(src_mat_2f, dst_vec, CV_RANSAC, reproj_threshold, mask[1]), - cv::findHomography(src_vec, dst_mat_2f, CV_RANSAC, reproj_threshold, mask[2]), - cv::findHomography(src_vec, dst_vec, CV_RANSAC, reproj_threshold, mask[3]) }; + Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, RANSAC, reproj_threshold, mask[0]), + cv::findHomography(src_mat_2f, dst_vec, RANSAC, reproj_threshold, mask[1]), + cv::findHomography(src_vec, dst_mat_2f, RANSAC, reproj_threshold, mask[2]), + cv::findHomography(src_vec, dst_vec, RANSAC, reproj_threshold, mask[3]) }; for (int j = 0; j < 4; ++j) { @@ -411,7 +411,7 @@ void CV_HomographyTest::run(int) switch (method) { case 0: - case CV_LMEDS: + case LMEDS: { Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f), cv::findHomography(src_mat_2f, dst_vec), @@ -466,14 +466,14 @@ void CV_HomographyTest::run(int) continue; } - case CV_RANSAC: + case RANSAC: { cv::Mat mask_res [4]; - Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, CV_RANSAC, reproj_threshold, mask_res[0]), - cv::findHomography(src_mat_2f, dst_vec, CV_RANSAC, reproj_threshold, mask_res[1]), - cv::findHomography(src_vec, dst_mat_2f, CV_RANSAC, reproj_threshold, mask_res[2]), - cv::findHomography(src_vec, dst_vec, CV_RANSAC, reproj_threshold, mask_res[3]) }; + Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f, RANSAC, reproj_threshold, mask_res[0]), + cv::findHomography(src_mat_2f, dst_vec, RANSAC, reproj_threshold, mask_res[1]), + cv::findHomography(src_vec, dst_mat_2f, RANSAC, reproj_threshold, mask_res[2]), + cv::findHomography(src_vec, dst_vec, RANSAC, reproj_threshold, mask_res[3]) }; for (int j = 0; j < 4; ++j) { diff --git a/modules/calib3d/test/test_posit.cpp b/modules/calib3d/test/test_posit.cpp index 186c4f2d4..8a77d19ad 100644 --- a/modules/calib3d/test/test_posit.cpp +++ b/modules/calib3d/test/test_posit.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" using namespace cv; using namespace std; diff --git a/modules/calib3d/test/test_reproject_image_to_3d.cpp b/modules/calib3d/test/test_reproject_image_to_3d.cpp index a93804f74..3b44566ab 100644 --- a/modules/calib3d/test/test_reproject_image_to_3d.cpp +++ b/modules/calib3d/test/test_reproject_image_to_3d.cpp @@ -41,6 +41,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" #include #include diff --git a/modules/calib3d/test/test_solvepnp_ransac.cpp b/modules/calib3d/test/test_solvepnp_ransac.cpp index 7e9336967..c0aff188d 100644 --- a/modules/calib3d/test/test_solvepnp_ransac.cpp +++ b/modules/calib3d/test/test_solvepnp_ransac.cpp @@ -54,9 +54,9 @@ class CV_solvePnPRansac_Test : public cvtest::BaseTest public: CV_solvePnPRansac_Test() { - eps[CV_ITERATIVE] = 1.0e-2; - eps[CV_EPNP] = 1.0e-2; - eps[CV_P3P] = 1.0e-2; + eps[ITERATIVE] = 1.0e-2; + eps[EPNP] = 1.0e-2; + eps[P3P] = 1.0e-2; totalTestsCount = 10; } ~CV_solvePnPRansac_Test() {} @@ -193,9 +193,9 @@ class CV_solvePnP_Test : public CV_solvePnPRansac_Test public: CV_solvePnP_Test() { - eps[CV_ITERATIVE] = 1.0e-6; - eps[CV_EPNP] = 1.0e-6; - eps[CV_P3P] = 1.0e-4; + eps[ITERATIVE] = 1.0e-6; + eps[EPNP] = 1.0e-6; + eps[P3P] = 1.0e-4; totalTestsCount = 1000; } diff --git a/modules/calib3d/test/test_stereomatching.cpp b/modules/calib3d/test/test_stereomatching.cpp index 4e58fcadf..8e1120e47 100644 --- a/modules/calib3d/test/test_stereomatching.cpp +++ b/modules/calib3d/test/test_stereomatching.cpp @@ -75,7 +75,7 @@ void computeTextureBasedMasks( const Mat& _img, Mat* texturelessMask, Mat* textu if( !texturelessMask && !texturedMask ) return; if( _img.empty() ) - CV_Error( CV_StsBadArg, "img is empty" ); + CV_Error( Error::StsBadArg, "img is empty" ); Mat img = _img; if( _img.channels() > 1) @@ -95,21 +95,21 @@ void computeTextureBasedMasks( const Mat& _img, Mat* texturelessMask, Mat* textu void checkTypeAndSizeOfDisp( const Mat& dispMap, const Size* sz ) { if( dispMap.empty() ) - CV_Error( CV_StsBadArg, "dispMap is empty" ); + CV_Error( Error::StsBadArg, "dispMap is empty" ); if( dispMap.type() != CV_32FC1 ) - CV_Error( CV_StsBadArg, "dispMap must have CV_32FC1 type" ); + CV_Error( Error::StsBadArg, "dispMap must have CV_32FC1 type" ); if( sz && (dispMap.rows != sz->height || dispMap.cols != sz->width) ) - CV_Error( CV_StsBadArg, "dispMap has incorrect size" ); + CV_Error( Error::StsBadArg, "dispMap has incorrect size" ); } void checkTypeAndSizeOfMask( const Mat& mask, Size sz ) { if( mask.empty() ) - CV_Error( CV_StsBadArg, "mask is empty" ); + CV_Error( Error::StsBadArg, "mask is empty" ); if( mask.type() != CV_8UC1 ) - CV_Error( CV_StsBadArg, "mask must have CV_8UC1 type" ); + CV_Error( Error::StsBadArg, "mask must have CV_8UC1 type" ); if( mask.rows != sz.height || mask.cols != sz.width ) - CV_Error( CV_StsBadArg, "mask has incorrect size" ); + CV_Error( Error::StsBadArg, "mask has incorrect size" ); } void checkDispMapsAndUnknDispMasks( const Mat& leftDispMap, const Mat& rightDispMap, @@ -143,7 +143,7 @@ void checkDispMapsAndUnknDispMasks( const Mat& leftDispMap, const Mat& rightDisp minMaxLoc( rightDispMap, &rightMinVal, 0, 0, 0, ~rightUnknDispMask ); } if( leftMinVal < 0 || rightMinVal < 0) - CV_Error( CV_StsBadArg, "known disparity values must be positive" ); + CV_Error( Error::StsBadArg, "known disparity values must be positive" ); } /* @@ -163,7 +163,7 @@ void computeOcclusionBasedMasks( const Mat& leftDisp, const Mat& _rightDisp, if( _rightDisp.empty() ) { if( !rightUnknDispMask.empty() ) - CV_Error( CV_StsBadArg, "rightUnknDispMask must be empty if _rightDisp is empty" ); + CV_Error( Error::StsBadArg, "rightUnknDispMask must be empty if _rightDisp is empty" ); rightDisp.create(leftDisp.size(), CV_32FC1); rightDisp.setTo(Scalar::all(0) ); for( int leftY = 0; leftY < leftDisp.rows; leftY++ ) @@ -230,9 +230,9 @@ void computeDepthDiscontMask( const Mat& disp, Mat& depthDiscontMask, const Mat& float dispGap = EVAL_DISP_GAP, int discontWidth = EVAL_DISCONT_WIDTH ) { if( disp.empty() ) - CV_Error( CV_StsBadArg, "disp is empty" ); + CV_Error( Error::StsBadArg, "disp is empty" ); if( disp.type() != CV_32FC1 ) - CV_Error( CV_StsBadArg, "disp must have CV_32FC1 type" ); + CV_Error( Error::StsBadArg, "disp must have CV_32FC1 type" ); if( !unknDispMask.empty() ) checkTypeAndSizeOfMask( unknDispMask, disp.size() ); @@ -571,9 +571,9 @@ int CV_StereoMatchingTest::processStereoMatchingResults( FileStorage& fs, int ca if( isWrite ) { fs << caseNames[caseIdx] << "{"; - cvWriteComment( fs.fs, RMS_STR.c_str(), 0 ); + //cvWriteComment( fs.fs, RMS_STR.c_str(), 0 ); writeErrors( RMS_STR, rmss, &fs ); - cvWriteComment( fs.fs, BAD_PXLS_FRACTION_STR.c_str(), 0 ); + //cvWriteComment( fs.fs, BAD_PXLS_FRACTION_STR.c_str(), 0 ); writeErrors( BAD_PXLS_FRACTION_STR, badPxlsFractions, &fs ); fs << "}"; // datasetName } diff --git a/modules/contrib/src/ba.cpp b/modules/contrib/src/ba.cpp index fb361d49c..8e4faf221 100644 --- a/modules/contrib/src/ba.cpp +++ b/modules/contrib/src/ba.cpp @@ -41,6 +41,7 @@ #include "precomp.hpp" #include "opencv2/calib3d.hpp" +#include "opencv2/calib3d/calib3d_c.h" #include using namespace cv; diff --git a/modules/contrib/src/featuretracker.cpp b/modules/contrib/src/featuretracker.cpp index e94450db6..4350aec46 100644 --- a/modules/contrib/src/featuretracker.cpp +++ b/modules/contrib/src/featuretracker.cpp @@ -131,7 +131,7 @@ Rect CvFeatureTracker::updateTrackingWindowWithSIFT(Mat image) curr_keys.push_back(curr_keypoints[matches[i].trainIdx].pt); } - Mat T = findHomography(prev_keys, curr_keys, CV_LMEDS); + Mat T = findHomography(prev_keys, curr_keys, LMEDS); prev_trackwindow.x += cvRound(T.at (0, 2)); prev_trackwindow.y += cvRound(T.at (1, 2)); diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index 5997668fe..301b216d9 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -43,10 +43,8 @@ #ifndef __OPENCV_FEATURES_2D_HPP__ #define __OPENCV_FEATURES_2D_HPP__ -#ifdef __cplusplus #include "opencv2/core.hpp" #include "opencv2/flann/miniflann.hpp" -#include namespace cv { @@ -1521,8 +1519,4 @@ protected: } /* namespace cv */ -#endif /* __cplusplus */ - #endif - -/* End of file. */ diff --git a/modules/imgproc/src/gcgraph.hpp b/modules/imgproc/src/gcgraph.hpp index 59c9744e7..f93bd19a2 100644 --- a/modules/imgproc/src/gcgraph.hpp +++ b/modules/imgproc/src/gcgraph.hpp @@ -241,7 +241,7 @@ TWeight GCGraph::maxFlow() // find the minimum edge weight along the path minWeight = edgePtr[e0].weight; - assert( minWeight > 0 ); + CV_Assert( minWeight > 0 ); // k = 1: source tree, k = 0: destination tree for( int k = 1; k >= 0; k-- ) { @@ -251,11 +251,11 @@ TWeight GCGraph::maxFlow() break; weight = edgePtr[ei^k].weight; minWeight = MIN(minWeight, weight); - assert( minWeight > 0 ); + CV_Assert( minWeight > 0 ); } weight = fabs(v->weight); minWeight = MIN(minWeight, weight); - assert( minWeight > 0 ); + CV_Assert( minWeight > 0 ); } // modify weights of the edges along the path and collect orphans diff --git a/modules/java/android_test/src/org/opencv/test/calib3d/Calib3dTest.java b/modules/java/android_test/src/org/opencv/test/calib3d/Calib3dTest.java index 8bcaf58a0..e6520a43d 100644 --- a/modules/java/android_test/src/org/opencv/test/calib3d/Calib3dTest.java +++ b/modules/java/android_test/src/org/opencv/test/calib3d/Calib3dTest.java @@ -188,13 +188,13 @@ public class Calib3dTest extends OpenCVTestCase { assertTrue(!corners.empty()); } - public void testFindCirclesGridDefaultMatSizeMat() { + public void testFindCirclesGridMatSizeMat() { int size = 300; Mat img = new Mat(size, size, CvType.CV_8U); img.setTo(new Scalar(255)); Mat centers = new Mat(); - assertFalse(Calib3d.findCirclesGridDefault(img, new Size(5, 5), centers)); + assertFalse(Calib3d.findCirclesGrid(img, new Size(5, 5), centers)); for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) { @@ -202,20 +202,20 @@ public class Calib3dTest extends OpenCVTestCase { Core.circle(img, pt, 10, new Scalar(0), -1); } - assertTrue(Calib3d.findCirclesGridDefault(img, new Size(5, 5), centers)); + assertTrue(Calib3d.findCirclesGrid(img, new Size(5, 5), centers)); assertEquals(25, centers.rows()); assertEquals(1, centers.cols()); assertEquals(CvType.CV_32FC2, centers.type()); } - public void testFindCirclesGridDefaultMatSizeMatInt() { + public void testFindCirclesGridMatSizeMatInt() { int size = 300; Mat img = new Mat(size, size, CvType.CV_8U); img.setTo(new Scalar(255)); Mat centers = new Mat(); - assertFalse(Calib3d.findCirclesGridDefault(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING + assertFalse(Calib3d.findCirclesGrid(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING | Calib3d.CALIB_CB_ASYMMETRIC_GRID)); int step = size * 2 / 15; @@ -227,7 +227,7 @@ public class Calib3dTest extends OpenCVTestCase { Core.circle(img, pt, 10, new Scalar(0), -1); } - assertTrue(Calib3d.findCirclesGridDefault(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING + assertTrue(Calib3d.findCirclesGrid(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING | Calib3d.CALIB_CB_ASYMMETRIC_GRID)); assertEquals(15, centers.rows()); diff --git a/modules/legacy/include/opencv2/legacy.hpp b/modules/legacy/include/opencv2/legacy.hpp index 29714f25e..ed0ac9cc3 100644 --- a/modules/legacy/include/opencv2/legacy.hpp +++ b/modules/legacy/include/opencv2/legacy.hpp @@ -43,11 +43,11 @@ #define __OPENCV_LEGACY_HPP__ #include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/features2d.hpp" -#include "opencv2/calib3d.hpp" +#include "opencv2/calib3d/calib3d_c.h" #include "opencv2/ml.hpp" #ifdef __cplusplus +#include "opencv2/features2d.hpp" extern "C" { #endif diff --git a/modules/legacy/src/3dtracker.cpp b/modules/legacy/src/3dtracker.cpp index ae3742b47..a55a9f851 100644 --- a/modules/legacy/src/3dtracker.cpp +++ b/modules/legacy/src/3dtracker.cpp @@ -40,6 +40,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" #include #include diff --git a/modules/legacy/src/compat.cpp b/modules/legacy/src/compat.cpp index 5e7a0d6c6..52e05b99f 100644 --- a/modules/legacy/src/compat.cpp +++ b/modules/legacy/src/compat.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" CvMat cvMatArray( int rows, int cols, int type, int count, void* data) diff --git a/modules/legacy/src/planardetect.cpp b/modules/legacy/src/planardetect.cpp index a9e3190cb..2bffea0ed 100644 --- a/modules/legacy/src/planardetect.cpp +++ b/modules/legacy/src/planardetect.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/calib3d.hpp" #include namespace cv diff --git a/modules/legacy/src/trifocal.cpp b/modules/legacy/src/trifocal.cpp index a8ad68628..c8e7b0896 100644 --- a/modules/legacy/src/trifocal.cpp +++ b/modules/legacy/src/trifocal.cpp @@ -40,6 +40,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" //#include "cvtypes.h" #include diff --git a/modules/nonfree/test/test_features2d.cpp b/modules/nonfree/test/test_features2d.cpp index 5de09f2a0..09997abe5 100644 --- a/modules/nonfree/test/test_features2d.cpp +++ b/modules/nonfree/test/test_features2d.cpp @@ -275,12 +275,16 @@ static Mat readMatFromBin( const string& filename ) size_t elements_read4 = fread( (void*)&dataSize, sizeof(int), 1, f ); CV_Assert(elements_read1 == 1 && elements_read2 == 1 && elements_read3 == 1 && elements_read4 == 1); - uchar* data = (uchar*)cvAlloc(dataSize); - size_t elements_read = fread( (void*)data, 1, dataSize, f ); + size_t step = dataSize / rows / CV_ELEM_SIZE(type); + CV_Assert(step >= (size_t)cols); + + Mat m = Mat( rows, step, type).colRange(0, cols); + + size_t elements_read = fread( m.ptr(), 1, dataSize, f ); CV_Assert(elements_read == (size_t)(dataSize)); fclose(f); - return Mat( rows, cols, type, data ); + return m; } return Mat(); } @@ -402,7 +406,7 @@ protected: double t = (double)getTickCount(); dextractor->compute( img, keypoints, calcDescriptors ); t = getTickCount() - t; - ts->printf(cvtest::TS::LOG, "\nAverage time of computing one descriptor = %g ms.\n", t/((double)cvGetTickFrequency()*1000.)/calcDescriptors.rows ); + ts->printf(cvtest::TS::LOG, "\nAverage time of computing one descriptor = %g ms.\n", t/((double)getTickFrequency()*1000.)/calcDescriptors.rows ); if( calcDescriptors.rows != (int)keypoints.size() ) { diff --git a/modules/ocl/test/test_hough.cpp b/modules/ocl/test/test_hough.cpp index 3a5cec5f9..365e0dadb 100644 --- a/modules/ocl/test/test_hough.cpp +++ b/modules/ocl/test/test_hough.cpp @@ -80,7 +80,7 @@ TEST_P(HoughCircles, Accuracy) cv::ocl::oclMat d_src(src); cv::ocl::oclMat d_circles; - cv::ocl::HoughCircles(d_src, d_circles, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius); + cv::ocl::HoughCircles(d_src, d_circles, cv::HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius); ASSERT_TRUE(d_circles.rows > 0); cv::Mat circles; diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp index c5f79f1a4..144e9e32d 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers_inl.hpp @@ -45,6 +45,7 @@ #include "opencv2/core.hpp" #include "warpers.hpp" // Make your IDE see declarations +#include namespace cv { namespace detail { diff --git a/modules/stitching/src/blenders.cpp b/modules/stitching/src/blenders.cpp index a91e39b48..0a534643e 100644 --- a/modules/stitching/src/blenders.cpp +++ b/modules/stitching/src/blenders.cpp @@ -55,7 +55,7 @@ Ptr Blender::createDefault(int type, bool try_gpu) return new FeatherBlender(); if (type == MULTI_BAND) return new MultiBandBlender(try_gpu); - CV_Error(CV_StsBadArg, "unsupported blending method"); + CV_Error(Error::StsBadArg, "unsupported blending method"); return NULL; } diff --git a/modules/stitching/src/exposure_compensate.cpp b/modules/stitching/src/exposure_compensate.cpp index d2479b710..0a22daeb7 100644 --- a/modules/stitching/src/exposure_compensate.cpp +++ b/modules/stitching/src/exposure_compensate.cpp @@ -53,7 +53,7 @@ Ptr ExposureCompensator::createDefault(int type) return new GainCompensator(); if (type == GAIN_BLOCKS) return new BlocksGainCompensator(); - CV_Error(CV_StsBadArg, "unsupported exposure compensation method"); + CV_Error(Error::StsBadArg, "unsupported exposure compensation method"); return NULL; } diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index 65f2a0030..3a48711a8 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -322,7 +322,7 @@ SurfFeaturesFinder::SurfFeaturesFinder(double hess_thresh, int num_octaves, int { surf = Algorithm::create("Feature2D.SURF"); if( surf.empty() ) - CV_Error( CV_StsNotImplemented, "OpenCV was built without SURF support" ); + CV_Error( Error::StsNotImplemented, "OpenCV was built without SURF support" ); surf->set("hessianThreshold", hess_thresh); surf->set("nOctaves", num_octaves); surf->set("nOctaveLayers", num_layers); @@ -333,7 +333,7 @@ SurfFeaturesFinder::SurfFeaturesFinder(double hess_thresh, int num_octaves, int extractor_ = Algorithm::create("Feature2D.SURF"); if( detector_.empty() || extractor_.empty() ) - CV_Error( CV_StsNotImplemented, "OpenCV was built without SURF support" ); + CV_Error( Error::StsNotImplemented, "OpenCV was built without SURF support" ); detector_->set("hessianThreshold", hess_thresh); detector_->set("nOctaves", num_octaves); @@ -388,7 +388,7 @@ void OrbFeaturesFinder::find(const Mat &image, ImageFeatures &features) } else if (image.type() == CV_8UC1) { gray_image=image; } else { - CV_Error(CV_StsUnsupportedFormat, ""); + CV_Error(Error::StsUnsupportedFormat, ""); } if (grid_size.area() == 1) @@ -579,7 +579,7 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea } // Find pair-wise motion - matches_info.H = findHomography(src_points, dst_points, matches_info.inliers_mask, CV_RANSAC); + matches_info.H = findHomography(src_points, dst_points, matches_info.inliers_mask, RANSAC); if (matches_info.H.empty() || std::abs(determinant(matches_info.H)) < std::numeric_limits::epsilon()) return; @@ -626,7 +626,7 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea } // Rerun motion estimation on inliers only - matches_info.H = findHomography(src_points, dst_points, CV_RANSAC); + matches_info.H = findHomography(src_points, dst_points, RANSAC); } void BestOf2NearestMatcher::collectGarbage() diff --git a/modules/stitching/src/motion_estimators.cpp b/modules/stitching/src/motion_estimators.cpp index 43e539573..d7b64e108 100644 --- a/modules/stitching/src/motion_estimators.cpp +++ b/modules/stitching/src/motion_estimators.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/calib3d/calib3d_c.h" using namespace cv; using namespace cv::detail; diff --git a/modules/stitching/src/seam_finders.cpp b/modules/stitching/src/seam_finders.cpp index 3ecef1c78..b3bebb27a 100644 --- a/modules/stitching/src/seam_finders.cpp +++ b/modules/stitching/src/seam_finders.cpp @@ -716,7 +716,7 @@ void DpSeamFinder::computeCosts( else if (image1.type() == CV_8UC4 && image2.type() == CV_8UC4) diff = diffL2Square4; else - CV_Error(CV_StsBadArg, "both images must have CV_32FC3(4) or CV_8UC3(4) type"); + CV_Error(Error::StsBadArg, "both images must have CV_32FC3(4) or CV_8UC3(4) type"); int l = comp+1; Rect roi(tls_[comp], brs_[comp]); @@ -1279,7 +1279,7 @@ void GraphCutSeamFinder::Impl::findInPair(size_t first, size_t second, Rect roi) submask1, submask2, graph); break; default: - CV_Error(CV_StsBadArg, "unsupported pixel similarity measure"); + CV_Error(Error::StsBadArg, "unsupported pixel similarity measure"); } graph.maxFlow(); @@ -1420,7 +1420,7 @@ void GraphCutSeamFinderGpu::findInPair(size_t first, size_t second, Rect roi) submask1, submask2, terminals, leftT, rightT, top, bottom); break; default: - CV_Error(CV_StsBadArg, "unsupported pixel similarity measure"); + CV_Error(Error::StsBadArg, "unsupported pixel similarity measure"); } gpu::GpuMat terminals_d(terminals); diff --git a/modules/videostab/src/global_motion.cpp b/modules/videostab/src/global_motion.cpp index fcaf9932e..fd56e2b15 100644 --- a/modules/videostab/src/global_motion.cpp +++ b/modules/videostab/src/global_motion.cpp @@ -471,7 +471,7 @@ Mat MotionEstimatorRansacL2::estimate(InputArray points0, InputArray points1, bo else { std::vector mask; - M = findHomography(points0, points1, mask, CV_LMEDS); + M = findHomography(points0, points1, mask, LMEDS); for (int i = 0; i < npoints; ++i) if (mask[i]) ninliers++; } @@ -504,7 +504,7 @@ Mat MotionEstimatorL1::estimate(InputArray points0, InputArray points1, bool *ok #ifndef HAVE_CLP - CV_Error(CV_StsError, "The library is built without Clp support"); + CV_Error(Error::StsError, "The library is built without Clp support"); if (ok) *ok = false; return Mat::eye(3, 3, CV_32F); diff --git a/modules/videostab/src/inpainting.cpp b/modules/videostab/src/inpainting.cpp index 09ae1423c..ada8792f1 100644 --- a/modules/videostab/src/inpainting.cpp +++ b/modules/videostab/src/inpainting.cpp @@ -326,7 +326,7 @@ MotionInpainter::MotionInpainter() #ifdef HAVE_OPENCV_GPU setOptFlowEstimator(new DensePyrLkOptFlowEstimatorGpu()); #else - CV_Error(CV_StsNotImplemented, "Current implementation of MotionInpainter requires GPU"); + CV_Error(Error::StsNotImplemented, "Current implementation of MotionInpainter requires GPU"); #endif setFlowErrorThreshold(1e-4f); setDistThreshold(5.f); diff --git a/modules/videostab/src/motion_stabilizing.cpp b/modules/videostab/src/motion_stabilizing.cpp index 6e9ef7ea3..c1f3442e7 100644 --- a/modules/videostab/src/motion_stabilizing.cpp +++ b/modules/videostab/src/motion_stabilizing.cpp @@ -134,7 +134,7 @@ LpMotionStabilizer::LpMotionStabilizer(MotionModel model) void LpMotionStabilizer::stabilize(int, const std::vector&, std::pair, Mat*) { - CV_Error(CV_StsError, "The library is built without Clp support"); + CV_Error(Error::StsError, "The library is built without Clp support"); } #else diff --git a/samples/cpp/3calibration.cpp b/samples/cpp/3calibration.cpp index 24e9e2686..a6ee45d85 100644 --- a/samples/cpp/3calibration.cpp +++ b/samples/cpp/3calibration.cpp @@ -81,14 +81,14 @@ static bool run3Calibration( vector > imagePoints1, objpt.resize(imgpt.size(),objpt[0]); Mat cameraMatrix = Mat::eye(3, 3, CV_64F); - if( flags & CV_CALIB_FIX_ASPECT_RATIO ) + if( flags & CALIB_FIX_ASPECT_RATIO ) cameraMatrix.at(0,0) = aspectRatio; Mat distCoeffs = Mat::zeros(5, 1, CV_64F); double err = calibrateCamera(objpt, imgpt, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs, - flags|CV_CALIB_FIX_K3/*|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5|CV_CALIB_FIX_K6*/); + flags|CALIB_FIX_K3/*|CALIB_FIX_K4|CALIB_FIX_K5|CALIB_FIX_K6*/); bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs); if(!ok) { @@ -138,7 +138,7 @@ static bool run3Calibration( vector > imagePoints1, cameraMatrix, distCoeffs, imageSize, R, T, E, F, TermCriteria(TermCriteria::COUNT, 30, 0), - CV_CALIB_FIX_INTRINSIC); + CALIB_FIX_INTRINSIC); printf("Pair (1,%d) calibration reprojection error = %g\n", c, sqrt(err/(N*2))); if( c == 2 ) { @@ -212,15 +212,15 @@ int main( int argc, char** argv ) { if( sscanf( argv[++i], "%f", &aspectRatio ) != 1 || aspectRatio <= 0 ) return printf("Invalid aspect ratio\n" ), -1; - flags |= CV_CALIB_FIX_ASPECT_RATIO; + flags |= CALIB_FIX_ASPECT_RATIO; } else if( strcmp( s, "-zt" ) == 0 ) { - flags |= CV_CALIB_ZERO_TANGENT_DIST; + flags |= CALIB_ZERO_TANGENT_DIST; } else if( strcmp( s, "-p" ) == 0 ) { - flags |= CV_CALIB_FIX_PRINCIPAL_POINT; + flags |= CALIB_FIX_PRINCIPAL_POINT; } else if( strcmp( s, "-o" ) == 0 ) { @@ -272,7 +272,7 @@ int main( int argc, char** argv ) vector ptvec; imageSize = view.size(); cvtColor(view, viewGray, COLOR_BGR2GRAY); - bool found = findChessboardCorners( view, boardSize, ptvec, CV_CALIB_CB_ADAPTIVE_THRESH ); + bool found = findChessboardCorners( view, boardSize, ptvec, CALIB_CB_ADAPTIVE_THRESH ); drawChessboardCorners( view, boardSize, Mat(ptvec), found ); if( found ) @@ -291,13 +291,13 @@ int main( int argc, char** argv ) printf("Running calibration ...\n"); run3Calibration(imgpt[0], imgpt[1], imgpt[2], imageSize, - boardSize, squareSize, aspectRatio, flags|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5, + boardSize, squareSize, aspectRatio, flags|CALIB_FIX_K4|CALIB_FIX_K5, cameraMatrix[0], distCoeffs[0], cameraMatrix[1], distCoeffs[1], cameraMatrix[2], distCoeffs[2], R12, T12, R13, T13); - fs.open(outputFilename, CV_STORAGE_WRITE); + fs.open(outputFilename, FileStorage::WRITE); fs << "cameraMatrix1" << cameraMatrix[0]; fs << "cameraMatrix2" << cameraMatrix[1]; @@ -323,7 +323,7 @@ int main( int argc, char** argv ) imgpt[0], imgpt[2], imageSize, R12, T12, R13, T13, R[0], R[1], R[2], P[0], P[1], P[2], Q, -1., - imageSize, 0, 0, CV_CALIB_ZERO_DISPARITY); + imageSize, 0, 0, CALIB_ZERO_DISPARITY); Mat map1[3], map2[3]; fs << "R1" << R[0]; diff --git a/samples/cpp/build3dmodel.cpp b/samples/cpp/build3dmodel.cpp index 7150064a4..5c4d79b49 100644 --- a/samples/cpp/build3dmodel.cpp +++ b/samples/cpp/build3dmodel.cpp @@ -360,7 +360,7 @@ static void triangulatePoint_test(void) pts[0] = imgpt1[i]; pts[1] = imgpt2[i]; objptt[i] = triangulatePoint(pts, Rv, tv, cameraMatrix); } - double err = norm(Mat(objpt), Mat(objptt), CV_C); + double err = norm(Mat(objpt), Mat(objptt), NORM_INF); CV_Assert(err < 1e-1); } @@ -694,7 +694,7 @@ static void build3dmodel( const Ptr& detector, projectPoints(Mat(model.points), Rs[i], ts[i], cameraMatrix, Mat(), imagePoints); for( int k = 0; k < (int)imagePoints.size(); k++ ) - circle(img, imagePoints[k], 2, Scalar(0,255,0), -1, CV_AA, 0); + circle(img, imagePoints[k], 2, Scalar(0,255,0), -1, LINE_AA, 0); imshow("Test", img); int c = waitKey(); diff --git a/samples/cpp/calibration.cpp b/samples/cpp/calibration.cpp index 8cb982912..bb7c396b4 100644 --- a/samples/cpp/calibration.cpp +++ b/samples/cpp/calibration.cpp @@ -96,7 +96,7 @@ static double computeReprojectionErrors( { projectPoints(Mat(objectPoints[i]), rvecs[i], tvecs[i], cameraMatrix, distCoeffs, imagePoints2); - err = norm(Mat(imagePoints[i]), Mat(imagePoints2), CV_L2); + err = norm(Mat(imagePoints[i]), Mat(imagePoints2), NORM_L2); int n = (int)objectPoints[i].size(); perViewErrors[i] = (float)std::sqrt(err*err/n); totalErr += err*err; @@ -128,7 +128,7 @@ static void calcChessboardCorners(Size boardSize, float squareSize, vector > imagePoints, double& totalAvgErr) { cameraMatrix = Mat::eye(3, 3, CV_64F); - if( flags & CV_CALIB_FIX_ASPECT_RATIO ) + if( flags & CALIB_FIX_ASPECT_RATIO ) cameraMatrix.at(0,0) = aspectRatio; distCoeffs = Mat::zeros(8, 1, CV_64F); @@ -152,8 +152,8 @@ static bool runCalibration( vector > imagePoints, objectPoints.resize(imagePoints.size(),objectPoints[0]); double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, - distCoeffs, rvecs, tvecs, flags|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5); - ///*|CV_CALIB_FIX_K3*/|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5); + distCoeffs, rvecs, tvecs, flags|CALIB_FIX_K4|CALIB_FIX_K5); + ///*|CALIB_FIX_K3*/|CALIB_FIX_K4|CALIB_FIX_K5); printf("RMS error reported by calibrateCamera: %g\n", rms); bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs); @@ -192,17 +192,17 @@ static void saveCameraParams( const string& filename, fs << "board_height" << boardSize.height; fs << "square_size" << squareSize; - if( flags & CV_CALIB_FIX_ASPECT_RATIO ) + if( flags & CALIB_FIX_ASPECT_RATIO ) fs << "aspectRatio" << aspectRatio; if( flags != 0 ) { sprintf( buf, "flags: %s%s%s%s", - flags & CV_CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" : "", - flags & CV_CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "", - flags & CV_CALIB_FIX_PRINCIPAL_POINT ? "+fix_principal_point" : "", - flags & CV_CALIB_ZERO_TANGENT_DIST ? "+zero_tangent_dist" : "" ); - cvWriteComment( *fs, buf, 0 ); + flags & CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" : "", + flags & CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "", + flags & CALIB_FIX_PRINCIPAL_POINT ? "+fix_principal_point" : "", + flags & CALIB_ZERO_TANGENT_DIST ? "+zero_tangent_dist" : "" ); + //cvWriteComment( *fs, buf, 0 ); } fs << "flags" << flags; @@ -229,7 +229,7 @@ static void saveCameraParams( const string& filename, r = rvecs[i].t(); t = tvecs[i].t(); } - cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0 ); + //cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0 ); fs << "extrinsic_parameters" << bigmat; } @@ -361,7 +361,7 @@ int main( int argc, char** argv ) { if( sscanf( argv[++i], "%f", &aspectRatio ) != 1 || aspectRatio <= 0 ) return printf("Invalid aspect ratio\n" ), -1; - flags |= CV_CALIB_FIX_ASPECT_RATIO; + flags |= CALIB_FIX_ASPECT_RATIO; } else if( strcmp( s, "-d" ) == 0 ) { @@ -378,11 +378,11 @@ int main( int argc, char** argv ) } else if( strcmp( s, "-zt" ) == 0 ) { - flags |= CV_CALIB_ZERO_TANGENT_DIST; + flags |= CALIB_ZERO_TANGENT_DIST; } else if( strcmp( s, "-p" ) == 0 ) { - flags |= CV_CALIB_FIX_PRINCIPAL_POINT; + flags |= CALIB_FIX_PRINCIPAL_POINT; } else if( strcmp( s, "-v" ) == 0 ) { @@ -469,7 +469,7 @@ int main( int argc, char** argv ) { case CHESSBOARD: found = findChessboardCorners( view, boardSize, pointbuf, - CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE); + CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK | CALIB_CB_NORMALIZE_IMAGE); break; case CIRCLES_GRID: found = findCirclesGrid( view, boardSize, pointbuf ); @@ -483,7 +483,7 @@ int main( int argc, char** argv ) // improve the found corners' coordinate accuracy if( pattern == CHESSBOARD && found) cornerSubPix( viewGray, pointbuf, Size(11,11), - Size(-1,-1), TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 )); + Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.1 )); if( mode == CAPTURING && found && (!capture.isOpened() || clock() - prevTimestamp > delay*1e-3*CLOCKS_PER_SEC) ) diff --git a/samples/cpp/calibration_artificial.cpp b/samples/cpp/calibration_artificial.cpp index f2a8f1b70..f77a8f30a 100644 --- a/samples/cpp/calibration_artificial.cpp +++ b/samples/cpp/calibration_artificial.cpp @@ -259,15 +259,15 @@ Mat cv::ChessBoardGenerator::generageChessBoard(const Mat& bg, const Mat& camMat if (rendererResolutionMultiplier == 1) { result = bg.clone(); - drawContours(result, whole_contour, -1, Scalar::all(255), CV_FILLED, CV_AA); - drawContours(result, squares_black, -1, Scalar::all(0), CV_FILLED, CV_AA); + drawContours(result, whole_contour, -1, Scalar::all(255), FILLED, LINE_AA); + drawContours(result, squares_black, -1, Scalar::all(0), FILLED, LINE_AA); } else { Mat tmp; resize(bg, tmp, bg.size() * rendererResolutionMultiplier); - drawContours(tmp, whole_contour, -1, Scalar::all(255), CV_FILLED, CV_AA); - drawContours(tmp, squares_black, -1, Scalar::all(0), CV_FILLED, CV_AA); + drawContours(tmp, whole_contour, -1, Scalar::all(255), FILLED, LINE_AA); + drawContours(tmp, squares_black, -1, Scalar::all(0), FILLED, LINE_AA); resize(tmp, result, bg.size(), 0, 0, INTER_AREA); } return result; diff --git a/samples/cpp/descriptor_extractor_matcher.cpp b/samples/cpp/descriptor_extractor_matcher.cpp index 7aa529910..43baed2fe 100644 --- a/samples/cpp/descriptor_extractor_matcher.cpp +++ b/samples/cpp/descriptor_extractor_matcher.cpp @@ -45,7 +45,7 @@ static int getMatcherFilterType( const string& str ) return NONE_FILTER; if( str == "CrossCheckFilter" ) return CROSS_CHECK_FILTER; - CV_Error(CV_StsBadArg, "Invalid filter name"); + CV_Error(Error::StsBadArg, "Invalid filter name"); return -1; } @@ -109,12 +109,12 @@ static void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective, Ptr& descriptorMatcher, int matcherFilter, bool eval, double ransacReprojThreshold, RNG& rng ) { - assert( !img1.empty() ); + CV_Assert( !img1.empty() ); Mat H12; if( isWarpPerspective ) warpPerspectiveRand(img1, img2, H12, rng ); else - assert( !img2.empty()/* && img2.cols==img1.cols && img2.rows==img1.rows*/ ); + CV_Assert( !img2.empty()/* && img2.cols==img1.cols && img2.rows==img1.rows*/ ); cout << endl << "< Extracting keypoints from second image..." << endl; vector keypoints2; @@ -189,7 +189,7 @@ static void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective, cout << "< Computing homography (RANSAC)..." << endl; vector points1; KeyPoint::convert(keypoints1, points1, queryIdxs); vector points2; KeyPoint::convert(keypoints2, points2, trainIdxs); - H12 = findHomography( Mat(points1), Mat(points2), CV_RANSAC, ransacReprojThreshold ); + H12 = findHomography( Mat(points1), Mat(points2), RANSAC, ransacReprojThreshold ); cout << ">" << endl; } @@ -208,7 +208,7 @@ static void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective, matchesMask[i1] = 1; } // draw inliers - drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, CV_RGB(0, 255, 0), CV_RGB(0, 0, 255), matchesMask + drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, Scalar(0, 255, 0), Scalar(0, 0, 255), matchesMask #if DRAW_RICH_KEYPOINTS_MODE , DrawMatchesFlags::DRAW_RICH_KEYPOINTS #endif @@ -218,7 +218,7 @@ static void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective, // draw outliers for( size_t i1 = 0; i1 < matchesMask.size(); i1++ ) matchesMask[i1] = !matchesMask[i1]; - drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, CV_RGB(0, 0, 255), CV_RGB(255, 0, 0), matchesMask, + drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, Scalar(0, 0, 255), Scalar(255, 0, 0), matchesMask, DrawMatchesFlags::DRAW_OVER_OUTIMG | DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); #endif diff --git a/samples/cpp/generic_descriptor_match.cpp b/samples/cpp/generic_descriptor_match.cpp index 5d38ddadf..888c24f7e 100644 --- a/samples/cpp/generic_descriptor_match.cpp +++ b/samples/cpp/generic_descriptor_match.cpp @@ -80,7 +80,7 @@ Mat DrawCorrespondences(const Mat& img1, const vector& features1, cons for (size_t i = 0; i < features1.size(); i++) { - circle(img_corr, features1[i].pt, 3, CV_RGB(255, 0, 0)); + circle(img_corr, features1[i].pt, 3, Scalar(255, 0, 0)); } for (size_t i = 0; i < features2.size(); i++) diff --git a/samples/cpp/select3dobj.cpp b/samples/cpp/select3dobj.cpp index a6aa2a7f4..32d30552f 100644 --- a/samples/cpp/select3dobj.cpp +++ b/samples/cpp/select3dobj.cpp @@ -148,25 +148,25 @@ static Rect extract3DBox(const Mat& frame, Mat& shownFrame, Mat& selectedObjFram if( shownFrame.data ) { if( nobjpt == 1 ) - circle(shownFrame, imgpt[0], 3, Scalar(0,255,0), -1, CV_AA); + circle(shownFrame, imgpt[0], 3, Scalar(0,255,0), -1, LINE_AA); else if( nobjpt == 2 ) { - circle(shownFrame, imgpt[0], 3, Scalar(0,255,0), -1, CV_AA); - circle(shownFrame, imgpt[1], 3, Scalar(0,255,0), -1, CV_AA); - line(shownFrame, imgpt[0], imgpt[1], Scalar(0,255,0), 3, CV_AA); + circle(shownFrame, imgpt[0], 3, Scalar(0,255,0), -1, LINE_AA); + circle(shownFrame, imgpt[1], 3, Scalar(0,255,0), -1, LINE_AA); + line(shownFrame, imgpt[0], imgpt[1], Scalar(0,255,0), 3, LINE_AA); } else if( nobjpt == 3 ) for( int i = 0; i < 4; i++ ) { - circle(shownFrame, imgpt[i], 3, Scalar(0,255,0), -1, CV_AA); - line(shownFrame, imgpt[i], imgpt[(i+1)%4], Scalar(0,255,0), 3, CV_AA); + circle(shownFrame, imgpt[i], 3, Scalar(0,255,0), -1, LINE_AA); + line(shownFrame, imgpt[i], imgpt[(i+1)%4], Scalar(0,255,0), 3, LINE_AA); } else for( int i = 0; i < 8; i++ ) { - circle(shownFrame, imgpt[i], 3, Scalar(0,255,0), -1, CV_AA); - line(shownFrame, imgpt[i], imgpt[(i+1)%4 + (i/4)*4], Scalar(0,255,0), 3, CV_AA); - line(shownFrame, imgpt[i], imgpt[i%4], Scalar(0,255,0), 3, CV_AA); + circle(shownFrame, imgpt[i], 3, Scalar(0,255,0), -1, LINE_AA); + line(shownFrame, imgpt[i], imgpt[(i+1)%4 + (i/4)*4], Scalar(0,255,0), 3, LINE_AA); + line(shownFrame, imgpt[i], imgpt[i%4], Scalar(0,255,0), 3, LINE_AA); } } diff --git a/samples/cpp/stereo_calib.cpp b/samples/cpp/stereo_calib.cpp index 57fde453c..44be2d64e 100644 --- a/samples/cpp/stereo_calib.cpp +++ b/samples/cpp/stereo_calib.cpp @@ -106,7 +106,7 @@ StereoCalib(const vector& imagelist, Size boardSize, bool useCalibrated= else resize(img, timg, Size(), scale, scale); found = findChessboardCorners(timg, boardSize, corners, - CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE); + CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE); if( found ) { if( scale > 1 ) @@ -135,7 +135,7 @@ StereoCalib(const vector& imagelist, Size boardSize, bool useCalibrated= if( !found ) break; cornerSubPix(img, corners, Size(11,11), Size(-1,-1), - TermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, + TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01)); } if( k == 2 ) @@ -175,12 +175,12 @@ StereoCalib(const vector& imagelist, Size boardSize, bool useCalibrated= cameraMatrix[0], distCoeffs[0], cameraMatrix[1], distCoeffs[1], imageSize, R, T, E, F, - TermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-5), - CV_CALIB_FIX_ASPECT_RATIO + - CV_CALIB_ZERO_TANGENT_DIST + - CV_CALIB_SAME_FOCAL_LENGTH + - CV_CALIB_RATIONAL_MODEL + - CV_CALIB_FIX_K3 + CV_CALIB_FIX_K4 + CV_CALIB_FIX_K5); + TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 100, 1e-5), + CALIB_FIX_ASPECT_RATIO + + CALIB_ZERO_TANGENT_DIST + + CALIB_SAME_FOCAL_LENGTH + + CALIB_RATIONAL_MODEL + + CALIB_FIX_K3 + CALIB_FIX_K4 + CALIB_FIX_K5); cout << "done with RMS error=" << rms << endl; // CALIBRATION QUALITY CHECK @@ -214,7 +214,7 @@ StereoCalib(const vector& imagelist, Size boardSize, bool useCalibrated= cout << "average reprojection err = " << err/npoints << endl; // save intrinsic parameters - FileStorage fs("intrinsics.yml", CV_STORAGE_WRITE); + FileStorage fs("intrinsics.yml", FileStorage::WRITE); if( fs.isOpened() ) { fs << "M1" << cameraMatrix[0] << "D1" << distCoeffs[0] << @@ -232,7 +232,7 @@ StereoCalib(const vector& imagelist, Size boardSize, bool useCalibrated= imageSize, R, T, R1, R2, P1, P2, Q, CALIB_ZERO_DISPARITY, 1, imageSize, &validRoi[0], &validRoi[1]); - fs.open("extrinsics.yml", CV_STORAGE_WRITE); + fs.open("extrinsics.yml", FileStorage::WRITE); if( fs.isOpened() ) { fs << "R" << R << "T" << T << "R1" << R1 << "R2" << R2 << "P1" << P1 << "P2" << P2 << "Q" << Q; diff --git a/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp b/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp index a3c3f6ee2..bf74e21a0 100644 --- a/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp +++ b/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp @@ -24,7 +24,7 @@ class Settings public: Settings() : goodInput(false) {} enum Pattern { NOT_EXISTING, CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID }; - enum InputType {INVALID, CAMERA, VIDEO_FILE, IMAGE_LIST}; + enum InputType { INVALID, CAMERA, VIDEO_FILE, IMAGE_LIST }; void write(FileStorage& fs) const //Write serialization for this class { @@ -120,9 +120,9 @@ public: } flag = 0; - if(calibFixPrincipalPoint) flag |= CV_CALIB_FIX_PRINCIPAL_POINT; - if(calibZeroTangentDist) flag |= CV_CALIB_ZERO_TANGENT_DIST; - if(aspectRatio) flag |= CV_CALIB_FIX_ASPECT_RATIO; + if(calibFixPrincipalPoint) flag |= CALIB_FIX_PRINCIPAL_POINT; + if(calibZeroTangentDist) flag |= CALIB_ZERO_TANGENT_DIST; + if(aspectRatio) flag |= CALIB_FIX_ASPECT_RATIO; calibrationPattern = NOT_EXISTING; @@ -272,7 +272,7 @@ int main(int argc, char* argv[]) { case Settings::CHESSBOARD: found = findChessboardCorners( view, s.boardSize, pointBuf, - CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE); + CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK | CALIB_CB_NORMALIZE_IMAGE); break; case Settings::CIRCLES_GRID: found = findCirclesGrid( view, s.boardSize, pointBuf ); @@ -293,7 +293,7 @@ int main(int argc, char* argv[]) Mat viewGray; cvtColor(view, viewGray, COLOR_BGR2GRAY); cornerSubPix( viewGray, pointBuf, Size(11,11), - Size(-1,-1), TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 )); + Size(-1,-1), TermCriteria( TermCriteria::EPS+TermCriteria::COUNT, 30, 0.1 )); } if( mode == CAPTURING && // For camera only take new samples after delay time @@ -392,7 +392,7 @@ static double computeReprojectionErrors( const vector >& objectP { projectPoints( Mat(objectPoints[i]), rvecs[i], tvecs[i], cameraMatrix, distCoeffs, imagePoints2); - err = norm(Mat(imagePoints[i]), Mat(imagePoints2), CV_L2); + err = norm(Mat(imagePoints[i]), Mat(imagePoints2), NORM_L2); int n = (int)objectPoints[i].size(); perViewErrors[i] = (float) std::sqrt(err*err/n); @@ -433,7 +433,7 @@ static bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat { cameraMatrix = Mat::eye(3, 3, CV_64F); - if( s.flag & CV_CALIB_FIX_ASPECT_RATIO ) + if( s.flag & CALIB_FIX_ASPECT_RATIO ) cameraMatrix.at(0,0) = 1.0; distCoeffs = Mat::zeros(8, 1, CV_64F); @@ -445,7 +445,7 @@ static bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat //Find intrinsic and extrinsic camera parameters double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, - distCoeffs, rvecs, tvecs, s.flag|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5); + distCoeffs, rvecs, tvecs, s.flag|CALIB_FIX_K4|CALIB_FIX_K5); cout << "Re-projection error reported by calibrateCamera: "<< rms << endl; @@ -481,17 +481,17 @@ static void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, M fs << "board_Height" << s.boardSize.height; fs << "square_Size" << s.squareSize; - if( s.flag & CV_CALIB_FIX_ASPECT_RATIO ) + if( s.flag & CALIB_FIX_ASPECT_RATIO ) fs << "FixAspectRatio" << s.aspectRatio; if( s.flag ) { sprintf( buf, "flags: %s%s%s%s", - s.flag & CV_CALIB_USE_INTRINSIC_GUESS ? " +use_intrinsic_guess" : "", - s.flag & CV_CALIB_FIX_ASPECT_RATIO ? " +fix_aspectRatio" : "", - s.flag & CV_CALIB_FIX_PRINCIPAL_POINT ? " +fix_principal_point" : "", - s.flag & CV_CALIB_ZERO_TANGENT_DIST ? " +zero_tangent_dist" : "" ); - cvWriteComment( *fs, buf, 0 ); + s.flag & CALIB_USE_INTRINSIC_GUESS ? " +use_intrinsic_guess" : "", + s.flag & CALIB_FIX_ASPECT_RATIO ? " +fix_aspectRatio" : "", + s.flag & CALIB_FIX_PRINCIPAL_POINT ? " +fix_principal_point" : "", + s.flag & CALIB_ZERO_TANGENT_DIST ? " +zero_tangent_dist" : "" ); + //cvWriteComment( *fs, buf, 0 ); } @@ -519,7 +519,7 @@ static void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, M r = rvecs[i].t(); t = tvecs[i].t(); } - cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0 ); + //cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0 ); fs << "Extrinsic_Parameters" << bigmat; } diff --git a/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp b/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp index 93826053f..47bc3ecfe 100644 --- a/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp +++ b/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp @@ -92,12 +92,12 @@ int main( int argc, char** argv ) scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt ); } - Mat H = findHomography( obj, scene, CV_RANSAC ); + Mat H = findHomography( obj, scene, RANSAC ); //-- Get the corners from the image_1 ( the object to be "detected" ) std::vector obj_corners(4); - obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( img_object.cols, 0 ); - obj_corners[2] = cvPoint( img_object.cols, img_object.rows ); obj_corners[3] = cvPoint( 0, img_object.rows ); + obj_corners[0] = Point(0,0); obj_corners[1] = Point( img_object.cols, 0 ); + obj_corners[2] = Point( img_object.cols, img_object.rows ); obj_corners[3] = Point( 0, img_object.rows ); std::vector scene_corners(4); perspectiveTransform( obj_corners, scene_corners, H); diff --git a/samples/ocl/surf_matcher.cpp b/samples/ocl/surf_matcher.cpp index ba4bc102f..9af7e54a7 100644 --- a/samples/ocl/surf_matcher.cpp +++ b/samples/ocl/surf_matcher.cpp @@ -207,7 +207,7 @@ int main(int argc, char* argv[]) obj.push_back( keypoints1[ good_matches[i].queryIdx ].pt ); scene.push_back( keypoints2[ good_matches[i].trainIdx ].pt ); } - Mat H = findHomography( obj, scene, CV_RANSAC ); + Mat H = findHomography( obj, scene, RANSAC ); //-- Get the corners from the image_1 ( the object to be "detected" ) std::vector obj_corners(4); From 5e048d1fa5ee1277669b784f650e310c3233f71d Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Fri, 12 Apr 2013 12:11:11 +0400 Subject: [PATCH 3/6] Move C API of opencv_objdetect to separate file Also move cv::linemod to own header --- include/opencv/cv.h | 3 +- include/opencv/cv.hpp | 1 + include/opencv/cvaux.h | 3 +- modules/contrib/include/opencv2/contrib.hpp | 2 + .../objdetect/include/opencv2/objdetect.hpp | 783 ++---------------- .../include/opencv2/objdetect/linemod.hpp | 455 ++++++++++ .../include/opencv2/objdetect/objdetect_c.h | 289 +++++++ modules/objdetect/src/_lsvm_routine.h | 2 + modules/objdetect/src/_lsvmparser.h | 1 + modules/objdetect/src/cascadedetect.cpp | 1 + modules/objdetect/src/datamatrix.cpp | 2 +- modules/objdetect/src/haar.cpp | 1 + modules/objdetect/src/hog.cpp | 7 +- modules/objdetect/src/latentsvmdetector.cpp | 1 + modules/objdetect/src/linemod.cpp | 8 +- modules/objdetect/src/matching.cpp | 1 + modules/objdetect/test/test_cascadeandhog.cpp | 23 +- .../objdetect/test/test_latentsvmdetector.cpp | 1 + modules/python/src2/cv2.cpp | 4 +- modules/superres/src/btv_l1_gpu.cpp | 2 +- samples/c/convert_cascade.c | 2 +- samples/c/facedetect.cpp | 20 +- samples/c/latentsvmdetect.cpp | 2 +- samples/c/smiledetect.cpp | 20 +- samples/cpp/dbt_face_detection.cpp | 2 +- samples/cpp/peopledetect.cpp | 2 +- .../objectDetection/objectDetection.cpp | 4 +- .../objectDetection/objectDetection2.cpp | 2 +- samples/gpu/cascadeclassifier.cpp | 4 +- samples/gpu/hog.cpp | 2 +- samples/gpu/houghlines.cpp | 4 +- samples/gpu/performance/performance.cpp | 2 +- 32 files changed, 881 insertions(+), 775 deletions(-) create mode 100644 modules/objdetect/include/opencv2/objdetect/linemod.hpp create mode 100644 modules/objdetect/include/opencv2/objdetect/objdetect_c.h diff --git a/include/opencv/cv.h b/include/opencv/cv.h index 09a2baa31..5a517dc73 100644 --- a/include/opencv/cv.h +++ b/include/opencv/cv.h @@ -64,11 +64,10 @@ #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/photo/photo_c.h" #include "opencv2/video/tracking_c.h" +#include "opencv2/objdetect/objdetect_c.h" #include "opencv2/legacy.hpp" #include "opencv2/legacy/compat.hpp" -#include "opencv2/objdetect.hpp" - #if !defined(CV_IMPL) #define CV_IMPL extern "C" #endif //CV_IMPL diff --git a/include/opencv/cv.hpp b/include/opencv/cv.hpp index f9fa3aee2..e498d7ac1 100644 --- a/include/opencv/cv.hpp +++ b/include/opencv/cv.hpp @@ -55,5 +55,6 @@ #include "opencv2/highgui.hpp" #include "opencv2/features2d.hpp" #include "opencv2/calib3d.hpp" +#include "opencv2/objdetect.hpp" #endif diff --git a/include/opencv/cvaux.h b/include/opencv/cvaux.h index 345036b24..2332c8798 100644 --- a/include/opencv/cvaux.h +++ b/include/opencv/cvaux.h @@ -50,12 +50,11 @@ #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/photo/photo_c.h" #include "opencv2/video/tracking_c.h" +#include "opencv2/objdetect/objdetect_c.h" #include "opencv2/legacy.hpp" #include "opencv2/legacy/compat.hpp" #include "opencv2/legacy/blobtrack.hpp" - -#include "opencv2/objdetect.hpp" #include "opencv2/contrib.hpp" #endif diff --git a/modules/contrib/include/opencv2/contrib.hpp b/modules/contrib/include/opencv2/contrib.hpp index dc4a72ae1..35bac1b90 100644 --- a/modules/contrib/include/opencv2/contrib.hpp +++ b/modules/contrib/include/opencv2/contrib.hpp @@ -48,6 +48,8 @@ #include "opencv2/features2d.hpp" #include "opencv2/objdetect.hpp" +#include "opencv2/core/core_c.h" + #include #ifdef __cplusplus diff --git a/modules/objdetect/include/opencv2/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect.hpp index bde149e16..3ccb057e3 100644 --- a/modules/objdetect/include/opencv2/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect.hpp @@ -7,11 +7,12 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -43,248 +44,10 @@ #ifndef __OPENCV_OBJDETECT_HPP__ #define __OPENCV_OBJDETECT_HPP__ -#ifdef __cplusplus -# include "opencv2/core.hpp" -#endif -#include "opencv2/core/core_c.h" +#include "opencv2/core.hpp" -#ifdef __cplusplus -#include -#include - -extern "C" { -#endif - -/****************************************************************************************\ -* Haar-like Object Detection functions * -\****************************************************************************************/ - -#define CV_HAAR_MAGIC_VAL 0x42500000 -#define CV_TYPE_NAME_HAAR "opencv-haar-classifier" - -#define CV_IS_HAAR_CLASSIFIER( haar ) \ - ((haar) != NULL && \ - (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL) - -#define CV_HAAR_FEATURE_MAX 3 - -typedef struct CvHaarFeature -{ - int tilted; - struct - { - CvRect r; - float weight; - } rect[CV_HAAR_FEATURE_MAX]; -} CvHaarFeature; - -typedef struct CvHaarClassifier -{ - int count; - CvHaarFeature* haar_feature; - float* threshold; - int* left; - int* right; - float* alpha; -} CvHaarClassifier; - -typedef struct CvHaarStageClassifier -{ - int count; - float threshold; - CvHaarClassifier* classifier; - - int next; - int child; - int parent; -} CvHaarStageClassifier; - -typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade; - -typedef struct CvHaarClassifierCascade -{ - int flags; - int count; - CvSize orig_window_size; - CvSize real_window_size; - double scale; - CvHaarStageClassifier* stage_classifier; - CvHidHaarClassifierCascade* hid_cascade; -} CvHaarClassifierCascade; - -typedef struct CvAvgComp -{ - CvRect rect; - int neighbors; -} CvAvgComp; - -/* Loads haar classifier cascade from a directory. - It is obsolete: convert your cascade to xml and use cvLoad instead */ -CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade( - const char* directory, CvSize orig_window_size); - -CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade ); - -#define CV_HAAR_DO_CANNY_PRUNING 1 -#define CV_HAAR_SCALE_IMAGE 2 -#define CV_HAAR_FIND_BIGGEST_OBJECT 4 -#define CV_HAAR_DO_ROUGH_SEARCH 8 - -//CVAPI(CvSeq*) cvHaarDetectObjectsForROC( const CvArr* image, -// CvHaarClassifierCascade* cascade, CvMemStorage* storage, -// CvSeq** rejectLevels, CvSeq** levelWeightds, -// double scale_factor CV_DEFAULT(1.1), -// int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0), -// CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0)), -// bool outputRejectLevels = false ); - - -CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image, - CvHaarClassifierCascade* cascade, CvMemStorage* storage, - double scale_factor CV_DEFAULT(1.1), - int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0), - CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0))); - -/* sets images for haar classifier cascade */ -CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade, - const CvArr* sum, const CvArr* sqsum, - const CvArr* tilted_sum, double scale ); - -/* runs the cascade on the specified window */ -CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade, - CvPoint pt, int start_stage CV_DEFAULT(0)); - - -/****************************************************************************************\ -* Latent SVM Object Detection functions * -\****************************************************************************************/ - -// DataType: STRUCT position -// Structure describes the position of the filter in the feature pyramid -// l - level in the feature pyramid -// (x, y) - coordinate in level l -typedef struct CvLSVMFilterPosition -{ - int x; - int y; - int l; -} CvLSVMFilterPosition; - -// DataType: STRUCT filterObject -// Description of the filter, which corresponds to the part of the object -// V - ideal (penalty = 0) position of the partial filter -// from the root filter position (V_i in the paper) -// penaltyFunction - vector describes penalty function (d_i in the paper) -// pf[0] * x + pf[1] * y + pf[2] * x^2 + pf[3] * y^2 -// FILTER DESCRIPTION -// Rectangular map (sizeX x sizeY), -// every cell stores feature vector (dimension = p) -// H - matrix of feature vectors -// to set and get feature vectors (i,j) -// used formula H[(j * sizeX + i) * p + k], where -// k - component of feature vector in cell (i, j) -// END OF FILTER DESCRIPTION -typedef struct CvLSVMFilterObject{ - CvLSVMFilterPosition V; - float fineFunction[4]; - int sizeX; - int sizeY; - int numFeatures; - float *H; -} CvLSVMFilterObject; - -// data type: STRUCT CvLatentSvmDetector -// structure contains internal representation of trained Latent SVM detector -// num_filters - total number of filters (root plus part) in model -// num_components - number of components in model -// num_part_filters - array containing number of part filters for each component -// filters - root and part filters for all model components -// b - biases for all model components -// score_threshold - confidence level threshold -typedef struct CvLatentSvmDetector -{ - int num_filters; - int num_components; - int* num_part_filters; - CvLSVMFilterObject** filters; - float* b; - float score_threshold; -} -CvLatentSvmDetector; - -// data type: STRUCT CvObjectDetection -// structure contains the bounding box and confidence level for detected object -// rect - bounding box for a detected object -// score - confidence level -typedef struct CvObjectDetection -{ - CvRect rect; - float score; -} CvObjectDetection; - -//////////////// Object Detection using Latent SVM ////////////// - - -/* -// load trained detector from a file -// -// API -// CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename); -// INPUT -// filename - path to the file containing the parameters of - - trained Latent SVM detector -// OUTPUT -// trained Latent SVM detector in internal representation -*/ -CVAPI(CvLatentSvmDetector*) cvLoadLatentSvmDetector(const char* filename); - -/* -// release memory allocated for CvLatentSvmDetector structure -// -// API -// void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector); -// INPUT -// detector - CvLatentSvmDetector structure to be released -// OUTPUT -*/ -CVAPI(void) cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector); - -/* -// find rectangular regions in the given image that are likely -// to contain objects and corresponding confidence levels -// -// API -// CvSeq* cvLatentSvmDetectObjects(const IplImage* image, -// CvLatentSvmDetector* detector, -// CvMemStorage* storage, -// float overlap_threshold = 0.5f, -// int numThreads = -1); -// INPUT -// image - image to detect objects in -// detector - Latent SVM detector in internal representation -// storage - memory storage to store the resultant sequence -// of the object candidate rectangles -// overlap_threshold - threshold for the non-maximum suppression algorithm - = 0.5f [here will be the reference to original paper] -// OUTPUT -// sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures) -*/ -CVAPI(CvSeq*) cvLatentSvmDetectObjects(IplImage* image, - CvLatentSvmDetector* detector, - CvMemStorage* storage, - float overlap_threshold CV_DEFAULT(0.5f), - int numThreads CV_DEFAULT(-1)); - -#ifdef __cplusplus -} - -CV_EXPORTS CvSeq* cvHaarDetectObjectsForROC( const CvArr* image, - CvHaarClassifierCascade* cascade, CvMemStorage* storage, - std::vector& rejectLevels, std::vector& levelWeightds, - double scale_factor CV_DEFAULT(1.1), - int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0), - CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0)), - bool outputRejectLevels = false ); +typedef struct CvLatentSvmDetector CvLatentSvmDetector; +typedef struct CvHaarClassifierCascade CvHaarClassifierCascade; namespace cv { @@ -303,24 +66,24 @@ public: struct CV_EXPORTS ObjectDetection { ObjectDetection(); - ObjectDetection( const Rect& rect, float score, int classID=-1 ); + ObjectDetection( const Rect& rect, float score, int classID = -1 ); Rect rect; float score; int classID; }; LatentSvmDetector(); - LatentSvmDetector( const std::vector& filenames, const std::vector& classNames=std::vector() ); + LatentSvmDetector( const std::vector& filenames, const std::vector& classNames = std::vector() ); virtual ~LatentSvmDetector(); virtual void clear(); virtual bool empty() const; - bool load( const std::vector& filenames, const std::vector& classNames=std::vector() ); + bool load( const std::vector& filenames, const std::vector& classNames = std::vector() ); virtual void detect( const Mat& image, std::vector& objectDetections, - float overlapThreshold=0.5f, - int numThreads=-1 ); + float overlapThreshold = 0.5f, + int numThreads = -1 ); const std::vector& getClassNames() const; size_t getClassCount() const; @@ -330,19 +93,22 @@ private: std::vector classNames; }; -CV_EXPORTS void groupRectangles(CV_OUT CV_IN_OUT std::vector& rectList, int groupThreshold, double eps=0.2); -CV_EXPORTS_W void groupRectangles(CV_OUT CV_IN_OUT std::vector& rectList, CV_OUT std::vector& weights, int groupThreshold, double eps=0.2); -CV_EXPORTS void groupRectangles( std::vector& rectList, int groupThreshold, double eps, std::vector* weights, std::vector* levelWeights ); -CV_EXPORTS void groupRectangles(std::vector& rectList, std::vector& rejectLevels, - std::vector& levelWeights, int groupThreshold, double eps=0.2); -CV_EXPORTS void groupRectangles_meanshift(std::vector& rectList, std::vector& foundWeights, std::vector& foundScales, +CV_EXPORTS void groupRectangles(std::vector& rectList, int groupThreshold, double eps = 0.2); +CV_EXPORTS_W void groupRectangles(CV_IN_OUT std::vector& rectList, CV_OUT std::vector& weights, int groupThreshold, double eps = 0.2); +CV_EXPORTS void groupRectangles(std::vector& rectList, int groupThreshold, double eps, std::vector* weights, std::vector* levelWeights ); +CV_EXPORTS void groupRectangles(std::vector& rectList, std::vector& rejectLevels, + std::vector& levelWeights, int groupThreshold, double eps = 0.2); +CV_EXPORTS void groupRectangles_meanshift(std::vector& rectList, std::vector& foundWeights, std::vector& foundScales, double detectThreshold = 0.0, Size winDetSize = Size(64, 128)); - class CV_EXPORTS FeatureEvaluator { public: - enum { HAAR = 0, LBP = 1, HOG = 2 }; + enum { HAAR = 0, + LBP = 1, + HOG = 2 + }; + virtual ~FeatureEvaluator(); virtual bool read(const FileNode& node); @@ -360,13 +126,11 @@ public: template<> CV_EXPORTS void Ptr::delete_obj(); -enum -{ - CASCADE_DO_CANNY_PRUNING=1, - CASCADE_SCALE_IMAGE=2, - CASCADE_FIND_BIGGEST_OBJECT=4, - CASCADE_DO_ROUGH_SEARCH=8 -}; +enum { CASCADE_DO_CANNY_PRUNING = 1, + CASCADE_SCALE_IMAGE = 2, + CASCADE_FIND_BIGGEST_OBJECT = 4, + CASCADE_DO_ROUGH_SEARCH = 8 + }; class CV_EXPORTS_W CascadeClassifier { @@ -380,20 +144,20 @@ public: virtual bool read( const FileNode& node ); CV_WRAP virtual void detectMultiScale( const Mat& image, CV_OUT std::vector& objects, - double scaleFactor=1.1, - int minNeighbors=3, int flags=0, - Size minSize=Size(), - Size maxSize=Size() ); + double scaleFactor = 1.1, + int minNeighbors = 3, int flags = 0, + Size minSize = Size(), + Size maxSize = Size() ); CV_WRAP virtual void detectMultiScale( const Mat& image, CV_OUT std::vector& objects, CV_OUT std::vector& rejectLevels, CV_OUT std::vector& levelWeights, - double scaleFactor=1.1, - int minNeighbors=3, int flags=0, - Size minSize=Size(), - Size maxSize=Size(), - bool outputRejectLevels=false ); + double scaleFactor = 1.1, + int minNeighbors = 3, int flags = 0, + Size minSize = Size(), + Size maxSize = Size(), + bool outputRejectLevels = false ); bool isOldFormatCascade() const; @@ -402,17 +166,18 @@ public: bool setImage( const Mat& ); protected: - //virtual bool detectSingleScale( const Mat& image, int stripCount, Size processingRectSize, - // int stripSize, int yStep, double factor, std::vector& candidates ); - virtual bool detectSingleScale( const Mat& image, int stripCount, Size processingRectSize, int stripSize, int yStep, double factor, std::vector& candidates, - std::vector& rejectLevels, std::vector& levelWeights, bool outputRejectLevels=false); + std::vector& rejectLevels, std::vector& levelWeights, bool outputRejectLevels = false); protected: - enum { BOOST = 0 }; - enum { DO_CANNY_PRUNING = 1, SCALE_IMAGE = 2, - FIND_BIGGEST_OBJECT = 4, DO_ROUGH_SEARCH = 8 }; + enum { BOOST = 0 + }; + enum { DO_CANNY_PRUNING = CASCADE_DO_CANNY_PRUNING, + SCALE_IMAGE = CASCADE_SCALE_IMAGE, + FIND_BIGGEST_OBJECT = CASCADE_FIND_BIGGEST_OBJECT, + DO_ROUGH_SEARCH = CASCADE_DO_ROUGH_SEARCH + }; friend class CascadeClassifierInvoker; @@ -507,8 +272,10 @@ struct DetectionROI struct CV_EXPORTS_W HOGDescriptor { public: - enum { L2Hys=0 }; - enum { DEFAULT_NLEVELS=64 }; + enum { L2Hys = 0 + }; + enum { DEFAULT_NLEVELS = 64 + }; CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8), cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1), @@ -548,38 +315,38 @@ public: virtual bool read(FileNode& fn); virtual void write(FileStorage& fs, const String& objname) const; - CV_WRAP virtual bool load(const String& filename, const String& objname=String()); - CV_WRAP virtual void save(const String& filename, const String& objname=String()) const; + CV_WRAP virtual bool load(const String& filename, const String& objname = String()); + CV_WRAP virtual void save(const String& filename, const String& objname = String()) const; virtual void copyTo(HOGDescriptor& c) const; CV_WRAP virtual void compute(const Mat& img, CV_OUT std::vector& descriptors, - Size winStride=Size(), Size padding=Size(), - const std::vector& locations=std::vector()) const; + Size winStride = Size(), Size padding = Size(), + const std::vector& locations = std::vector()) const; //with found weights output CV_WRAP virtual void detect(const Mat& img, CV_OUT std::vector& foundLocations, CV_OUT std::vector& weights, - double hitThreshold=0, Size winStride=Size(), - Size padding=Size(), - const std::vector& searchLocations=std::vector()) const; + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), + const std::vector& searchLocations = std::vector()) const; //without found weights output virtual void detect(const Mat& img, CV_OUT std::vector& foundLocations, - double hitThreshold=0, Size winStride=Size(), - Size padding=Size(), + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), const std::vector& searchLocations=std::vector()) const; //with result weights output CV_WRAP virtual void detectMultiScale(const Mat& img, CV_OUT std::vector& foundLocations, - CV_OUT std::vector& foundWeights, double hitThreshold=0, - Size winStride=Size(), Size padding=Size(), double scale=1.05, - double finalThreshold=2.0,bool useMeanshiftGrouping = false) const; + CV_OUT std::vector& foundWeights, double hitThreshold = 0, + Size winStride = Size(), Size padding = Size(), double scale = 1.05, + double finalThreshold = 2.0,bool useMeanshiftGrouping = false) const; //without found weights output virtual void detectMultiScale(const Mat& img, CV_OUT std::vector& foundLocations, - double hitThreshold=0, Size winStride=Size(), - Size padding=Size(), double scale=1.05, - double finalThreshold=2.0, bool useMeanshiftGrouping = false) const; + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), double scale = 1.05, + double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const; CV_WRAP virtual void computeGradient(const Mat& img, CV_OUT Mat& grad, CV_OUT Mat& angleOfs, - Size paddingTL=Size(), Size paddingBR=Size()) const; + Size paddingTL = Size(), Size paddingBR = Size()) const; CV_WRAP static std::vector getDefaultPeopleDetector(); CV_WRAP static std::vector getDaimlerPeopleDetector(); @@ -618,430 +385,14 @@ public: CV_EXPORTS_W void findDataMatrix(InputArray image, CV_OUT std::vector& codes, - OutputArray corners=noArray(), - OutputArrayOfArrays dmtx=noArray()); + OutputArray corners = noArray(), + OutputArrayOfArrays dmtx = noArray()); + CV_EXPORTS_W void drawDataMatrixCodes(InputOutputArray image, const std::vector& codes, InputArray corners); } -/****************************************************************************************\ -* Datamatrix * -\****************************************************************************************/ - -struct CV_EXPORTS CvDataMatrixCode { - char msg[4]; - CvMat *original; - CvMat *corners; -}; - -CV_EXPORTS std::deque cvFindDataMatrix(CvMat *im); - -/****************************************************************************************\ -* LINE-MOD * -\****************************************************************************************/ - -namespace cv { -namespace linemod { - -/// @todo Convert doxy comments to rst - -/** - * \brief Discriminant feature described by its location and label. - */ -struct CV_EXPORTS Feature -{ - int x; ///< x offset - int y; ///< y offset - int label; ///< Quantization - - Feature() : x(0), y(0), label(0) {} - Feature(int x, int y, int label); - - void read(const FileNode& fn); - void write(FileStorage& fs) const; -}; - -inline Feature::Feature(int _x, int _y, int _label) : x(_x), y(_y), label(_label) {} - -struct CV_EXPORTS Template -{ - int width; - int height; - int pyramid_level; - std::vector features; - - void read(const FileNode& fn); - void write(FileStorage& fs) const; -}; - -/** - * \brief Represents a modality operating over an image pyramid. - */ -class QuantizedPyramid -{ -public: - // Virtual destructor - virtual ~QuantizedPyramid() {} - - /** - * \brief Compute quantized image at current pyramid level for online detection. - * - * \param[out] dst The destination 8-bit image. For each pixel at most one bit is set, - * representing its classification. - */ - virtual void quantize(Mat& dst) const =0; - - /** - * \brief Extract most discriminant features at current pyramid level to form a new template. - * - * \param[out] templ The new template. - */ - virtual bool extractTemplate(Template& templ) const =0; - - /** - * \brief Go to the next pyramid level. - * - * \todo Allow pyramid scale factor other than 2 - */ - virtual void pyrDown() =0; - -protected: - /// Candidate feature with a score - struct Candidate - { - Candidate(int x, int y, int label, float score); - - /// Sort candidates with high score to the front - bool operator<(const Candidate& rhs) const - { - return score > rhs.score; - } - - Feature f; - float score; - }; - - /** - * \brief Choose candidate features so that they are not bunched together. - * - * \param[in] candidates Candidate features sorted by score. - * \param[out] features Destination vector of selected features. - * \param[in] num_features Number of candidates to select. - * \param[in] distance Hint for desired distance between features. - */ - static void selectScatteredFeatures(const std::vector& candidates, - std::vector& features, - size_t num_features, float distance); -}; - -inline QuantizedPyramid::Candidate::Candidate(int x, int y, int label, float _score) : f(x, y, label), score(_score) {} - -/** - * \brief Interface for modalities that plug into the LINE template matching representation. - * - * \todo Max response, to allow optimization of summing (255/MAX) features as uint8 - */ -class CV_EXPORTS Modality -{ -public: - // Virtual destructor - virtual ~Modality() {} - - /** - * \brief Form a quantized image pyramid from a source image. - * - * \param[in] src The source image. Type depends on the modality. - * \param[in] mask Optional mask. If not empty, unmasked pixels are set to zero - * in quantized image and cannot be extracted as features. - */ - Ptr process(const Mat& src, - const Mat& mask = Mat()) const - { - return processImpl(src, mask); - } - - virtual String name() const =0; - - virtual void read(const FileNode& fn) =0; - virtual void write(FileStorage& fs) const =0; - - /** - * \brief Create modality by name. - * - * The following modality types are supported: - * - "ColorGradient" - * - "DepthNormal" - */ - static Ptr create(const String& modality_type); - - /** - * \brief Load a modality from file. - */ - static Ptr create(const FileNode& fn); - -protected: - // Indirection is because process() has a default parameter. - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const =0; -}; - -/** - * \brief Modality that computes quantized gradient orientations from a color image. - */ -class CV_EXPORTS ColorGradient : public Modality -{ -public: - /** - * \brief Default constructor. Uses reasonable default parameter values. - */ - ColorGradient(); - - /** - * \brief Constructor. - * - * \param weak_threshold When quantizing, discard gradients with magnitude less than this. - * \param num_features How many features a template must contain. - * \param strong_threshold Consider as candidate features only gradients whose norms are - * larger than this. - */ - ColorGradient(float weak_threshold, size_t num_features, float strong_threshold); - - virtual String name() const; - - virtual void read(const FileNode& fn); - virtual void write(FileStorage& fs) const; - - float weak_threshold; - size_t num_features; - float strong_threshold; - -protected: - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const; -}; - -/** - * \brief Modality that computes quantized surface normals from a dense depth map. - */ -class CV_EXPORTS DepthNormal : public Modality -{ -public: - /** - * \brief Default constructor. Uses reasonable default parameter values. - */ - DepthNormal(); - - /** - * \brief Constructor. - * - * \param distance_threshold Ignore pixels beyond this distance. - * \param difference_threshold When computing normals, ignore contributions of pixels whose - * depth difference with the central pixel is above this threshold. - * \param num_features How many features a template must contain. - * \param extract_threshold Consider as candidate feature only if there are no differing - * orientations within a distance of extract_threshold. - */ - DepthNormal(int distance_threshold, int difference_threshold, size_t num_features, - int extract_threshold); - - virtual String name() const; - - virtual void read(const FileNode& fn); - virtual void write(FileStorage& fs) const; - - int distance_threshold; - int difference_threshold; - size_t num_features; - int extract_threshold; - -protected: - virtual Ptr processImpl(const Mat& src, - const Mat& mask) const; -}; - -/** - * \brief Debug function to colormap a quantized image for viewing. - */ -void colormap(const Mat& quantized, Mat& dst); - -/** - * \brief Represents a successful template match. - */ -struct CV_EXPORTS Match -{ - Match() - { - } - - Match(int x, int y, float similarity, const String& class_id, int template_id); - - /// Sort matches with high similarity to the front - bool operator<(const Match& rhs) const - { - // Secondarily sort on template_id for the sake of duplicate removal - if (similarity != rhs.similarity) - return similarity > rhs.similarity; - else - return template_id < rhs.template_id; - } - - bool operator==(const Match& rhs) const - { - return x == rhs.x && y == rhs.y && similarity == rhs.similarity && class_id == rhs.class_id; - } - - int x; - int y; - float similarity; - String class_id; - int template_id; -}; - -inline Match::Match(int _x, int _y, float _similarity, const String& _class_id, int _template_id) - : x(_x), y(_y), similarity(_similarity), class_id(_class_id), template_id(_template_id) - { - } - -/** - * \brief Object detector using the LINE template matching algorithm with any set of - * modalities. - */ -class CV_EXPORTS Detector -{ -public: - /** - * \brief Empty constructor, initialize with read(). - */ - Detector(); - - /** - * \brief Constructor. - * - * \param modalities Modalities to use (color gradients, depth normals, ...). - * \param T_pyramid Value of the sampling step T at each pyramid level. The - * number of pyramid levels is T_pyramid.size(). - */ - Detector(const std::vector< Ptr >& modalities, const std::vector& T_pyramid); - - /** - * \brief Detect objects by template matching. - * - * Matches globally at the lowest pyramid level, then refines locally stepping up the pyramid. - * - * \param sources Source images, one for each modality. - * \param threshold Similarity threshold, a percentage between 0 and 100. - * \param[out] matches Template matches, sorted by similarity score. - * \param class_ids If non-empty, only search for the desired object classes. - * \param[out] quantized_images Optionally return vector of quantized images. - * \param masks The masks for consideration during matching. The masks should be CV_8UC1 - * where 255 represents a valid pixel. If non-empty, the vector must be - * the same size as sources. Each element must be - * empty or the same size as its corresponding source. - */ - void match(const std::vector& sources, float threshold, std::vector& matches, - const std::vector& class_ids = std::vector(), - OutputArrayOfArrays quantized_images = noArray(), - const std::vector& masks = std::vector()) const; - - /** - * \brief Add new object template. - * - * \param sources Source images, one for each modality. - * \param class_id Object class ID. - * \param object_mask Mask separating object from background. - * \param[out] bounding_box Optionally return bounding box of the extracted features. - * - * \return Template ID, or -1 if failed to extract a valid template. - */ - int addTemplate(const std::vector& sources, const String& class_id, - const Mat& object_mask, Rect* bounding_box = NULL); - - /** - * \brief Add a new object template computed by external means. - */ - int addSyntheticTemplate(const std::vector