Commit 73b6dcd8 authored by jaco's avatar jaco

wip windows 32 64 bit safe types

parent 861d7bcf
......@@ -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);
}
......@@ -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<int> 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 <intrin.h>
......
......@@ -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_<INT64> Tig1 = Mat_<INT64>::zeros( sz ), Tig2 = Mat_<INT64>::zeros( sz );
Mat_<INT64> Tig4 = Mat_<INT64>::zeros( sz ), Tig8 = Mat_<INT64>::zeros( sz );
Mat_<byte_> Row1 = Mat_<byte_>::zeros( sz ), Row2 = Mat_<byte_>::zeros( sz );
Mat_<byte_> Row4 = Mat_<byte_>::zeros( sz ), Row8 = Mat_<byte_>::zeros( sz );
Mat_<int64_t> Tig1 = Mat_<int64_t>::zeros( sz ), Tig2 = Mat_<int64_t>::zeros( sz );
Mat_<int64_t> Tig4 = Mat_<int64_t>::zeros( sz ), Tig8 = Mat_<int64_t>::zeros( sz );
Mat_<byte> Row1 = Mat_<byte>::zeros( sz ), Row2 = Mat_<byte>::zeros( sz );
Mat_<byte> Row4 = Mat_<byte>::zeros( sz ), Row8 = Mat_<byte>::zeros( sz );
Mat_<float> scores( sz );
for ( int y = 1; y <= H; y++ )
{
const byte_* G = mag1u.ptr<byte_>( y - 1 );
INT64* T1 = Tig1.ptr<INT64>( y ); // Binary TIG of current row
INT64* T2 = Tig2.ptr<INT64>( y );
INT64* T4 = Tig4.ptr<INT64>( y );
INT64* T8 = Tig8.ptr<INT64>( y );
INT64* Tu1 = Tig1.ptr<INT64>( y - 1 ); // Binary TIG of upper row
INT64* Tu2 = Tig2.ptr<INT64>( y - 1 );
INT64* Tu4 = Tig4.ptr<INT64>( y - 1 );
INT64* Tu8 = Tig8.ptr<INT64>( y - 1 );
byte_* R1 = Row1.ptr<byte_>( y );
byte_* R2 = Row2.ptr<byte_>( y );
byte_* R4 = Row4.ptr<byte_>( y );
byte_* R8 = Row8.ptr<byte_>( y );
const byte* G = mag1u.ptr<byte>( y - 1 );
int64_t* T1 = Tig1.ptr<int64_t>( y ); // Binary TIG of current row
int64_t* T2 = Tig2.ptr<int64_t>( y );
int64_t* T4 = Tig4.ptr<int64_t>( y );
int64_t* T8 = Tig8.ptr<int64_t>( y );
int64_t* Tu1 = Tig1.ptr<int64_t>( y - 1 ); // Binary TIG of upper row
int64_t* Tu2 = Tig2.ptr<int64_t>( y - 1 );
int64_t* Tu4 = Tig4.ptr<int64_t>( y - 1 );
int64_t* Tu8 = Tig8.ptr<int64_t>( y - 1 );
byte* R1 = Row1.ptr<byte>( y );
byte* R2 = Row2.ptr<byte>( y );
byte* R4 = Row4.ptr<byte>( y );
byte* R8 = Row8.ptr<byte>( y );
float *s = scores.ptr<float>( 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 );
......
......@@ -230,7 +230,7 @@ void ObjectnessBING::nonMaxSup( CMat &matchCost1f, ValStructVec<float, Point> &m
for ( int i = 0; i < valPnt.size(); i++ )
{
Point &pnt = valPnt[i];
if( isMax1u.at<byte_>( pnt ) )
if( isMax1u.at<byte>( pnt ) )
{
matchCost.pushBack( valPnt( i ), pnt );
for ( int dy = -NSS; dy <= NSS; dy++ )
......@@ -239,7 +239,7 @@ void ObjectnessBING::nonMaxSup( CMat &matchCost1f, ValStructVec<float, Point> &m
Point neighbor = pnt + Point( dx, dy );
if( !CHK_IND( neighbor ) )
continue;
isMax1u.at<byte_>( neighbor ) = false;
isMax1u.at<byte>( 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<int>( y, 0 ) = abs( g1u.at<byte_>( y, 1 ) - g1u.at<byte_>( y, 0 ) ) * 2;
Ix.at<int>( y, W - 1 ) = abs( g1u.at<byte_>( y, W - 1 ) - g1u.at<byte_>( y, W - 2 ) ) * 2;
Ix.at<int>( y, 0 ) = abs( g1u.at<byte>( y, 1 ) - g1u.at<byte>( y, 0 ) ) * 2;
Ix.at<int>( y, W - 1 ) = abs( g1u.at<byte>( y, W - 1 ) - g1u.at<byte>( y, W - 2 ) ) * 2;
}
// Top/bottom most column Iy
for ( int x = 0; x < W; x++ )
{
Iy.at<int>( 0, x ) = abs( g1u.at<byte_>( 1, x ) - g1u.at<byte_>( 0, x ) ) * 2;
Iy.at<int>( H - 1, x ) = abs( g1u.at<byte_>( H - 1, x ) - g1u.at<byte_>( H - 2, x ) ) * 2;
Iy.at<int>( 0, x ) = abs( g1u.at<byte>( 1, x ) - g1u.at<byte>( 0, x ) ) * 2;
Iy.at<int>( H - 1, x ) = abs( g1u.at<byte>( H - 1, x ) - g1u.at<byte>( 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<int>( y, x ) = abs( g1u.at<byte_>( y, x + 1 ) - g1u.at<byte_>( y, x - 1 ) );
Ix.at<int>( y, x ) = abs( g1u.at<byte>( y, x + 1 ) - g1u.at<byte>( y, x - 1 ) );
for ( int y = 1; y < H - 1; y++ )
for ( int x = 0; x < W; x++ )
Iy.at<int>( y, x ) = abs( g1u.at<byte_>( y + 1, x ) - g1u.at<byte_>( y - 1, x ) );
Iy.at<int>( y, x ) = abs( g1u.at<byte>( y + 1, x ) - g1u.at<byte>( 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<int>( r ), *y = y1i.ptr<int>( r );
byte_* m = mag1u.ptr<byte_>( r );
byte* m = mag1u.ptr<byte>( 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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment