1 #ifndef gra_FeaturePointsDetector_Harris
2 #define gra_FeaturePointsDetector_Harris
10 #include "../dsa/DisjointSet.h"
11 #include "../math/utility.h"
25 template <
class Pixel,
class MyFP = FeaturePo
int<
double,
double> >
27 # define FPD_Harris FeaturePointsDetector_Harris
49 Myself(Myself
const& m):
51 thresholdR_(m.thresholdR_),
55 featureG_(m.featureG_),
62 Self<Myself>
const self;
95 return self->thresholdR_;
105 return self->noiseN_;
110 return self->featureG_;
115 return self->lightL_;
120 return self->boundB_;
125 return self->angleA_;
136 self()->thresholdR_ = r;
160 self()->featureG_ = g;
195 for (ssize_t y = 0, Y = input.height(); y < Y; y++)
196 for (ssize_t x = 0, X = input.width(); x < X; x++) {
197 Pixel gx(input_gx(y, x));
198 Pixel gy(input_gy(y, x));
203 Ixys.gaussianed(self->sizeW_, self->sizeW_);
209 Bitmap<bool> good(input.height(), input.width(),
false);
210 for (ssize_t y = 0, Y = input.height(); y < Y; y++)
211 for (ssize_t x = 0, X = input.width(); x < X; x++) {
212 double det = Ixys(y, x)(0) * Ixys(y, x)(1) -
squ(Ixys(y, x)(2));
213 double tra = Ixys(y, x)(0) + Ixys(y, x)(1);
214 double r = det -
self->ratioK_ *
squ(tra);
216 good.pixel(y, x, (r >= self->thresholdR_));
222 ssize_t dy[2] = {0, 1};
223 ssize_t dx[2] = {1, 0};
224 for (ssize_t y = 0, Y = input.height(); y + 1 < Y; y++)
225 for (ssize_t x = 0, X = input.width(); x + 1 < X; x++)
226 if(good.pixel((
size_t)y, (
size_t)x))
227 for (
size_t k = 0; k < 2u; k++)
228 if (good.pixel((
size_t)(y + dy[k]), (
size_t)(x + dx[k])))
229 dsj.
merge( y * input.width() + x,
230 (y + dy[k]) * input.width() + (x + dx[k]));
233 std::vector<size_t> max_i(input.size());
234 for (
size_t i = 0, I = input.size(); i < I; i++)
237 for (
size_t i = 0, I = input.size(); i < I; i++) {
238 size_t ri = dsj.root(i);
239 if (R.
pixel( i / input.width(), i % input.width()) >
240 R.
pixel(max_i[ri] / input.width(), max_i[ri] % input.width()))
245 ssize_t b = std::max<int>(std::max<int>(
self->boundB_,
248 std::vector<MyFP> ret;
250 for (ssize_t y = b, Y = -b + input.height(); y < Y; y++)
251 for (ssize_t x = b, X = -b + input.width(); x < X; x++) {
252 if (!good.pixel((
size_t)y, (
size_t)x))
continue;
253 size_t i = y * input.width() + x;
254 if (max_i[dsj.root(i)] != i)
continue;
257 for (ssize_t dx = -B; dx <= B; ++dx)
258 for (ssize_t dy = -B; dy <= B; ++dy) {
259 double gx = input_gx.pixel(y+dy, x+dx) * input_gx.pixel(y+dy, x+dx);
260 double gy = input_gy.pixel(y+dy, x+dx) * input_gy.pixel(y+dy, x+dx);
261 double light = sqrt(gx + gy);
262 double angle =
circle(atan2(sqrt(gy), sqrt(gx)));
263 int a = angle / (2 *
PI /
paramA());
264 for (
size_t k = 0; k <
paramA(); ++k) {
310 bool write(FILE* f,
bool bin,
unsigned int fg)
const {
319 bool read (FILE* f,
bool bin,
unsigned int fg) {
329 return (
ObjBase*)
new FPD_Harris<Pixel>();
350 return typeid(*this).name();
358 return std::string(
ctype());
365 #endif // gra_FeaturePointsDetector_Harris
Bitmap< Pixel > gradianceY(double radiusY, double radiusX) const
回傳對y偏微分
bool write(FILE *f, bool bin, unsigned int fg) const
寫到檔案裡
ObjBase * create() const
new一個自己
ObjBase * copyFrom(ObjBase const *b)
複製資料
Bitmap gaussian(double radiusY, double radiusX) const
回傳高斯模糊
bool read(FILE *f, bool bin, unsigned int fg)
將資料讀入
double paramW(double w)
W.
double paramN(double n)
N.
size_t paramB(size_t b)
B.
size_t paramB() const
bound
size_t paramA() const
algle
std::vector< MyFP > operator()(Bitmap< Pixel > const &bmp) const
same as detect(bmp)
Pixel pixel(size_t y, size_t x) const
取得 (y, x) 的pixel
一切物件的Base, 並要求每個物件都要有read, write, create, ... 等功能
size_t merge(size_t a, size_t b)
合併
FPD_Harris & operator=(FPD_Harris const &fps)
same as copyFrom(fps)
FPD_Harris & copyFrom(FPD_Harris const &fps)
複製
FPD_Harris()
constructor 使用預設參數
Bitmap gradianceX(double radiusY, double radiusX) const
回傳對x偏微分
std::vector< MyFP > detect(Bitmap< Pixel > const &bmp) const
找出特徵點
Scalar scalar(size_t i) const
return i -th scalar
std::string type() const
回傳class的type
static const double PI
圓周率...
Harris-Corner-Detect algorithm for finding feature points.
size_t paramA(size_t a)
A.
double paramL(double l)
L.
For developer to pack the attributes of a class.
char const * ctype() const
回傳class的type
FPD_Harris(FPD_Harris const &fps)
constructor 參數複製自另一個 FeaturePointsDetector_Harris
double paramG(double g)
G.
size_t descriptionDimension() const
double paramR(double r)
R.
double paramK(double k)
K.
FPD_Harris & referenceFrom(FPD_Harris const &fps)
參照