-
Notifications
You must be signed in to change notification settings - Fork 1
/
removal.cpp
50 lines (43 loc) · 1.25 KB
/
removal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "function.h"
void OutlierRemoval(vector<Point2i>& srcFeatures, vector<Point2i>& refFeatures, const Mat srcDisp /* = Mat()*/)
{
int width = srcDisp.size().width;
int height = srcDisp.size().height;
int sz = srcFeatures.size();
for (int i = 0; i < sz; ++i)
{
int sx = srcFeatures[i].x;
int sy = srcFeatures[i].y;
if (sx < 0 || sx >= width || sy < 0 || sy >= height)
{
cout << "out of boundary" << endl;
refFeatures[i].x = -1;
refFeatures[i].y = -1;
}
else
{
int rx = sx + srcDisp.at<uchar>(sy, sx);
int ry = sy;
refFeatures[i].x = rx;
refFeatures[i].y = ry;
}
}
//½â¾ö±ß½çÎÊÌâ
vector<Point2i> tmpsrc, tmpref;
for (int i = 0; i < sz; ++i)
{
if (srcFeatures[i].x >= 0 && srcFeatures[i].x < width && srcFeatures[i].y >= 0 && srcFeatures[i].y < height &&
refFeatures[i].x >= 0 && refFeatures[i].x < width && refFeatures[i].y >= 0 && refFeatures[i].y < height)
{
tmpsrc.push_back(srcFeatures[i]);
tmpref.push_back(refFeatures[i]);
}
}
srcFeatures.clear();
srcFeatures.resize(tmpsrc.size());
refFeatures.clear();
refFeatures.resize(tmpref.size());
copy(tmpsrc.begin(), tmpsrc.end(), srcFeatures.begin());
copy(tmpref.begin(), tmpref.end(), refFeatures.begin());
cout << "Outliers Removal done." << endl;
}