Reduced some tegra stubs

This commit is contained in:
Andrey Kamaev 2012-06-14 14:09:04 +00:00
parent a98d6b6217
commit 913d4541a5
2 changed files with 56 additions and 160 deletions

View File

@ -2839,6 +2839,11 @@ void cv::warpAffine( InputArray _src, OutputArray _dst,
CV_Assert( (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 2 && M0.cols == 3 ); CV_Assert( (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 2 && M0.cols == 3 );
M0.convertTo(matM, matM.type()); M0.convertTo(matM, matM.type());
#ifdef HAVE_TEGRA_OPTIMIZATION
if( tegra::warpAffine(src, dst, M, flags, borderType, borderValue) )
return;
#endif
if( !(flags & WARP_INVERSE_MAP) ) if( !(flags & WARP_INVERSE_MAP) )
{ {
double D = M[0]*M[4] - M[1]*M[3]; double D = M[0]*M[4] - M[1]*M[3];
@ -2851,22 +2856,6 @@ void cv::warpAffine( InputArray _src, OutputArray _dst,
M[2] = b1; M[5] = b2; M[2] = b1; M[5] = b2;
} }
#ifdef HAVE_TEGRA_OPTIMIZATION
if (borderType == BORDER_REPLICATE)
{
if( tegra::warpAffine(src, dst, M, interpolation, borderType, borderValue) )
return;
}
else
{
double warp_mat[6];
Mat warp_m(2, 3, CV_64F, warp_mat);
M0.convertTo(warp_m, warp_m.type());
if( tegra::warpAffine(src, dst, warp_mat, interpolation, borderType, borderValue) )
return;
}
#endif
int x, y, x1, y1, width = dst.cols, height = dst.rows; int x, y, x1, y1, width = dst.cols, height = dst.rows;
AutoBuffer<int> _abdelta(width*2); AutoBuffer<int> _abdelta(width*2);
int* adelta = &_abdelta[0], *bdelta = adelta + width; int* adelta = &_abdelta[0], *bdelta = adelta + width;
@ -2995,14 +2984,14 @@ void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0,
CV_Assert( (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 3 && M0.cols == 3 ); CV_Assert( (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 3 && M0.cols == 3 );
M0.convertTo(matM, matM.type()); M0.convertTo(matM, matM.type());
if( !(flags & WARP_INVERSE_MAP) )
invert(matM, matM);
#ifdef HAVE_TEGRA_OPTIMIZATION #ifdef HAVE_TEGRA_OPTIMIZATION
if( tegra::warpPerspective(src, dst, M, interpolation, borderType, borderValue) ) if( tegra::warpPerspective(src, dst, M, flags, borderType, borderValue) )
return; return;
#endif #endif
if( !(flags & WARP_INVERSE_MAP) )
invert(matM, matM);
int x, y, x1, y1, width = dst.cols, height = dst.rows; int x, y, x1, y1, width = dst.cols, height = dst.rows;
int bh0 = std::min(BLOCK_SZ/2, height); int bh0 = std::min(BLOCK_SZ/2, height);

View File

@ -60,41 +60,10 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type )
} }
#ifdef HAVE_TEGRA_OPTIMIZATION #ifdef HAVE_TEGRA_OPTIMIZATION
switch( type ) if (tegra::thresh_8u(_src, _dst, roi.width, roi.height, thresh, maxval, type))
{ return;
case THRESH_BINARY:
if(tegra::thresh_8u_binary(_src, _dst, roi.width, roi.height, thresh, maxval))
{
return;
}
break;
case THRESH_BINARY_INV:
if(tegra::thresh_8u_binary_inv(_src, _dst, roi.width, roi.height, thresh, maxval))
{
return;
}
break;
case THRESH_TRUNC:
if(tegra::thresh_8u_trunc(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
case THRESH_TOZERO:
if(tegra::thresh_8u_tozero(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
case THRESH_TOZERO_INV:
if(tegra::thresh_8u_tozero_inv(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
}
#endif #endif
switch( type ) switch( type )
{ {
case THRESH_BINARY: case THRESH_BINARY:
@ -139,7 +108,7 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type )
__m128i thresh_s = _mm_set1_epi8(thresh ^ 0x80); __m128i thresh_s = _mm_set1_epi8(thresh ^ 0x80);
__m128i maxval_ = _mm_set1_epi8(maxval); __m128i maxval_ = _mm_set1_epi8(maxval);
j_scalar = roi.width & -8; j_scalar = roi.width & -8;
for( i = 0; i < roi.height; i++ ) for( i = 0; i < roi.height; i++ )
{ {
const uchar* src = (const uchar*)(_src.data + _src.step*i); const uchar* src = (const uchar*)(_src.data + _src.step*i);
@ -255,7 +224,7 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type )
} }
} }
} }
#endif #endif
if( j_scalar < roi.width ) if( j_scalar < roi.width )
{ {
@ -263,8 +232,8 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type )
{ {
const uchar* src = (const uchar*)(_src.data + _src.step*i); const uchar* src = (const uchar*)(_src.data + _src.step*i);
uchar* dst = (uchar*)(_dst.data + _dst.step*i); uchar* dst = (uchar*)(_dst.data + _dst.step*i);
j = j_scalar; j = j_scalar;
#if CV_ENABLE_UNROLLED #if CV_ENABLE_UNROLLED
for( ; j <= roi.width - 4; j += 4 ) for( ; j <= roi.width - 4; j += 4 )
{ {
uchar t0 = tab[src[j]]; uchar t0 = tab[src[j]];
@ -279,7 +248,7 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type )
dst[j+2] = t0; dst[j+2] = t0;
dst[j+3] = t1; dst[j+3] = t1;
} }
#endif #endif
for( ; j < roi.width; j++ ) for( ; j < roi.width; j++ )
dst[j] = tab[src[j]]; dst[j] = tab[src[j]];
} }
@ -297,7 +266,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type )
short* dst = (short*)_dst.data; short* dst = (short*)_dst.data;
size_t src_step = _src.step/sizeof(src[0]); size_t src_step = _src.step/sizeof(src[0]);
size_t dst_step = _dst.step/sizeof(dst[0]); size_t dst_step = _dst.step/sizeof(dst[0]);
#if CV_SSE2 #if CV_SSE2
volatile bool useSIMD = checkHardwareSupport(CV_CPU_SSE); volatile bool useSIMD = checkHardwareSupport(CV_CPU_SSE);
#endif #endif
@ -307,41 +276,12 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type )
roi.width *= roi.height; roi.width *= roi.height;
roi.height = 1; roi.height = 1;
} }
#ifdef HAVE_TEGRA_OPTIMIZATION #ifdef HAVE_TEGRA_OPTIMIZATION
switch( type ) if (tegra::thresh_16s(_src, _dst, roi.width, roi.height, thresh, maxval, type))
{ return;
case THRESH_BINARY: #endif
if(tegra::thresh_16s_binary(_src, _dst, roi.width, roi.height, thresh, maxval))
{
return;
}
break;
case THRESH_BINARY_INV:
if(tegra::thresh_16s_binary_inv(_src, _dst, roi.width, roi.height, thresh, maxval))
{
return;
}
break;
case THRESH_TRUNC:
if(tegra::thresh_16s_trunc(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
case THRESH_TOZERO:
if(tegra::thresh_16s_tozero(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
case THRESH_TOZERO_INV:
if(tegra::thresh_16s_tozero_inv(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
}
#endif
switch( type ) switch( type )
{ {
case THRESH_BINARY: case THRESH_BINARY:
@ -393,8 +333,8 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type )
_mm_storeu_si128((__m128i*)(dst + j + 8), v1 ); _mm_storeu_si128((__m128i*)(dst + j + 8), v1 );
} }
} }
#endif #endif
for( ; j < roi.width; j++ ) for( ; j < roi.width; j++ )
dst[j] = src[j] <= thresh ? maxval : 0; dst[j] = src[j] <= thresh ? maxval : 0;
} }
@ -419,8 +359,8 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type )
_mm_storeu_si128((__m128i*)(dst + j + 8), v1 ); _mm_storeu_si128((__m128i*)(dst + j + 8), v1 );
} }
} }
#endif #endif
for( ; j < roi.width; j++ ) for( ; j < roi.width; j++ )
dst[j] = std::min(src[j], thresh); dst[j] = std::min(src[j], thresh);
} }
@ -446,7 +386,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type )
} }
} }
#endif #endif
for( ; j < roi.width; j++ ) for( ; j < roi.width; j++ )
{ {
short v = src[j]; short v = src[j];
@ -487,7 +427,7 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type )
} }
} }
static void static void
thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type ) thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
{ {
@ -498,52 +438,22 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
float* dst = (float*)_dst.data; float* dst = (float*)_dst.data;
size_t src_step = _src.step/sizeof(src[0]); size_t src_step = _src.step/sizeof(src[0]);
size_t dst_step = _dst.step/sizeof(dst[0]); size_t dst_step = _dst.step/sizeof(dst[0]);
#if CV_SSE2 #if CV_SSE2
volatile bool useSIMD = checkHardwareSupport(CV_CPU_SSE); volatile bool useSIMD = checkHardwareSupport(CV_CPU_SSE);
#endif #endif
if( _src.isContinuous() && _dst.isContinuous() ) if( _src.isContinuous() && _dst.isContinuous() )
{ {
roi.width *= roi.height; roi.width *= roi.height;
roi.height = 1; roi.height = 1;
} }
#ifdef HAVE_TEGRA_OPTIMIZATION #ifdef HAVE_TEGRA_OPTIMIZATION
switch( type ) if (tegra::thresh_32f(_src, _dst, roi.width, roi.height, thresh, maxval, type))
{ return;
case THRESH_BINARY: #endif
if(tegra::thresh_32f_binary(_src, _dst, roi.width, roi.height, thresh, maxval))
{
return;
}
break;
case THRESH_BINARY_INV:
if(tegra::thresh_32f_binary_inv(_src, _dst, roi.width, roi.height, thresh, maxval))
{
return;
}
break;
case THRESH_TRUNC:
if(tegra::thresh_32f_trunc(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
case THRESH_TOZERO:
if(tegra::thresh_32f_tozero(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
case THRESH_TOZERO_INV:
if(tegra::thresh_32f_tozero_inv(_src, _dst, roi.width, roi.height, thresh))
{
return;
}
break;
}
#endif
switch( type ) switch( type )
{ {
case THRESH_BINARY: case THRESH_BINARY:
@ -568,12 +478,12 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
} }
} }
#endif #endif
for( ; j < roi.width; j++ ) for( ; j < roi.width; j++ )
dst[j] = src[j] > thresh ? maxval : 0; dst[j] = src[j] > thresh ? maxval : 0;
} }
break; break;
case THRESH_BINARY_INV: case THRESH_BINARY_INV:
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step ) for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
{ {
@ -595,13 +505,13 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
_mm_storeu_ps( dst + j + 4, v1 ); _mm_storeu_ps( dst + j + 4, v1 );
} }
} }
#endif #endif
for( ; j < roi.width; j++ ) for( ; j < roi.width; j++ )
dst[j] = src[j] <= thresh ? maxval : 0; dst[j] = src[j] <= thresh ? maxval : 0;
} }
break; break;
case THRESH_TRUNC: case THRESH_TRUNC:
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step ) for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
{ {
@ -621,13 +531,13 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
_mm_storeu_ps( dst + j + 4, v1 ); _mm_storeu_ps( dst + j + 4, v1 );
} }
} }
#endif #endif
for( ; j < roi.width; j++ ) for( ; j < roi.width; j++ )
dst[j] = std::min(src[j], thresh); dst[j] = std::min(src[j], thresh);
} }
break; break;
case THRESH_TOZERO: case THRESH_TOZERO:
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step ) for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
{ {
@ -648,7 +558,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
} }
} }
#endif #endif
for( ; j < roi.width; j++ ) for( ; j < roi.width; j++ )
{ {
float v = src[j]; float v = src[j];
@ -656,7 +566,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
} }
} }
break; break;
case THRESH_TOZERO_INV: case THRESH_TOZERO_INV:
for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step ) for( i = 0; i < roi.height; i++, src += src_step, dst += dst_step )
{ {
@ -688,7 +598,7 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type )
return CV_Error( CV_StsBadArg, "" ); return CV_Error( CV_StsBadArg, "" );
} }
} }
static double static double
getThreshVal_Otsu_8u( const Mat& _src ) getThreshVal_Otsu_8u( const Mat& _src )
@ -704,8 +614,8 @@ getThreshVal_Otsu_8u( const Mat& _src )
for( i = 0; i < size.height; i++ ) for( i = 0; i < size.height; i++ )
{ {
const uchar* src = _src.data + _src.step*i; const uchar* src = _src.data + _src.step*i;
j = 0; j = 0;
#if CV_ENABLE_UNROLLED #if CV_ENABLE_UNROLLED
for( ; j <= size.width - 4; j += 4 ) for( ; j <= size.width - 4; j += 4 )
{ {
int v0 = src[j], v1 = src[j+1]; int v0 = src[j], v1 = src[j+1];
@ -721,7 +631,7 @@ getThreshVal_Otsu_8u( const Mat& _src )
double mu = 0, scale = 1./(size.width*size.height); double mu = 0, scale = 1./(size.width*size.height);
for( i = 0; i < N; i++ ) for( i = 0; i < N; i++ )
mu += i*(double)h[i]; mu += i*(double)h[i];
mu *= scale; mu *= scale;
double mu1 = 0, q1 = 0; double mu1 = 0, q1 = 0;
double max_sigma = 0, max_val = 0; double max_sigma = 0, max_val = 0;
@ -803,7 +713,7 @@ private:
}; };
} }
double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double maxval, int type ) double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double maxval, int type )
{ {
Mat src = _src.getMat(); Mat src = _src.getMat();
@ -815,12 +725,12 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
CV_Assert( src.type() == CV_8UC1 ); CV_Assert( src.type() == CV_8UC1 );
thresh = getThreshVal_Otsu_8u(src); thresh = getThreshVal_Otsu_8u(src);
} }
_dst.create( src.size(), src.type() ); _dst.create( src.size(), src.type() );
Mat dst = _dst.getMat(); Mat dst = _dst.getMat();
int nStripes = 1; int nStripes = 1;
#if defined HAVE_TBB && defined HAVE_TEGRA_OPTIMIZATION #if defined HAVE_TBB && defined ANDROID
nStripes = 4; nStripes = 4;
#endif #endif
@ -849,7 +759,6 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
} }
else else
{ {
//thresh_8u( src, dst, (uchar)ithresh, (uchar)imaxval, type );
parallel_for(BlockedRange(0, nStripes), parallel_for(BlockedRange(0, nStripes),
ThresholdRunner(src, dst, nStripes, (uchar)ithresh, (uchar)imaxval, type)); ThresholdRunner(src, dst, nStripes, (uchar)ithresh, (uchar)imaxval, type));
} }
@ -862,7 +771,7 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
if( type == THRESH_TRUNC ) if( type == THRESH_TRUNC )
imaxval = ithresh; imaxval = ithresh;
imaxval = saturate_cast<short>(imaxval); imaxval = saturate_cast<short>(imaxval);
if( ithresh < SHRT_MIN || ithresh >= SHRT_MAX ) if( ithresh < SHRT_MIN || ithresh >= SHRT_MAX )
{ {
if( type == THRESH_BINARY || type == THRESH_BINARY_INV || if( type == THRESH_BINARY || type == THRESH_BINARY_INV ||
@ -879,14 +788,12 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
} }
else else
{ {
//thresh_16s( src, dst, (short)ithresh, (short)imaxval, type );
parallel_for(BlockedRange(0, nStripes), parallel_for(BlockedRange(0, nStripes),
ThresholdRunner(src, dst, nStripes, (short)ithresh, (short)imaxval, type)); ThresholdRunner(src, dst, nStripes, (short)ithresh, (short)imaxval, type));
} }
} }
else if( src.depth() == CV_32F ) else if( src.depth() == CV_32F )
{ {
//thresh_32f( src, dst, (float)thresh, (float)maxval, type );
parallel_for(BlockedRange(0, nStripes), parallel_for(BlockedRange(0, nStripes),
ThresholdRunner(src, dst, nStripes, (float)thresh, (float)maxval, type)); ThresholdRunner(src, dst, nStripes, (float)thresh, (float)maxval, type));
} }
@ -913,7 +820,7 @@ void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue,
dst = Scalar(0); dst = Scalar(0);
return; return;
} }
Mat mean; Mat mean;
if( src.data != dst.data ) if( src.data != dst.data )
@ -930,7 +837,7 @@ void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue,
int i, j; int i, j;
uchar imaxval = saturate_cast<uchar>(maxValue); uchar imaxval = saturate_cast<uchar>(maxValue);
int idelta = type == THRESH_BINARY ? cvCeil(delta) : cvFloor(delta); int idelta = type == THRESH_BINARY ? cvCeil(delta) : cvFloor(delta);
uchar tab[768]; uchar tab[768];
if( type == CV_THRESH_BINARY ) if( type == CV_THRESH_BINARY )
for( i = 0; i < 768; i++ ) for( i = 0; i < 768; i++ )