Ocean
Loading...
Searching...
No Matches
HarrisCorner.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_CV_DETECTOR_HARRIS_CORNER_H
9#define META_OCEAN_CV_DETECTOR_HARRIS_CORNER_H
10
13
14namespace Ocean
15{
16
17namespace CV
18{
19
20namespace Detector
21{
22
23// Forward declaration.
24class HarrisCorner;
25
26/**
27 * Definition of a vector holding Harris corners.
28 * @ingroup cvdetector
29 */
30typedef std::vector<HarrisCorner> HarrisCorners;
31
32/**
33 * This class implements a Harris corner.
34 * @ingroup cvdetector
35 */
36class OCEAN_CV_DETECTOR_EXPORT HarrisCorner : public PointFeature
37{
38 public:
39
40 /**
41 * Creates a new empty Harris corner object.
42 */
43 inline HarrisCorner();
44
45 /**
46 * Creates a new feature object by a given 2D observation position in e.g. an image.
47 * @param observation 2D feature observation
48 * @param distortionState Distortion state of the 2D feature position
49 * @param strength Feature strength
50 */
51 inline HarrisCorner(const Vector2& observation, const DistortionState distortionState, const Scalar strength);
52
53 /**
54 * Converts a Harris corner to a simple 2D image position.
55 * @param corner Harris corner to be converted
56 * @return Resulting image point
57 */
58 static inline Geometry::ImagePoint corner2imagePoint(const HarrisCorner& corner);
59
60 /**
61 * Converts Harris corners to simple 2D image positions.
62 * Thus, the 2D positions are preserved only.
63 * @param corners Harris corners to convert
64 * @return Resulting image points
65 */
66 static inline Geometry::ImagePoints corners2imagePoints(const HarrisCorners& corners);
67
68 /**
69 * Converts Harris corners to simple 2D image positions.
70 * Thus, the 2D positions are preserved only.
71 * @param corners Harris corners to convert
72 * @param number Number of corners to be converted, with range [0, corners.size()]
73 * @return Resulting image points
74 */
75 static inline Geometry::ImagePoints corners2imagePoints(const HarrisCorners& corners, const size_t number);
76
77 /**
78 * Converts Harris corners to point features.
79 * @param corners Harris corners to convert
80 * @return Resulting point features
81 */
82 static inline PointFeatures corners2pointFeatures(const HarrisCorners& corners);
83
84 /**
85 * Converts Harris corners to point features.
86 * @param corners Harris coners to convert
87 * @param number Number of corners to be converted, with range [0, corners.size()]
88 * @return Resulting point features
89 */
90 static inline PointFeatures corners2pointFeatures(const HarrisCorners& corners, const size_t number);
91};
92
95{
96 // nothing to do here
97}
98
99inline HarrisCorner::HarrisCorner(const Vector2& observation, const DistortionState distortionState, const Scalar strength) :
100 PointFeature(observation, distortionState, strength)
101{
102 // nothing to do here
103}
104
106{
107 return corner.observation();
108}
109
111{
113 result.reserve(corners.size());
114
115 for (HarrisCorners::const_iterator i = corners.begin(); i != corners.end(); ++i)
116 result.push_back(i->observation());
117
118 return result;
119}
120
122{
123 ocean_assert(number < corners.size());
124 const size_t realNumber = min(number, corners.size());
125
127 result.reserve(realNumber);
128
129 for (size_t n = 0; n < realNumber; ++n)
130 result.push_back(corners[n].observation());
131
132 return result;
133}
134
136{
137 PointFeatures result;
138 result.reserve(corners.size());
139
140 for (HarrisCorners::const_iterator i = corners.begin(); i != corners.end(); ++i)
141 result.push_back(*i);
142
143 return result;
144}
145
146inline PointFeatures HarrisCorner::corners2pointFeatures(const HarrisCorners& corners, const size_t number)
147{
148 ocean_assert(number < corners.size());
149 const size_t realNumber = min(number, corners.size());
150
151 PointFeatures result;
152 result.reserve(realNumber);
153
154 for (size_t n = 0; n < realNumber; ++n)
155 result.push_back(corners[n]);
156
157 return result;
158}
159
160}
161
162}
163
164}
165
166#endif // META_OCEAN_CV_DETECTOR_HARRIS_CORNER_H
This class implements a Harris corner.
Definition HarrisCorner.h:37
static Geometry::ImagePoint corner2imagePoint(const HarrisCorner &corner)
Converts a Harris corner to a simple 2D image position.
Definition HarrisCorner.h:105
static PointFeatures corners2pointFeatures(const HarrisCorners &corners)
Converts Harris corners to point features.
Definition HarrisCorner.h:135
static Geometry::ImagePoints corners2imagePoints(const HarrisCorners &corners)
Converts Harris corners to simple 2D image positions.
Definition HarrisCorner.h:110
HarrisCorner()
Creates a new empty Harris corner object.
Definition HarrisCorner.h:93
This class implements the base class for all computer vision features mainly basing on points.
Definition PointFeature.h:44
DistortionState
Definition of individual distortion states.
Definition PointFeature.h:51
const Vector2 & observation() const
Returns the 2D observation position of this feature e.g.
Definition PointFeature.h:200
std::vector< PointFeature > PointFeatures
Definition of a vector holding point features.
Definition PointFeature.h:35
std::vector< HarrisCorner > HarrisCorners
Definition of a vector holding Harris corners.
Definition HarrisCorner.h:30
std::vector< ImagePoint > ImagePoints
Definition of a vector holding 2D image points.
Definition geometry/Geometry.h:123
float Scalar
Definition of a scalar type.
Definition Math.h:129
The namespace covering the entire Ocean framework.
Definition Accessor.h:15