From c039dafde22146f1c09a054d90bf69600ff47246 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Fri, 6 Jun 2014 16:54:14 +0400 Subject: [PATCH] Right Level --- src/Test.cpp | 90 +++++++++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 58 deletions(-) diff --git a/src/Test.cpp b/src/Test.cpp index e2762f4..95a33ab 100644 --- a/src/Test.cpp +++ b/src/Test.cpp @@ -21,8 +21,8 @@ typedef struct { } StereoData; #define WINDOW_START 0 -#define WINDOW_SIZE 220 -#define MATCH_SIZE 4 +#define WINDOW_SIZE 70 +#define MATCH_SIZE 3 #define ERROR_LEVEL 1 int getPixelValue(Mat* data, int x, int y) @@ -75,81 +75,57 @@ int getPixelColor(int cursor) return (val * val * val) * 255.0; } -void putPixel(StereoData ¶ms, int x, int y, int cursor) +void putPixel(Mat* mat, int x, int y, int cursor) { uchar* data; - data = params.stereo->ptr(y, x); + data = mat->ptr(y, x); data[0] = getPixelColor(cursor); } void calcDepthMapMy2(StereoData ¶ms) { - int x, y, cursor, cursor2, matched, closest; - int minErrorValue, tmp, d; + int x, y, cursor, cursor2, closest; + int minErrorValue, tmp, minLevel = 0, tmpSmoothed; + int rightLevel = 0, matched; for (y = 0; y < params.stereo->rows; y++) { - cursor = 0; cursor2 = 0; + cursor = 0; cursor2 = 0;rightLevel=0; for (x = 0; x < params.stereo->cols; x++) { + closest = 999; minErrorValue = 999;matched=0; + for (int i = 0; i < WINDOW_SIZE; i++) { + if (getPixelValue(params.visited, x + i, y)) { + continue; + } - closest = 999;minErrorValue = 999; d = 999; + tmp = match(params, x, y, i); + tmpSmoothed = tmp; - for (int i = WINDOW_START; i < WINDOW_SIZE; i++) { - tmp = match(params, x, y, i) / 1; if (tmp < minErrorValue) { minErrorValue = tmp; closest = i; - d = abs(cursor - i); - } - - if (tmp == minErrorValue) { + matched = 1; + } else if (tmp == minErrorValue) { if (abs(cursor - i) < abs(cursor - closest)) { - closest = i; - d = abs(cursor - i); + closest = i ; + matched++; } } } - if (closest != 999) { - //if (cursor != closest) { - cursor = closest; - putPixel(params, x + cursor + 1, y, cursor); - //} + if (matched) { + cursor = closest; + putPixel(params.visited, x + cursor, y, 50); + putPixel(params.stereo, x, y, cursor); } - - /*closest = 999;minErrorValue = 999; d = 999; - - for (int i = WINDOW_START; i < WINDOW_SIZE; i++) { - tmp = rmatch(params, params.stereo->cols - x, y, i) / 50; - if (tmp < minErrorValue) { - minErrorValue = tmp; - closest = i; - } - - if (tmp == minErrorValue) { - if (abs(cursor2 - i) < abs(cursor2 - closest)) { - closest = i; - } - } - } - - if (closest != 999) { - //if (cursor2 != closest) { - cursor2 = closest; - putPixel(params, params.stereo->cols - x, y, cursor2); - //} - }*/ - - - - /*closest = 999;minErrorValue = 999; + for (int i = WINDOW_START; i < WINDOW_SIZE; i++) { - tmp = rmatch(params, params.stereo->cols - x - 1, y, i) / ERROR_LEVEL; + tmp = rmatch(params, params.stereo->cols - x, y, i) ; if (tmp < minErrorValue) { minErrorValue = tmp; closest = i; @@ -163,14 +139,11 @@ void calcDepthMapMy2(StereoData ¶ms) { } if (closest != 999) { - cursor2 = closest; - } - - tmp = getPixelValue(params.stereo, params.stereo->cols - x - 1, y); - if (!tmp || tmp > cursor2) { - putPixel(params, params.stereo->cols - x - 1, y, cursor2); + if (cursor2 != closest) { + cursor2 = closest; + putPixel(params, params.stereo->cols - x, y, cursor2); + } }*/ - } } } @@ -178,8 +151,8 @@ void calcDepthMapMy2(StereoData ¶ms) { int main(int argc, char** argv) { StereoData params; - Mat left = imread("left7.png", 1); - Mat right = imread("right7.png", 1); + Mat left = imread("left6.png", 1); + Mat right = imread("right6.png", 1); cvtColor(left, left, CV_BGR2GRAY); cvtColor(right, right, CV_BGR2GRAY); @@ -196,6 +169,7 @@ int main(int argc, char** argv) { calcDepthMapMy2(params); imshow("Display Image Dyn Progr", stereo); + //imshow("Display Image Dyn Progr1", visited); waitKey(); return 0;