1 #ifndef gra_FeaturePointsDetector_Harris
2 #define gra_FeaturePointsDetector_Harris
10 #include "../dsa/DisjointSet.h"
25 # define FPD_Harris FeaturePointsDetector_Harris
45 Myself(Myself
const& m):
47 thresholdR_(m.thresholdR_),
51 featureG_(m.featureG_),
58 Self<Myself>
const self;
93 return self->thresholdR_;
103 return self->noiseN_;
108 return self->featureG_;
113 return self->lightL_;
118 return self->boundB_;
129 self()->thresholdR_ = r;
153 self()->featureG_ = g;
179 for (ssize_t y = 0, Y = input.
height(); y < Y; y++) {
180 for (ssize_t x = 0, X = input.
width(); x < X; x++) {
181 Pixel gx(input_gx(y, x));
182 Pixel gy(input_gy(y, x));
183 Ixx.
pixel(y, x, gx * gx);
184 Iyy.
pixel(y, x, gy * gy);
185 Ixy.
pixel(y, x, gx * gy);
197 ssize_t b =
self->boundB_;
198 for (ssize_t y = b, Y = -b + input.
height(); y < Y; y++) {
199 for (ssize_t x = b, X = -b + input.
width(); x < X; x++) {
200 double det = Ixx(y, x) * Iyy(y, x) -
squ(Ixy(y, x));
201 double tra = Ixx(y, x) + Iyy(y, x);
202 double r = det -
self->ratioK_ *
squ(tra);
204 good.pixel(y, x, (r >= self->thresholdR_));
210 ssize_t dy[2] = {0, 1};
211 ssize_t dx[2] = {1, 0};
212 for (ssize_t y = b, Y = -b + input.
height(); y < Y; y++) {
213 for (ssize_t x = b, X = -b + input.
width(); x < X; x++) {
214 if(good.pixel((
size_t)y, (
size_t)x)){
215 for (
size_t k = 0; k < 2u; k++) {
216 if (good.pixel((
size_t)(y + dy[k]), (
size_t)(x + dx[k]))) {
218 (y + dy[k]) * input.
width() + (x + dx[k]));
226 std::vector<size_t> max_i(input.
size());
227 for (
size_t i = 0, I = input.
size(); i < I; i++) {
230 for (
size_t i = 0, I = input.
size(); i < I; i++) {
231 size_t ri = dsj.root(i);
239 input.
gaussianed(self->featureG_, self->featureG_);
242 for (ssize_t y = b, Y = -b + input.
height(); y < Y; y++) {
243 for (ssize_t x = b, X = -b + input.
width(); x < X; x++) {
244 if (!good.pixel((
size_t)y, (
size_t)x)) {
247 size_t i = y * input.
width() + x;
248 if (max_i[dsj.root(i)] != i) {
251 ssize_t dx[4] = {1, 0, -1, 0};
252 ssize_t dy[4] = {0, 1, 0, -1};
253 std::vector<double> desc;
254 for (ssize_t d = 1; d <= (ssize_t)self->boundB_; d++) {
255 std::vector<double> light;
257 size_t x0 = x - d, y0 = y - d;
258 for (
size_t k = 0; k < 4; k++) {
261 n++, x0 += dx[k], y0 += dy[k]){
262 Pixel diff = input.
pixel(y0, x0) - input.
pixel(y, x) * 0.2;
263 light.push_back(diff * diff * self->lightL_);
264 if (light[max_id] < light[-1 + light.size()]) {
265 max_id = -1 + (ssize_t)light.size();
269 for (ssize_t n = 0, N = light.size(); n < N; n++) {
270 desc.push_back((max_id + n) % N);
271 desc.push_back(light[(max_id + n) % N]);
298 bool write(FILE* f,
bool bin,
unsigned int fg)
const {
307 bool read (FILE* f,
bool bin,
unsigned int fg) {
317 return (
ObjBase*)
new FPD_Harris<Pixel>();
338 return typeid(*this).name();
346 return std::string(
ctype());
353 #endif // gra_FeaturePointsDetector_Harris
size_t paramB(size_t b)
B.
double paramK(double k)
K.
Bitmap< Pixel > gradianceY(double radiusY, double radiusX) const
回傳對y偏微分
size_t height() const
回傳高度
char const * ctype() const
回傳class的type
FPD_Harris & referenceFrom(FPD_Harris const &fps)
參照
MyFeaturePoints detect(Bitmap< Pixel > const &bmp) const
找出特徵點
std::string type() const
回傳class的type
ObjBase * copyFrom(ObjBase const *b)
複製資料
MyFeaturePoints operator()(Bitmap< Pixel > const &bmp) const
same as detect(bmp)
FeaturePoint< double, double > MyFeaturePoint
double paramW(double w)
W.
Pixel pixel(size_t y, size_t x) const
取得 (y, x) 的pixel
double paramL(double l)
L.
size_t width() const
回傳寬度
一切物件的Base, 並要求每個物件都要有read, write, create, ... 等功能
size_t merge(size_t a, size_t b)
合併
FPD_Harris(FPD_Harris const &fps)
constructor 參數複製自另一個 FeaturePointsDetector_Harris
double paramR(double r)
R.
FPD_Harris & operator=(FPD_Harris const &fps)
same as copyFrom(fps)
size_t size() const
回傳高度乘以寬度
bool read(FILE *f, bool bin, unsigned int fg)
將資料讀入
Bitmap gradianceX(double radiusY, double radiusX) const
回傳對x偏微分
std::vector< MyFeaturePoint > MyFeaturePoints
FPD_Harris()
constructor 使用預設參數
FPD_Harris & copyFrom(FPD_Harris const &fps)
複製
double paramG(double g)
G.
size_t paramB() const
bound
ObjBase * create() const
new一個自己
A little class use for packing the data part of another class. With this technique, it can achieve Copy-On-Write(COR) mechanism at background and have a reference mechanism which much more flexible then the one C++ has.
Vector< Scalar > const & position() const
回傳position
double paramN(double n)
N.
bool write(FILE *f, bool bin, unsigned int fg) const
寫到檔案裡
Bitmap & gaussianed(double radiusY, double radiusX)
把自己高斯模糊