Commit 426b3f61 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #4139 from swook:spatial_gradient

parents d5afd070 20bf88ba
......@@ -1369,6 +1369,28 @@ CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,
double scale = 1, double delta = 0,
int borderType = BORDER_DEFAULT );
/** @brief Calculates the first order image derivative in both x and y using a Sobel operator
Equivalent to calling:
@code
Sobel( src, dx, CV_16SC1, 1, 0, 3 );
Sobel( src, dy, CV_16SC1, 0, 1, 3 );
@endcode
@param src input image.
@param dx output image with first-order derivative in x.
@param dy output image with first-order derivative in y.
@param ksize size of Sobel kernel. It must be 3.
@param borderType pixel extrapolation method, see cv::BorderTypes
@sa Sobel
*/
CV_EXPORTS_W void spatialGradient( InputArray src, OutputArray dx,
OutputArray dy, int ksize = 3,
int borderType = BORDER_DEFAULT );
/** @brief Calculates the first x- or y- image derivative using Scharr operator.
The function computes the first x- or y- spatial image derivative using the Scharr operator. The
......
#include "perf_precomp.hpp"
using namespace std;
using namespace cv;
using namespace perf;
using namespace testing;
using std::tr1::make_tuple;
using std::tr1::get;
typedef std::tr1::tuple<Size, int, int> Size_Ksize_BorderType_t;
typedef perf::TestBaseWithParam<Size_Ksize_BorderType_t> Size_Ksize_BorderType;
PERF_TEST_P( Size_Ksize_BorderType, spatialGradient,
Combine(
SZ_ALL_HD,
Values( 3 ),
Values( BORDER_DEFAULT, BORDER_REPLICATE )
)
)
{
Size size = std::tr1::get<0>(GetParam());
int ksize = std::tr1::get<1>(GetParam());
int borderType = std::tr1::get<2>(GetParam());
Mat src(size, CV_8UC1);
Mat dx(size, CV_16SC1);
Mat dy(size, CV_16SC1);
declare.in(src, WARMUP_RNG).out(dx, dy);
TEST_CYCLE() spatialGradient(src, dx, dy, ksize, borderType);
SANITY_CHECK(dx);
SANITY_CHECK(dy);
}
......@@ -49,6 +49,7 @@
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/private.hpp"
#include "opencv2/core/ocl.hpp"
#include "opencv2/hal.hpp"
#include <math.h>
#include <assert.h>
......
This diff is collapsed.
......@@ -552,6 +552,68 @@ void CV_SobelTest::prepare_to_validation( int /*test_case_idx*/ )
}
/////////////// spatialGradient ///////////////
class CV_SpatialGradientTest : public CV_DerivBaseTest
{
public:
CV_SpatialGradientTest();
protected:
void prepare_to_validation( int test_case_idx );
void run_func();
void get_test_array_types_and_sizes( int test_case_idx,
vector<vector<Size> >& sizes, vector<vector<int> >& types );
int ksize;
};
CV_SpatialGradientTest::CV_SpatialGradientTest() {
test_array[OUTPUT].push_back(NULL);
test_array[REF_OUTPUT].push_back(NULL);
inplace = false;
}
void CV_SpatialGradientTest::get_test_array_types_and_sizes( int test_case_idx,
vector<vector<Size> >& sizes,
vector<vector<int> >& types )
{
CV_DerivBaseTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
sizes[OUTPUT][1] = sizes[REF_OUTPUT][1] = sizes[OUTPUT][0];
// 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;
border = BORDER_DEFAULT; // TODO: Add BORDER_REPLICATE
}
void CV_SpatialGradientTest::run_func()
{
spatialGradient( test_mat[INPUT][0], test_mat[OUTPUT][0],
test_mat[OUTPUT][1], ksize, border );
}
void CV_SpatialGradientTest::prepare_to_validation( int /*test_case_idx*/ )
{
int dx, dy;
dx = 1; dy = 0;
Sobel( test_mat[INPUT][0], test_mat[REF_OUTPUT][0], CV_16SC1, dx, dy, ksize,
1, 0, border );
dx = 0; dy = 1;
Sobel( test_mat[INPUT][0], test_mat[REF_OUTPUT][1], CV_16SC1, dx, dy, ksize,
1, 0, border );
}
/////////////// laplace ///////////////
class CV_LaplaceTest : public CV_DerivBaseTest
......@@ -1773,6 +1835,7 @@ TEST(Imgproc_Dilate, accuracy) { CV_DilateTest test; test.safe_run(); }
TEST(Imgproc_MorphologyEx, accuracy) { CV_MorphExTest test; test.safe_run(); }
TEST(Imgproc_Filter2D, accuracy) { CV_FilterTest test; test.safe_run(); }
TEST(Imgproc_Sobel, accuracy) { CV_SobelTest test; test.safe_run(); }
TEST(Imgproc_SpatialGradient, accuracy) { CV_SpatialGradientTest test; test.safe_run(); }
TEST(Imgproc_Laplace, accuracy) { CV_LaplaceTest test; test.safe_run(); }
TEST(Imgproc_Blur, accuracy) { CV_BlurTest test; test.safe_run(); }
TEST(Imgproc_GaussianBlur, accuracy) { CV_GaussianBlurTest test; test.safe_run(); }
......
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