From 909d6fcf5139fa68dba94c6f2c488534bcb8b24b Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Fri, 12 Apr 2013 16:19:48 +0400 Subject: [PATCH] Move legacy part of opencv_contrib to separate header --- include/opencv/cvaux.h | 3 +- modules/contrib/include/opencv2/contrib.hpp | 1295 ++++++----------- .../include/opencv2/contrib/compat.hpp | 384 +++++ modules/contrib/src/adaptiveskindetector.cpp | 1 + modules/contrib/src/ba.cpp | 1 + modules/contrib/src/chamfermatching.cpp | 18 +- modules/contrib/src/colormap.cpp | 16 +- modules/contrib/src/facerec.cpp | 54 +- modules/contrib/src/fuzzymeanshifttracker.cpp | 1 + modules/contrib/src/gencolors.cpp | 2 +- modules/contrib/src/lda.cpp | 28 +- modules/contrib/src/octree.cpp | 2 +- modules/contrib/src/retina.cpp | 2 +- modules/contrib/src/rgbdodometry.cpp | 2 +- modules/contrib/src/spinimages.cpp | 75 +- modules/contrib/src/stereovar.cpp | 12 +- samples/c/adaptiveskindetector.cpp | 2 +- samples/cpp/facerec_demo.cpp | 6 +- samples/cpp/stereo_match.cpp | 4 +- samples/gpu/cascadeclassifier.cpp | 6 +- 20 files changed, 976 insertions(+), 938 deletions(-) create mode 100644 modules/contrib/include/opencv2/contrib/compat.hpp diff --git a/include/opencv/cvaux.h b/include/opencv/cvaux.h index 2332c8798b..cb49c086ba 100644 --- a/include/opencv/cvaux.h +++ b/include/opencv/cvaux.h @@ -51,11 +51,12 @@ #include "opencv2/photo/photo_c.h" #include "opencv2/video/tracking_c.h" #include "opencv2/objdetect/objdetect_c.h" +#include "opencv2/contrib/compat.hpp" + #include "opencv2/legacy.hpp" #include "opencv2/legacy/compat.hpp" #include "opencv2/legacy/blobtrack.hpp" -#include "opencv2/contrib.hpp" #endif diff --git a/modules/contrib/include/opencv2/contrib.hpp b/modules/contrib/include/opencv2/contrib.hpp index 35bac1b90a..be83152db5 100644 --- a/modules/contrib/include/opencv2/contrib.hpp +++ b/modules/contrib/include/opencv2/contrib.hpp @@ -48,931 +48,592 @@ #include "opencv2/features2d.hpp" #include "opencv2/objdetect.hpp" -#include "opencv2/core/core_c.h" - -#include - -#ifdef __cplusplus - -/****************************************************************************************\ -* Adaptive Skin Detector * -\****************************************************************************************/ - -class CV_EXPORTS CvAdaptiveSkinDetector +namespace cv +{ +class CV_EXPORTS Octree { -private: - enum { - GSD_HUE_LT = 3, - GSD_HUE_UT = 33, - GSD_INTENSITY_LT = 15, - GSD_INTENSITY_UT = 250 - }; - - class CV_EXPORTS Histogram - { - private: - enum { - HistogramSize = (GSD_HUE_UT - GSD_HUE_LT + 1) - }; - - protected: - int findCoverageIndex(double surfaceToCover, int defaultValue = 0); - - public: - CvHistogram *fHistogram; - Histogram(); - virtual ~Histogram(); - - void findCurveThresholds(int &x1, int &x2, double percent = 0.05); - void mergeWith(Histogram *source, double weight); - }; - - int nStartCounter, nFrameCount, nSkinHueLowerBound, nSkinHueUpperBound, nMorphingMethod, nSamplingDivider; - double fHistogramMergeFactor, fHuePercentCovered; - Histogram histogramHueMotion, skinHueHistogram; - IplImage *imgHueFrame, *imgSaturationFrame, *imgLastGrayFrame, *imgMotionFrame, *imgFilteredFrame; - IplImage *imgShrinked, *imgTemp, *imgGrayFrame, *imgHSVFrame; - -protected: - void initData(IplImage *src, int widthDivider, int heightDivider); - void adaptiveFilter(); - public: - - enum { - MORPHING_METHOD_NONE = 0, - MORPHING_METHOD_ERODE = 1, - MORPHING_METHOD_ERODE_ERODE = 2, - MORPHING_METHOD_ERODE_DILATE = 3 + struct Node + { + Node() {} + int begin, end; + float x_min, x_max, y_min, y_max, z_min, z_max; + int maxLevels; + bool isLeaf; + int children[8]; }; - CvAdaptiveSkinDetector(int samplingDivider = 1, int morphingMethod = MORPHING_METHOD_NONE); - virtual ~CvAdaptiveSkinDetector(); - - virtual void process(IplImage *inputBGRImage, IplImage *outputHueMask); -}; - - -/****************************************************************************************\ - * Fuzzy MeanShift Tracker * - \****************************************************************************************/ - -class CV_EXPORTS CvFuzzyPoint { -public: - double x, y, value; - - CvFuzzyPoint(double _x, double _y); -}; + Octree(); + Octree( const std::vector& points, int maxLevels = 10, int minPoints = 20 ); + virtual ~Octree(); -class CV_EXPORTS CvFuzzyCurve { + virtual void buildTree( const std::vector& points, int maxLevels = 10, int minPoints = 20 ); + virtual void getPointsWithinSphere( const Point3f& center, float radius, + std::vector& points ) const; + const std::vector& getNodes() const { return nodes; } private: - std::vector points; - double value, centre; + int minPoints; + std::vector points; + std::vector nodes; - bool between(double x, double x1, double x2); - -public: - CvFuzzyCurve(); - ~CvFuzzyCurve(); - - void setCentre(double _centre); - double getCentre(); - void clear(); - void addPoint(double x, double y); - double calcValue(double param); - double getValue(); - void setValue(double _value); + virtual void buildNext(size_t node_ind); }; -class CV_EXPORTS CvFuzzyFunction { -public: - std::vector curves; - - CvFuzzyFunction(); - ~CvFuzzyFunction(); - void addCurve(CvFuzzyCurve *curve, double value = 0); - void resetValues(); - double calcValue(); - CvFuzzyCurve *newCurve(); -}; -class CV_EXPORTS CvFuzzyRule { -private: - CvFuzzyCurve *fuzzyInput1, *fuzzyInput2; - CvFuzzyCurve *fuzzyOutput; -public: - CvFuzzyRule(); - ~CvFuzzyRule(); - void setRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1); - double calcValue(double param1, double param2); - CvFuzzyCurve *getOutputCurve(); -}; - -class CV_EXPORTS CvFuzzyController { -private: - std::vector rules; -public: - CvFuzzyController(); - ~CvFuzzyController(); - void addRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1); - double calcOutput(double param1, double param2); -}; - -class CV_EXPORTS CvFuzzyMeanShiftTracker +class CV_EXPORTS Mesh3D { -private: - class FuzzyResizer - { - private: - CvFuzzyFunction iInput, iOutput; - CvFuzzyController fuzzyController; - public: - FuzzyResizer(); - int calcOutput(double edgeDensity, double density); - }; - - class SearchWindow - { - public: - FuzzyResizer *fuzzyResizer; - int x, y; - int width, height, maxWidth, maxHeight, ellipseHeight, ellipseWidth; - int ldx, ldy, ldw, ldh, numShifts, numIters; - int xGc, yGc; - long m00, m01, m10, m11, m02, m20; - double ellipseAngle; - double density; - unsigned int depthLow, depthHigh; - int verticalEdgeLeft, verticalEdgeRight, horizontalEdgeTop, horizontalEdgeBottom; - - SearchWindow(); - ~SearchWindow(); - void setSize(int _x, int _y, int _width, int _height); - void initDepthValues(IplImage *maskImage, IplImage *depthMap); - bool shift(); - void extractInfo(IplImage *maskImage, IplImage *depthMap, bool initDepth); - void getResizeAttribsEdgeDensityLinear(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); - void getResizeAttribsInnerDensity(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); - void getResizeAttribsEdgeDensityFuzzy(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); - bool meanShift(IplImage *maskImage, IplImage *depthMap, int maxIteration, bool initDepth); - }; - public: - enum TrackingState - { - tsNone = 0, - tsSearching = 1, - tsTracking = 2, - tsSetWindow = 3, - tsDisabled = 10 - }; + struct EmptyMeshException {}; - enum ResizeMethod { - rmEdgeDensityLinear = 0, - rmEdgeDensityFuzzy = 1, - rmInnerDensity = 2 - }; - - enum { - MinKernelMass = 1000 - }; + Mesh3D(); + Mesh3D(const std::vector& vtx); + ~Mesh3D(); - SearchWindow kernel; - int searchMode; + void buildOctree(); + void clearOctree(); + float estimateResolution(float tryRatio = 0.1f); + void computeNormals(float normalRadius, int minNeighbors = 20); + void computeNormals(const std::vector& subset, float normalRadius, int minNeighbors = 20); -private: - enum - { - MaxMeanShiftIteration = 5, - MaxSetSizeIteration = 5 - }; + void writeAsVrml(const String& file, const std::vector& colors = std::vector()) const; - void findOptimumSearchWindow(SearchWindow &searchWindow, IplImage *maskImage, IplImage *depthMap, int maxIteration, int resizeMethod, bool initDepth); + std::vector vtx; + std::vector normals; + float resolution; + Octree octree; -public: - CvFuzzyMeanShiftTracker(); - ~CvFuzzyMeanShiftTracker(); - - void track(IplImage *maskImage, IplImage *depthMap, int resizeMethod, bool resetSearch, int minKernelMass = MinKernelMass); + const static Point3f allzero; }; - -namespace cv +class CV_EXPORTS SpinImageModel { +public: - class CV_EXPORTS Octree - { - public: - struct Node - { - Node() {} - int begin, end; - float x_min, x_max, y_min, y_max, z_min, z_max; - int maxLevels; - bool isLeaf; - int children[8]; - }; - - Octree(); - Octree( const std::vector& points, int maxLevels = 10, int minPoints = 20 ); - virtual ~Octree(); - - virtual void buildTree( const std::vector& points, int maxLevels = 10, int minPoints = 20 ); - virtual void getPointsWithinSphere( const Point3f& center, float radius, - std::vector& points ) const; - const std::vector& getNodes() const { return nodes; } - private: - int minPoints; - std::vector points; - std::vector nodes; - - virtual void buildNext(size_t node_ind); - }; - - - class CV_EXPORTS Mesh3D - { - public: - struct EmptyMeshException {}; - - Mesh3D(); - Mesh3D(const std::vector& vtx); - ~Mesh3D(); - - void buildOctree(); - void clearOctree(); - float estimateResolution(float tryRatio = 0.1f); - void computeNormals(float normalRadius, int minNeighbors = 20); - void computeNormals(const std::vector& subset, float normalRadius, int minNeighbors = 20); - - void writeAsVrml(const String& file, const std::vector& colors = std::vector()) const; - - std::vector vtx; - std::vector normals; - float resolution; - Octree octree; - - const static Point3f allzero; - }; - - class CV_EXPORTS SpinImageModel - { - public: - - /* model parameters, leave unset for default or auto estimate */ - float normalRadius; - int minNeighbors; - - float binSize; - int imageWidth; + /* model parameters, leave unset for default or auto estimate */ + float normalRadius; + int minNeighbors; - float lambda; - float gamma; + float binSize; + int imageWidth; - float T_GeometriccConsistency; - float T_GroupingCorespondances; + float lambda; + float gamma; - /* public interface */ - SpinImageModel(); - explicit SpinImageModel(const Mesh3D& mesh); - ~SpinImageModel(); + float T_GeometriccConsistency; + float T_GroupingCorespondances; - void setLogger(std::ostream* log); - void selectRandomSubset(float ratio); - void setSubset(const std::vector& subset); - void compute(); + /* public interface */ + SpinImageModel(); + explicit SpinImageModel(const Mesh3D& mesh); + ~SpinImageModel(); - void match(const SpinImageModel& scene, std::vector< std::vector >& result); + void selectRandomSubset(float ratio); + void setSubset(const std::vector& subset); + void compute(); - Mat packRandomScaledSpins(bool separateScale = false, size_t xCount = 10, size_t yCount = 10) const; + void match(const SpinImageModel& scene, std::vector< std::vector >& result); - size_t getSpinCount() const { return spinImages.rows; } - Mat getSpinImage(size_t index) const { return spinImages.row((int)index); } - const Point3f& getSpinVertex(size_t index) const { return mesh.vtx[subset[index]]; } - const Point3f& getSpinNormal(size_t index) const { return mesh.normals[subset[index]]; } + Mat packRandomScaledSpins(bool separateScale = false, size_t xCount = 10, size_t yCount = 10) const; - const Mesh3D& getMesh() const { return mesh; } - Mesh3D& getMesh() { return mesh; } + size_t getSpinCount() const { return spinImages.rows; } + Mat getSpinImage(size_t index) const { return spinImages.row((int)index); } + const Point3f& getSpinVertex(size_t index) const { return mesh.vtx[subset[index]]; } + const Point3f& getSpinNormal(size_t index) const { return mesh.normals[subset[index]]; } - /* static utility functions */ - static bool spinCorrelation(const Mat& spin1, const Mat& spin2, float lambda, float& result); + const Mesh3D& getMesh() const { return mesh; } + Mesh3D& getMesh() { return mesh; } - static Point2f calcSpinMapCoo(const Point3f& point, const Point3f& vertex, const Point3f& normal); + /* static utility functions */ + static bool spinCorrelation(const Mat& spin1, const Mat& spin2, float lambda, float& result); - static float geometricConsistency(const Point3f& pointScene1, const Point3f& normalScene1, - const Point3f& pointModel1, const Point3f& normalModel1, - const Point3f& pointScene2, const Point3f& normalScene2, - const Point3f& pointModel2, const Point3f& normalModel2); + static Point2f calcSpinMapCoo(const Point3f& point, const Point3f& vertex, const Point3f& normal); - static float groupingCreteria(const Point3f& pointScene1, const Point3f& normalScene1, + static float geometricConsistency(const Point3f& pointScene1, const Point3f& normalScene1, const Point3f& pointModel1, const Point3f& normalModel1, const Point3f& pointScene2, const Point3f& normalScene2, - const Point3f& pointModel2, const Point3f& normalModel2, - float gamma); - protected: - void defaultParams(); + const Point3f& pointModel2, const Point3f& normalModel2); - void matchSpinToModel(const Mat& spin, std::vector& indeces, - std::vector& corrCoeffs, bool useExtremeOutliers = true) const; + static float groupingCreteria(const Point3f& pointScene1, const Point3f& normalScene1, + const Point3f& pointModel1, const Point3f& normalModel1, + const Point3f& pointScene2, const Point3f& normalScene2, + const Point3f& pointModel2, const Point3f& normalModel2, + float gamma); +protected: + void defaultParams(); - void repackSpinImages(const std::vector& mask, Mat& spinImages, bool reAlloc = true) const; + void matchSpinToModel(const Mat& spin, std::vector& indeces, + std::vector& corrCoeffs, bool useExtremeOutliers = true) const; - std::vector subset; - Mesh3D mesh; - Mat spinImages; - std::ostream* out; - }; + void repackSpinImages(const std::vector& mask, Mat& spinImages, bool reAlloc = true) const; - class CV_EXPORTS TickMeter - { - public: - TickMeter(); - void start(); - void stop(); - - int64 getTimeTicks() const; - double getTimeMicro() const; - double getTimeMilli() const; - double getTimeSec() const; - int64 getCounter() const; - - void reset(); - private: - int64 counter; - int64 sumTime; - int64 startTime; - }; - - CV_EXPORTS std::ostream& operator<<(std::ostream& out, const TickMeter& tm); + std::vector subset; + Mesh3D mesh; + Mat spinImages; +}; - class CV_EXPORTS SelfSimDescriptor - { - public: - SelfSimDescriptor(); - SelfSimDescriptor(int _ssize, int _lsize, - int _startDistanceBucket=DEFAULT_START_DISTANCE_BUCKET, - int _numberOfDistanceBuckets=DEFAULT_NUM_DISTANCE_BUCKETS, - int _nangles=DEFAULT_NUM_ANGLES); - SelfSimDescriptor(const SelfSimDescriptor& ss); - virtual ~SelfSimDescriptor(); - SelfSimDescriptor& operator = (const SelfSimDescriptor& ss); - - size_t getDescriptorSize() const; - Size getGridSize( Size imgsize, Size winStride ) const; - - virtual void compute(const Mat& img, std::vector& descriptors, Size winStride=Size(), - const std::vector& locations=std::vector()) const; - virtual void computeLogPolarMapping(Mat& mappingMask) const; - virtual void SSD(const Mat& img, Point pt, Mat& ssd) const; - - int smallSize; - int largeSize; - int startDistanceBucket; - int numberOfDistanceBuckets; - int numberOfAngles; - - enum { DEFAULT_SMALL_SIZE = 5, DEFAULT_LARGE_SIZE = 41, - DEFAULT_NUM_ANGLES = 20, DEFAULT_START_DISTANCE_BUCKET = 3, - DEFAULT_NUM_DISTANCE_BUCKETS = 7 }; - }; +class CV_EXPORTS TickMeter +{ +public: + TickMeter(); + void start(); + void stop(); + int64 getTimeTicks() const; + double getTimeMicro() const; + double getTimeMilli() const; + double getTimeSec() const; + int64 getCounter() const; - typedef bool (*BundleAdjustCallback)(int iteration, double norm_error, void* user_data); + void reset(); +private: + int64 counter; + int64 sumTime; + int64 startTime; +}; - class CV_EXPORTS LevMarqSparse { - public: - LevMarqSparse(); - LevMarqSparse(int npoints, // number of points - int ncameras, // number of cameras - int nPointParams, // number of params per one point (3 in case of 3D points) - int nCameraParams, // number of parameters per one camera - int nErrParams, // number of parameters in measurement vector - // for 1 point at one camera (2 in case of 2D projections) - Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras - // 1 - point is visible for the camera, 0 - invisible - Mat& P0, // starting vector of parameters, first cameras then points - Mat& X, // measurements, in order of visibility. non visible cases are skipped - TermCriteria criteria, // termination criteria - - // callback for estimation of Jacobian matrices - void (CV_CDECL * fjac)(int i, int j, Mat& point_params, - Mat& cam_params, Mat& A, Mat& B, void* data), - // callback for estimation of backprojection errors - void (CV_CDECL * func)(int i, int j, Mat& point_params, - Mat& cam_params, Mat& estim, void* data), - void* data, // user-specific data passed to the callbacks - BundleAdjustCallback cb, void* user_data - ); - - virtual ~LevMarqSparse(); - - virtual void run( int npoints, // number of points - int ncameras, // number of cameras - int nPointParams, // number of params per one point (3 in case of 3D points) - int nCameraParams, // number of parameters per one camera - int nErrParams, // number of parameters in measurement vector - // for 1 point at one camera (2 in case of 2D projections) - Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras - // 1 - point is visible for the camera, 0 - invisible - Mat& P0, // starting vector of parameters, first cameras then points - Mat& X, // measurements, in order of visibility. non visible cases are skipped - TermCriteria criteria, // termination criteria - - // callback for estimation of Jacobian matrices - void (CV_CDECL * fjac)(int i, int j, Mat& point_params, - Mat& cam_params, Mat& A, Mat& B, void* data), - // callback for estimation of backprojection errors - void (CV_CDECL * func)(int i, int j, Mat& point_params, - Mat& cam_params, Mat& estim, void* data), - void* data // user-specific data passed to the callbacks - ); - - virtual void clear(); - - // useful function to do simple bundle adjustment tasks - static void bundleAdjust(std::vector& points, // positions of points in global coordinate system (input and output) - const std::vector >& imagePoints, // projections of 3d points for every camera - const std::vector >& visibility, // visibility of 3d points for every camera - std::vector& cameraMatrix, // intrinsic matrices of all cameras (input and output) - std::vector& R, // rotation matrices of all cameras (input and output) - std::vector& T, // translation vector of all cameras (input and output) - std::vector& distCoeffs, // distortion coefficients of all cameras (input and output) - const TermCriteria& criteria= - TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON), - BundleAdjustCallback cb = 0, void* user_data = 0); +//CV_EXPORTS std::ostream& operator<<(std::ostream& out, const TickMeter& tm); - public: - virtual void optimize(CvMat &_vis); //main function that runs minimization +class CV_EXPORTS SelfSimDescriptor +{ +public: + SelfSimDescriptor(); + SelfSimDescriptor(int _ssize, int _lsize, + int _startDistanceBucket=DEFAULT_START_DISTANCE_BUCKET, + int _numberOfDistanceBuckets=DEFAULT_NUM_DISTANCE_BUCKETS, + int _nangles=DEFAULT_NUM_ANGLES); + SelfSimDescriptor(const SelfSimDescriptor& ss); + virtual ~SelfSimDescriptor(); + SelfSimDescriptor& operator = (const SelfSimDescriptor& ss); + + size_t getDescriptorSize() const; + Size getGridSize( Size imgsize, Size winStride ) const; + + virtual void compute(const Mat& img, std::vector& descriptors, Size winStride=Size(), + const std::vector& locations=std::vector()) const; + virtual void computeLogPolarMapping(Mat& mappingMask) const; + virtual void SSD(const Mat& img, Point pt, Mat& ssd) const; + + int smallSize; + int largeSize; + int startDistanceBucket; + int numberOfDistanceBuckets; + int numberOfAngles; + + enum { DEFAULT_SMALL_SIZE = 5, DEFAULT_LARGE_SIZE = 41, + DEFAULT_NUM_ANGLES = 20, DEFAULT_START_DISTANCE_BUCKET = 3, + DEFAULT_NUM_DISTANCE_BUCKETS = 7 }; +}; - //iteratively asks for measurement for visible camera-point pairs - void ask_for_proj(CvMat &_vis,bool once=false); - //iteratively asks for Jacobians for every camera_point pair - void ask_for_projac(CvMat &_vis); - CvMat* err; //error X-hX - double prevErrNorm, errNorm; - double lambda; - CvTermCriteria criteria; - int iters; +CV_EXPORTS_W int chamerMatching( Mat& img, Mat& templ, + CV_OUT std::vector >& results, CV_OUT std::vector& cost, + double templScale=1, int maxMatches = 20, + double minMatchDistance = 1.0, int padX = 3, + int padY = 3, int scales = 5, double minScale = 0.6, double maxScale = 1.6, + double orientationWeight = 0.5, double truncate = 20); - CvMat** U; //size of array is equal to number of cameras - CvMat** V; //size of array is equal to number of points - CvMat** inv_V_star; //inverse of V* - CvMat** A; - CvMat** B; - CvMat** W; +class CV_EXPORTS_W StereoVar +{ +public: + // Flags + enum {USE_INITIAL_DISPARITY = 1, USE_EQUALIZE_HIST = 2, USE_SMART_ID = 4, USE_AUTO_PARAMS = 8, USE_MEDIAN_FILTERING = 16}; + enum {CYCLE_O, CYCLE_V}; + enum {PENALIZATION_TICHONOV, PENALIZATION_CHARBONNIER, PENALIZATION_PERONA_MALIK}; + + //! the default constructor + CV_WRAP StereoVar(); + + //! the full constructor taking all the necessary algorithm parameters + CV_WRAP StereoVar(int levels, double pyrScale, int nIt, int minDisp, int maxDisp, int poly_n, double poly_sigma, float fi, float lambda, int penalization, int cycle, int flags); + + //! the destructor + virtual ~StereoVar(); + + //! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair + CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, CV_OUT Mat& disp); + + CV_PROP_RW int levels; + CV_PROP_RW double pyrScale; + CV_PROP_RW int nIt; + CV_PROP_RW int minDisp; + CV_PROP_RW int maxDisp; + CV_PROP_RW int poly_n; + CV_PROP_RW double poly_sigma; + CV_PROP_RW float fi; + CV_PROP_RW float lambda; + CV_PROP_RW int penalization; + CV_PROP_RW int cycle; + CV_PROP_RW int flags; - CvMat* X; //measurement - CvMat* hX; //current measurement extimation given new parameter vector +private: + void autoParams(); + void FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level); + void VCycle_MyFAS(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level); + void VariationalSolver(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level); +}; - CvMat* prevP; //current already accepted parameter. - CvMat* P; // parameters used to evaluate function with new params - // this parameters may be rejected +CV_EXPORTS void polyfit(const Mat& srcx, const Mat& srcy, Mat& dst, int order); - CvMat* deltaP; //computed increase of parameters (result of normal system solution ) +class CV_EXPORTS Directory +{ + public: + static std::vector GetListFiles ( const String& path, const String & exten = "*", bool addPath = true ); + static std::vector GetListFilesR ( const String& path, const String & exten = "*", bool addPath = true ); + static std::vector GetListFolders( const String& path, const String & exten = "*", bool addPath = true ); +}; - CvMat** ea; // sum_i AijT * e_ij , used as right part of normal equation - // length of array is j = number of cameras - CvMat** eb; // sum_j BijT * e_ij , used as right part of normal equation - // length of array is i = number of points +/* + * Generation of a set of different colors by the following way: + * 1) generate more then need colors (in "factor" times) in RGB, + * 2) convert them to Lab, + * 3) choose the needed count of colors from the set that are more different from + * each other, + * 4) convert the colors back to RGB + */ +CV_EXPORTS void generateColors( std::vector& colors, size_t count, size_t factor=100 ); + + +/* + * Estimate the rigid body motion from frame0 to frame1. The method is based on the paper + * "Real-Time Visual Odometry from Dense RGB-D Images", F. Steinbucker, J. Strum, D. Cremers, ICCV, 2011. + */ +enum { ROTATION = 1, + TRANSLATION = 2, + RIGID_BODY_MOTION = 4 + }; +CV_EXPORTS bool RGBDOdometry( Mat& Rt, const Mat& initRt, + const Mat& image0, const Mat& depth0, const Mat& mask0, + const Mat& image1, const Mat& depth1, const Mat& mask1, + const Mat& cameraMatrix, float minDepth=0.f, float maxDepth=4.f, float maxDepthDiff=0.07f, + const std::vector& iterCounts=std::vector(), + const std::vector& minGradientMagnitudes=std::vector(), + int transformType=RIGID_BODY_MOTION ); + +/** +*Bilinear interpolation technique. +* +*The value of a desired cortical pixel is obtained through a bilinear interpolation of the values +*of the four nearest neighbouring Cartesian pixels to the center of the RF. +*The same principle is applied to the inverse transformation. +* +*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 +*/ +class CV_EXPORTS LogPolar_Interp +{ +public: - CvMat** Yj; //length of array is i = num_points + LogPolar_Interp() {} - CvMat* S; //big matrix of block Sjk , each block has size num_cam_params x num_cam_params + /** + *Constructor + *\param w the width of the input image + *\param h the height of the input image + *\param center the transformation center: where the output precision is maximal + *\param R the number of rings of the cortical image (default value 70 pixel) + *\param ro0 the radius of the blind spot (default value 3 pixel) + *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. + * \a 0 means that the retinal image is computed within the inscribed circle. + *\param S the number of sectors of the cortical image (default value 70 pixel). + * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. + *\param sp \a 1 (default value) means that the parameter \a S is internally computed. + * \a 0 means that the parameter \a S is provided by the user. + */ + LogPolar_Interp(int w, int h, Point2i center, int R=70, double ro0=3.0, + int interp=INTER_LINEAR, int full=1, int S=117, int sp=1); + /** + *Transformation from Cartesian image to cortical (log-polar) image. + *\param source the Cartesian image + *\return the transformed image (cortical image) + */ + const Mat to_cortical(const Mat &source); + /** + *Transformation from cortical image to retinal (inverse log-polar) image. + *\param source the cortical image + *\return the transformed image (retinal image) + */ + const Mat to_cartesian(const Mat &source); + /** + *Destructor + */ + ~LogPolar_Interp(); - CvMat* JtJ_diag; //diagonal of JtJ, used to backup diagonal elements before augmentation +protected: - CvMat* Vis_index; // matrix which element is index of measurement for point i and camera j + Mat Rsri; + Mat Csri; - int num_cams; - int num_points; - int num_err_param; - int num_cam_param; - int num_point_param; + int S, R, M, N; + int top, bottom,left,right; + double ro0, romax, a, q; + int interp; - //target function and jacobian pointers, which needs to be initialized - void (*fjac)(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data); - void (*func)(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data); + Mat ETAyx; + Mat CSIyx; - void* data; + void create_map(int M, int N, int R, int S, double ro0); +}; - BundleAdjustCallback cb; - void* user_data; - }; +/** +*Overlapping circular receptive fields technique +* +*The Cartesian plane is divided in two regions: the fovea and the periphery. +*The fovea (oversampling) is handled by using the bilinear interpolation technique described above, whereas in +*the periphery we use the overlapping Gaussian circular RFs. +* +*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 +*/ +class CV_EXPORTS LogPolar_Overlapping +{ +public: + LogPolar_Overlapping() {} - CV_EXPORTS_W int chamerMatching( Mat& img, Mat& templ, - CV_OUT std::vector >& results, CV_OUT std::vector& cost, - double templScale=1, int maxMatches = 20, - double minMatchDistance = 1.0, int padX = 3, - int padY = 3, int scales = 5, double minScale = 0.6, double maxScale = 1.6, - double orientationWeight = 0.5, double truncate = 20); + /** + *Constructor + *\param w the width of the input image + *\param h the height of the input image + *\param center the transformation center: where the output precision is maximal + *\param R the number of rings of the cortical image (default value 70 pixel) + *\param ro0 the radius of the blind spot (default value 3 pixel) + *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. + * \a 0 means that the retinal image is computed within the inscribed circle. + *\param S the number of sectors of the cortical image (default value 70 pixel). + * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. + *\param sp \a 1 (default value) means that the parameter \a S is internally computed. + * \a 0 means that the parameter \a S is provided by the user. + */ + LogPolar_Overlapping(int w, int h, Point2i center, int R=70, + double ro0=3.0, int full=1, int S=117, int sp=1); + /** + *Transformation from Cartesian image to cortical (log-polar) image. + *\param source the Cartesian image + *\return the transformed image (cortical image) + */ + const Mat to_cortical(const Mat &source); + /** + *Transformation from cortical image to retinal (inverse log-polar) image. + *\param source the cortical image + *\return the transformed image (retinal image) + */ + const Mat to_cartesian(const Mat &source); + /** + *Destructor + */ + ~LogPolar_Overlapping(); +protected: - class CV_EXPORTS_W StereoVar - { - public: - // Flags - enum {USE_INITIAL_DISPARITY = 1, USE_EQUALIZE_HIST = 2, USE_SMART_ID = 4, USE_AUTO_PARAMS = 8, USE_MEDIAN_FILTERING = 16}; - enum {CYCLE_O, CYCLE_V}; - enum {PENALIZATION_TICHONOV, PENALIZATION_CHARBONNIER, PENALIZATION_PERONA_MALIK}; - - //! the default constructor - CV_WRAP StereoVar(); - - //! the full constructor taking all the necessary algorithm parameters - CV_WRAP StereoVar(int levels, double pyrScale, int nIt, int minDisp, int maxDisp, int poly_n, double poly_sigma, float fi, float lambda, int penalization, int cycle, int flags); - - //! the destructor - virtual ~StereoVar(); - - //! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair - CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, CV_OUT Mat& disp); - - CV_PROP_RW int levels; - CV_PROP_RW double pyrScale; - CV_PROP_RW int nIt; - CV_PROP_RW int minDisp; - CV_PROP_RW int maxDisp; - CV_PROP_RW int poly_n; - CV_PROP_RW double poly_sigma; - CV_PROP_RW float fi; - CV_PROP_RW float lambda; - CV_PROP_RW int penalization; - CV_PROP_RW int cycle; - CV_PROP_RW int flags; - - private: - void autoParams(); - void FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level); - void VCycle_MyFAS(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level); - void VariationalSolver(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level); - }; + Mat Rsri; + Mat Csri; + std::vector Rsr; + std::vector Csr; + std::vector Wsr; - CV_EXPORTS void polyfit(const Mat& srcx, const Mat& srcy, Mat& dst, int order); + int S, R, M, N, ind1; + int top, bottom,left,right; + double ro0, romax, a, q; - class CV_EXPORTS Directory + struct kernel { - public: - static std::vector GetListFiles ( const String& path, const String & exten = "*", bool addPath = true ); - static std::vector GetListFilesR ( const String& path, const String & exten = "*", bool addPath = true ); - static std::vector GetListFolders( const String& path, const String & exten = "*", bool addPath = true ); + kernel() { w = 0; } + std::vector weights; + int w; }; - /* - * Generation of a set of different colors by the following way: - * 1) generate more then need colors (in "factor" times) in RGB, - * 2) convert them to Lab, - * 3) choose the needed count of colors from the set that are more different from - * each other, - * 4) convert the colors back to RGB - */ - CV_EXPORTS void generateColors( std::vector& colors, size_t count, size_t factor=100 ); + Mat ETAyx; + Mat CSIyx; + std::vector w_ker_2D; + void create_map(int M, int N, int R, int S, double ro0); +}; - /* - * Estimate the rigid body motion from frame0 to frame1. The method is based on the paper - * "Real-Time Visual Odometry from Dense RGB-D Images", F. Steinbucker, J. Strum, D. Cremers, ICCV, 2011. - */ - enum { ROTATION = 1, - TRANSLATION = 2, - RIGID_BODY_MOTION = 4 - }; - CV_EXPORTS bool RGBDOdometry( Mat& Rt, const Mat& initRt, - const Mat& image0, const Mat& depth0, const Mat& mask0, - const Mat& image1, const Mat& depth1, const Mat& mask1, - const Mat& cameraMatrix, float minDepth=0.f, float maxDepth=4.f, float maxDepthDiff=0.07f, - const std::vector& iterCounts=std::vector(), - const std::vector& minGradientMagnitudes=std::vector(), - int transformType=RIGID_BODY_MOTION ); +/** +* Adjacent receptive fields technique +* +*All the Cartesian pixels, whose coordinates in the cortical domain share the same integer part, are assigned to the same RF. +*The precision of the boundaries of the RF can be improved by breaking each pixel into subpixels and assigning each of them to the correct RF. +*This technique is implemented from: Traver, V., Pla, F.: Log-polar mapping template design: From task-level requirements +*to geometry parameters. Image Vision Comput. 26(10) (2008) 1354-1370 +* +*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 +*/ +class CV_EXPORTS LogPolar_Adjacent +{ +public: + LogPolar_Adjacent() {} /** - *Bilinear interpolation technique. - * - *The value of a desired cortical pixel is obtained through a bilinear interpolation of the values - *of the four nearest neighbouring Cartesian pixels to the center of the RF. - *The same principle is applied to the inverse transformation. - * - *More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 - */ - class CV_EXPORTS LogPolar_Interp - { - public: - - LogPolar_Interp() {} - - /** - *Constructor - *\param w the width of the input image - *\param h the height of the input image - *\param center the transformation center: where the output precision is maximal - *\param R the number of rings of the cortical image (default value 70 pixel) - *\param ro0 the radius of the blind spot (default value 3 pixel) - *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. - * \a 0 means that the retinal image is computed within the inscribed circle. - *\param S the number of sectors of the cortical image (default value 70 pixel). - * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. - *\param sp \a 1 (default value) means that the parameter \a S is internally computed. - * \a 0 means that the parameter \a S is provided by the user. - */ - LogPolar_Interp(int w, int h, Point2i center, int R=70, double ro0=3.0, - int interp=INTER_LINEAR, int full=1, int S=117, int sp=1); - /** - *Transformation from Cartesian image to cortical (log-polar) image. - *\param source the Cartesian image - *\return the transformed image (cortical image) - */ - const Mat to_cortical(const Mat &source); - /** - *Transformation from cortical image to retinal (inverse log-polar) image. - *\param source the cortical image - *\return the transformed image (retinal image) - */ - const Mat to_cartesian(const Mat &source); - /** - *Destructor - */ - ~LogPolar_Interp(); - - protected: - - Mat Rsri; - Mat Csri; - - int S, R, M, N; - int top, bottom,left,right; - double ro0, romax, a, q; - int interp; - - Mat ETAyx; - Mat CSIyx; - - void create_map(int M, int N, int R, int S, double ro0); - }; - + *Constructor + *\param w the width of the input image + *\param h the height of the input image + *\param center the transformation center: where the output precision is maximal + *\param R the number of rings of the cortical image (default value 70 pixel) + *\param ro0 the radius of the blind spot (default value 3 pixel) + *\param smin the size of the subpixel (default value 0.25 pixel) + *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. + * \a 0 means that the retinal image is computed within the inscribed circle. + *\param S the number of sectors of the cortical image (default value 70 pixel). + * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. + *\param sp \a 1 (default value) means that the parameter \a S is internally computed. + * \a 0 means that the parameter \a S is provided by the user. + */ + LogPolar_Adjacent(int w, int h, Point2i center, int R=70, double ro0=3.0, double smin=0.25, int full=1, int S=117, int sp=1); /** - *Overlapping circular receptive fields technique - * - *The Cartesian plane is divided in two regions: the fovea and the periphery. - *The fovea (oversampling) is handled by using the bilinear interpolation technique described above, whereas in - *the periphery we use the overlapping Gaussian circular RFs. - * - *More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 - */ - class CV_EXPORTS LogPolar_Overlapping - { - public: - LogPolar_Overlapping() {} - - /** - *Constructor - *\param w the width of the input image - *\param h the height of the input image - *\param center the transformation center: where the output precision is maximal - *\param R the number of rings of the cortical image (default value 70 pixel) - *\param ro0 the radius of the blind spot (default value 3 pixel) - *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. - * \a 0 means that the retinal image is computed within the inscribed circle. - *\param S the number of sectors of the cortical image (default value 70 pixel). - * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. - *\param sp \a 1 (default value) means that the parameter \a S is internally computed. - * \a 0 means that the parameter \a S is provided by the user. - */ - LogPolar_Overlapping(int w, int h, Point2i center, int R=70, - double ro0=3.0, int full=1, int S=117, int sp=1); - /** - *Transformation from Cartesian image to cortical (log-polar) image. - *\param source the Cartesian image - *\return the transformed image (cortical image) - */ - const Mat to_cortical(const Mat &source); - /** - *Transformation from cortical image to retinal (inverse log-polar) image. - *\param source the cortical image - *\return the transformed image (retinal image) - */ - const Mat to_cartesian(const Mat &source); - /** - *Destructor - */ - ~LogPolar_Overlapping(); - - protected: - - Mat Rsri; - Mat Csri; - std::vector Rsr; - std::vector Csr; - std::vector Wsr; - - int S, R, M, N, ind1; - int top, bottom,left,right; - double ro0, romax, a, q; - - struct kernel - { - kernel() { w = 0; } - std::vector weights; - int w; - }; - - Mat ETAyx; - Mat CSIyx; - std::vector w_ker_2D; - - void create_map(int M, int N, int R, int S, double ro0); - }; - + *Transformation from Cartesian image to cortical (log-polar) image. + *\param source the Cartesian image + *\return the transformed image (cortical image) + */ + const Mat to_cortical(const Mat &source); /** - * Adjacent receptive fields technique - * - *All the Cartesian pixels, whose coordinates in the cortical domain share the same integer part, are assigned to the same RF. - *The precision of the boundaries of the RF can be improved by breaking each pixel into subpixels and assigning each of them to the correct RF. - *This technique is implemented from: Traver, V., Pla, F.: Log-polar mapping template design: From task-level requirements - *to geometry parameters. Image Vision Comput. 26(10) (2008) 1354-1370 - * - *More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 - */ - class CV_EXPORTS LogPolar_Adjacent + *Transformation from cortical image to retinal (inverse log-polar) image. + *\param source the cortical image + *\return the transformed image (retinal image) + */ + const Mat to_cartesian(const Mat &source); + /** + *Destructor + */ + ~LogPolar_Adjacent(); + +protected: + struct pixel { - public: - LogPolar_Adjacent() {} - - /** - *Constructor - *\param w the width of the input image - *\param h the height of the input image - *\param center the transformation center: where the output precision is maximal - *\param R the number of rings of the cortical image (default value 70 pixel) - *\param ro0 the radius of the blind spot (default value 3 pixel) - *\param smin the size of the subpixel (default value 0.25 pixel) - *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. - * \a 0 means that the retinal image is computed within the inscribed circle. - *\param S the number of sectors of the cortical image (default value 70 pixel). - * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. - *\param sp \a 1 (default value) means that the parameter \a S is internally computed. - * \a 0 means that the parameter \a S is provided by the user. - */ - LogPolar_Adjacent(int w, int h, Point2i center, int R=70, double ro0=3.0, double smin=0.25, int full=1, int S=117, int sp=1); - /** - *Transformation from Cartesian image to cortical (log-polar) image. - *\param source the Cartesian image - *\return the transformed image (cortical image) - */ - const Mat to_cortical(const Mat &source); - /** - *Transformation from cortical image to retinal (inverse log-polar) image. - *\param source the cortical image - *\return the transformed image (retinal image) - */ - const Mat to_cartesian(const Mat &source); - /** - *Destructor - */ - ~LogPolar_Adjacent(); - - protected: - struct pixel - { - pixel() { u = v = 0; a = 0.; } - int u; - int v; - double a; - }; - int S, R, M, N; - int top, bottom,left,right; - double ro0, romax, a, q; - std::vector > L; - std::vector A; - - void subdivide_recursively(double x, double y, int i, int j, double length, double smin); - bool get_uv(double x, double y, int&u, int&v); - void create_map(int M, int N, int R, int S, double ro0, double smin); + pixel() { u = v = 0; a = 0.; } + int u; + int v; + double a; }; + int S, R, M, N; + int top, bottom,left,right; + double ro0, romax, a, q; + std::vector > L; + std::vector A; + + void subdivide_recursively(double x, double y, int i, int j, double length, double smin); + bool get_uv(double x, double y, int&u, int&v); + void create_map(int M, int N, int R, int S, double ro0, double smin); +}; - CV_EXPORTS Mat subspaceProject(InputArray W, InputArray mean, InputArray src); - CV_EXPORTS Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src); +CV_EXPORTS Mat subspaceProject(InputArray W, InputArray mean, InputArray src); +CV_EXPORTS Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src); - class CV_EXPORTS LDA +class CV_EXPORTS LDA +{ +public: + // Initializes a LDA with num_components (default 0) and specifies how + // samples are aligned (default dataAsRow=true). + LDA(int num_components = 0) : + _num_components(num_components) {}; + + // Initializes and performs a Discriminant Analysis with Fisher's + // Optimization Criterion on given data in src and corresponding labels + // in labels. If 0 (or less) number of components are given, they are + // automatically determined for given data in computation. + LDA(InputArrayOfArrays src, InputArray labels, + int num_components = 0) : + _num_components(num_components) { - public: - // Initializes a LDA with num_components (default 0) and specifies how - // samples are aligned (default dataAsRow=true). - LDA(int num_components = 0) : - _num_components(num_components) {}; + this->compute(src, labels); //! compute eigenvectors and eigenvalues + } - // Initializes and performs a Discriminant Analysis with Fisher's - // Optimization Criterion on given data in src and corresponding labels - // in labels. If 0 (or less) number of components are given, they are - // automatically determined for given data in computation. - LDA(InputArrayOfArrays src, InputArray labels, - int num_components = 0) : - _num_components(num_components) - { - this->compute(src, labels); //! compute eigenvectors and eigenvalues - } + // Serializes this object to a given filename. + void save(const String& filename) const; - // Serializes this object to a given filename. - void save(const String& filename) const; + // Deserializes this object from a given filename. + void load(const String& filename); - // Deserializes this object from a given filename. - void load(const String& filename); + // Serializes this object to a given cv::FileStorage. + void save(FileStorage& fs) const; - // Serializes this object to a given cv::FileStorage. - void save(FileStorage& fs) const; - - // Deserializes this object from a given cv::FileStorage. - void load(const FileStorage& node); + // Deserializes this object from a given cv::FileStorage. + void load(const FileStorage& node); - // Destructor. - ~LDA() {} + // Destructor. + ~LDA() {} - //! Compute the discriminants for data in src and labels. - void compute(InputArrayOfArrays src, InputArray labels); + //! Compute the discriminants for data in src and labels. + void compute(InputArrayOfArrays src, InputArray labels); - // Projects samples into the LDA subspace. - Mat project(InputArray src); + // Projects samples into the LDA subspace. + Mat project(InputArray src); - // Reconstructs projections from the LDA subspace. - Mat reconstruct(InputArray src); + // Reconstructs projections from the LDA subspace. + Mat reconstruct(InputArray src); - // Returns the eigenvectors of this LDA. - Mat eigenvectors() const { return _eigenvectors; }; + // Returns the eigenvectors of this LDA. + Mat eigenvectors() const { return _eigenvectors; }; - // Returns the eigenvalues of this LDA. - Mat eigenvalues() const { return _eigenvalues; } + // Returns the eigenvalues of this LDA. + Mat eigenvalues() const { return _eigenvalues; } - protected: - bool _dataAsRow; - int _num_components; - Mat _eigenvectors; - Mat _eigenvalues; +protected: + bool _dataAsRow; + int _num_components; + Mat _eigenvectors; + Mat _eigenvalues; - void lda(InputArrayOfArrays src, InputArray labels); - }; + void lda(InputArrayOfArrays src, InputArray labels); +}; - class CV_EXPORTS_W FaceRecognizer : public Algorithm - { - public: - //! virtual destructor - virtual ~FaceRecognizer() {} +class CV_EXPORTS_W FaceRecognizer : public Algorithm +{ +public: + //! virtual destructor + virtual ~FaceRecognizer() {} - // Trains a FaceRecognizer. - CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0; + // Trains a FaceRecognizer. + CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0; - // Updates a FaceRecognizer. - CV_WRAP virtual void update(InputArrayOfArrays src, InputArray labels); + // Updates a FaceRecognizer. + CV_WRAP virtual void update(InputArrayOfArrays src, InputArray labels); - // Gets a prediction from a FaceRecognizer. - virtual int predict(InputArray src) const = 0; + // Gets a prediction from a FaceRecognizer. + virtual int predict(InputArray src) const = 0; - // Predicts the label and confidence for a given sample. - CV_WRAP virtual void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) const = 0; + // Predicts the label and confidence for a given sample. + CV_WRAP virtual void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) const = 0; - // Serializes this object to a given filename. - CV_WRAP virtual void save(const String& filename) const; + // Serializes this object to a given filename. + CV_WRAP virtual void save(const String& filename) const; - // Deserializes this object from a given filename. - CV_WRAP virtual void load(const String& filename); + // Deserializes this object from a given filename. + CV_WRAP virtual void load(const String& filename); - // Serializes this object to a given cv::FileStorage. - virtual void save(FileStorage& fs) const = 0; + // Serializes this object to a given cv::FileStorage. + virtual void save(FileStorage& fs) const = 0; - // Deserializes this object from a given cv::FileStorage. - virtual void load(const FileStorage& fs) = 0; + // Deserializes this object from a given cv::FileStorage. + virtual void load(const FileStorage& fs) = 0; - }; +}; - CV_EXPORTS_W Ptr createEigenFaceRecognizer(int num_components = 0, double threshold = DBL_MAX); - CV_EXPORTS_W Ptr createFisherFaceRecognizer(int num_components = 0, double threshold = DBL_MAX); - CV_EXPORTS_W Ptr createLBPHFaceRecognizer(int radius=1, int neighbors=8, - int grid_x=8, int grid_y=8, double threshold = DBL_MAX); +CV_EXPORTS_W Ptr createEigenFaceRecognizer(int num_components = 0, double threshold = DBL_MAX); +CV_EXPORTS_W Ptr createFisherFaceRecognizer(int num_components = 0, double threshold = DBL_MAX); +CV_EXPORTS_W Ptr createLBPHFaceRecognizer(int radius=1, int neighbors=8, + int grid_x=8, int grid_y=8, double threshold = DBL_MAX); - enum - { - COLORMAP_AUTUMN = 0, - COLORMAP_BONE = 1, - COLORMAP_JET = 2, - COLORMAP_WINTER = 3, - COLORMAP_RAINBOW = 4, - COLORMAP_OCEAN = 5, - COLORMAP_SUMMER = 6, - COLORMAP_SPRING = 7, - COLORMAP_COOL = 8, - COLORMAP_HSV = 9, - COLORMAP_PINK = 10, - COLORMAP_HOT = 11 - }; +enum +{ + COLORMAP_AUTUMN = 0, + COLORMAP_BONE = 1, + COLORMAP_JET = 2, + COLORMAP_WINTER = 3, + COLORMAP_RAINBOW = 4, + COLORMAP_OCEAN = 5, + COLORMAP_SUMMER = 6, + COLORMAP_SPRING = 7, + COLORMAP_COOL = 8, + COLORMAP_HSV = 9, + COLORMAP_PINK = 10, + COLORMAP_HOT = 11 +}; - CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap); +CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap); - CV_EXPORTS bool initModule_contrib(); +CV_EXPORTS bool initModule_contrib(); } #include "opencv2/contrib/retina.hpp" - #include "opencv2/contrib/openfabmap.hpp" #endif - -#endif diff --git a/modules/contrib/include/opencv2/contrib/compat.hpp b/modules/contrib/include/opencv2/contrib/compat.hpp new file mode 100644 index 0000000000..ba758c235f --- /dev/null +++ b/modules/contrib/include/opencv2/contrib/compat.hpp @@ -0,0 +1,384 @@ +/*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-2011, Willow Garage Inc., 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_CONTRIB_COMPAT_HPP__ +#define __OPENCV_CONTRIB_COMPAT_HPP__ + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus + +/****************************************************************************************\ +* Adaptive Skin Detector * +\****************************************************************************************/ + +class CV_EXPORTS CvAdaptiveSkinDetector +{ +private: + enum { + GSD_HUE_LT = 3, + GSD_HUE_UT = 33, + GSD_INTENSITY_LT = 15, + GSD_INTENSITY_UT = 250 + }; + + class CV_EXPORTS Histogram + { + private: + enum { + HistogramSize = (GSD_HUE_UT - GSD_HUE_LT + 1) + }; + + protected: + int findCoverageIndex(double surfaceToCover, int defaultValue = 0); + + public: + CvHistogram *fHistogram; + Histogram(); + virtual ~Histogram(); + + void findCurveThresholds(int &x1, int &x2, double percent = 0.05); + void mergeWith(Histogram *source, double weight); + }; + + int nStartCounter, nFrameCount, nSkinHueLowerBound, nSkinHueUpperBound, nMorphingMethod, nSamplingDivider; + double fHistogramMergeFactor, fHuePercentCovered; + Histogram histogramHueMotion, skinHueHistogram; + IplImage *imgHueFrame, *imgSaturationFrame, *imgLastGrayFrame, *imgMotionFrame, *imgFilteredFrame; + IplImage *imgShrinked, *imgTemp, *imgGrayFrame, *imgHSVFrame; + +protected: + void initData(IplImage *src, int widthDivider, int heightDivider); + void adaptiveFilter(); + +public: + + enum { + MORPHING_METHOD_NONE = 0, + MORPHING_METHOD_ERODE = 1, + MORPHING_METHOD_ERODE_ERODE = 2, + MORPHING_METHOD_ERODE_DILATE = 3 + }; + + CvAdaptiveSkinDetector(int samplingDivider = 1, int morphingMethod = MORPHING_METHOD_NONE); + virtual ~CvAdaptiveSkinDetector(); + + virtual void process(IplImage *inputBGRImage, IplImage *outputHueMask); +}; + + +/****************************************************************************************\ + * Fuzzy MeanShift Tracker * + \****************************************************************************************/ + +class CV_EXPORTS CvFuzzyPoint { +public: + double x, y, value; + + CvFuzzyPoint(double _x, double _y); +}; + +class CV_EXPORTS CvFuzzyCurve { +private: + std::vector points; + double value, centre; + + bool between(double x, double x1, double x2); + +public: + CvFuzzyCurve(); + ~CvFuzzyCurve(); + + void setCentre(double _centre); + double getCentre(); + void clear(); + void addPoint(double x, double y); + double calcValue(double param); + double getValue(); + void setValue(double _value); +}; + +class CV_EXPORTS CvFuzzyFunction { +public: + std::vector curves; + + CvFuzzyFunction(); + ~CvFuzzyFunction(); + void addCurve(CvFuzzyCurve *curve, double value = 0); + void resetValues(); + double calcValue(); + CvFuzzyCurve *newCurve(); +}; + +class CV_EXPORTS CvFuzzyRule { +private: + CvFuzzyCurve *fuzzyInput1, *fuzzyInput2; + CvFuzzyCurve *fuzzyOutput; +public: + CvFuzzyRule(); + ~CvFuzzyRule(); + void setRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1); + double calcValue(double param1, double param2); + CvFuzzyCurve *getOutputCurve(); +}; + +class CV_EXPORTS CvFuzzyController { +private: + std::vector rules; +public: + CvFuzzyController(); + ~CvFuzzyController(); + void addRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1); + double calcOutput(double param1, double param2); +}; + +class CV_EXPORTS CvFuzzyMeanShiftTracker +{ +private: + class FuzzyResizer + { + private: + CvFuzzyFunction iInput, iOutput; + CvFuzzyController fuzzyController; + public: + FuzzyResizer(); + int calcOutput(double edgeDensity, double density); + }; + + class SearchWindow + { + public: + FuzzyResizer *fuzzyResizer; + int x, y; + int width, height, maxWidth, maxHeight, ellipseHeight, ellipseWidth; + int ldx, ldy, ldw, ldh, numShifts, numIters; + int xGc, yGc; + long m00, m01, m10, m11, m02, m20; + double ellipseAngle; + double density; + unsigned int depthLow, depthHigh; + int verticalEdgeLeft, verticalEdgeRight, horizontalEdgeTop, horizontalEdgeBottom; + + SearchWindow(); + ~SearchWindow(); + void setSize(int _x, int _y, int _width, int _height); + void initDepthValues(IplImage *maskImage, IplImage *depthMap); + bool shift(); + void extractInfo(IplImage *maskImage, IplImage *depthMap, bool initDepth); + void getResizeAttribsEdgeDensityLinear(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); + void getResizeAttribsInnerDensity(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); + void getResizeAttribsEdgeDensityFuzzy(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); + bool meanShift(IplImage *maskImage, IplImage *depthMap, int maxIteration, bool initDepth); + }; + +public: + enum TrackingState + { + tsNone = 0, + tsSearching = 1, + tsTracking = 2, + tsSetWindow = 3, + tsDisabled = 10 + }; + + enum ResizeMethod { + rmEdgeDensityLinear = 0, + rmEdgeDensityFuzzy = 1, + rmInnerDensity = 2 + }; + + enum { + MinKernelMass = 1000 + }; + + SearchWindow kernel; + int searchMode; + +private: + enum + { + MaxMeanShiftIteration = 5, + MaxSetSizeIteration = 5 + }; + + void findOptimumSearchWindow(SearchWindow &searchWindow, IplImage *maskImage, IplImage *depthMap, int maxIteration, int resizeMethod, bool initDepth); + +public: + CvFuzzyMeanShiftTracker(); + ~CvFuzzyMeanShiftTracker(); + + void track(IplImage *maskImage, IplImage *depthMap, int resizeMethod, bool resetSearch, int minKernelMass = MinKernelMass); +}; + + +namespace cv +{ + +typedef bool (*BundleAdjustCallback)(int iteration, double norm_error, void* user_data); + +class CV_EXPORTS LevMarqSparse { +public: + LevMarqSparse(); + LevMarqSparse(int npoints, // number of points + int ncameras, // number of cameras + int nPointParams, // number of params per one point (3 in case of 3D points) + int nCameraParams, // number of parameters per one camera + int nErrParams, // number of parameters in measurement vector + // for 1 point at one camera (2 in case of 2D projections) + Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras + // 1 - point is visible for the camera, 0 - invisible + Mat& P0, // starting vector of parameters, first cameras then points + Mat& X, // measurements, in order of visibility. non visible cases are skipped + TermCriteria criteria, // termination criteria + + // callback for estimation of Jacobian matrices + void (*fjac)(int i, int j, Mat& point_params, + Mat& cam_params, Mat& A, Mat& B, void* data), + // callback for estimation of backprojection errors + void (*func)(int i, int j, Mat& point_params, + Mat& cam_params, Mat& estim, void* data), + void* data, // user-specific data passed to the callbacks + BundleAdjustCallback cb, void* user_data + ); + + virtual ~LevMarqSparse(); + + virtual void run( int npoints, // number of points + int ncameras, // number of cameras + int nPointParams, // number of params per one point (3 in case of 3D points) + int nCameraParams, // number of parameters per one camera + int nErrParams, // number of parameters in measurement vector + // for 1 point at one camera (2 in case of 2D projections) + Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras + // 1 - point is visible for the camera, 0 - invisible + Mat& P0, // starting vector of parameters, first cameras then points + Mat& X, // measurements, in order of visibility. non visible cases are skipped + TermCriteria criteria, // termination criteria + + // callback for estimation of Jacobian matrices + void (CV_CDECL * fjac)(int i, int j, Mat& point_params, + Mat& cam_params, Mat& A, Mat& B, void* data), + // callback for estimation of backprojection errors + void (CV_CDECL * func)(int i, int j, Mat& point_params, + Mat& cam_params, Mat& estim, void* data), + void* data // user-specific data passed to the callbacks + ); + + virtual void clear(); + + // useful function to do simple bundle adjustment tasks + static void bundleAdjust(std::vector& points, // positions of points in global coordinate system (input and output) + const std::vector >& imagePoints, // projections of 3d points for every camera + const std::vector >& visibility, // visibility of 3d points for every camera + std::vector& cameraMatrix, // intrinsic matrices of all cameras (input and output) + std::vector& R, // rotation matrices of all cameras (input and output) + std::vector& T, // translation vector of all cameras (input and output) + std::vector& distCoeffs, // distortion coefficients of all cameras (input and output) + const TermCriteria& criteria= + TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON), + BundleAdjustCallback cb = 0, void* user_data = 0); + +public: + virtual void optimize(CvMat &_vis); //main function that runs minimization + + //iteratively asks for measurement for visible camera-point pairs + void ask_for_proj(CvMat &_vis,bool once=false); + //iteratively asks for Jacobians for every camera_point pair + void ask_for_projac(CvMat &_vis); + + CvMat* err; //error X-hX + double prevErrNorm, errNorm; + double lambda; + CvTermCriteria criteria; + int iters; + + CvMat** U; //size of array is equal to number of cameras + CvMat** V; //size of array is equal to number of points + CvMat** inv_V_star; //inverse of V* + + CvMat** A; + CvMat** B; + CvMat** W; + + CvMat* X; //measurement + CvMat* hX; //current measurement extimation given new parameter vector + + CvMat* prevP; //current already accepted parameter. + CvMat* P; // parameters used to evaluate function with new params + // this parameters may be rejected + + CvMat* deltaP; //computed increase of parameters (result of normal system solution ) + + CvMat** ea; // sum_i AijT * e_ij , used as right part of normal equation + // length of array is j = number of cameras + CvMat** eb; // sum_j BijT * e_ij , used as right part of normal equation + // length of array is i = number of points + + CvMat** Yj; //length of array is i = num_points + + CvMat* S; //big matrix of block Sjk , each block has size num_cam_params x num_cam_params + + CvMat* JtJ_diag; //diagonal of JtJ, used to backup diagonal elements before augmentation + + CvMat* Vis_index; // matrix which element is index of measurement for point i and camera j + + int num_cams; + int num_points; + int num_err_param; + int num_cam_param; + int num_point_param; + + //target function and jacobian pointers, which needs to be initialized + void (*fjac)(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data); + void (*func)(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data); + + void* data; + + BundleAdjustCallback cb; + void* user_data; +}; + +} // cv + +#endif /* __cplusplus */ + +#endif /* __OPENCV_CONTRIB_COMPAT_HPP__ */ diff --git a/modules/contrib/src/adaptiveskindetector.cpp b/modules/contrib/src/adaptiveskindetector.cpp index 35d945837e..1448e63842 100644 --- a/modules/contrib/src/adaptiveskindetector.cpp +++ b/modules/contrib/src/adaptiveskindetector.cpp @@ -36,6 +36,7 @@ #include "precomp.hpp" #include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/contrib/compat.hpp" #define ASD_INTENSITY_SET_PIXEL(pointer, qq) {(*pointer) = (unsigned char)qq;} diff --git a/modules/contrib/src/ba.cpp b/modules/contrib/src/ba.cpp index 8e4faf2216..ff58073fc9 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/contrib/compat.hpp" #include "opencv2/calib3d/calib3d_c.h" #include diff --git a/modules/contrib/src/chamfermatching.cpp b/modules/contrib/src/chamfermatching.cpp index 16ac947d63..fd2899c5f0 100644 --- a/modules/contrib/src/chamfermatching.cpp +++ b/modules/contrib/src/chamfermatching.cpp @@ -142,7 +142,7 @@ private: LocationScaleImageRange(const std::vector& locations, const std::vector& _scales) : locations_(locations), scales_(_scales) { - assert(locations.size()==_scales.size()); + CV_Assert(locations.size()==_scales.size()); } ImageIterator* iterator() const @@ -393,7 +393,7 @@ private: LocationScaleImageIterator(const std::vector& locations, const std::vector& _scales) : locations_(locations), scales_(_scales) { - assert(locations.size()==_scales.size()); + CV_Assert(locations.size()==_scales.size()); reset(); } @@ -622,7 +622,7 @@ void ChamferMatcher::Matching::followContour(Mat& templ_img, template_coords_t& coordinate_t next; unsigned char ptr; - assert (direction==-1 || !coords.empty()); + CV_Assert (direction==-1 || !coords.empty()); coordinate_t crt = coords.back(); @@ -903,18 +903,18 @@ void ChamferMatcher::Template::show() const p2.x = x + pad*(int)(sin(orientations[i])*100)/100; p2.y = y + pad*(int)(cos(orientations[i])*100)/100; - line(templ_color, p1,p2, CV_RGB(255,0,0)); + line(templ_color, p1,p2, Scalar(255,0,0)); } } - circle(templ_color,Point(center.x + pad, center.y + pad),1,CV_RGB(0,255,0)); + circle(templ_color,Point(center.x + pad, center.y + pad),1,Scalar(0,255,0)); #ifdef HAVE_OPENCV_HIGHGUI namedWindow("templ",1); imshow("templ",templ_color); waitKey(); #else - CV_Error(CV_StsNotImplemented, "OpenCV has been compiled without GUI support"); + CV_Error(Error::StsNotImplemented, "OpenCV has been compiled without GUI support"); #endif templ_color.release(); @@ -1059,7 +1059,7 @@ void ChamferMatcher::Matching::fillNonContourOrientations(Mat& annotated_img, Ma int cols = annotated_img.cols; int rows = annotated_img.rows; - assert(orientation_img.cols==cols && orientation_img.rows==rows); + CV_Assert(orientation_img.cols==cols && orientation_img.rows==rows); for (int y=0;ycoords; for (size_t i=0;i indices = _indices.getMat(); _dst.create(src.rows, src.cols, src.type()); @@ -64,8 +64,8 @@ static Mat argsort(InputArray _src, bool ascending=true) { Mat src = _src.getMat(); if (src.rows != 1 && src.cols != 1) - CV_Error(CV_StsBadArg, "cv::argsort only sorts 1D matrices."); - int flags = CV_SORT_EVERY_ROW+(ascending ? CV_SORT_ASCENDING : CV_SORT_DESCENDING); + CV_Error(Error::StsBadArg, "cv::argsort only sorts 1D matrices."); + int flags = SORT_EVERY_ROW | (ascending ? SORT_ASCENDING : SORT_DESCENDING); Mat sorted_indices; sortIdx(src.reshape(1,1),sorted_indices,flags); return sorted_indices; @@ -116,8 +116,8 @@ static Mat interp1(InputArray _x, InputArray _Y, InputArray _xi) Mat Y = _Y.getMat(); Mat xi = _xi.getMat(); // check types & alignment - assert((x.type() == Y.type()) && (Y.type() == xi.type())); - assert((x.cols == 1) && (x.rows == Y.rows) && (x.cols == Y.cols)); + CV_Assert((x.type() == Y.type()) && (Y.type() == xi.type())); + CV_Assert((x.cols == 1) && (x.rows == Y.rows) && (x.cols == Y.cols)); // call templated interp1 switch(x.type()) { case CV_8SC1: return interp1_(x,Y,xi); break; @@ -127,7 +127,7 @@ static Mat interp1(InputArray _x, InputArray _Y, InputArray _xi) case CV_32SC1: return interp1_(x,Y,xi); break; case CV_32FC1: return interp1_(x,Y,xi); break; case CV_64FC1: return interp1_(x,Y,xi); break; - default: CV_Error(CV_StsUnsupportedFormat, ""); break; + default: CV_Error(Error::StsUnsupportedFormat, ""); break; } return Mat(); } @@ -473,7 +473,7 @@ namespace colormap void ColorMap::operator()(InputArray _src, OutputArray _dst) const { if(_lut.total() != 256) - CV_Error(CV_StsAssert, "cv::LUT only supports tables of size 256."); + CV_Error(Error::StsAssert, "cv::LUT only supports tables of size 256."); Mat src = _src.getMat(); // Return original matrix if wrong type is given (is fail loud better here?) if(src.type() != CV_8UC1 && src.type() != CV_8UC3) @@ -521,7 +521,7 @@ namespace colormap colormap == COLORMAP_WINTER ? (colormap::ColorMap*)(new colormap::Winter) : 0; if( !cm ) - CV_Error( CV_StsBadArg, "Unknown colormap id; use one of COLORMAP_*"); + CV_Error( Error::StsBadArg, "Unknown colormap id; use one of COLORMAP_*"); (*cm)(src, dst); diff --git a/modules/contrib/src/facerec.cpp b/modules/contrib/src/facerec.cpp index bb1d21e96a..8fc401d559 100644 --- a/modules/contrib/src/facerec.cpp +++ b/modules/contrib/src/facerec.cpp @@ -51,7 +51,7 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double // make sure the input data is a vector of matrices or vector of vector if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) { String error_message = "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector) or _InputArray::STD_VECTOR_VECTOR (a std::vector< std::vector<...> >)."; - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // number of samples size_t n = src.total(); @@ -67,7 +67,7 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double // make sure data can be reshaped, throw exception if not! if(src.getMat(i).total() != d) { String error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src.getMat(i).total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // get a hold of the current row Mat xi = data.row(i); @@ -306,13 +306,13 @@ void FaceRecognizer::update(InputArrayOfArrays src, InputArray labels ) { } String error_msg = format("This FaceRecognizer (%s) does not support updating, you have to use FaceRecognizer::train to update it.", this->name().c_str()); - CV_Error(CV_StsNotImplemented, error_msg); + CV_Error(Error::StsNotImplemented, error_msg); } void FaceRecognizer::save(const String& filename) const { FileStorage fs(filename, FileStorage::WRITE); if (!fs.isOpened()) - CV_Error(CV_StsError, "File can't be opened for writing!"); + CV_Error(Error::StsError, "File can't be opened for writing!"); this->save(fs); fs.release(); } @@ -320,7 +320,7 @@ void FaceRecognizer::save(const String& filename) const { void FaceRecognizer::load(const String& filename) { FileStorage fs(filename, FileStorage::READ); if (!fs.isOpened()) - CV_Error(CV_StsError, "File can't be opened for writing!"); + CV_Error(Error::StsError, "File can't be opened for writing!"); this->load(fs); fs.release(); } @@ -331,17 +331,17 @@ void FaceRecognizer::load(const String& filename) { void Eigenfaces::train(InputArrayOfArrays _src, InputArray _local_labels) { if(_src.total() == 0) { String error_message = format("Empty training data was given. You'll need more than one sample to learn a model."); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } else if(_local_labels.getMat().type() != CV_32SC1) { String error_message = format("Labels must be given as integer (CV_32SC1). Expected %d, but was %d.", CV_32SC1, _local_labels.type()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // make sure data has correct size if(_src.total() > 1) { for(int i = 1; i < static_cast(_src.total()); i++) { if(_src.getMat(i-1).total() != _src.getMat(i).total()) { String error_message = format("In the Eigenfaces method all input samples (training images) must be of equal size! Expected %d pixels, but was %d pixels.", _src.getMat(i-1).total(), _src.getMat(i).total()); - CV_Error(CV_StsUnsupportedFormat, error_message); + CV_Error(Error::StsUnsupportedFormat, error_message); } } } @@ -355,7 +355,7 @@ void Eigenfaces::train(InputArrayOfArrays _src, InputArray _local_labels) { // assert there are as much samples as labels if(static_cast(labels.total()) != n) { String error_message = format("The number of samples (src) must equal the number of labels (labels)! len(src)=%d, len(labels)=%d.", n, labels.total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // clear existing model data _labels.release(); @@ -365,7 +365,7 @@ void Eigenfaces::train(InputArrayOfArrays _src, InputArray _local_labels) { _num_components = n; // perform the PCA - PCA pca(data, Mat(), CV_PCA_DATA_AS_ROW, _num_components); + PCA pca(data, Mat(), PCA::DATA_AS_ROW, _num_components); // copy the PCA results _mean = pca.mean.reshape(1,1); // store the mean vector _eigenvalues = pca.eigenvalues.clone(); // eigenvalues by row @@ -386,11 +386,11 @@ void Eigenfaces::predict(InputArray _src, int &minClass, double &minDist) const if(_projections.empty()) { // throw error if no data (or simply return -1?) String error_message = "This Eigenfaces model is not computed yet. Did you call Eigenfaces::train?"; - CV_Error(CV_StsError, error_message); + CV_Error(Error::StsError, error_message); } else if(_eigenvectors.rows != static_cast(src.total())) { // check data alignment just for clearer exception messages String error_message = format("Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with %d elements, but got %d.", _eigenvectors.rows, src.total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // project into PCA subspace Mat q = subspaceProject(_eigenvectors, _mean, src.reshape(1,1)); @@ -440,17 +440,17 @@ void Eigenfaces::save(FileStorage& fs) const { void Fisherfaces::train(InputArrayOfArrays src, InputArray _lbls) { if(src.total() == 0) { String error_message = format("Empty training data was given. You'll need more than one sample to learn a model."); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } else if(_lbls.getMat().type() != CV_32SC1) { String error_message = format("Labels must be given as integer (CV_32SC1). Expected %d, but was %d.", CV_32SC1, _lbls.type()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // make sure data has correct size if(src.total() > 1) { for(int i = 1; i < static_cast(src.total()); i++) { if(src.getMat(i-1).total() != src.getMat(i).total()) { String error_message = format("In the Fisherfaces method all input samples (training images) must be of equal size! Expected %d pixels, but was %d pixels.", src.getMat(i-1).total(), src.getMat(i).total()); - CV_Error(CV_StsUnsupportedFormat, error_message); + CV_Error(Error::StsUnsupportedFormat, error_message); } } } @@ -462,10 +462,10 @@ void Fisherfaces::train(InputArrayOfArrays src, InputArray _lbls) { // make sure labels are passed in correct shape if(labels.total() != (size_t) N) { String error_message = format("The number of samples (src) must equal the number of labels (labels)! len(src)=%d, len(labels)=%d.", N, labels.total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } else if(labels.rows != 1 && labels.cols != 1) { String error_message = format("Expected the labels in a matrix with one row or column! Given dimensions are rows=%s, cols=%d.", labels.rows, labels.cols); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // clear existing model data _labels.release(); @@ -481,7 +481,7 @@ void Fisherfaces::train(InputArrayOfArrays src, InputArray _lbls) { if((_num_components <= 0) || (_num_components > (C-1))) _num_components = (C-1); // perform a PCA and keep (N-C) components - PCA pca(data, Mat(), CV_PCA_DATA_AS_ROW, (N-C)); + PCA pca(data, Mat(), PCA::DATA_AS_ROW, (N-C)); // project the data and perform a LDA on it LDA lda(pca.project(data),labels, _num_components); // store the total mean vector @@ -506,10 +506,10 @@ void Fisherfaces::predict(InputArray _src, int &minClass, double &minDist) const if(_projections.empty()) { // throw error if no data (or simply return -1?) String error_message = "This Fisherfaces model is not computed yet. Did you call Fisherfaces::train?"; - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } else if(src.total() != (size_t) _eigenvectors.rows) { String error_message = format("Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with %d elements, but got %d.", _eigenvectors.rows, src.total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // project into LDA subspace Mat q = subspaceProject(_eigenvectors, _mean, src.reshape(1,1)); @@ -641,7 +641,7 @@ static void elbp(InputArray src, OutputArray dst, int radius, int neighbors) case CV_64FC1: elbp_(src,dst, radius, neighbors); break; default: String error_msg = format("Using Original Local Binary Patterns for feature extraction only works on single-channel images (given %d). Please pass the image data as a grayscale image!", type); - CV_Error(CV_StsNotImplemented, error_msg); + CV_Error(Error::StsNotImplemented, error_msg); break; } } @@ -687,7 +687,7 @@ static Mat histc(InputArray _src, int minVal, int maxVal, bool normed) return histc_(src, minVal, maxVal, normed); break; default: - CV_Error(CV_StsUnmatchedFormats, "This type is not implemented yet."); break; + CV_Error(Error::StsUnmatchedFormats, "This type is not implemented yet."); break; } return Mat(); } @@ -769,14 +769,14 @@ void LBPH::update(InputArrayOfArrays _in_src, InputArray _in_labels) { void LBPH::train(InputArrayOfArrays _in_src, InputArray _in_labels, bool preserveData) { if(_in_src.kind() != _InputArray::STD_VECTOR_MAT && _in_src.kind() != _InputArray::STD_VECTOR_VECTOR) { String error_message = "The images are expected as InputArray::STD_VECTOR_MAT (a std::vector) or _InputArray::STD_VECTOR_VECTOR (a std::vector< std::vector<...> >)."; - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } if(_in_src.total() == 0) { String error_message = format("Empty training data was given. You'll need more than one sample to learn a model."); - CV_Error(CV_StsUnsupportedFormat, error_message); + CV_Error(Error::StsUnsupportedFormat, error_message); } else if(_in_labels.getMat().type() != CV_32SC1) { String error_message = format("Labels must be given as integer (CV_32SC1). Expected %d, but was %d.", CV_32SC1, _in_labels.type()); - CV_Error(CV_StsUnsupportedFormat, error_message); + CV_Error(Error::StsUnsupportedFormat, error_message); } // get the vector of matrices std::vector src; @@ -786,7 +786,7 @@ void LBPH::train(InputArrayOfArrays _in_src, InputArray _in_labels, bool preserv // check if data is well- aligned if(labels.total() != src.size()) { String error_message = format("The number of samples (src) must equal the number of labels (labels). Was len(samples)=%d, len(labels)=%d.", src.size(), _labels.total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // if this model should be trained without preserving old data, delete old model data if(!preserveData) { @@ -817,7 +817,7 @@ void LBPH::predict(InputArray _src, int &minClass, double &minDist) const { if(_histograms.empty()) { // throw error if no data (or simply return -1?) String error_message = "This LBPH model is not computed yet. Did you call the train method?"; - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } Mat src = _src.getMat(); // get the spatial histogram from input image diff --git a/modules/contrib/src/fuzzymeanshifttracker.cpp b/modules/contrib/src/fuzzymeanshifttracker.cpp index c83f915b03..7ad8cd838e 100644 --- a/modules/contrib/src/fuzzymeanshifttracker.cpp +++ b/modules/contrib/src/fuzzymeanshifttracker.cpp @@ -35,6 +35,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/contrib/compat.hpp" CvFuzzyPoint::CvFuzzyPoint(double _x, double _y) { diff --git a/modules/contrib/src/gencolors.cpp b/modules/contrib/src/gencolors.cpp index 688c98d9ff..24796ec03d 100644 --- a/modules/contrib/src/gencolors.cpp +++ b/modules/contrib/src/gencolors.cpp @@ -85,7 +85,7 @@ static void downsamplePoints( const Mat& src, Mat& dst, size_t count ) candidatePointsMask.at(0, maxLoc.x) = 0; Mat minDists; - reduce( activedDists, minDists, 0, CV_REDUCE_MIN ); + reduce( activedDists, minDists, 0, REDUCE_MIN ); minMaxLoc( minDists, 0, &maxVal, 0, &maxLoc, candidatePointsMask ); dst.at >((int)i) = src.at >(maxLoc.x); } diff --git a/modules/contrib/src/lda.cpp b/modules/contrib/src/lda.cpp index e643529ae0..60693fc772 100644 --- a/modules/contrib/src/lda.cpp +++ b/modules/contrib/src/lda.cpp @@ -43,9 +43,9 @@ static Mat argsort(InputArray _src, bool ascending=true) Mat src = _src.getMat(); if (src.rows != 1 && src.cols != 1) { String error_message = "Wrong shape of input matrix! Expected a matrix with one row or column."; - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } - int flags = CV_SORT_EVERY_ROW+(ascending ? CV_SORT_ASCENDING : CV_SORT_DESCENDING); + int flags = SORT_EVERY_ROW | (ascending ? SORT_ASCENDING : SORT_DESCENDING); Mat sorted_indices; sortIdx(src.reshape(1,1),sorted_indices,flags); return sorted_indices; @@ -55,7 +55,7 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double // make sure the input data is a vector of matrices or vector of vector if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) { String error_message = "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector) or _InputArray::STD_VECTOR_VECTOR (a std::vector< std::vector<...> >)."; - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // number of samples size_t n = src.total(); @@ -71,7 +71,7 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double // make sure data can be reshaped, throw exception if not! if(src.getMat(i).total() != d) { String error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, (int)d, (int)src.getMat(i).total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // get a hold of the current row Mat xi = data.row(i); @@ -87,7 +87,7 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double static void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) { if(_indices.getMat().type() != CV_32SC1) { - CV_Error(CV_StsUnsupportedFormat, "cv::sortColumnsByIndices only works on integer indices!"); + CV_Error(Error::StsUnsupportedFormat, "cv::sortColumnsByIndices only works on integer indices!"); } Mat src = _src.getMat(); std::vector indices = _indices.getMat(); @@ -179,12 +179,12 @@ Mat subspaceProject(InputArray _W, InputArray _mean, InputArray _src) { // make sure the data has the correct shape if(W.rows != d) { String error_message = format("Wrong shapes for given matrices. Was size(src) = (%d,%d), size(W) = (%d,%d).", src.rows, src.cols, W.rows, W.cols); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // make sure mean is correct if not empty if(!mean.empty() && (mean.total() != (size_t) d)) { String error_message = format("Wrong mean shape for the given data matrix. Expected %d, but was %d.", d, mean.total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // create temporary matrices Mat X, Y; @@ -217,12 +217,12 @@ Mat subspaceReconstruct(InputArray _W, InputArray _mean, InputArray _src) // make sure the data has the correct shape if(W.cols != d) { String error_message = format("Wrong shapes for given matrices. Was size(src) = (%d,%d), size(W) = (%d,%d).", src.rows, src.cols, W.rows, W.cols); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // make sure mean is correct if not empty if(!mean.empty() && (mean.total() != (size_t) W.rows)) { String error_message = format("Wrong mean shape for the given eigenvector matrix. Expected %d, but was %d.", W.cols, mean.total()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // initalize temporary matrices Mat X, Y; @@ -939,7 +939,7 @@ public: void LDA::save(const String& filename) const { FileStorage fs(filename, FileStorage::WRITE); if (!fs.isOpened()) { - CV_Error(CV_StsError, "File can't be opened for writing!"); + CV_Error(Error::StsError, "File can't be opened for writing!"); } this->save(fs); fs.release(); @@ -949,7 +949,7 @@ void LDA::save(const String& filename) const { void LDA::load(const String& filename) { FileStorage fs(filename, FileStorage::READ); if (!fs.isOpened()) - CV_Error(CV_StsError, "File can't be opened for writing!"); + CV_Error(Error::StsError, "File can't be opened for writing!"); this->load(fs); fs.release(); } @@ -1002,12 +1002,12 @@ void LDA::lda(InputArrayOfArrays _src, InputArray _lbls) { // want to separate from each other then? if(C == 1) { String error_message = "At least two classes are needed to perform a LDA. Reason: Only one class was given!"; - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // throw error if less labels, than samples if (labels.size() != static_cast(N)) { String error_message = format("The number of samples must equal the number of labels. Given %d labels, %d samples. ", labels.size(), N); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } // warn if within-classes scatter matrix becomes singular if (N < D) { @@ -1090,7 +1090,7 @@ void LDA::compute(InputArrayOfArrays _src, InputArray _lbls) { break; default: String error_message= format("InputArray Datatype %d is not supported.", _src.kind()); - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); break; } } diff --git a/modules/contrib/src/octree.cpp b/modules/contrib/src/octree.cpp index 80d2564945..b612372753 100644 --- a/modules/contrib/src/octree.cpp +++ b/modules/contrib/src/octree.cpp @@ -258,7 +258,7 @@ namespace cv void Octree::buildTree(const std::vector& points3d, int maxLevels, int _minPoints) { - assert((size_t)maxLevels * 8 < MAX_STACK_SIZE); + CV_Assert((size_t)maxLevels * 8 < MAX_STACK_SIZE); points.resize(points3d.size()); std::copy(points3d.begin(), points3d.end(), points.begin()); minPoints = _minPoints; diff --git a/modules/contrib/src/retina.cpp b/modules/contrib/src/retina.cpp index 5dae919bff..5175480fea 100644 --- a/modules/contrib/src/retina.cpp +++ b/modules/contrib/src/retina.cpp @@ -450,7 +450,7 @@ bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, std:: inputMatToConvert.convertTo(dst, dsttype); } else - CV_Error(CV_StsUnsupportedFormat, "input image must be single channel (gray levels), bgr format (color) or bgra (color with transparency which won't be considered"); + CV_Error(Error::StsUnsupportedFormat, "input image must be single channel (gray levels), bgr format (color) or bgra (color with transparency which won't be considered"); return imageNumberOfChannels>1; // return bool : false for gray level image processing, true for color mode } diff --git a/modules/contrib/src/rgbdodometry.cpp b/modules/contrib/src/rgbdodometry.cpp index 6e1f217d09..6f86f17ec4 100644 --- a/modules/contrib/src/rgbdodometry.cpp +++ b/modules/contrib/src/rgbdodometry.cpp @@ -422,7 +422,7 @@ bool computeKsi( int transformType, computeCFuncPtr = computeC_Translation; } else - CV_Error( CV_StsBadFlag, "Unsupported value of transformation type flag."); + CV_Error(Error::StsBadFlag, "Unsupported value of transformation type flag."); Mat C( correspsCount, Cwidth, CV_64FC1 ); Mat dI_dt( correspsCount, 1, CV_64FC1 ); diff --git a/modules/contrib/src/spinimages.cpp b/modules/contrib/src/spinimages.cpp index 54eaf825c8..4e58472bfb 100644 --- a/modules/contrib/src/spinimages.cpp +++ b/modules/contrib/src/spinimages.cpp @@ -56,24 +56,24 @@ namespace { const static Scalar colors[] = { - CV_RGB(255, 0, 0), - CV_RGB( 0, 255, 0), - CV_RGB( 0, 0, 255), - CV_RGB(255, 255, 0), - CV_RGB(255, 0, 255), - CV_RGB( 0, 255, 255), - CV_RGB(255, 127, 127), - CV_RGB(127, 127, 255), - CV_RGB(127, 255, 127), - CV_RGB(255, 255, 127), - CV_RGB(127, 255, 255), - CV_RGB(255, 127, 255), - CV_RGB(127, 0, 0), - CV_RGB( 0, 127, 0), - CV_RGB( 0, 0, 127), - CV_RGB(127, 127, 0), - CV_RGB(127, 0, 127), - CV_RGB( 0, 127, 127) + Scalar(255, 0, 0), + Scalar( 0, 255, 0), + Scalar( 0, 0, 255), + Scalar(255, 255, 0), + Scalar(255, 0, 255), + Scalar( 0, 255, 255), + Scalar(255, 127, 127), + Scalar(127, 127, 255), + Scalar(127, 255, 127), + Scalar(255, 255, 127), + Scalar(127, 255, 255), + Scalar(255, 127, 255), + Scalar(127, 0, 0), + Scalar( 0, 127, 0), + Scalar( 0, 0, 127), + Scalar(127, 127, 0), + Scalar(127, 0, 127), + Scalar( 0, 127, 127) }; size_t colors_mum = sizeof(colors)/sizeof(colors[0]); @@ -199,7 +199,7 @@ void convertTransformMatrix(const float* matrix, float* sseMatrix) inline __m128 transformSSE(const __m128* matrix, const __m128& in) { - assert(((size_t)matrix & 15) == 0); + CV_DbgAssert(((size_t)matrix & 15) == 0); __m128 a0 = _mm_mul_ps(_mm_load_ps((float*)(matrix+0)), _mm_shuffle_ps(in,in,_MM_SHUFFLE(0,0,0,0))); __m128 a1 = _mm_mul_ps(_mm_load_ps((float*)(matrix+1)), _mm_shuffle_ps(in,in,_MM_SHUFFLE(1,1,1,1))); __m128 a2 = _mm_mul_ps(_mm_load_ps((float*)(matrix+2)), _mm_shuffle_ps(in,in,_MM_SHUFFLE(2,2,2,2))); @@ -221,8 +221,8 @@ void computeSpinImages( const Octree& Octree, const std::vector& points float pixelsPerMeter = 1.f / binSize; float support = imageWidth * binSize; - assert(normals.size() == points.size()); - assert(mask.size() == points.size()); + CV_Assert(normals.size() == points.size()); + CV_Assert(mask.size() == points.size()); size_t points_size = points.size(); mask.resize(points_size); @@ -250,7 +250,7 @@ void computeSpinImages( const Octree& Octree, const std::vector& points if (mask[i] == 0) continue; - int t = cvGetThreadNum(); + int t = getThreadNum(); std::vector& pointsInSphere = pointsInSpherePool[t]; const Point3f& center = points[i]; @@ -289,7 +289,7 @@ void computeSpinImages( const Octree& Octree, const std::vector& points __m128 ppm4 = _mm_set1_ps(pixelsPerMeter); __m128i height4m1 = _mm_set1_epi32(spinImage.rows-1); __m128i width4m1 = _mm_set1_epi32(spinImage.cols-1); - assert( spinImage.step <= 0xffff ); + CV_Assert( spinImage.step <= 0xffff ); __m128i step4 = _mm_set1_epi16((short)step); __m128i zero4 = _mm_setzero_si128(); __m128i one4i = _mm_set1_epi32(1); @@ -472,7 +472,7 @@ float cv::Mesh3D::estimateResolution(float /*tryRatio*/) return resolution = (float)dist[ dist.size() / 2 ]; #else - CV_Error(CV_StsNotImplemented, ""); + CV_Error(Error::StsNotImplemented, ""); return 1.f; #endif } @@ -686,16 +686,15 @@ inline float cv::SpinImageModel::groupingCreteria(const Point3f& pointScene1, co } -cv::SpinImageModel::SpinImageModel(const Mesh3D& _mesh) : mesh(_mesh) , out(0) +cv::SpinImageModel::SpinImageModel(const Mesh3D& _mesh) : mesh(_mesh) { if (mesh.vtx.empty()) throw Mesh3D::EmptyMeshException(); defaultParams(); } -cv::SpinImageModel::SpinImageModel() : out(0) { defaultParams(); } -cv::SpinImageModel::~SpinImageModel() {} -void cv::SpinImageModel::setLogger(std::ostream* log) { out = log; } +cv::SpinImageModel::SpinImageModel() { defaultParams(); } +cv::SpinImageModel::~SpinImageModel() {} void cv::SpinImageModel::defaultParams() { @@ -756,7 +755,7 @@ Mat cv::SpinImageModel::packRandomScaledSpins(bool separateScale, size_t xCount, int sz = spins.front().cols; Mat result((int)(yCount * sz + (yCount - 1)), (int)(xCount * sz + (xCount - 1)), CV_8UC3); - result = colors[(static_cast(cvGetTickCount()/cvGetTickFrequency())/1000) % colors_mum]; + result = colors[(static_cast(getTickCount()/getTickFrequency())/1000) % colors_mum]; int pos = 0; for(int y = 0; y < (int)yCount; ++y) @@ -1030,12 +1029,8 @@ private: matchSpinToModel(scene.spinImages.row(i), indeces, coeffs); for(size_t t = 0; t < indeces.size(); ++t) allMatches.push_back(Match(i, indeces[t], coeffs[t])); - - if (out) if (i % 100 == 0) *out << "Comparing scene spinimage " << i << " of " << scene.spinImages.rows << std::endl; } corr_timer.stop(); - if (out) *out << "Spin correlation time = " << corr_timer << std::endl; - if (out) *out << "Matches number = " << allMatches.size() << std::endl; if(allMatches.empty()) return; @@ -1046,7 +1041,6 @@ private: allMatches.erase( remove_if(allMatches.begin(), allMatches.end(), bind2nd(std::less(), maxMeasure * fraction)), allMatches.end()); - if (out) *out << "Matches number [filtered by similarity measure] = " << allMatches.size() << std::endl; int matchesSize = (int)allMatches.size(); if(matchesSize == 0) @@ -1095,15 +1089,12 @@ private: allMatches.erase( std::remove_if(allMatches.begin(), allMatches.end(), std::bind2nd(std::equal_to(), infinity)), allMatches.end()); - if (out) *out << "Matches number [filtered by geometric consistency] = " << allMatches.size() << std::endl; matchesSize = (int)allMatches.size(); if(matchesSize == 0) return; - if (out) *out << "grouping ..." << std::endl; - Mat groupingMat((int)matchesSize, (int)matchesSize, CV_32F); groupingMat = Scalar(0); @@ -1151,8 +1142,6 @@ private: for(int g = 0; g < matchesSize; ++g) { - if (out) if (g % 100 == 0) *out << "G = " << g << std::endl; - group_t left = allMatchesInds; group_t group; @@ -1201,16 +1190,16 @@ private: cv::TickMeter::TickMeter() { reset(); } int64 cv::TickMeter::getTimeTicks() const { return sumTime; } -double cv::TickMeter::getTimeMicro() const { return (double)getTimeTicks()/cvGetTickFrequency(); } +double cv::TickMeter::getTimeMicro() const { return (double)getTimeTicks()/getTickFrequency(); } double cv::TickMeter::getTimeMilli() const { return getTimeMicro()*1e-3; } double cv::TickMeter::getTimeSec() const { return getTimeMilli()*1e-3; } int64 cv::TickMeter::getCounter() const { return counter; } void cv::TickMeter::reset() {startTime = 0; sumTime = 0; counter = 0; } -void cv::TickMeter::start(){ startTime = cvGetTickCount(); } +void cv::TickMeter::start(){ startTime = getTickCount(); } void cv::TickMeter::stop() { - int64 time = cvGetTickCount(); + int64 time = getTickCount(); if ( startTime == 0 ) return; @@ -1220,4 +1209,4 @@ void cv::TickMeter::stop() startTime = 0; } -std::ostream& cv::operator<<(std::ostream& out, const TickMeter& tm){ return out << tm.getTimeSec() << "sec"; } +//std::ostream& cv::operator<<(std::ostream& out, const TickMeter& tm){ return out << tm.getTimeSec() << "sec"; } diff --git a/modules/contrib/src/stereovar.cpp b/modules/contrib/src/stereovar.cpp index 30cd12d4c1..54dd82ac9f 100644 --- a/modules/contrib/src/stereovar.cpp +++ b/modules/contrib/src/stereovar.cpp @@ -239,8 +239,8 @@ void StereoVar::VariationalSolver(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level) void StereoVar::VCycle_MyFAS(Mat &I1, Mat &I2, Mat &I2x, Mat &_u, int level) { - CvSize imgSize = _u.size(); - CvSize frmSize = cvSize((int) (imgSize.width * pyrScale + 0.5), (int) (imgSize.height * pyrScale + 0.5)); + Size imgSize = _u.size(); + Size frmSize = Size((int) (imgSize.width * pyrScale + 0.5), (int) (imgSize.height * pyrScale + 0.5)); Mat I1_h, I2_h, I2x_h, u_h, U, U_h; //PRE relaxation @@ -285,7 +285,7 @@ void StereoVar::VCycle_MyFAS(Mat &I1, Mat &I2, Mat &I2x, Mat &_u, int level) void StereoVar::FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level) { double scale = std::pow(pyrScale, (double) level); - CvSize frmSize = cvSize((int) (u.cols * scale + 0.5), (int) (u.rows * scale + 0.5)); + Size frmSize = Size((int) (u.cols * scale + 0.5), (int) (u.rows * scale + 0.5)); Mat I1_h, I2_h, I2x_h, u_h; //scaling DOWN @@ -350,7 +350,7 @@ void StereoVar::autoParams() void StereoVar::operator ()( const Mat& left, const Mat& right, Mat& disp ) { CV_Assert(left.size() == right.size() && left.type() == right.type()); - CvSize imgSize = left.size(); + Size imgSize = left.size(); int MaxD = MAX(labs(minDisp), labs(maxDisp)); int SignD = 1; if (MIN(minDisp, maxDisp) < 0) SignD = -1; if (minDisp >= maxDisp) {MaxD = 256; SignD = 1;} @@ -378,8 +378,8 @@ void StereoVar::operator ()( const Mat& left, const Mat& right, Mat& disp ) equalizeHist(rightgray, rightgray); } if (poly_sigma > 0.0001) { - GaussianBlur(leftgray, leftgray, cvSize(poly_n, poly_n), poly_sigma); - GaussianBlur(rightgray, rightgray, cvSize(poly_n, poly_n), poly_sigma); + GaussianBlur(leftgray, leftgray, Size(poly_n, poly_n), poly_sigma); + GaussianBlur(rightgray, rightgray, Size(poly_n, poly_n), poly_sigma); } if (flags & USE_AUTO_PARAMS) { diff --git a/samples/c/adaptiveskindetector.cpp b/samples/c/adaptiveskindetector.cpp index a561440af0..e1f777cc19 100644 --- a/samples/c/adaptiveskindetector.cpp +++ b/samples/c/adaptiveskindetector.cpp @@ -39,7 +39,7 @@ #include #include #include -#include "opencv2/contrib/contrib.hpp" +#include "opencv2/contrib/compat.hpp" #include "opencv2/highgui/highgui_c.h" static void help(char **argv) diff --git a/samples/cpp/facerec_demo.cpp b/samples/cpp/facerec_demo.cpp index 81953e3c80..3a104b86b3 100644 --- a/samples/cpp/facerec_demo.cpp +++ b/samples/cpp/facerec_demo.cpp @@ -32,7 +32,7 @@ static Mat toGrayscale(InputArray _src) { Mat src = _src.getMat(); // only allow one channel if(src.channels() != 1) { - CV_Error(CV_StsBadArg, "Only Matrices with one channel are supported"); + CV_Error(Error::StsBadArg, "Only Matrices with one channel are supported"); } // create and return normalized image Mat dst; @@ -44,7 +44,7 @@ static void read_csv(const string& filename, vector& images, vector& l std::ifstream file(filename.c_str(), ifstream::in); if (!file) { string error_message = "No valid input file was given, please check the given filename."; - CV_Error(CV_StsBadArg, error_message); + CV_Error(Error::StsBadArg, error_message); } string line, path, classlabel; while (getline(file, line)) { @@ -82,7 +82,7 @@ int main(int argc, const char *argv[]) { // Quit if there are not enough images for this demo. if(images.size() <= 1) { string error_message = "This demo needs at least 2 images to work. Please add more images to your data set!"; - CV_Error(CV_StsError, error_message); + CV_Error(Error::StsError, error_message); } // Get the height from the first image. We'll need this // later in code to reshape the images to their original diff --git a/samples/cpp/stereo_match.cpp b/samples/cpp/stereo_match.cpp index 2d4bb5fec6..6f0b9f38b6 100644 --- a/samples/cpp/stereo_match.cpp +++ b/samples/cpp/stereo_match.cpp @@ -178,7 +178,7 @@ int main(int argc, char** argv) if( intrinsic_filename ) { // reading intrinsic parameters - FileStorage fs(intrinsic_filename, CV_STORAGE_READ); + FileStorage fs(intrinsic_filename, FileStorage::READ); if(!fs.isOpened()) { printf("Failed to open file %s\n", intrinsic_filename); @@ -194,7 +194,7 @@ int main(int argc, char** argv) M1 *= scale; M2 *= scale; - fs.open(extrinsic_filename, CV_STORAGE_READ); + fs.open(extrinsic_filename, FileStorage::READ); if(!fs.isOpened()) { printf("Failed to open file %s\n", extrinsic_filename); diff --git a/samples/gpu/cascadeclassifier.cpp b/samples/gpu/cascadeclassifier.cpp index c2e5a7af58..271e7dca85 100644 --- a/samples/gpu/cascadeclassifier.cpp +++ b/samples/gpu/cascadeclassifier.cpp @@ -59,15 +59,15 @@ static void matPrint(Mat &img, int lineOffsY, Scalar fontColor, const string &ss Point org; org.x = 1; org.y = 3 * fontSize.height * (lineOffsY + 1) / 2; - putText(img, ss, org, fontFace, fontScale, CV_RGB(0,0,0), 5*fontThickness/2, 16); + putText(img, ss, org, fontFace, fontScale, Scalar(0,0,0), 5*fontThickness/2, 16); putText(img, ss, org, fontFace, fontScale, fontColor, fontThickness, 16); } static void displayState(Mat &canvas, bool bHelp, bool bGpu, bool bLargestFace, bool bFilter, double fps) { - Scalar fontColorRed = CV_RGB(255,0,0); - Scalar fontColorNV = CV_RGB(118,185,0); + Scalar fontColorRed = Scalar(255,0,0); + Scalar fontColorNV = Scalar(118,185,0); ostringstream ss; ss << "FPS = " << setprecision(1) << fixed << fps;