21 compare_scale (T
const& descr1, T
const& descr2)
23 return descr1.scale > descr2.scale;
31 this->positions.clear();
32 this->width = image->width();
33 this->height = image->height();
36 if (this->opts.feature_types & FEATURE_SIFT)
37 this->compute_sift(image);
38 if (this->opts.feature_types & FEATURE_SURF)
39 this->compute_surf(image);
43FeatureSet::normalize_feature_positions (
float px,
float py)
46 float const fwidth =
static_cast<float>(this->width);
47 float const fheight =
static_cast<float>(this->height);
48 float const fnorm = std::max(fwidth, fheight);
49 for (std::size_t i = 0; i < this->positions.size(); ++i)
52 pos[0] = (pos[0] + 0.5f - fwidth * px) / fnorm;
53 pos[1] = (pos[1] + 0.5f - fheight * py) / fnorm;
63 Sift sift(this->opts.sift_opts);
64 sift.set_image(image);
66 descr = sift.get_descriptors();
70 std::sort(descr.begin(), descr.end(), compare_scale<sfm::Sift::Descriptor>);
73 std::size_t offset = this->positions.size();
74 this->positions.resize(offset + descr.size());
75 this->colors.resize(offset + descr.size());
77 for (std::size_t i = 0; i < descr.size(); ++i)
79 Sift::Descriptor
const& d = descr[i];
80 this->positions[offset + i] =
math::Vec2f(d.x, d.y);
81 image->linear_at(d.x, d.y, this->colors[offset + i].begin());
92 Surf::Descriptors descr;
94 Surf surf(this->opts.surf_opts);
95 surf.set_image(image);
97 descr = surf.get_descriptors();
101 std::sort(descr.begin(), descr.end(), compare_scale<sfm::Surf::Descriptor>);
104 std::size_t offset = this->positions.size();
105 this->positions.resize(offset + descr.size());
106 this->colors.resize(offset + descr.size());
108 for (std::size_t i = 0; i < descr.size(); ++i)
110 Surf::Descriptor
const& d = descr[i];
111 this->positions[offset + i] =
math::Vec2f(d.x, d.y);
112 image->linear_at(d.x, d.y, this->colors[offset + i].begin());
116 std::swap(descr, this->surf_descriptors);
120FeatureSet::clear_descriptors (
void)
122 this->sift_descriptors.clear();
123 this->sift_descriptors.shrink_to_fit();
124 this->surf_descriptors.clear();
125 this->surf_descriptors.shrink_to_fit();
Vector class for arbitrary dimensions and types.
std::shared_ptr< Image< T > > Ptr
std::shared_ptr< Image< T > const > ConstPtr
Implementation of the SIFT feature detector and descriptor.
std::vector< Descriptor > Descriptors
void swap(mve::Image< T > &a, mve::Image< T > &b)
Specialization of std::swap for efficient image swapping.
#define SFM_NAMESPACE_END
#define SFM_NAMESPACE_BEGIN