spatialGradient: Add asserts

This commit is contained in:
Seon-Wook Park 2015-06-19 01:23:01 +02:00
parent 9f1c641199
commit 11fb1f74cc
2 changed files with 26 additions and 11 deletions

View File

@ -45,12 +45,24 @@
namespace cv
{
void spatialGradient( InputArray src, OutputArray dx, OutputArray dy, int ksize )
void spatialGradient( InputArray _src, OutputArray _dx, OutputArray _dy, int ksize )
{
Mat src = _src.getMat();
CV_Assert(!src.empty());
CV_Assert(src.isContinuous());
CV_Assert(src.type() == CV_8UC1);
_dx.create(src.size(), CV_16SC1);
_dy.create(src.size(), CV_16SC1);
Mat dx = _dx.getMat(),
dy = _dy.getMat();
CV_Assert(dx.isContinuous());
CV_Assert(dy.isContinuous());
// TODO: Vectorize using hal intrinsics
Sobel( src, dx, CV_16S, 1, 0, 3 );
Sobel( src, dy, CV_16S, 0, 1, 3 );
Sobel( src, dx, CV_16SC1, 1, 0, ksize );
Sobel( src, dy, CV_16SC1, 0, 1, ksize );
}
}

View File

@ -582,9 +582,12 @@ void CV_SpatialGradientTest::get_test_array_types_and_sizes( int test_case_idx,
sizes[OUTPUT][1] = sizes[REF_OUTPUT][1] = sizes[OUTPUT][0];
// Only CV_16S1 for now
types[INPUT][0] = types[OUTPUT][0] = types[OUTPUT][1] = types[REF_OUTPUT][0]
= types[REF_OUTPUT][1] = CV_MAKETYPE(CV_16S, 1);
// Inputs are only CV_8UC1 for now
types[INPUT][0] = CV_8UC1;
// Outputs are only CV_16SC1 for now
types[OUTPUT][0] = types[OUTPUT][1] = types[REF_OUTPUT][0]
= types[REF_OUTPUT][1] = CV_16SC1;
ksize = 3;
}
@ -592,11 +595,11 @@ void CV_SpatialGradientTest::get_test_array_types_and_sizes( int test_case_idx,
void CV_SpatialGradientTest::run_func()
{
spatialGradient( cvarrToMat(test_array[INPUT][0]),
cvarrToMat(test_array[OUTPUT][0]),
cvarrToMat(test_array[OUTPUT][1]),
ksize
);
Mat dx, dy;
spatialGradient( test_mat[INPUT][0].clone(), dx, dy, ksize );
test_mat[OUTPUT][0] = dx;
test_mat[OUTPUT][1] = dy;
}