Commit e97dd57d authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

hopefully fixed test failures and complains from the doc builder

parent a760c454
...@@ -2261,7 +2261,7 @@ void _OutputArray::release() const ...@@ -2261,7 +2261,7 @@ void _OutputArray::release() const
((Mat*)obj)->release(); ((Mat*)obj)->release();
return; return;
} }
if( k == UMAT ) if( k == UMAT )
{ {
((UMat*)obj)->release(); ((UMat*)obj)->release();
......
...@@ -370,14 +370,14 @@ static bool ocl_moments( InputArray _src, Moments& m) ...@@ -370,14 +370,14 @@ static bool ocl_moments( InputArray _src, Moments& m)
ocl::Kernel k("moments", ocl::imgproc::moments_oclsrc, format("-D TILE_SIZE=%d", TILE_SIZE)); ocl::Kernel k("moments", ocl::imgproc::moments_oclsrc, format("-D TILE_SIZE=%d", TILE_SIZE));
if( k.empty() ) if( k.empty() )
return false; return false;
UMat src = _src.getUMat(); UMat src = _src.getUMat();
Size sz = src.size(); Size sz = src.size();
int xtiles = (sz.width + TILE_SIZE-1)/TILE_SIZE; int xtiles = (sz.width + TILE_SIZE-1)/TILE_SIZE;
int ytiles = (sz.height + TILE_SIZE-1)/TILE_SIZE; int ytiles = (sz.height + TILE_SIZE-1)/TILE_SIZE;
int ntiles = xtiles*ytiles; int ntiles = xtiles*ytiles;
UMat umbuf(1, ntiles*K, CV_32S); UMat umbuf(1, ntiles*K, CV_32S);
size_t globalsize[] = {xtiles, ytiles}; size_t globalsize[] = {xtiles, ytiles};
bool ok = k.args(ocl::KernelArg::ReadOnly(src), bool ok = k.args(ocl::KernelArg::ReadOnly(src),
ocl::KernelArg::PtrWriteOnly(umbuf), ocl::KernelArg::PtrWriteOnly(umbuf),
...@@ -390,43 +390,43 @@ static bool ocl_moments( InputArray _src, Moments& m) ...@@ -390,43 +390,43 @@ static bool ocl_moments( InputArray _src, Moments& m)
double x = (i % xtiles)*TILE_SIZE, y = (i / xtiles)*TILE_SIZE; double x = (i % xtiles)*TILE_SIZE, y = (i / xtiles)*TILE_SIZE;
const int* mom = mbuf.ptr<int>() + i*K; const int* mom = mbuf.ptr<int>() + i*K;
double xm = x * mom[0], ym = y * mom[0]; double xm = x * mom[0], ym = y * mom[0];
// accumulate moments computed in each tile // accumulate moments computed in each tile
// + m00 ( = m00' ) // + m00 ( = m00' )
m.m00 += mom[0]; m.m00 += mom[0];
// + m10 ( = m10' + x*m00' ) // + m10 ( = m10' + x*m00' )
m.m10 += mom[1] + xm; m.m10 += mom[1] + xm;
// + m01 ( = m01' + y*m00' ) // + m01 ( = m01' + y*m00' )
m.m01 += mom[2] + ym; m.m01 += mom[2] + ym;
// + m20 ( = m20' + 2*x*m10' + x*x*m00' ) // + m20 ( = m20' + 2*x*m10' + x*x*m00' )
m.m20 += mom[3] + x * (mom[1] * 2 + xm); m.m20 += mom[3] + x * (mom[1] * 2 + xm);
// + m11 ( = m11' + x*m01' + y*m10' + x*y*m00' ) // + m11 ( = m11' + x*m01' + y*m10' + x*y*m00' )
m.m11 += mom[4] + x * (mom[2] + ym) + y * mom[1]; m.m11 += mom[4] + x * (mom[2] + ym) + y * mom[1];
// + m02 ( = m02' + 2*y*m01' + y*y*m00' ) // + m02 ( = m02' + 2*y*m01' + y*y*m00' )
m.m02 += mom[5] + y * (mom[2] * 2 + ym); m.m02 += mom[5] + y * (mom[2] * 2 + ym);
// + m30 ( = m30' + 3*x*m20' + 3*x*x*m10' + x*x*x*m00' ) // + m30 ( = m30' + 3*x*m20' + 3*x*x*m10' + x*x*x*m00' )
m.m30 += mom[6] + x * (3. * mom[3] + x * (3. * mom[1] + xm)); m.m30 += mom[6] + x * (3. * mom[3] + x * (3. * mom[1] + xm));
// + m21 ( = m21' + x*(2*m11' + 2*y*m10' + x*m01' + x*y*m00') + y*m20') // + m21 ( = m21' + x*(2*m11' + 2*y*m10' + x*m01' + x*y*m00') + y*m20')
m.m21 += mom[7] + x * (2 * (mom[4] + y * mom[1]) + x * (mom[2] + ym)) + y * mom[3]; m.m21 += mom[7] + x * (2 * (mom[4] + y * mom[1]) + x * (mom[2] + ym)) + y * mom[3];
// + m12 ( = m12' + y*(2*m11' + 2*x*m01' + y*m10' + x*y*m00') + x*m02') // + m12 ( = m12' + y*(2*m11' + 2*x*m01' + y*m10' + x*y*m00') + x*m02')
m.m12 += mom[8] + y * (2 * (mom[4] + x * mom[2]) + y * (mom[1] + xm)) + x * mom[5]; m.m12 += mom[8] + y * (2 * (mom[4] + x * mom[2]) + y * (mom[1] + xm)) + x * mom[5];
// + m03 ( = m03' + 3*y*m02' + 3*y*y*m01' + y*y*y*m00' ) // + m03 ( = m03' + 3*y*m02' + 3*y*y*m01' + y*y*y*m00' )
m.m03 += mom[9] + y * (3. * mom[5] + y * (3. * mom[2] + ym)); m.m03 += mom[9] + y * (3. * mom[5] + y * (3. * mom[2] + ym));
} }
return true; return true;
} }
} }
...@@ -441,13 +441,10 @@ cv::Moments cv::moments( InputArray _src, bool binary ) ...@@ -441,13 +441,10 @@ cv::Moments cv::moments( InputArray _src, bool binary )
int cn = CV_MAT_CN( type ); int cn = CV_MAT_CN( type );
Size size = _src.size(); Size size = _src.size();
if( cn > 1 )
CV_Error( CV_StsBadArg, "Invalid image type (must be single-channel)" );
if( size.width <= 0 || size.height <= 0 ) if( size.width <= 0 || size.height <= 0 )
return m; return m;
if( ocl::useOpenCL() && depth == CV_8U && !binary && if( ocl::useOpenCL() && type == CV_8UC1 && !binary &&
_src.isUMat() && ocl_moments(_src, m) ) _src.isUMat() && ocl_moments(_src, m) )
; ;
else else
...@@ -456,6 +453,9 @@ cv::Moments cv::moments( InputArray _src, bool binary ) ...@@ -456,6 +453,9 @@ cv::Moments cv::moments( InputArray _src, bool binary )
if( mat.checkVector(2) >= 0 && (depth == CV_32F || depth == CV_32S)) if( mat.checkVector(2) >= 0 && (depth == CV_32F || depth == CV_32S))
return contourMoments(mat); return contourMoments(mat);
if( cn > 1 )
CV_Error( CV_StsBadArg, "Invalid image type (must be single-channel)" );
if( binary || depth == CV_8U ) if( binary || depth == CV_8U )
func = momentsInTile<uchar, int, int>; func = momentsInTile<uchar, int, int>;
else if( depth == CV_16U ) else if( depth == CV_16U )
......
...@@ -31,17 +31,17 @@ __kernel void moments(__global const uchar* src, int src_step, int src_offset, ...@@ -31,17 +31,17 @@ __kernel void moments(__global const uchar* src, int src_step, int src_offset,
{ {
p = convert_int4(vload4(0, ptr)); p = convert_int4(vload4(0, ptr));
S += SUM_ELEM(p.s0, 0) + SUM_ELEM(p.s1, 1) + SUM_ELEM(p.s2, 2) + SUM_ELEM(p.s3, 3); S += SUM_ELEM(p.s0, 0) + SUM_ELEM(p.s1, 1) + SUM_ELEM(p.s2, 2) + SUM_ELEM(p.s3, 3);
if( x_max >= 8 ) if( x_max >= 8 )
{ {
p = convert_int4(vload4(0, ptr+4)); p = convert_int4(vload4(0, ptr+4));
S += SUM_ELEM(p.s0, 4) + SUM_ELEM(p.s1, 5) + SUM_ELEM(p.s2, 6) + SUM_ELEM(p.s3, 7); S += SUM_ELEM(p.s0, 4) + SUM_ELEM(p.s1, 5) + SUM_ELEM(p.s2, 6) + SUM_ELEM(p.s3, 7);
if( x_max >= 12 ) if( x_max >= 12 )
{ {
p = convert_int4(vload4(0, ptr+8)); p = convert_int4(vload4(0, ptr+8));
S += SUM_ELEM(p.s0, 8) + SUM_ELEM(p.s1, 9) + SUM_ELEM(p.s2, 10) + SUM_ELEM(p.s3, 11); S += SUM_ELEM(p.s0, 8) + SUM_ELEM(p.s1, 9) + SUM_ELEM(p.s2, 10) + SUM_ELEM(p.s3, 11);
if( x_max >= 16 ) if( x_max >= 16 )
{ {
p = convert_int4(vload4(0, ptr+12)); p = convert_int4(vload4(0, ptr+12));
...@@ -50,7 +50,7 @@ __kernel void moments(__global const uchar* src, int src_step, int src_offset, ...@@ -50,7 +50,7 @@ __kernel void moments(__global const uchar* src, int src_step, int src_offset,
} }
} }
} }
if( x < x_max ) if( x < x_max )
{ {
int ps = ptr[x]; int ps = ptr[x];
...@@ -66,7 +66,7 @@ __kernel void moments(__global const uchar* src, int src_step, int src_offset, ...@@ -66,7 +66,7 @@ __kernel void moments(__global const uchar* src, int src_step, int src_offset,
} }
} }
} }
int sy = y*y; int sy = y*y;
m00 += S.s0; m00 += S.s0;
m10 += S.s1; m10 += S.s1;
......
...@@ -113,16 +113,16 @@ void CV_MomentsTest::get_test_array_types_and_sizes( int test_case_idx, ...@@ -113,16 +113,16 @@ void CV_MomentsTest::get_test_array_types_and_sizes( int test_case_idx,
int cn = (cvtest::randInt(rng) % 4) + 1; int cn = (cvtest::randInt(rng) % 4) + 1;
int depth = cvtest::randInt(rng) % 4; int depth = cvtest::randInt(rng) % 4;
depth = depth == 0 ? CV_8U : depth == 1 ? CV_16U : depth == 2 ? CV_16S : CV_32F; depth = depth == 0 ? CV_8U : depth == 1 ? CV_16U : depth == 2 ? CV_16S : CV_32F;
is_binary = cvtest::randInt(rng) % 2 != 0; is_binary = cvtest::randInt(rng) % 2 != 0;
if( depth == 0 && !is_binary ) if( depth == 0 && !is_binary )
try_umat = cvtest::randInt(rng) % 5 != 0; try_umat = cvtest::randInt(rng) % 5 != 0;
else else
try_umat = cvtest::randInt(rng) % 2 != 0; try_umat = cvtest::randInt(rng) % 2 != 0;
if( cn == 2 || try_umat ) if( cn == 2 || try_umat )
cn = 1; cn = 1;
OCL_TUNING_MODE_ONLY( OCL_TUNING_MODE_ONLY(
cn = 1; cn = 1;
depth = CV_8U; depth = CV_8U;
...@@ -136,7 +136,7 @@ void CV_MomentsTest::get_test_array_types_and_sizes( int test_case_idx, ...@@ -136,7 +136,7 @@ void CV_MomentsTest::get_test_array_types_and_sizes( int test_case_idx,
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(MOMENT_COUNT,1); sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(MOMENT_COUNT,1);
if(CV_MAT_DEPTH(types[INPUT][0])>=CV_32S) if(CV_MAT_DEPTH(types[INPUT][0])>=CV_32S)
sizes[INPUT][0].width = MAX(sizes[INPUT][0].width, 3); sizes[INPUT][0].width = MAX(sizes[INPUT][0].width, 3);
coi = 0; coi = 0;
cvmat_allowed = true; cvmat_allowed = true;
if( cn > 1 ) if( cn > 1 )
...@@ -189,7 +189,7 @@ void CV_MomentsTest::run_func() ...@@ -189,7 +189,7 @@ void CV_MomentsTest::run_func()
} }
else else
cvMoments( test_array[INPUT][0], m, is_binary ); cvMoments( test_array[INPUT][0], m, is_binary );
others[0] = cvGetNormalizedCentralMoment( m, 2, 0 ); others[0] = cvGetNormalizedCentralMoment( m, 2, 0 );
others[1] = cvGetNormalizedCentralMoment( m, 1, 1 ); others[1] = cvGetNormalizedCentralMoment( m, 1, 1 );
others[2] = cvGetNormalizedCentralMoment( m, 0, 2 ); others[2] = cvGetNormalizedCentralMoment( m, 0, 2 );
......
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