diff --git a/modules/bgsegm/src/bgfg_gmg.cpp b/modules/bgsegm/src/bgfg_gmg.cpp index 2258451ba..5036f1968 100644 --- a/modules/bgsegm/src/bgfg_gmg.cpp +++ b/modules/bgsegm/src/bgfg_gmg.cpp @@ -194,7 +194,7 @@ private: String name_; Mat_ nfeatures_; - Mat_ colors_; + Mat_ colors_; Mat_ weights_; Mat buf_; @@ -223,7 +223,7 @@ void BackgroundSubtractorGMGImpl::initialize(Size frameSize, double minVal, doub nfeatures_.setTo(Scalar::all(0)); } -static float findFeature(unsigned int color, const unsigned int* colors, const float* weights, int nfeatures) +static float findFeature(int color, const int* colors, const float* weights, int nfeatures) { for (int i = 0; i < nfeatures; ++i) { @@ -248,7 +248,7 @@ static void normalizeHistogram(float* weights, int nfeatures) } } -static bool insertFeature(unsigned int color, float weight, unsigned int* colors, float* weights, int& nfeatures, int maxFeatures) +static bool insertFeature(int color, float weight, int* colors, float* weights, int& nfeatures, int maxFeatures) { int idx = -1; for (int i = 0; i < nfeatures; ++i) @@ -266,7 +266,7 @@ static bool insertFeature(unsigned int color, float weight, unsigned int* colors { // move feature to beginning of list - ::memmove(colors + 1, colors, idx * sizeof(unsigned int)); + ::memmove(colors + 1, colors, idx * sizeof(int)); ::memmove(weights + 1, weights, idx * sizeof(float)); colors[0] = color; @@ -276,7 +276,7 @@ static bool insertFeature(unsigned int color, float weight, unsigned int* colors { // discard oldest feature - ::memmove(colors + 1, colors, (nfeatures - 1) * sizeof(unsigned int)); + ::memmove(colors + 1, colors, (nfeatures - 1) * sizeof(int)); ::memmove(weights + 1, weights, (nfeatures - 1) * sizeof(float)); colors[0] = color; @@ -297,7 +297,7 @@ static bool insertFeature(unsigned int color, float weight, unsigned int* colors template struct Quantization { - static unsigned int apply(const void* src_, int x, int cn, double minVal, double maxVal, int quantizationLevels) + static int apply(const void* src_, int x, int cn, double minVal, double maxVal, int quantizationLevels) { const T* src = static_cast(src_); src += x * cn; @@ -313,7 +313,7 @@ template struct Quantization class GMG_LoopBody : public ParallelLoopBody { public: - GMG_LoopBody(const Mat& frame, const Mat& fgmask, const Mat_& nfeatures, const Mat_& colors, const Mat_& weights, + GMG_LoopBody(const Mat& frame, const Mat& fgmask, const Mat_& nfeatures, const Mat_& colors, const Mat_& weights, int maxFeatures, double learningRate, int numInitializationFrames, int quantizationLevels, double backgroundPrior, double decisionThreshold, double maxVal, double minVal, int frameNum, bool updateBackgroundModel) : frame_(frame), fgmask_(fgmask), nfeatures_(nfeatures), colors_(colors), weights_(weights), @@ -331,7 +331,7 @@ private: mutable Mat_ fgmask_; mutable Mat_ nfeatures_; - mutable Mat_ colors_; + mutable Mat_ colors_; mutable Mat_ weights_; int maxFeatures_; @@ -349,7 +349,7 @@ private: void GMG_LoopBody::operator() (const Range& range) const { - typedef unsigned int (*func_t)(const void* src_, int x, int cn, double minVal, double maxVal, int quantizationLevels); + typedef int (*func_t)(const void* src_, int x, int cn, double minVal, double maxVal, int quantizationLevels); static const func_t funcs[] = { Quantization::apply, @@ -375,10 +375,10 @@ void GMG_LoopBody::operator() (const Range& range) const for (int x = 0; x < frame_.cols; ++x, ++featureIdx) { int nfeatures = nfeatures_row[x]; - unsigned int* colors = colors_[featureIdx]; + int* colors = colors_[featureIdx]; float* weights = weights_[featureIdx]; - unsigned int newFeatureColor = func(frame_row, x, cn, minVal_, maxVal_, quantizationLevels_); + int newFeatureColor = func(frame_row, x, cn, minVal_, maxVal_, quantizationLevels_); bool isForeground = false; diff --git a/modules/saliency/src/BING/FilterTIG.cpp b/modules/saliency/src/BING/FilterTIG.cpp index 07206180b..05a1b5893 100644 --- a/modules/saliency/src/BING/FilterTIG.cpp +++ b/modules/saliency/src/BING/FilterTIG.cpp @@ -47,19 +47,22 @@ namespace cv namespace saliency { +typedef int64_t TIG_TYPE; +typedef double MAT_TIG_TYPE; // cv::Mat has no native support for int64/uint64 + struct TIGbits { TIGbits() : bc0(0), bc1(0) {} - inline void accumulate(int64_t tig, int64_t tigMask0, int64_t tigMask1, uchar shift) + inline void accumulate(TIG_TYPE tig, TIG_TYPE tigMask0, TIG_TYPE tigMask1, uchar shift) { bc0 += ((POPCNT64(tigMask0 & tig) << 1) - POPCNT64(tig)) << shift; bc1 += ((POPCNT64(tigMask1 & tig) << 1) - POPCNT64(tig)) << shift; } - int64_t bc0; - int64_t bc1; + TIG_TYPE bc0; + TIG_TYPE bc1; }; -float ObjectnessBING::FilterTIG::dot( int64_t tig1, int64_t tig2, int64_t tig4, int64_t tig8 ) +float ObjectnessBING::FilterTIG::dot( TIG_TYPE tig1, TIG_TYPE tig2, TIG_TYPE tig4, TIG_TYPE tig8 ) { TIGbits x; x.accumulate(tig1, _bTIGs[0], _bTIGs[1], 0); @@ -111,22 +114,22 @@ Mat ObjectnessBING::FilterTIG::matchTemplate( const Mat &mag1u ) { const int H = mag1u.rows, W = mag1u.cols; const Size sz( W + 1, H + 1 ); // Expand original size to avoid dealing with boundary conditions - Mat_ Tig1 = Mat_::zeros( sz ), Tig2 = Mat_::zeros( sz ); - Mat_ Tig4 = Mat_::zeros( sz ), Tig8 = Mat_::zeros( sz ); + Mat_ Tig1 = Mat_::zeros( sz ), Tig2 = Mat_::zeros( sz ); + Mat_ Tig4 = Mat_::zeros( sz ), Tig8 = Mat_::zeros( sz ); Mat_ Row1 = Mat_::zeros( sz ), Row2 = Mat_::zeros( sz ); Mat_ Row4 = Mat_::zeros( sz ), Row8 = Mat_::zeros( sz ); Mat_ scores( sz ); for ( int y = 1; y <= H; y++ ) { const BYTE* G = mag1u.ptr( y - 1 ); - int64_t* T1 = Tig1.ptr( y ); // Binary TIG of current row - int64_t* T2 = Tig2.ptr( y ); - int64_t* T4 = Tig4.ptr( y ); - int64_t* T8 = Tig8.ptr( y ); - int64_t* Tu1 = Tig1.ptr( y - 1 ); // Binary TIG of upper row - int64_t* Tu2 = Tig2.ptr( y - 1 ); - int64_t* Tu4 = Tig4.ptr( y - 1 ); - int64_t* Tu8 = Tig8.ptr( y - 1 ); + TIG_TYPE* T1 = Tig1.ptr( y ); // Binary TIG of current row + TIG_TYPE* T2 = Tig2.ptr( y ); + TIG_TYPE* T4 = Tig4.ptr( y ); + TIG_TYPE* T8 = Tig8.ptr( y ); + TIG_TYPE* Tu1 = Tig1.ptr( y - 1 ); // Binary TIG of upper row + TIG_TYPE* Tu2 = Tig2.ptr( y - 1 ); + TIG_TYPE* Tu4 = Tig4.ptr( y - 1 ); + TIG_TYPE* Tu8 = Tig8.ptr( y - 1 ); BYTE* R1 = Row1.ptr( y ); BYTE* R2 = Row2.ptr( y ); BYTE* R4 = Row4.ptr( y );