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
9e47672b
Commit
9e47672b
authored
May 07, 2014
by
Alexander Alekhin
Committed by
OpenCV Buildbot
May 07, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2658 from akarsakov:ipp_hough
parents
d54aa307
f6a8ac2f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
185 additions
and
63 deletions
+185
-63
perf_houghLines.cpp
modules/imgproc/perf/perf_houghLines.cpp
+4
-0
hough.cpp
modules/imgproc/src/hough.cpp
+48
-0
test_houghLines.cpp
modules/imgproc/test/test_houghLines.cpp
+133
-63
No files found.
modules/imgproc/perf/perf_houghLines.cpp
View file @
9e47672b
...
...
@@ -37,5 +37,9 @@ PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines,
TEST_CYCLE
()
HoughLines
(
image
,
lines
,
rhoStep
,
thetaStep
,
threshold
);
transpose
(
lines
,
lines
);
#if (0 && defined(HAVE_IPP) && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 801)
SANITY_CHECK_NOTHING
();
#else
SANITY_CHECK
(
lines
);
#endif
}
modules/imgproc/src/hough.cpp
View file @
9e47672b
...
...
@@ -12,6 +12,7 @@
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Copyright (C) 2014, Itseez, Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
...
...
@@ -97,6 +98,28 @@ HoughLinesStandard( const Mat& img, float rho, float theta,
int
numangle
=
cvRound
((
max_theta
-
min_theta
)
/
theta
);
int
numrho
=
cvRound
(((
width
+
height
)
*
2
+
1
)
/
rho
);
#if (0 && defined(HAVE_IPP) && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 801)
IppiSize
srcSize
=
{
width
,
height
};
IppPointPolar
delta
=
{
rho
,
theta
};
IppPointPolar
dstRoi
[
2
]
=
{{(
Ipp32f
)
-
(
width
+
height
),
(
Ipp32f
)
min_theta
},{(
Ipp32f
)
(
width
+
height
),
(
Ipp32f
)
max_theta
}};
int
bufferSize
;
int
nz
=
countNonZero
(
img
);
int
ipp_linesMax
=
std
::
min
(
linesMax
,
nz
*
numangle
/
threshold
);
int
linesCount
=
0
;
lines
.
resize
(
ipp_linesMax
);
IppStatus
ok
=
ippiHoughLineGetSize_8u_C1R
(
srcSize
,
delta
,
ipp_linesMax
,
&
bufferSize
);
Ipp8u
*
buffer
=
ippsMalloc_8u
(
bufferSize
);
if
(
ok
>=
0
)
ok
=
ippiHoughLine_Region_8u32f_C1R
(
image
,
step
,
srcSize
,
(
IppPointPolar
*
)
&
lines
[
0
],
dstRoi
,
ipp_linesMax
,
&
linesCount
,
delta
,
threshold
,
buffer
);
ippsFree
(
buffer
);
if
(
ok
>=
0
)
{
lines
.
resize
(
linesCount
);
return
;
}
lines
.
clear
();
setIppErrorStatus
();
#endif
AutoBuffer
<
int
>
_accum
((
numangle
+
2
)
*
(
numrho
+
2
));
std
::
vector
<
int
>
_sort_buf
;
AutoBuffer
<
float
>
_tabSin
(
numangle
);
...
...
@@ -404,6 +427,31 @@ HoughLinesProbabilistic( Mat& image,
int
numangle
=
cvRound
(
CV_PI
/
theta
);
int
numrho
=
cvRound
(((
width
+
height
)
*
2
+
1
)
/
rho
);
#if (0 && defined(HAVE_IPP) && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 801)
IppiSize
srcSize
=
{
width
,
height
};
IppPointPolar
delta
=
{
rho
,
theta
};
IppiHoughProbSpec
*
pSpec
;
int
bufferSize
,
specSize
;
int
ipp_linesMax
=
std
::
min
(
linesMax
,
numangle
*
numrho
);
int
linesCount
=
0
;
lines
.
resize
(
ipp_linesMax
);
IppStatus
ok
=
ippiHoughProbLineGetSize_8u_C1R
(
srcSize
,
delta
,
&
specSize
,
&
bufferSize
);
Ipp8u
*
buffer
=
ippsMalloc_8u
(
bufferSize
);
pSpec
=
(
IppiHoughProbSpec
*
)
malloc
(
specSize
);
if
(
ok
>=
0
)
ok
=
ippiHoughProbLineInit_8u32f_C1R
(
srcSize
,
delta
,
ippAlgHintNone
,
pSpec
);
if
(
ok
>=
0
)
ok
=
ippiHoughProbLine_8u32f_C1R
(
image
.
data
,
image
.
step
,
srcSize
,
threshold
,
lineLength
,
lineGap
,
(
IppiPoint
*
)
&
lines
[
0
],
ipp_linesMax
,
&
linesCount
,
buffer
,
pSpec
);
free
(
pSpec
);
ippsFree
(
buffer
);
if
(
ok
>=
0
)
{
lines
.
resize
(
linesCount
);
return
;
}
lines
.
clear
();
setIppErrorStatus
();
#endif
Mat
accum
=
Mat
::
zeros
(
numangle
,
numrho
,
CV_32SC1
);
Mat
mask
(
height
,
width
,
CV_8UC1
);
std
::
vector
<
float
>
trigtab
(
numangle
*
2
);
...
...
modules/imgproc/test/test_houghLines.cpp
View file @
9e47672b
...
...
@@ -12,6 +12,7 @@
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2014, Itseez, Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
...
...
@@ -45,107 +46,176 @@
using
namespace
cv
;
using
namespace
std
;
class
CV_HoughLinesTest
:
public
cvtest
::
BaseTest
template
<
typename
T
>
struct
SimilarWith
{
public
:
enum
{
STANDART
=
0
,
PROBABILISTIC
};
CV_HoughLinesTest
()
{}
~
CV_HoughLinesTest
()
{}
protected
:
void
run_test
(
int
type
);
T
value
;
float
theta_eps
;
float
rho_eps
;
SimilarWith
<
T
>
(
T
val
,
float
e
,
float
r_e
)
:
value
(
val
),
theta_eps
(
e
),
rho_eps
(
r_e
)
{
};
bool
operator
()(
T
other
);
};
class
CV_StandartHoughLinesTest
:
public
CV_HoughLinesTest
template
<>
bool
SimilarWith
<
Vec2f
>::
operator
()(
Vec2f
other
)
{
public
:
CV_StandartHoughLinesTest
()
{}
~
CV_StandartHoughLinesTest
()
{}
virtual
void
run
(
int
);
};
return
abs
(
other
[
0
]
-
value
[
0
])
<
rho_eps
&&
abs
(
other
[
1
]
-
value
[
1
])
<
theta_eps
;
}
class
CV_ProbabilisticHoughLinesTest
:
public
CV_HoughLinesTest
template
<>
bool
SimilarWith
<
Vec4i
>::
operator
()(
Vec4i
other
)
{
public
:
CV_ProbabilisticHoughLinesTest
()
{}
~
CV_ProbabilisticHoughLinesTest
()
{}
virtual
void
run
(
int
);
};
return
norm
(
value
,
other
)
<
theta_eps
;
}
void
CV_StandartHoughLinesTest
::
run
(
int
)
template
<
typename
T
>
int
countMatIntersection
(
Mat
expect
,
Mat
actual
,
float
eps
,
float
rho_eps
)
{
run_test
(
STANDART
);
int
count
=
0
;
if
(
!
expect
.
empty
()
&&
!
actual
.
empty
())
{
for
(
MatIterator_
<
T
>
it
=
expect
.
begin
<
T
>
();
it
!=
expect
.
end
<
T
>
();
it
++
)
{
MatIterator_
<
T
>
f
=
std
::
find_if
(
actual
.
begin
<
T
>
(),
actual
.
end
<
T
>
(),
SimilarWith
<
T
>
(
*
it
,
eps
,
rho_eps
));
if
(
f
!=
actual
.
end
<
T
>
())
count
++
;
}
}
return
count
;
}
void
CV_ProbabilisticHoughLinesTest
::
run
(
int
)
String
getTestCaseName
(
String
filename
)
{
run_test
(
PROBABILISTIC
);
string
temp
(
filename
);
size_t
pos
=
temp
.
find_first_of
(
"
\\
/."
);
while
(
pos
!=
string
::
npos
)
{
temp
.
replace
(
pos
,
1
,
"_"
);
pos
=
temp
.
find_first_of
(
"
\\
/."
);
}
return
String
(
temp
);
}
void
CV_HoughLinesTest
::
run_test
(
int
type
)
class
BaseHoughLineTest
{
Mat
src
=
imread
(
string
(
ts
->
get_data_path
())
+
"shared/pic1.png"
);
if
(
src
.
empty
())
public
:
enum
{
STANDART
=
0
,
PROBABILISTIC
};
protected
:
void
run_test
(
int
type
);
string
picture_name
;
double
rhoStep
;
double
thetaStep
;
int
threshold
;
int
minLineLength
;
int
maxGap
;
};
typedef
std
::
tr1
::
tuple
<
string
,
double
,
double
,
int
>
Image_RhoStep_ThetaStep_Threshold_t
;
class
StandartHoughLinesTest
:
public
BaseHoughLineTest
,
public
testing
::
TestWithParam
<
Image_RhoStep_ThetaStep_Threshold_t
>
{
public
:
StandartHoughLinesTest
()
{
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_TEST_DATA
);
return
;
picture_name
=
std
::
tr1
::
get
<
0
>
(
GetParam
());
rhoStep
=
std
::
tr1
::
get
<
1
>
(
GetParam
());
thetaStep
=
std
::
tr1
::
get
<
2
>
(
GetParam
());
threshold
=
std
::
tr1
::
get
<
3
>
(
GetParam
());
minLineLength
=
0
;
maxGap
=
0
;
}
};
typedef
std
::
tr1
::
tuple
<
string
,
double
,
double
,
int
,
int
,
int
>
Image_RhoStep_ThetaStep_Threshold_MinLine_MaxGap_t
;
class
ProbabilisticHoughLinesTest
:
public
BaseHoughLineTest
,
public
testing
::
TestWithParam
<
Image_RhoStep_ThetaStep_Threshold_MinLine_MaxGap_t
>
{
public
:
ProbabilisticHoughLinesTest
()
{
picture_name
=
std
::
tr1
::
get
<
0
>
(
GetParam
());
rhoStep
=
std
::
tr1
::
get
<
1
>
(
GetParam
());
thetaStep
=
std
::
tr1
::
get
<
2
>
(
GetParam
());
threshold
=
std
::
tr1
::
get
<
3
>
(
GetParam
());
minLineLength
=
std
::
tr1
::
get
<
4
>
(
GetParam
());
maxGap
=
std
::
tr1
::
get
<
5
>
(
GetParam
());
}
};
void
BaseHoughLineTest
::
run_test
(
int
type
)
{
string
filename
=
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
picture_name
;
Mat
src
=
imread
(
filename
,
IMREAD_GRAYSCALE
);
EXPECT_FALSE
(
src
.
empty
())
<<
"Invalid test image: "
<<
filename
;
string
xml
;
if
(
type
==
STANDART
)
xml
=
string
(
ts
->
get_data_path
())
+
"imgproc/HoughLines.xml"
;
xml
=
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
())
+
"imgproc/HoughLines.xml"
;
else
if
(
type
==
PROBABILISTIC
)
xml
=
string
(
ts
->
get_data_path
())
+
"imgproc/HoughLinesP.xml"
;
else
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"Error: unknown HoughLines algorithm type.
\n
"
);
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_GENERIC
);
return
;
}
xml
=
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
())
+
"imgproc/HoughLinesP.xml"
;
Mat
dst
;
Canny
(
src
,
dst
,
50
,
200
,
3
);
Canny
(
src
,
dst
,
100
,
150
,
3
);
EXPECT_FALSE
(
dst
.
empty
())
<<
"Failed Canny edge detector"
;
Mat
lines
;
if
(
type
==
STANDART
)
HoughLines
(
dst
,
lines
,
1
,
CV_PI
/
180
,
100
,
0
,
0
);
HoughLines
(
dst
,
lines
,
rhoStep
,
thetaStep
,
threshold
,
0
,
0
);
else
if
(
type
==
PROBABILISTIC
)
HoughLinesP
(
dst
,
lines
,
1
,
CV_PI
/
180
,
100
,
0
,
0
);
HoughLinesP
(
dst
,
lines
,
rhoStep
,
thetaStep
,
threshold
,
minLineLength
,
maxGap
);
String
test_case_name
=
format
(
"lines_%s_%.0f_%.2f_%d_%d_%d"
,
picture_name
.
c_str
(),
rhoStep
,
thetaStep
,
threshold
,
minLineLength
,
maxGap
);
test_case_name
=
getTestCaseName
(
test_case_name
);
FileStorage
fs
(
xml
,
FileStorage
::
READ
);
if
(
!
fs
.
isOpened
())
FileNode
node
=
fs
[
test_case_name
];
if
(
node
.
empty
())
{
fs
.
open
(
xml
,
FileStorage
::
WRITE
);
if
(
!
fs
.
isOpened
())
{
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_TEST_DATA
);
return
;
}
fs
<<
"exp_lines"
<<
lines
;
fs
.
release
();
fs
.
open
(
xml
,
FileStorage
::
APPEND
);
EXPECT_TRUE
(
fs
.
isOpened
())
<<
"Cannot open sanity data file: "
<<
xml
;
fs
<<
test_case_name
<<
lines
;
fs
.
release
();
fs
.
open
(
xml
,
FileStorage
::
READ
);
if
(
!
fs
.
isOpened
())
{
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_TEST_DATA
);
return
;
}
EXPECT_TRUE
(
fs
.
isOpened
())
<<
"Cannot open sanity data file: "
<<
xml
;
}
Mat
exp_lines
;
read
(
fs
[
"exp_lines"
],
exp_lines
,
Mat
()
);
read
(
fs
[
test_case_name
],
exp_lines
,
Mat
()
);
fs
.
release
();
if
(
exp_lines
.
size
!=
lines
.
size
)
transpose
(
lines
,
lines
);
int
count
=
-
1
;
if
(
type
==
STANDART
)
count
=
countMatIntersection
<
Vec2f
>
(
exp_lines
,
lines
,
(
float
)
thetaStep
+
FLT_EPSILON
,
(
float
)
rhoStep
+
FLT_EPSILON
);
else
if
(
type
==
PROBABILISTIC
)
count
=
countMatIntersection
<
Vec4i
>
(
exp_lines
,
lines
,
1e-4
f
,
0.
f
);
if
(
exp_lines
.
size
!=
lines
.
size
||
cvtest
::
norm
(
exp_lines
,
lines
,
NORM_INF
)
>
1e-4
)
{
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_MISMATCH
);
return
;
}
#if (0 && defined(HAVE_IPP) && !defined(HAVE_IPP_ICV_ONLY) && IPP_VERSION_X100 >= 801)
EXPECT_GE
(
count
,
(
int
)
(
exp_lines
.
total
()
*
0.8
)
);
#else
EXPECT_EQ
(
count
,
(
int
)
exp_lines
.
total
());
#endif
}
ts
->
set_failed_test_info
(
cvtest
::
TS
::
OK
);
TEST_P
(
StandartHoughLinesTest
,
regression
)
{
run_test
(
STANDART
);
}
TEST
(
Imgproc_HoughLines
,
regression
)
{
CV_StandartHoughLinesTest
test
;
test
.
safe_run
();
}
TEST_P
(
ProbabilisticHoughLinesTest
,
regression
)
{
run_test
(
PROBABILISTIC
);
}
TEST
(
Imgproc_HoughLinesP
,
regression
)
{
CV_ProbabilisticHoughLinesTest
test
;
test
.
safe_run
();
}
INSTANTIATE_TEST_CASE_P
(
ImgProc
,
StandartHoughLinesTest
,
testing
::
Combine
(
testing
::
Values
(
"shared/pic5.png"
,
"../stitching/a1.png"
),
testing
::
Values
(
1
,
10
),
testing
::
Values
(
0.05
,
0.1
),
testing
::
Values
(
80
,
150
)
));
INSTANTIATE_TEST_CASE_P
(
ImgProc
,
ProbabilisticHoughLinesTest
,
testing
::
Combine
(
testing
::
Values
(
"shared/pic5.png"
,
"shared/pic1.png"
),
testing
::
Values
(
5
,
10
),
testing
::
Values
(
0.05
,
0.1
),
testing
::
Values
(
75
,
150
),
testing
::
Values
(
0
,
10
),
testing
::
Values
(
0
,
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