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
43716f31
Commit
43716f31
authored
Nov 24, 2010
by
Maria Dimashova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added to FeatureDetector test the check of detect() on empty data
parent
27690e3b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
43 deletions
+107
-43
afeatures2d.cpp
tests/cv/src/afeatures2d.cpp
+107
-43
No files found.
tests/cv/src/afeatures2d.cpp
View file @
43716f31
...
@@ -60,45 +60,67 @@ public:
...
@@ -60,45 +60,67 @@ public:
CvTest
(
testName
,
"cv::FeatureDetector::detect"
),
fdetector
(
_fdetector
)
{}
CvTest
(
testName
,
"cv::FeatureDetector::detect"
),
fdetector
(
_fdetector
)
{}
protected
:
protected
:
virtual
void
run
(
int
/*start_from*/
)
bool
isSimilarKeypoints
(
const
KeyPoint
&
p1
,
const
KeyPoint
&
p2
);
{
void
compareKeypointSets
(
const
vector
<
KeyPoint
>&
validKeypoints
,
const
vector
<
KeyPoint
>&
calcKeypoints
);
const
float
maxPtDif
=
1.
f
;
const
float
maxSizeDif
=
1.
f
;
const
float
maxAngleDif
=
2.
f
;
const
float
maxResponseDif
=
0.1
f
;
string
imgFilename
=
string
(
ts
->
get_data_path
())
+
FEATURES2D_DIR
+
"/"
+
IMAGE_FILENAME
;
void
emptyDataTest
()
;
string
resFilename
=
string
(
ts
->
get_data_path
())
+
DETECTOR_DIR
+
"/"
+
string
(
name
)
+
".xml.gz"
;
void
regressionTest
();
// TODO test of detect() with mask
if
(
fdetector
.
empty
()
)
virtual
void
run
(
int
);
Ptr
<
FeatureDetector
>
fdetector
;
};
void
CV_FeatureDetectorTest
::
emptyDataTest
()
{
Mat
image
;
vector
<
KeyPoint
>
keypoints
;
try
{
{
ts
->
printf
(
CvTS
::
LOG
,
"Feature detector is empty"
);
fdetector
->
detect
(
image
,
keypoints
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_INVALID_TEST_DATA
);
}
catch
(...)
{
ts
->
printf
(
CvTS
::
LOG
,
"emptyDataTest: Detect() on empty image must not generate exeption
\n
"
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_INVALID_OUTPUT
);
return
;
return
;
}
}
Mat
image
=
imread
(
imgFilename
,
0
);
if
(
!
keypoints
.
empty
()
)
if
(
image
.
empty
()
)
{
{
ts
->
printf
(
CvTS
::
LOG
,
"image %s can not be read
\n
"
,
imgFilename
.
c_str
()
);
ts
->
printf
(
CvTS
::
LOG
,
"emptyDataTest: Detect() on empty image must return empty keypoints vector
\n
"
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_INVALID_TEST_DATA
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_INVALID_OUTPUT
);
return
;
return
;
}
}
}
FileStorage
fs
(
resFilename
,
FileStorage
::
READ
);
bool
CV_FeatureDetectorTest
::
isSimilarKeypoints
(
const
KeyPoint
&
p1
,
const
KeyPoint
&
p2
)
{
const
float
maxPtDif
=
1.
f
;
const
float
maxSizeDif
=
1.
f
;
const
float
maxAngleDif
=
2.
f
;
const
float
maxResponseDif
=
0.1
f
;
vector
<
KeyPoint
>
calcKeypoints
;
float
dist
=
(
float
)
norm
(
p1
.
pt
-
p2
.
pt
);
fdetector
->
detect
(
image
,
calcKeypoints
);
return
(
dist
<
maxPtDif
&&
fabs
(
p1
.
size
-
p2
.
size
)
<
maxSizeDif
&&
abs
(
p1
.
angle
-
p2
.
angle
)
<
maxAngleDif
&&
abs
(
p1
.
response
-
p2
.
response
)
<
maxResponseDif
&&
p1
.
octave
==
p2
.
octave
&&
p1
.
class_id
==
p2
.
class_id
);
}
if
(
fs
.
isOpened
()
)
// compare computed and valid keypoints
void
CV_FeatureDetectorTest
::
compareKeypointSets
(
const
vector
<
KeyPoint
>&
validKeypoints
,
const
vector
<
KeyPoint
>&
calcKeypoints
)
{
{
// TODO compare saved feature detector params with current ones
const
float
maxCountRatioDif
=
0.01
f
;
vector
<
KeyPoint
>
validKeypoints
;
read
(
fs
[
"keypoints"
],
validKeypoints
);
// Compare counts of validation and calculated keypoints.
if
(
validKeypoints
.
empty
()
)
float
countRatio
=
(
float
)
validKeypoints
.
size
()
/
(
float
)
calcKeypoints
.
size
();
if
(
countRatio
<
1
-
maxCountRatioDif
||
countRatio
>
1.
f
+
maxCountRatioDif
)
{
{
ts
->
printf
(
CvTS
::
LOG
,
"Keypoints can nod be read
\n
"
);
ts
->
printf
(
CvTS
::
LOG
,
"Bad keypoints count ratio (validCount = %d, calcCount = %d)!
\n
"
,
ts
->
set_failed_test_info
(
CvTS
::
FAIL_INVALID_TEST_DATA
);
validKeypoints
.
size
(),
calcKeypoints
.
size
()
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_BAD_ACCURACY
);
return
;
return
;
}
}
...
@@ -120,29 +142,59 @@ protected:
...
@@ -120,29 +142,59 @@ protected:
}
}
}
}
if
(
minDist
>
maxPtDif
||
assert
(
minDist
>=
0
);
fabs
(
calcKeypoints
[
nearestIdx
].
size
-
validKeypoints
[
v
].
size
)
>
maxSizeDif
||
if
(
!
isSimilarKeypoints
(
validKeypoints
[
v
],
calcKeypoints
[
nearestIdx
]
)
)
abs
(
calcKeypoints
[
nearestIdx
].
angle
-
validKeypoints
[
v
].
angle
)
>
maxAngleDif
||
abs
(
calcKeypoints
[
nearestIdx
].
response
-
validKeypoints
[
v
].
response
)
>
maxResponseDif
||
calcKeypoints
[
nearestIdx
].
octave
!=
validKeypoints
[
v
].
octave
// TODO !!!!!!!
/*||
calcKeypoints[nearestIdx].class_id != validKeypoints[v].class_id*/
)
{
badPointCount
++
;
badPointCount
++
;
}
}
}
ts
->
printf
(
CvTS
::
LOG
,
"regressionTest: badPointCount = %d; validPointCount = %d; calcPointCount = %d
\n
"
,
ts
->
printf
(
CvTS
::
LOG
,
"badPointCount = %d; validPointCount = %d; calcPointCount = %d
\n
"
,
badPointCount
,
validKeypoints
.
size
(),
calcKeypoints
.
size
()
);
badPointCount
,
validKeypoints
.
size
(),
calcKeypoints
.
size
()
);
if
(
badPointCount
>
0.9
*
commonPointCount
)
if
(
badPointCount
>
0.9
*
commonPointCount
)
{
{
ts
->
printf
(
CvTS
::
LOG
,
"
Bad accuracy!
\n
"
);
ts
->
printf
(
CvTS
::
LOG
,
" -
Bad accuracy!
\n
"
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_BAD_ACCURACY
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_BAD_ACCURACY
);
return
;
return
;
}
}
ts
->
printf
(
CvTS
::
LOG
,
" - OK
\n
"
);
}
void
CV_FeatureDetectorTest
::
regressionTest
()
{
assert
(
!
fdetector
.
empty
()
);
string
imgFilename
=
string
(
ts
->
get_data_path
())
+
FEATURES2D_DIR
+
"/"
+
IMAGE_FILENAME
;
string
resFilename
=
string
(
ts
->
get_data_path
())
+
DETECTOR_DIR
+
"/"
+
string
(
name
)
+
".xml.gz"
;
// Read the test image.
Mat
image
=
imread
(
imgFilename
,
0
);
if
(
image
.
empty
()
)
{
ts
->
printf
(
CvTS
::
LOG
,
"image %s can not be read
\n
"
,
imgFilename
.
c_str
()
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_INVALID_TEST_DATA
);
return
;
}
}
else
// write
FileStorage
fs
(
resFilename
,
FileStorage
::
READ
);
// Compute keypoints.
vector
<
KeyPoint
>
calcKeypoints
;
fdetector
->
detect
(
image
,
calcKeypoints
);
if
(
fs
.
isOpened
()
)
// Compare computed and valid keypoints.
{
// TODO compare saved feature detector params with current ones
// Read validation keypoints set.
vector
<
KeyPoint
>
validKeypoints
;
read
(
fs
[
"keypoints"
],
validKeypoints
);
if
(
validKeypoints
.
empty
()
)
{
ts
->
printf
(
CvTS
::
LOG
,
"Keypoints can nod be read
\n
"
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_INVALID_TEST_DATA
);
return
;
}
compareKeypointSets
(
validKeypoints
,
calcKeypoints
);
}
else
// Write detector parameters and computed keypoints as validation data.
{
{
fs
.
open
(
resFilename
,
FileStorage
::
WRITE
);
fs
.
open
(
resFilename
,
FileStorage
::
WRITE
);
if
(
!
fs
.
isOpened
()
)
if
(
!
fs
.
isOpened
()
)
...
@@ -160,11 +212,22 @@ protected:
...
@@ -160,11 +212,22 @@ protected:
write
(
fs
,
"keypoints"
,
calcKeypoints
);
write
(
fs
,
"keypoints"
,
calcKeypoints
);
}
}
}
}
ts
->
set_failed_test_info
(
CvTS
::
OK
);
}
void
CV_FeatureDetectorTest
::
run
(
int
/*start_from*/
)
{
if
(
fdetector
.
empty
()
)
{
ts
->
printf
(
CvTS
::
LOG
,
"Feature detector is empty"
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_INVALID_TEST_DATA
);
return
;
}
}
Ptr
<
FeatureDetector
>
fdetector
;
emptyDataTest
();
};
regressionTest
();
ts
->
set_failed_test_info
(
CvTS
::
OK
);
}
/****************************************************************************************\
/****************************************************************************************\
* Regression tests for descriptor extractors. *
* Regression tests for descriptor extractors. *
...
@@ -707,6 +770,7 @@ void CV_DescriptorMatcherTest::run( int )
...
@@ -707,6 +770,7 @@ void CV_DescriptorMatcherTest::run( int )
/*
/*
* Detectors
* Detectors
* "detector-fast, detector-gftt, detector-harris, detector-mser, detector-sift, detector-star, detector-surf"
*/
*/
CV_FeatureDetectorTest
fastTest
(
"detector-fast"
,
createFeatureDetector
(
"FAST"
)
);
CV_FeatureDetectorTest
fastTest
(
"detector-fast"
,
createFeatureDetector
(
"FAST"
)
);
CV_FeatureDetectorTest
gfttTest
(
"detector-gftt"
,
createFeatureDetector
(
"GFTT"
)
);
CV_FeatureDetectorTest
gfttTest
(
"detector-gftt"
,
createFeatureDetector
(
"GFTT"
)
);
...
...
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