From a8c5e356199057538d65b7fbd8db573f96089089 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 9 Oct 2012 15:56:16 +0400 Subject: [PATCH] some more fixes towards binary compatibility --- modules/core/include/opencv2/core/core.hpp | 25 ++++- modules/core/src/algorithm.cpp | 34 +++++- .../include/opencv2/features2d/features2d.hpp | 2 +- modules/imgproc/src/imgwarp.cpp | 122 +++++++++------------ modules/ml/include/opencv2/ml/ml.hpp | 3 +- modules/ml/src/data.cpp | 2 +- modules/objdetect/src/haar.cpp | 4 - 7 files changed, 103 insertions(+), 89 deletions(-) diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 8174070..9ffe7d4 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -1388,7 +1388,7 @@ public: virtual bool fixedType() const; virtual bool needed() const; virtual Mat& getMatRef(int i=-1) const; - virtual gpu::GpuMat& getGpuMatRef() const; + /*virtual*/ gpu::GpuMat& getGpuMatRef() const; virtual void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; virtual void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const; @@ -2131,7 +2131,7 @@ CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst); //! copies each plane of a multi-channel array to a dedicated array CV_EXPORTS void split(const Mat& src, Mat* mvbegin); -CV_EXPORTS void split(const Mat& src, vector& mv ); +CV_EXPORTS void split(const Mat& m, vector& mv ); //! copies each plane of a multi-channel array to a dedicated array CV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv); @@ -4393,6 +4393,11 @@ public: void (Algorithm::*setter)(int)=0, const string& help=string()); void addParam(Algorithm& algo, const char* name, + short& value, bool readOnly=false, + int (Algorithm::*getter)()=0, + void (Algorithm::*setter)(int)=0, + const string& help=string()); + void addParam(Algorithm& algo, const char* name, bool& value, bool readOnly=false, int (Algorithm::*getter)()=0, void (Algorithm::*setter)(int)=0, @@ -4441,7 +4446,7 @@ protected: struct CV_EXPORTS Param { - enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, UNSIGNED_INT=8, UINT64=9 }; + enum { INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, UNSIGNED_INT=8, UINT64=9, SHORT=10 }; Param(); Param(int _type, bool _readonly, int _offset, @@ -4472,6 +4477,14 @@ template<> struct ParamType enum { type = Param::INT }; }; +template<> struct ParamType +{ + typedef int const_param_type; + typedef int member_type; + + enum { type = Param::SHORT }; +}; + template<> struct ParamType { typedef double const_param_type; @@ -4542,8 +4555,8 @@ template<> struct ParamType class CV_EXPORTS CommandLineParser { public: - CommandLineParser(int argc, const char* const argv[], const char* keys); - CommandLineParser(int argc, const char* const argv[], const string& keys); + CommandLineParser(int argc, const char* const argv[], const char* key_map); + CommandLineParser(int argc, const char* const argv[], const string& key_map); CommandLineParser(const CommandLineParser& parser); CommandLineParser& operator = (const CommandLineParser& parser); @@ -4565,7 +4578,7 @@ public: return val; } - bool has(const string& name); + bool has(const string& keys); bool check() const; void about(const string& message); diff --git a/modules/core/src/algorithm.cpp b/modules/core/src/algorithm.cpp index 3fedfaa..39b4743 100644 --- a/modules/core/src/algorithm.cpp +++ b/modules/core/src/algorithm.cpp @@ -456,18 +456,27 @@ void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, con if( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL ) { - CV_Assert( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN ); + CV_Assert( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN || + (p->type == Param::SHORT && argType == Param::INT) ); if( p->type == Param::INT ) { int val = argType == Param::INT ? *(const int*)value : - argType == Param::BOOLEAN ? (int)*(const bool*)value : - saturate_cast(*(const double*)value); + argType == Param::BOOLEAN ? (int)*(const bool*)value : + saturate_cast(*(const double*)value); if( p->setter ) (algo->*f.set_int)(val); else *(int*)((uchar*)algo + p->offset) = val; } + else if( p->type == Param::SHORT ) + { + int val = *(const int*)value; + if( p->setter ) + (algo->*f.set_int)(val); + else + *(short*)((uchar*)algo + p->offset) = (short)val; + } else if( p->type == Param::BOOLEAN ) { bool val = argType == Param::INT ? *(const int*)value != 0 : @@ -554,6 +563,13 @@ void AlgorithmInfo::get(const Algorithm* algo, const char* parameter, int argTyp else *(double*)value = val; } + else if( p->type == Param::SHORT ) + { + CV_Assert( argType == Param::INT ); + int val = p->getter ? (algo->*f.get_int)() : *(short*)((uchar*)algo + p->offset); + + *(int*)value = val; + } else if( p->type == Param::BOOLEAN ) { CV_Assert( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL ); @@ -639,7 +655,7 @@ void AlgorithmInfo::addParam_(Algorithm& algo, const char* parameter, int argTyp CV_Assert( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL || argType == Param::STRING || argType == Param::MAT || argType == Param::MAT_VECTOR || - argType == Param::ALGORITHM ); + argType == Param::ALGORITHM || argType == Param::SHORT ); data->params.add(string(parameter), Param(argType, readOnly, (int)((size_t)value - (size_t)(void*)&algo), getter, setter, help)); @@ -657,6 +673,16 @@ void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, } void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, + short& value, bool readOnly, + int (Algorithm::*getter)(), + void (Algorithm::*setter)(int), + const string& help) +{ + addParam_(algo, parameter, ParamType::type, &value, readOnly, + (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); +} + +void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, bool& value, bool readOnly, int (Algorithm::*getter)(), void (Algorithm::*setter)(int), diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index 375c861..0b6d884 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -586,7 +586,7 @@ protected: int threshold; bool nonmaxSuppression; - int type; + short type; }; diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index a4e393e..cca3d45 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -1192,15 +1192,12 @@ public: } private: - const Mat src; + Mat src; Mat dst; const int* xofs, *yofs; const AT* alpha, *_beta; - const Size ssize, dsize; - const int ksize, xmin, xmax; - - resizeGeneric_Invoker(const resizeGeneric_Invoker&); - resizeGeneric_Invoker& operator=(const resizeGeneric_Invoker&); + Size ssize, dsize; + int ksize, xmin, xmax; }; template @@ -1236,10 +1233,10 @@ struct ResizeAreaFastNoVec int operator() (const T* /*S*/, T* /*D*/, int /*w*/) const { return 0; } }; -template -struct ResizeAreaFast_2x2_8u +template +struct ResizeAreaFastVec { - ResizeAreaFast_2x2_8u(int _scale_x, int _scale_y, int _cn, int _step/*, const int* _ofs*/) : + ResizeAreaFastVec(int _scale_x, int _scale_y, int _cn, int _step/*, const int* _ofs*/) : scale_x(_scale_x), scale_y(_scale_y), cn(_cn), step(_step)/*, ofs(_ofs)*/ { fast_mode = scale_x == 2 && scale_y == 2 && (cn == 1 || cn == 3 || cn == 4); @@ -1250,47 +1247,44 @@ struct ResizeAreaFast_2x2_8u if( !fast_mode ) return 0; - const T* nextS = S + step; + const T* nextS = (const T*)((const uchar*)S + step); int dx = 0; if (cn == 1) - for( ; dx < w; ++dx ) - { - int index = dx*2; - D[dx] = (S[index] + S[index+1] + nextS[index] + nextS[index+1] + 2) >> 2; - } + for( ; dx < w; ++dx ) + { + int index = dx*2; + D[dx] = (T)((S[index] + S[index+1] + nextS[index] + nextS[index+1] + 2) >> 2); + } else if (cn == 3) - for( ; dx < w; dx += 3 ) - { - int index = dx*2; - D[dx] = (S[index] + S[index+3] + nextS[index] + nextS[index+3] + 2) >> 2; - D[dx+1] = (S[index+1] + S[index+4] + nextS[index+1] + nextS[index+4] + 2) >> 2; - D[dx+2] = (S[index+2] + S[index+5] + nextS[index+2] + nextS[index+5] + 2) >> 2; - } - else - { - assert(cn == 4); - for( ; dx < w; dx += 4 ) + for( ; dx < w; dx += 3 ) { int index = dx*2; - D[dx] = (S[index] + S[index+4] + nextS[index] + nextS[index+4] + 2) >> 2; - D[dx+1] = (S[index+1] + S[index+5] + nextS[index+1] + nextS[index+5] + 2) >> 2; - D[dx+2] = (S[index+2] + S[index+6] + nextS[index+2] + nextS[index+6] + 2) >> 2; - D[dx+3] = (S[index+3] + S[index+7] + nextS[index+3] + nextS[index+7] + 2) >> 2; + D[dx] = (T)((S[index] + S[index+3] + nextS[index] + nextS[index+3] + 2) >> 2); + D[dx+1] = (T)((S[index+1] + S[index+4] + nextS[index+1] + nextS[index+4] + 2) >> 2); + D[dx+2] = (T)((S[index+2] + S[index+5] + nextS[index+2] + nextS[index+5] + 2) >> 2); + } + else + { + assert(cn == 4); + for( ; dx < w; dx += 4 ) + { + int index = dx*2; + D[dx] = (T)((S[index] + S[index+4] + nextS[index] + nextS[index+4] + 2) >> 2); + D[dx+1] = (T)((S[index+1] + S[index+5] + nextS[index+1] + nextS[index+5] + 2) >> 2); + D[dx+2] = (T)((S[index+2] + S[index+6] + nextS[index+2] + nextS[index+6] + 2) >> 2); + D[dx+3] = (T)((S[index+3] + S[index+7] + nextS[index+3] + nextS[index+7] + 2) >> 2); + } } - } return dx; } private: - const int scale_x, scale_y; - const int cn; + int scale_x, scale_y; + int cn; bool fast_mode; - const int step; - - ResizeAreaFast_2x2_8u(const ResizeAreaFast_2x2_8u&); - ResizeAreaFast_2x2_8u& operator=(const ResizeAreaFast_2x2_8u&); + int step; }; template @@ -1376,11 +1370,8 @@ public: private: const Mat src; Mat dst; - const int scale_x, scale_y; + int scale_x, scale_y; const int *ofs, *xofs; - - resizeAreaFast_Invoker(const resizeAreaFast_Invoker&); - resizeAreaFast_Invoker& operator=(const resizeAreaFast_Invoker&); }; template @@ -1413,7 +1404,7 @@ public: { } - void resize_signle_band(const Range& range) const + void resize_single_band(const Range& range) const { Size ssize = src.size(), dsize = dst.size(); int cn = src.channels(); @@ -1520,21 +1511,18 @@ public: for (int i = range.start; i < range.end; ++i) { Range band_range(bands[i].first, bands[i].second); - resize_signle_band(band_range); + resize_single_band(band_range); } } private: - const Mat src; + Mat src; Mat dst; const DecimateAlpha* xofs; - const int xofs_count; - const double scale_y_; + int xofs_count; + double scale_y_; const int *cur_dy_ofs; std::vector > bands; - - resizeArea_Invoker(const resizeArea_Invoker&); - resizeArea_Invoker& operator=(const resizeArea_Invoker&); }; template @@ -1566,7 +1554,8 @@ static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, in Range range(0, bands.size()); resizeArea_Invoker invoker(src, dst, xofs, xofs_count, scale_y_, cur_dy_ofs, bands); - parallel_for_(range, invoker); + //parallel_for_(range, invoker); + invoker(Range(range.start, range.end)); } @@ -1678,10 +1667,10 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize, static ResizeAreaFastFunc areafast_tab[] = { - resizeAreaFast_ >, + resizeAreaFast_ >, 0, - resizeAreaFast_ >, - resizeAreaFast_ >, + resizeAreaFast_ >, + resizeAreaFast_ >, 0, resizeAreaFast_ >, resizeAreaFast_ >, @@ -1739,11 +1728,9 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize, // in case of scale_x && scale_y is equal to 2 // INTER_AREA (fast) also is equal to INTER_LINEAR - if ( interpolation == INTER_LINEAR && std::abs(scale_x - 2.0) < DBL_EPSILON && - std::abs(scale_y - 2.0) < DBL_EPSILON) + if( interpolation == INTER_LINEAR && is_area_fast && iscale_x == 2 && iscale_y == 2 ) { interpolation = INTER_AREA; - is_area_fast = true; } // true "area" interpolation is only implemented for the case (scale_x <= 1 && scale_y <= 1). @@ -2882,18 +2869,16 @@ public: } private: - const Mat src; + Mat src; Mat dst; - const Mat map1, map2, *m1, *m2; + Mat map1, map2; + const Mat *m1, *m2; int interpolation, borderType; - const Scalar borderValue; + Scalar borderValue; int planar_input; RemapNNFunc nnfunc; RemapFunc ifunc; const void *ctab; - - remapInvoker(const remapInvoker&); - remapInvoker& operator=(const remapInvoker&); }; } @@ -3252,15 +3237,12 @@ public: } private: - const Mat src; + Mat src; Mat dst; int interpolation, borderType; - const Scalar borderValue; + Scalar borderValue; int *adelta, *bdelta; double *M; - - warpAffineInvoker(const warpAffineInvoker&); - warpAffineInvoker& operator=(const warpAffineInvoker&); }; } @@ -3409,13 +3391,11 @@ public: } private: - const Mat src; + Mat src; Mat dst; double* M; int interpolation, borderType; - const Scalar borderValue; - warpPerspectiveInvoker(const warpPerspectiveInvoker&); - warpPerspectiveInvoker& operator=(const warpPerspectiveInvoker&); + Scalar borderValue; }; } diff --git a/modules/ml/include/opencv2/ml/ml.hpp b/modules/ml/include/opencv2/ml/ml.hpp index eaa4bde..d6246be 100644 --- a/modules/ml/include/opencv2/ml/ml.hpp +++ b/modules/ml/include/opencv2/ml/ml.hpp @@ -2069,6 +2069,7 @@ protected: char delimiter; char miss_ch; + short header_lines_number; //char flt_separator; CvMat* values; @@ -2093,8 +2094,6 @@ protected: int* sample_idx; // data of train_sample_idx and test_sample_idx cv::RNG* rng; - - int header_lines_number; }; diff --git a/modules/ml/src/data.cpp b/modules/ml/src/data.cpp index 01d51da..9894591 100644 --- a/modules/ml/src/data.cpp +++ b/modules/ml/src/data.cpp @@ -121,7 +121,7 @@ void CvMLData::clear() void CvMLData::set_header_lines_number( int idx ) { - header_lines_number = std::max(0, idx); + header_lines_number = (short)std::max(0, idx); } int CvMLData::get_header_lines_number() const diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index e9eda9d..04524d6 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -1572,13 +1572,9 @@ cvHaarDetectObjectsForROC( const CvArr* _img, cvIntegral( &img1, &sum1, &sqsum1, _tilted ); int ystep = factor > 2 ? 1 : 2; - #ifdef HAVE_TBB const int LOCS_PER_THREAD = 1000; int stripCount = ((sz1.width/ystep)*(sz1.height + ystep-1)/ystep + LOCS_PER_THREAD/2)/LOCS_PER_THREAD; stripCount = std::min(std::max(stripCount, 1), 100); - #else - const int stripCount = 1; - #endif #ifdef HAVE_IPP if( use_ipp ) -- 2.7.4