Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
a455858d
Commit
a455858d
authored
Jul 20, 2016
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6878 from alalek:canny_custom_gradient
parents
848c66ba
e20a93f7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
12 deletions
+69
-12
imgproc.hpp
modules/imgproc/include/opencv2/imgproc.hpp
+13
-0
canny.cpp
modules/imgproc/src/canny.cpp
+0
-0
test_canny.cpp
modules/imgproc/test/ocl/test_canny.cpp
+30
-7
test_canny.cpp
modules/imgproc/test/test_canny.cpp
+24
-3
ocl_test.hpp
modules/ts/include/opencv2/ts/ocl_test.hpp
+2
-2
No files found.
modules/imgproc/include/opencv2/imgproc.hpp
View file @
a455858d
...
...
@@ -1664,6 +1664,19 @@ CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
double
threshold1
,
double
threshold2
,
int
apertureSize
=
3
,
bool
L2gradient
=
false
);
/** \overload
Finds edges in an image using the Canny algorithm with custom image gradient.
@param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3).
@param dy 16-bit y derivative of input image (same type as dx).
@param edges,threshold1,threshold2,L2gradient See cv::Canny
*/
CV_EXPORTS_W
void
Canny
(
InputArray
dx
,
InputArray
dy
,
OutputArray
edges
,
double
threshold1
,
double
threshold2
,
bool
L2gradient
=
false
);
/** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection.
The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal
...
...
modules/imgproc/src/canny.cpp
View file @
a455858d
This diff is collapsed.
Click to expand it.
modules/imgproc/test/ocl/test_canny.cpp
View file @
a455858d
...
...
@@ -54,13 +54,13 @@ namespace ocl {
////////////////////////////////////////////////////////
// Canny
IMPLEMENT_PARAM_CLASS
(
Ap
p
ertureSize
,
int
)
IMPLEMENT_PARAM_CLASS
(
ApertureSize
,
int
)
IMPLEMENT_PARAM_CLASS
(
L2gradient
,
bool
)
IMPLEMENT_PARAM_CLASS
(
UseRoi
,
bool
)
PARAM_TEST_CASE
(
Canny
,
Channels
,
Ap
p
ertureSize
,
L2gradient
,
UseRoi
)
PARAM_TEST_CASE
(
Canny
,
Channels
,
ApertureSize
,
L2gradient
,
UseRoi
)
{
int
cn
,
ap
p
erture_size
;
int
cn
,
aperture_size
;
bool
useL2gradient
,
use_roi
;
TEST_DECLARE_INPUT_PARAMETER
(
src
);
...
...
@@ -69,7 +69,7 @@ PARAM_TEST_CASE(Canny, Channels, AppertureSize, L2gradient, UseRoi)
virtual
void
SetUp
()
{
cn
=
GET_PARAM
(
0
);
ap
p
erture_size
=
GET_PARAM
(
1
);
aperture_size
=
GET_PARAM
(
1
);
useL2gradient
=
GET_PARAM
(
2
);
use_roi
=
GET_PARAM
(
3
);
}
...
...
@@ -105,8 +105,31 @@ OCL_TEST_P(Canny, Accuracy)
eps
=
12e-3
;
#endif
OCL_OFF
(
cv
::
Canny
(
src_roi
,
dst_roi
,
low_thresh
,
high_thresh
,
apperture_size
,
useL2gradient
));
OCL_ON
(
cv
::
Canny
(
usrc_roi
,
udst_roi
,
low_thresh
,
high_thresh
,
apperture_size
,
useL2gradient
));
OCL_OFF
(
cv
::
Canny
(
src_roi
,
dst_roi
,
low_thresh
,
high_thresh
,
aperture_size
,
useL2gradient
));
OCL_ON
(
cv
::
Canny
(
usrc_roi
,
udst_roi
,
low_thresh
,
high_thresh
,
aperture_size
,
useL2gradient
));
EXPECT_MAT_SIMILAR
(
dst_roi
,
udst_roi
,
eps
);
EXPECT_MAT_SIMILAR
(
dst
,
udst
,
eps
);
}
OCL_TEST_P
(
Canny
,
AccuracyCustomGradient
)
{
generateTestData
();
const
double
low_thresh
=
50.0
,
high_thresh
=
100.0
;
double
eps
=
1e-2
;
#ifdef ANDROID
if
(
cv
::
ocl
::
Device
::
getDefault
().
isNVidia
())
eps
=
12e-3
;
#endif
OCL_OFF
(
cv
::
Canny
(
src_roi
,
dst_roi
,
low_thresh
,
high_thresh
,
aperture_size
,
useL2gradient
));
OCL_ON
(
UMat
dx
,
dy
;
Sobel
(
usrc_roi
,
dx
,
CV_16S
,
1
,
0
,
aperture_size
,
1
,
0
,
BORDER_REPLICATE
);
Sobel
(
usrc_roi
,
dy
,
CV_16S
,
0
,
1
,
aperture_size
,
1
,
0
,
BORDER_REPLICATE
);
cv
::
Canny
(
dx
,
dy
,
udst_roi
,
low_thresh
,
high_thresh
,
useL2gradient
);
);
EXPECT_MAT_SIMILAR
(
dst_roi
,
udst_roi
,
eps
);
EXPECT_MAT_SIMILAR
(
dst
,
udst
,
eps
);
...
...
@@ -114,7 +137,7 @@ OCL_TEST_P(Canny, Accuracy)
OCL_INSTANTIATE_TEST_CASE_P
(
ImgProc
,
Canny
,
testing
::
Combine
(
testing
::
Values
(
1
,
3
),
testing
::
Values
(
Ap
pertureSize
(
3
),
Ap
pertureSize
(
5
)),
testing
::
Values
(
Ap
ertureSize
(
3
),
A
pertureSize
(
5
)),
testing
::
Values
(
L2gradient
(
false
),
L2gradient
(
true
)),
testing
::
Values
(
UseRoi
(
false
),
UseRoi
(
true
))));
...
...
modules/imgproc/test/test_canny.cpp
View file @
a455858d
...
...
@@ -47,7 +47,7 @@ using namespace std;
class
CV_CannyTest
:
public
cvtest
::
ArrayTest
{
public
:
CV_CannyTest
();
CV_CannyTest
(
bool
custom_deriv
=
false
);
protected
:
void
get_test_array_types_and_sizes
(
int
test_case_idx
,
vector
<
vector
<
Size
>
>&
sizes
,
vector
<
vector
<
int
>
>&
types
);
...
...
@@ -61,10 +61,11 @@ protected:
bool
use_true_gradient
;
double
threshold1
,
threshold2
;
bool
test_cpp
;
bool
test_custom_deriv
;
};
CV_CannyTest
::
CV_CannyTest
()
CV_CannyTest
::
CV_CannyTest
(
bool
custom_deriv
)
{
test_array
[
INPUT
].
push_back
(
NULL
);
test_array
[
OUTPUT
].
push_back
(
NULL
);
...
...
@@ -75,6 +76,7 @@ CV_CannyTest::CV_CannyTest()
threshold1
=
threshold2
=
0
;
test_cpp
=
false
;
test_custom_deriv
=
custom_deriv
;
}
...
...
@@ -99,6 +101,9 @@ void CV_CannyTest::get_test_array_types_and_sizes( int test_case_idx,
use_true_gradient
=
cvtest
::
randInt
(
rng
)
%
2
!=
0
;
test_cpp
=
(
cvtest
::
randInt
(
rng
)
&
256
)
==
0
;
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"Canny(size = %d x %d, aperture_size = %d, threshold1 = %g, threshold2 = %g, L2 = %s) test_cpp = %s (test case #%d)
\n
"
,
sizes
[
0
][
0
].
width
,
sizes
[
0
][
0
].
height
,
aperture_size
,
threshold1
,
threshold2
,
use_true_gradient
?
"TRUE"
:
"FALSE"
,
test_cpp
?
"TRUE"
:
"FALSE"
,
test_case_idx
);
}
...
...
@@ -123,9 +128,24 @@ double CV_CannyTest::get_success_error_level( int /*test_case_idx*/, int /*i*/,
void
CV_CannyTest
::
run_func
()
{
if
(
!
test_cpp
)
if
(
test_custom_deriv
)
{
cv
::
Mat
_out
=
cv
::
cvarrToMat
(
test_array
[
OUTPUT
][
0
]);
cv
::
Mat
src
=
cv
::
cvarrToMat
(
test_array
[
INPUT
][
0
]);
cv
::
Mat
dx
,
dy
;
int
m
=
aperture_size
;
Point
anchor
(
m
/
2
,
m
/
2
);
Mat
dxkernel
=
cvtest
::
calcSobelKernel2D
(
1
,
0
,
m
,
0
);
Mat
dykernel
=
cvtest
::
calcSobelKernel2D
(
0
,
1
,
m
,
0
);
cvtest
::
filter2D
(
src
,
dx
,
CV_16S
,
dxkernel
,
anchor
,
0
,
BORDER_REPLICATE
);
cvtest
::
filter2D
(
src
,
dy
,
CV_16S
,
dykernel
,
anchor
,
0
,
BORDER_REPLICATE
);
cv
::
Canny
(
dx
,
dy
,
_out
,
threshold1
,
threshold2
,
use_true_gradient
);
}
else
if
(
!
test_cpp
)
{
cvCanny
(
test_array
[
INPUT
][
0
],
test_array
[
OUTPUT
][
0
],
threshold1
,
threshold2
,
aperture_size
+
(
use_true_gradient
?
CV_CANNY_L2_GRADIENT
:
0
));
}
else
{
cv
::
Mat
_out
=
cv
::
cvarrToMat
(
test_array
[
OUTPUT
][
0
]);
...
...
@@ -283,5 +303,6 @@ int CV_CannyTest::validate_test_results( int test_case_idx )
}
TEST
(
Imgproc_Canny
,
accuracy
)
{
CV_CannyTest
test
;
test
.
safe_run
();
}
TEST
(
Imgproc_Canny
,
accuracy_deriv
)
{
CV_CannyTest
test
(
true
);
test
.
safe_run
();
}
/* End of file. */
modules/ts/include/opencv2/ts/ocl_test.hpp
View file @
a455858d
...
...
@@ -349,8 +349,8 @@ IMPLEMENT_PARAM_CLASS(Channels, int)
#define OCL_TEST_F(name, ...) typedef name OCL_##name; TEST_F(OCL_##name, __VA_ARGS__)
#define OCL_TEST(name, ...) TEST(OCL_##name, __VA_ARGS__)
#define OCL_OFF(
fn) cv::ocl::setUseOpenCL(false); fn
#define OCL_ON(
fn) cv::ocl::setUseOpenCL(true); fn
#define OCL_OFF(
...) cv::ocl::setUseOpenCL(false); __VA_ARGS__ ;
#define OCL_ON(
...) cv::ocl::setUseOpenCL(true); __VA_ARGS__ ;
#define OCL_ALL_DEPTHS Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F)
#define OCL_ALL_CHANNELS Values(1, 2, 3, 4)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment