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
3f3c8823
Commit
3f3c8823
authored
Dec 18, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
features2d: fix retainBest() implementation
parent
55171b25
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
keypoint.cpp
modules/features2d/src/keypoint.cpp
+1
-1
test_utils.cpp
modules/features2d/test/test_utils.cpp
+38
-0
No files found.
modules/features2d/src/keypoint.cpp
View file @
3f3c8823
...
@@ -77,7 +77,7 @@ void KeyPointsFilter::retainBest(std::vector<KeyPoint>& keypoints, int n_points)
...
@@ -77,7 +77,7 @@ void KeyPointsFilter::retainBest(std::vector<KeyPoint>& keypoints, int n_points)
return
;
return
;
}
}
//first use nth element to partition the keypoints into the best and worst.
//first use nth element to partition the keypoints into the best and worst.
std
::
nth_element
(
keypoints
.
begin
(),
keypoints
.
begin
()
+
n_points
,
keypoints
.
end
(),
KeypointResponseGreater
());
std
::
nth_element
(
keypoints
.
begin
(),
keypoints
.
begin
()
+
n_points
-
1
,
keypoints
.
end
(),
KeypointResponseGreater
());
//this is the boundary response, and in the case of FAST may be ambiguous
//this is the boundary response, and in the case of FAST may be ambiguous
float
ambiguous_response
=
keypoints
[
n_points
-
1
].
response
;
float
ambiguous_response
=
keypoints
[
n_points
-
1
].
response
;
//use std::partition to grab all of the keypoints with the boundary response.
//use std::partition to grab all of the keypoints with the boundary response.
...
...
modules/features2d/test/test_utils.cpp
0 → 100644
View file @
3f3c8823
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
namespace
opencv_test
{
namespace
{
TEST
(
Features2D_KeypointUtils
,
retainBest_issue_12594
)
{
const
size_t
N
=
9
;
// Construct 4-way tie for 3rd highest - correct answer for "3 best" is 6
const
float
no_problem
[]
=
{
5.0
f
,
4.0
f
,
1.0
f
,
2.0
f
,
0.0
f
,
3.0
f
,
3.0
f
,
3.0
f
,
3.0
f
};
// Same set, different order that exposes partial sort property of std::nth_element
// Note: the problem case may depend on your particular implementation of STL
const
float
problem
[]
=
{
3.0
f
,
3.0
f
,
3.0
f
,
3.0
f
,
4.0
f
,
5.0
f
,
0.0
f
,
1.0
f
,
2.0
f
};
const
size_t
NBEST
=
3u
;
const
size_t
ANSWER
=
6u
;
std
::
vector
<
cv
::
KeyPoint
>
sorted_cv
(
N
);
std
::
vector
<
cv
::
KeyPoint
>
unsorted_cv
(
N
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
sorted_cv
[
i
].
response
=
no_problem
[
i
];
unsorted_cv
[
i
].
response
=
problem
[
i
];
}
cv
::
KeyPointsFilter
::
retainBest
(
sorted_cv
,
NBEST
);
cv
::
KeyPointsFilter
::
retainBest
(
unsorted_cv
,
NBEST
);
EXPECT_EQ
(
ANSWER
,
sorted_cv
.
size
());
EXPECT_EQ
(
ANSWER
,
unsorted_cv
.
size
());
}
}}
// namespace
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