Noize Reduce
This commit is contained in:
parent
bb59ba0d7e
commit
5045cea5f9
BIN
right8.png
Normal file
BIN
right8.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 275 KiB |
99
src/Test.cpp
99
src/Test.cpp
@ -21,7 +21,7 @@ typedef struct {
|
|||||||
} StereoData;
|
} StereoData;
|
||||||
|
|
||||||
#define WINDOW_START 0
|
#define WINDOW_START 0
|
||||||
#define WINDOW_SIZE 78
|
#define WINDOW_SIZE 70
|
||||||
#define MATCH_SIZE 3
|
#define MATCH_SIZE 3
|
||||||
#define ERROR_LEVEL 1
|
#define ERROR_LEVEL 1
|
||||||
|
|
||||||
@ -29,11 +29,36 @@ int getPixelValue(Mat* data, int x, int y)
|
|||||||
{
|
{
|
||||||
uchar* pixel = data->ptr(y, x);
|
uchar* pixel = data->ptr(y, x);
|
||||||
|
|
||||||
return pixel[0];
|
return pixel[0] + pixel[1] + pixel[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
void normalize(Mat* mat, int x_from, int x_to, int y)
|
||||||
|
{
|
||||||
|
int n = x_to - x_from, val;
|
||||||
|
int sum_xy = 0, sum_x = 0, sum_y = 0, sum_x2 = 0;
|
||||||
|
float a, b;
|
||||||
|
int tmp;
|
||||||
|
uchar* data;
|
||||||
|
|
||||||
|
for (int i = x_from; i < x_to; i++) {
|
||||||
|
val = getPixelValue(mat, i, y);
|
||||||
|
sum_xy += i * val;
|
||||||
|
sum_x += i;
|
||||||
|
sum_y += val;
|
||||||
|
sum_x2 += i * i;
|
||||||
|
}
|
||||||
|
|
||||||
|
a = 0; //((n * sum_xy) - (sum_x * sum_y)) / ((n * sum_x2) - (sum_x * sum_x));
|
||||||
|
b = (sum_y - a * sum_x) / n;
|
||||||
|
|
||||||
|
for (int i = x_from; i < x_to; i++) {
|
||||||
|
data = mat->ptr<uchar>(y, i);
|
||||||
|
//data[0] = a * i ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int match(StereoData ¶ms, int x, int y, int j) {
|
int match(StereoData ¶ms, int x, int y, int j) {
|
||||||
int error = 0;
|
int error = 0, val;
|
||||||
for (int i = 0; i < MATCH_SIZE; i++) {
|
for (int i = 0; i < MATCH_SIZE; i++) {
|
||||||
if (x + j + i >= params.right->cols) {
|
if (x + j + i >= params.right->cols) {
|
||||||
return 999;
|
return 999;
|
||||||
@ -43,7 +68,9 @@ int match(StereoData ¶ms, int x, int y, int j) {
|
|||||||
if (y + g >= params.right->rows) {
|
if (y + g >= params.right->rows) {
|
||||||
return 999;
|
return 999;
|
||||||
}
|
}
|
||||||
error += abs(getPixelValue(params.left, x + i, y + g) - getPixelValue(params.right, x + j + i, y + g));
|
val = abs(getPixelValue(params.left, x + i, y + g) - getPixelValue(params.right, x + j + i, y + g));
|
||||||
|
|
||||||
|
error += val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,23 +113,22 @@ void putPixel(Mat* mat, int x, int y, int cursor)
|
|||||||
|
|
||||||
|
|
||||||
void calcDepthMapMy2(StereoData ¶ms) {
|
void calcDepthMapMy2(StereoData ¶ms) {
|
||||||
int x, y, cursor, cursor2, closest;
|
int x, y, cursor, closest, tmp;
|
||||||
int minErrorValue, tmp, minLevel = 0, tmpSmoothed;
|
int minErrorValue, tmpSmoothed, matched;
|
||||||
int rightLevel = 0, matched;
|
|
||||||
|
|
||||||
for (y = 0; y < params.stereo->rows; y++) {
|
for (y = 0; y < params.stereo->rows; y++) {
|
||||||
cursor = 0; cursor2 = 0;rightLevel=0;
|
cursor = 0;
|
||||||
for (x = 0; x < params.stereo->cols; x++) {
|
for (x = 0; x < params.stereo->cols; x++) {
|
||||||
closest = 999; minErrorValue = 999;matched=0;
|
closest = 999; minErrorValue = 999;matched=0;
|
||||||
for (int i = 0; i < WINDOW_SIZE; i++) {
|
for (int i = WINDOW_START; i < WINDOW_SIZE; i++) {
|
||||||
tmp = match(params, x, y, i);
|
tmp = match(params, x, y, i);
|
||||||
tmpSmoothed = tmp;
|
tmpSmoothed = tmp + (1 * abs(cursor - i));
|
||||||
|
|
||||||
if (tmp < minErrorValue) {
|
if (tmpSmoothed < minErrorValue) {
|
||||||
minErrorValue = tmp;
|
minErrorValue = tmpSmoothed;
|
||||||
closest = i;
|
|
||||||
matched = 1;
|
matched = 1;
|
||||||
} else if (tmp == minErrorValue) {
|
closest = i ;
|
||||||
|
} else if (tmpSmoothed == minErrorValue) {
|
||||||
if (abs(cursor - i) < abs(cursor - closest)) {
|
if (abs(cursor - i) < abs(cursor - closest)) {
|
||||||
closest = i;
|
closest = i;
|
||||||
matched++;
|
matched++;
|
||||||
@ -112,50 +138,50 @@ void calcDepthMapMy2(StereoData ¶ms) {
|
|||||||
|
|
||||||
if (matched) {
|
if (matched) {
|
||||||
cursor = closest;
|
cursor = closest;
|
||||||
putPixel(params.stereo, x, y, cursor);
|
putPixel(params.stereo, x + cursor, y, cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*for (y = 0; y < params.stereo->rows; y++) {
|
||||||
|
cursor = 0;
|
||||||
|
for (x = 0; x < params.stereo->cols; x++) {
|
||||||
|
|
||||||
/*
|
closest = 999;minErrorValue = 999;matched=0;
|
||||||
closest = 999;minErrorValue = 999;
|
|
||||||
|
|
||||||
for (int i = WINDOW_START; i < WINDOW_SIZE; i++) {
|
for (int i = WINDOW_START; i < WINDOW_SIZE; i++) {
|
||||||
tmp = rmatch(params, params.stereo->cols - x, y, i);
|
tmp = rmatch(params, params.stereo->cols - x, y, i);
|
||||||
if (tmp < minErrorValue) {
|
tmpSmoothed = tmp + (1 * abs(cursor - i));
|
||||||
minErrorValue = tmp;
|
|
||||||
closest = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp == minErrorValue) {
|
if (tmpSmoothed < minErrorValue) {
|
||||||
if (abs(cursor2 - i) < abs(cursor2 - closest)) {
|
minErrorValue = tmpSmoothed;
|
||||||
|
matched = 1;
|
||||||
closest = i ;
|
closest = i ;
|
||||||
|
} else if (tmpSmoothed == minErrorValue) {
|
||||||
|
if (abs(cursor - i) < abs(cursor - closest)) {
|
||||||
|
closest = i;
|
||||||
|
matched++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closest != 999) {
|
if (matched) {
|
||||||
if (cursor2 != closest) {
|
cursor = closest;
|
||||||
cursor2 = closest;
|
putPixel(params.stereo, params.stereo->cols - x - cursor - 1, y, cursor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
putPixel(params.stereo, params.stereo->cols - x - cursor2, y, cursor2);
|
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
StereoData params;
|
StereoData params;
|
||||||
|
|
||||||
Mat left = imread("left2.png", 1);
|
Mat left = imread("left6.png", 1);
|
||||||
Mat right = imread("right2.png", 1);
|
Mat right = imread("right6.png", 1);
|
||||||
|
|
||||||
cvtColor(left, left, CV_BGR2GRAY);
|
|
||||||
cvtColor(right, right, CV_BGR2GRAY);
|
|
||||||
|
|
||||||
Mat stereo(Mat::zeros(left.rows, left.cols, CV_8U));
|
Mat stereo(Mat::zeros(left.rows, left.cols, CV_8U));
|
||||||
Mat visited(Mat::zeros(left.rows, left.cols, CV_8U));
|
|
||||||
|
|
||||||
params.visited = &visited;
|
|
||||||
params.left = &left;
|
params.left = &left;
|
||||||
params.right = &right;
|
params.right = &right;
|
||||||
params.stereo = &stereo;
|
params.stereo = &stereo;
|
||||||
@ -164,7 +190,6 @@ int main(int argc, char** argv) {
|
|||||||
calcDepthMapMy2(params);
|
calcDepthMapMy2(params);
|
||||||
|
|
||||||
imshow("Display Image Dyn Progr", stereo);
|
imshow("Display Image Dyn Progr", stereo);
|
||||||
//imshow("Display Image Dyn Progr1", visited);
|
|
||||||
waitKey();
|
waitKey();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user