From 73b6dcd8c8428265396103657b4c22cc52ed63d1 Mon Sep 17 00:00:00 2001 From: jaco Date: Fri, 1 Aug 2014 14:46:06 +0200 Subject: [PATCH] wip windows 32 64 bit safe types --- .../include/opencv2/saliency/FilterTIG.h | 30 +++++++------- .../include/opencv2/saliency/kyheader.h | 9 +++-- modules/saliency/src/BING/FilterTIG.cpp | 40 +++++++++---------- modules/saliency/src/BING/objectnessBING.cpp | 18 ++++----- 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/modules/saliency/include/opencv2/saliency/FilterTIG.h b/modules/saliency/include/opencv2/saliency/FilterTIG.h index 9ca24b90c..9473f4093 100644 --- a/modules/saliency/include/opencv2/saliency/FilterTIG.h +++ b/modules/saliency/include/opencv2/saliency/FilterTIG.h @@ -49,7 +49,7 @@ public: // For a W by H gradient magnitude map, find a W-7 by H-7 CV_32F matching score map cv::Mat matchTemplate(const cv::Mat &mag1u); - inline float dot(const INT64 tig1, const INT64 tig2, const INT64 tig4, const INT64 tig8); + inline float dot(const int64_t tig1, const int64_t tig2, const int64_t tig4, const int64_t tig8); public: void reconstruct(cv::Mat &w); // For illustration purpose @@ -57,7 +57,7 @@ public: private: static const int NUM_COMP = 2; // Number of components static const int D = 64; // Dimension of TIG - INT64 _bTIGs[NUM_COMP]; // Binary TIG features + int64_t _bTIGs[NUM_COMP]; // Binary TIG features float _coeffs1[NUM_COMP]; // Coefficients of binary TIG features // For efficiently deals with different bits in CV_8U gradient map @@ -65,22 +65,22 @@ private: }; -inline float FilterTIG::dot(const INT64 tig1, const INT64 tig2, const INT64 tig4, const INT64 tig8) +inline float FilterTIG::dot(const int64_t tig1, const int64_t tig2, const int64_t tig4, const int64_t tig8) { - INT64 bcT1 = (INT64)POPCNT64(tig1); - INT64 bcT2 = (INT64)POPCNT64(tig2); - INT64 bcT4 = (INT64)POPCNT64(tig4); - INT64 bcT8 = (INT64)POPCNT64(tig8); + int64_t bcT1 = (int64_t)POPCNT64(tig1); + int64_t bcT2 = (int64_t)POPCNT64(tig2); + int64_t bcT4 = (int64_t)POPCNT64(tig4); + int64_t bcT8 = (int64_t)POPCNT64(tig8); - INT64 bc01 = (INT64)(POPCNT64(_bTIGs[0] & tig1) << 1) - bcT1; - INT64 bc02 = (INT64)((POPCNT64(_bTIGs[0] & tig2) << 1) - bcT2) << 1; - INT64 bc04 = (INT64)((POPCNT64(_bTIGs[0] & tig4) << 1) - bcT4) << 2; - INT64 bc08 = (INT64)((POPCNT64(_bTIGs[0] & tig8) << 1) - bcT8) << 3; + int64_t bc01 = (int64_t)(POPCNT64(_bTIGs[0] & tig1) << 1) - bcT1; + int64_t bc02 = (int64_t)((POPCNT64(_bTIGs[0] & tig2) << 1) - bcT2) << 1; + int64_t bc04 = (int64_t)((POPCNT64(_bTIGs[0] & tig4) << 1) - bcT4) << 2; + int64_t bc08 = (int64_t)((POPCNT64(_bTIGs[0] & tig8) << 1) - bcT8) << 3; - INT64 bc11 = (INT64)(POPCNT64(_bTIGs[1] & tig1) << 1) - bcT1; - INT64 bc12 = (INT64)((POPCNT64(_bTIGs[1] & tig2) << 1) - bcT2) << 1; - INT64 bc14 = (INT64)((POPCNT64(_bTIGs[1] & tig4) << 1) - bcT4) << 2; - INT64 bc18 = (INT64)((POPCNT64(_bTIGs[1] & tig8) << 1) - bcT8) << 3; + int64_t bc11 = (int64_t)(POPCNT64(_bTIGs[1] & tig1) << 1) - bcT1; + int64_t bc12 = (int64_t)((POPCNT64(_bTIGs[1] & tig2) << 1) - bcT2) << 1; + int64_t bc14 = (int64_t)((POPCNT64(_bTIGs[1] & tig4) << 1) - bcT4) << 2; + int64_t bc18 = (int64_t)((POPCNT64(_bTIGs[1] & tig8) << 1) - bcT8) << 3; return _coeffs1[0] * (bc01 + bc02 + bc04 + bc08) + _coeffs1[1] * (bc11 + bc12 + bc14 + bc18); } diff --git a/modules/saliency/include/opencv2/saliency/kyheader.h b/modules/saliency/include/opencv2/saliency/kyheader.h index 940cc8144..3e49a804e 100644 --- a/modules/saliency/include/opencv2/saliency/kyheader.h +++ b/modules/saliency/include/opencv2/saliency/kyheader.h @@ -79,7 +79,10 @@ typedef unsigned short WORD; typedef unsigned int UNINT32; typedef bool BOOL; typedef void *HANDLE; -typedef unsigned char byte_; +#endif + +#ifndef _MSC_VER +typedef unsigned char byte; #endif typedef std::vector vecI; @@ -164,7 +167,7 @@ inline cv::Rect Vec4i2Rect( cv::Vec4i &v ) { return cv::Rect( cv::Point( v[0] - 1, v[1] - 1 ), cv::Point( v[2], v[3] ) ); } - +/* #ifdef __WIN32 #define INT64 long long #else @@ -172,7 +175,7 @@ inline cv::Rect Vec4i2Rect( cv::Vec4i &v ) typedef unsigned long UINT64_; //#define UINT64 unsigned long #endif - +*/ #if defined(_MSC_VER) # include diff --git a/modules/saliency/src/BING/FilterTIG.cpp b/modules/saliency/src/BING/FilterTIG.cpp index 9181881e0..2d3e13891 100644 --- a/modules/saliency/src/BING/FilterTIG.cpp +++ b/modules/saliency/src/BING/FilterTIG.cpp @@ -61,7 +61,7 @@ void FilterTIG::update( CMat &w1f ) _coeffs1[i] = avg, _coeffs2[i] = avg * 2, _coeffs4[i] = avg * 4, _coeffs8[i] = avg * 8; for ( int j = 0; j < D; j++ ) residuals[j] -= avg * b[j]; - UINT64_ tig = 0; + uint64_t tig = 0; for ( int j = 0; j < D; j++ ) tig = ( tig << 1 ) | ( b[j] > 0 ? 1 : 0 ); _bTIGs[i] = tig; @@ -74,7 +74,7 @@ void FilterTIG::reconstruct( Mat &w1f ) float *weight = (float*) w1f.data; for ( int i = 0; i < NUM_COMP; i++ ) { - UINT64_ tig = _bTIGs[i]; + uint64_t tig = _bTIGs[i]; for ( int j = 0; j < D; j++ ) weight[j] += _coeffs1[i] * ( ( ( tig >> ( 63 - j ) ) & 1 ) ? 1 : -1 ); } @@ -86,30 +86,30 @@ Mat 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_ Row1 = Mat_::zeros( sz ), Row2 = Mat_::zeros( sz ); - Mat_ Row4 = Mat_::zeros( sz ), Row8 = 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* T1 = Tig1.ptr( y ); // Binary TIG of current row - INT64* T2 = Tig2.ptr( y ); - INT64* T4 = Tig4.ptr( y ); - INT64* T8 = Tig8.ptr( y ); - INT64* Tu1 = Tig1.ptr( y - 1 ); // Binary TIG of upper row - INT64* Tu2 = Tig2.ptr( y - 1 ); - INT64* Tu4 = Tig4.ptr( y - 1 ); - INT64* Tu8 = Tig8.ptr( y - 1 ); - byte_* R1 = Row1.ptr( y ); - byte_* R2 = Row2.ptr( y ); - byte_* R4 = Row4.ptr( y ); - byte_* R8 = Row8.ptr( 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 ); + byte* R1 = Row1.ptr( y ); + byte* R2 = Row2.ptr( y ); + byte* R4 = Row4.ptr( y ); + byte* R8 = Row8.ptr( y ); float *s = scores.ptr( y ); for ( int x = 1; x <= W; x++ ) { - byte_ g = G[x - 1]; + byte g = G[x - 1]; R1[x] = ( R1[x - 1] << 1 ) | ( ( g >> 4 ) & 1 ); R2[x] = ( R2[x - 1] << 1 ) | ( ( g >> 5 ) & 1 ); R4[x] = ( R4[x - 1] << 1 ) | ( ( g >> 6 ) & 1 ); diff --git a/modules/saliency/src/BING/objectnessBING.cpp b/modules/saliency/src/BING/objectnessBING.cpp index 333be5504..4e3b7f56c 100644 --- a/modules/saliency/src/BING/objectnessBING.cpp +++ b/modules/saliency/src/BING/objectnessBING.cpp @@ -230,7 +230,7 @@ void ObjectnessBING::nonMaxSup( CMat &matchCost1f, ValStructVec &m for ( int i = 0; i < valPnt.size(); i++ ) { Point &pnt = valPnt[i]; - if( isMax1u.at( pnt ) ) + if( isMax1u.at( pnt ) ) { matchCost.pushBack( valPnt( i ), pnt ); for ( int dy = -NSS; dy <= NSS; dy++ ) @@ -239,7 +239,7 @@ void ObjectnessBING::nonMaxSup( CMat &matchCost1f, ValStructVec &m Point neighbor = pnt + Point( dx, dy ); if( !CHK_IND( neighbor ) ) continue; - isMax1u.at( neighbor ) = false; + isMax1u.at( neighbor ) = false; } } if( matchCost.size() >= maxPoint ) @@ -311,24 +311,24 @@ void ObjectnessBING::gradientGray( CMat &bgr3u, Mat &mag1u ) // Left/right most column Ix for ( int y = 0; y < H; y++ ) { - Ix.at( y, 0 ) = abs( g1u.at( y, 1 ) - g1u.at( y, 0 ) ) * 2; - Ix.at( y, W - 1 ) = abs( g1u.at( y, W - 1 ) - g1u.at( y, W - 2 ) ) * 2; + Ix.at( y, 0 ) = abs( g1u.at( y, 1 ) - g1u.at( y, 0 ) ) * 2; + Ix.at( y, W - 1 ) = abs( g1u.at( y, W - 1 ) - g1u.at( y, W - 2 ) ) * 2; } // Top/bottom most column Iy for ( int x = 0; x < W; x++ ) { - Iy.at( 0, x ) = abs( g1u.at( 1, x ) - g1u.at( 0, x ) ) * 2; - Iy.at( H - 1, x ) = abs( g1u.at( H - 1, x ) - g1u.at( H - 2, x ) ) * 2; + Iy.at( 0, x ) = abs( g1u.at( 1, x ) - g1u.at( 0, x ) ) * 2; + Iy.at( H - 1, x ) = abs( g1u.at( H - 1, x ) - g1u.at( H - 2, x ) ) * 2; } // Find the gradient for inner regions for ( int y = 0; y < H; y++ ) for ( int x = 1; x < W - 1; x++ ) - Ix.at( y, x ) = abs( g1u.at( y, x + 1 ) - g1u.at( y, x - 1 ) ); + Ix.at( y, x ) = abs( g1u.at( y, x + 1 ) - g1u.at( y, x - 1 ) ); for ( int y = 1; y < H - 1; y++ ) for ( int x = 0; x < W; x++ ) - Iy.at( y, x ) = abs( g1u.at( y + 1, x ) - g1u.at( y - 1, x ) ); + Iy.at( y, x ) = abs( g1u.at( y + 1, x ) - g1u.at( y - 1, x ) ); gradientXY( Ix, Iy, mag1u ); } @@ -372,7 +372,7 @@ void ObjectnessBING::gradientXY( CMat &x1i, CMat &y1i, Mat &mag1u ) for ( int r = 0; r < H; r++ ) { const int *x = x1i.ptr( r ), *y = y1i.ptr( r ); - byte_* m = mag1u.ptr( r ); + byte* m = mag1u.ptr( r ); for ( int c = 0; c < W; c++ ) m[c] = min( x[c] + y[c], 255 ); //((int)sqrt(sqr(x[c]) + sqr(y[c])), 255); }