This commit is contained in:
Andrey Tkachenko 2014-07-18 20:48:42 +04:00
parent cae9dc0641
commit 60ff52a6e4
11 changed files with 270 additions and 24 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2014-07-12T22:47:40. -->
<!-- Written by QtCreator 3.0.1, 2014-07-18T12:19:19. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -53,7 +53,7 @@
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{463a2572-9a8f-4eb1-bda2-3a5ffe83025f}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{7246c6ab-7a87-4118-a487-ab344a31d36b}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
@ -229,7 +229,7 @@
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">CSV</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/andrey/workspace/ComputerVision/CSV.pro</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/andrey/workspace/CSV/CSV.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">CSV.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
@ -251,7 +251,7 @@
</data>
<data>
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
<value type="QByteArray">{dedf9f3d-a494-4afd-b37a-86d04bd971d6}</value>
<value type="QByteArray">{35059b80-6449-4cca-8333-a4525005f807}</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>

View File

@ -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
}
}
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

@ -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);

View File

@ -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();
}

View File

@ -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();

View File

@ -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));
}
}

View File

@ -7,7 +7,7 @@ class SvKernelV1: public SvAbstractKernel
{
protected:
int m_windowSize = 80;
int m_windowSize = 150;
public:
void exec(int line) override;

View File

@ -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;
}

View File

@ -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