diff --git a/CSV.pro.user b/CSV.pro.user index 1d5de70..0bd4915 100644 --- a/CSV.pro.user +++ b/CSV.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -53,7 +53,7 @@ Desktop Desktop - {463a2572-9a8f-4eb1-bda2-3a5ffe83025f} + {7246c6ab-7a87-4118-a487-ab344a31d36b} 0 0 0 @@ -229,7 +229,7 @@ CSV - Qt4ProjectManager.Qt4RunConfiguration:/home/andrey/workspace/ComputerVision/CSV.pro + Qt4ProjectManager.Qt4RunConfiguration:/home/andrey/workspace/CSV/CSV.pro CSV.pro false @@ -251,7 +251,7 @@ ProjectExplorer.Project.Updater.EnvironmentId - {dedf9f3d-a494-4afd-b37a-86d04bd971d6} + {35059b80-6449-4cca-8333-a4525005f807} ProjectExplorer.Project.Updater.FileVersion diff --git a/Main.qml b/Main.qml index 8044afb..51c583b 100644 --- a/Main.qml +++ b/Main.qml @@ -174,11 +174,49 @@ ApplicationWindow { } } Tab { - id: pclView - title: "PCL View" + id: leftImageView + title: "Left Image" Item { - anchors.fill: parent + Flickable { + anchors.fill: parent + contentWidth: image.width + contentHeight: image.height + interactive: true + anchors.margins: 2 + clip: true + + Item { + Image { + id: leftImage + source: "image://images/left" + smooth: false + } + } + } + } + } + Tab { + id: rightImageView + title: "Right Image" + + Item { + Flickable { + anchors.fill: parent + contentWidth: image.width + contentHeight: image.height + interactive: true + anchors.margins: 2 + clip: true + + Item { + Image { + id: rightImage + source: "image://images/right" + smooth: false + } + } + } } } } diff --git a/img/left4.png b/img/left4.png index b0d42bc..842c62b 100644 Binary files a/img/left4.png and b/img/left4.png differ diff --git a/img/right4.png b/img/right4.png index 23fc506..e162ecb 100644 Binary files a/img/right4.png and b/img/right4.png differ diff --git a/main.cpp b/main.cpp index 4647712..b0cfb1b 100644 --- a/main.cpp +++ b/main.cpp @@ -15,14 +15,15 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; SvImageProvider imageProvider; - QImage imgLeft("../ComputerVision/img/left4_.png"); - QImage imgRight("../ComputerVision/img/right4_.png"); - QImage imgStereo(imgLeft.width(), imgRight.height(), QImage::Format_RGB32); + QImage imgLeft("../CSV/img/left9.png"); + QImage imgRight("../CSV/img/right.png"); + QImage imgStereo(imgLeft.width(), imgLeft.height(), QImage::Format_RGB32); SvImage left(imgLeft); SvImage right(imgRight); SvImage stereo(imgStereo); - SvProcessor proc(&left, &right, &stereo, 4); + + SvProcessor proc(&left, &right, &stereo, 4, 2); imageProvider.addImage("left", &left); imageProvider.addImage("right", &right); diff --git a/svimage.cpp b/svimage.cpp index 5cdec2d..6224f67 100644 --- a/svimage.cpp +++ b/svimage.cpp @@ -53,7 +53,23 @@ int SvImage::getPixelValue(int x, int y) { return color.value(); } -void SvImage::putPixel(int x, int y, int value) +int SvImage::getPixelSaturation(int x, int y) +{ + if (y >= m_image->height() || + y < 0 || + x >= m_image->width() + || x < 0) { + + return 0; + } + + QRgb rgb = m_image->pixel(x, y); + QColor color(rgb); + + return color.saturation(); +} + +void SvImage::putGrayPixel(int x, int y, int value) { if (y >= m_image->height() || y < 0 || @@ -66,6 +82,19 @@ void SvImage::putPixel(int x, int y, int value) m_image->setPixel(x, y, qRgb(value, value, value)); } +void SvImage::putPixel(int x, int y, int red, int green, int blue) +{ + if (y >= m_image->height() || + y < 0 || + x >= m_image->width() + || x < 0) { + + return; + } + + m_image->setPixel(x, y, qRgb(red, green, blue)); +} + unsigned int SvImage::getHeight() { return m_image->height(); } diff --git a/svimage.h b/svimage.h index 20847f1..cfd7e8e 100644 --- a/svimage.h +++ b/svimage.h @@ -14,7 +14,9 @@ public: int getPixel(int x, int y, int channel); int getPixelHue(int x, int y); int getPixelValue(int x, int y); - void putPixel(int x, int y, int val); + int getPixelSaturation(int x, int y); + void putGrayPixel(int x, int y, int val); + void putPixel(int x, int y, int red, int green, int blue); unsigned int getHeight(); unsigned int getWidth(); diff --git a/svkernelv1.cpp b/svkernelv1.cpp index a11a5a5..dd23b9d 100644 --- a/svkernelv1.cpp +++ b/svkernelv1.cpp @@ -22,21 +22,30 @@ int SvKernelV1::getPixelColor(int cursor) int SvKernelV1::diff(int lx, int ly, int rx, int ry) { - int Rvalue, Gvalue, Bvalue, color; + int Red, Green, Blue, color; - Rvalue = abs(m_left->getPixel(lx, ly, 0) - m_right->getPixel(rx, ry, 0)); - Gvalue = abs(m_left->getPixel(lx, ly, 1) - m_right->getPixel(rx, ry, 1)); - Bvalue = abs(m_left->getPixel(lx, ly, 2) - m_right->getPixel(rx, ry, 2)); - color = abs(Gvalue - Rvalue) + abs(Bvalue - Gvalue); + int Lvalue = m_left->getPixelValue(lx, ly); + int Rvalue = m_right->getPixelValue(rx, ry); - return (Gvalue + Rvalue + Bvalue) + - color << 2; + int dLvalue = m_left->getPixelValue(rx - 1, ry) - Lvalue; + int dRvalue = m_right->getPixelValue(rx - 1, ry) - Rvalue; + + int dLsign = dLvalue >= 0 ? 1 : -1; + int dRsign = dRvalue >= 0 ? 1 : -1; + + Red = abs(m_left->getPixel(lx, ly, 0) - m_right->getPixel(rx, ry, 0)); + Green = abs(m_left->getPixel(lx, ly, 1) - m_right->getPixel(rx, ry, 1)); + Blue = abs(m_left->getPixel(lx, ly, 2) - m_right->getPixel(rx, ry, 2)); + color = abs(Green - Red) + abs(Blue - Green); + + return ((Green + Red + Blue) + + color << 2) + (dLsign == dRsign ? 0 : 100); } int SvKernelV1::match(int x, int y, int j) { int error = 0; - int ms = 4; + int ms = 5; int c = diff(x, y, x + j, y), l = 0, r = 0, t = 0, b = 0; @@ -73,7 +82,7 @@ void SvKernelV1::exec(int line) dist = (abs(cursor - i)); tmp = match(x, line, i); - tmpSmoothed = tmp + dist; + tmpSmoothed = tmp; if (tmpSmoothed < minErrorValue || minErrorValue == -1) { minErrorValue = tmpSmoothed; @@ -91,6 +100,6 @@ void SvKernelV1::exec(int line) cursor = closest; } - m_result->putPixel(x/* + cursor*/, line, getPixelColor(cursor)); + m_result->putGrayPixel(x/* + cursor*/, line, getPixelColor(cursor)); } } diff --git a/svkernelv1.h b/svkernelv1.h index 8ac7510..41d8819 100644 --- a/svkernelv1.h +++ b/svkernelv1.h @@ -7,7 +7,7 @@ class SvKernelV1: public SvAbstractKernel { protected: - int m_windowSize = 80; + int m_windowSize = 150; public: void exec(int line) override; diff --git a/svkernelv2.cpp b/svkernelv2.cpp index 1995176..7d4b1d0 100644 --- a/svkernelv2.cpp +++ b/svkernelv2.cpp @@ -11,6 +11,94 @@ SvKernelV2::~SvKernelV2() } void SvKernelV2::exec(int line) +{ + int hue, value, saturation; + int _hue, _value, _saturation; + int __hue, __value, __saturation; + int dValue, dHue, dSaturation; + int tValue, tHue, tSaturation; + int _dValue, __dValue; + int _dSaturation, __dSaturation; + int _dHue, __dHue; + + for (int x = 0; x < m_result->getWidth(); x++) { + hue = m_left->getPixelHue(x, line); + value = m_left->getPixelValue(x, line); + saturation = m_left->getPixelSaturation(x, line); + + dHue = _hue - hue; + dSaturation = _saturation - saturation; + dValue = _value - value; + + int m1 = m_left->getPixelValue(x, line - 1); + int m2 = m_left->getPixelValue(x, line - 2); + int m3 = m_left->getPixelValue(x, line - 3); + + int dY = m1-value; + int _dY = m2-m1; + int __dY = m3-m2; + + int hV = 0; + + if (((_dValue > dValue && _dValue > __dValue) || + (_dValue < dValue && _dValue < __dValue))) { + + hV = abs(_dValue); + m_result->putGrayPixel(x, line, abs(_dValue)); + } + + if (((_dY > dY && _dY > __dY) || + (_dY < dY && _dY < __dY))) { + if (abs(_dY) > hV) { + m_result->putGrayPixel(x, line - 2, abs(_dY)); + } + } + + __hue = _hue; + __value = _value; + __saturation = _saturation; + + _hue = hue; + _value = value; + _saturation = saturation; + + __dValue = _dValue; + _dValue = dValue; + + __dSaturation = _dSaturation; + _dSaturation = dSaturation; + + __dHue = _dHue; + _dHue = dHue; + } +} + +int SvKernelV2::getPixelValueByBit(int bit) { } + +unsigned int SvKernelV2::figureType(int x, int y, int level) +{ + unsigned char typeCode, resultType; + int result, error = -1; + for (int type = 1; type < 20; type++) { + typeCode = m_figures[type - 1]; + result = 0; + for (int bit = 0; bit < 9; bit++) { + value = getPixelValueByBit(bit); + if (typeCode & (1 << bit)) { + result += abs(level - value); + } else { + result += value; + } + } + + if (error > result || error == -1) { + resultType = type; + error = result; + } + } + + return (error << 5) | resultType; +} diff --git a/svkernelv2.h b/svkernelv2.h index 6411f26..1f78732 100644 --- a/svkernelv2.h +++ b/svkernelv2.h @@ -3,12 +3,91 @@ #include "svabstractkernel.h" +#define sign(a) (a == 0 ? 0 : (a > 0 ? 1 : -1)) + class SvKernelV2: public SvAbstractKernel { + +private: + unsigned short* m_figures = { + 0b000111000, // TYPE_0 + + 0b100011000, // TYPE_11_1 + 0b110011000, // TYPE_22_2_1 + 0b000110011, // TYPE_22_2_2 + 0b000110001, // TYPE_33_3 + 0b100010001, // TYPE_45 + + 0b010010001, // TYPE_56_1 + 0b100110010, // TYPE_67_2_1 + 0b010011001, // TYPE_67_2_2 + 0b100010010, // TYPE_78_3 + 0b010010010, // TYPE_90 + + 0b001010010, // TYPE_101_1 + 0b001011010, // TYPE_112_2_1 + 0b010110100, // TYPE_112_2_2 + 0b010010100, // TYPE_123_3 + 0b001010100, // TYPE_135 + + 0b000011100, // TYPE_146_1 + 0b000011110, // TYPE_157_2_1 + 0b011110000, // TYPE_157_2_2 + 0b001110000, // TYPE_168_3 + }; + public: + enum FigureType { + TYPE_NONE = 0, + + TYPE_0, // 000 + // 111 + // 000 + + TYPE_11_1, // 100 + // 011 + // 000 + + TYPE_22_2_1,// 110 + // 011 + // 000 + + TYPE_22_2_2,// 000 + // 110 + // 011 + + TYPE_33_3, // 000 + // 110 + // 001 + + TYPE_45, // 100 + // 010 + // 001 + + TYPE_56_1, // 010 + // 010 + // 001 + TYPE_67_2_1, + TYPE_67_2_2, + TYPE_78_3, + TYPE_90, + TYPE_101_1, + TYPE_112_2_1, + TYPE_112_2_2, + TYPE_123_3, + TYPE_135, + TYPE_146_1, + TYPE_157_2_1, + TYPE_157_2_2, + TYPE_168_3 + }; + SvKernelV2(); virtual ~SvKernelV2(); void exec(int line) override; + + int max(int x, int y); + unsigned int figureType(int x, int y, int level); }; #endif // SVKERNELV2_H