SvPoint Update

This commit is contained in:
Andrey Tkachenko 2014-07-30 14:42:29 +04:00
parent 23f5479b35
commit 9f13434d12
10 changed files with 149 additions and 56 deletions

View File

@ -19,7 +19,8 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
SvImageProvider imageProvider;
QImage imgLeft("../ComputerVision/img/left9.png");
QImage imgLeft("../CSV/img/left3.png");
//QImage imgLeft("../CSV/img/right1.png");
QImage imgRight("../CSV/img/right1.png");
SvImage left(imgLeft);

View File

@ -15,12 +15,13 @@ protected:
SvFigure *m_outer;
QList<SvPoint*> m_points;
SvSimplePoint *m_keyPoints;
QList<SvSimplePoint*> m_keyPoints;
private:
SvCurve();
public:
QList<SvPoint*> &points() {return m_points; }
SvPoint* head() {return m_points.first(); }
SvPoint* tail() {return m_points.last(); }
void setInner(SvFigure *figure) {m_inner = figure; }

View File

@ -9,14 +9,16 @@
class SvFigure
{
protected:
QColor m_color;
QRgb m_color;
QList<SvCurve*> m_curves;
public:
SvFigure();
SvFigure(SvCurve *curve);
QRgb color() {return m_color;}
void addCurve(SvCurve *curve){m_curves.push_back(curve); }
QList<SvCurve*> &curves() { return m_curves; }
SvCurve *findCurveByPoint(SvPoint *point);
SvFigure split(SvPoint *point);
};

View File

@ -32,34 +32,32 @@ int SvKernel::rgbDiff(QRgb left, QRgb right)
int dsign = sign(diff);
dsign = dsign == 0 ? 1 : dsign;
return dsign * (abs(rightDiff - leftDiff)>>2) + diff /*+ (hsvDiff > 5 ? dsign * 10 : 0)*/;
return /*dsign * (abs(rightDiff - leftDiff)>>2) + */diff /*+ (hsvDiff > 5 ? dsign * 10 : 0)*/;
}
void SvKernel::exec(SvPointCloud *pc, SvImage *image, int line)
{
SvPoint p;
QRgb vtop, top, right, bottom, vbottom, _xy, xy;
QRgb vtop, top, right, bottom, vbottom, center;
QRgb rTop, lTop;
int __dX, _dX, dX, dX_,
__dY, _dY, dY, dY_;
int value;
int hDiff, vDiff;
for (int x = 0; x < image->getWidth(); x++) {
value = 0;
hDiff = 0; vDiff = 0;
vtop = image->getPixelRGB(x - 1, line - 3);
top = image->getPixelRGB(x - 1, line - 2);
right = image->getPixelRGB(x, line - 1);
bottom = image->getPixelRGB(x - 1, line);
vbottom = image->getPixelRGB(x - 1, line + 1);
xy = image->getPixelRGB(x - 1, line - 1);
vtop = image->getPixelRGB(x - 1, line - 3);
dX_ = rgbDiff(_xy, right);
dX_ = rgbDiff(center, right);
dY_ = rgbDiff(vtop, top);
dY = rgbDiff(top, _xy);
_dY = rgbDiff(_xy, bottom);
__dY = rgbDiff(bottom, vbottom);
dY = rgbDiff(top, center);
_dY = rgbDiff(center, bottom);
if ( dX >= _dX && dX > dX_ ||
dX <= _dX && dX < dX_) {
@ -67,10 +65,10 @@ void SvKernel::exec(SvPointCloud *pc, SvImage *image, int line)
if (dX > dX_ && _dX > __dX ||
dX < dX_ && _dX < __dX) {
value += abs(dX);
hDiff = abs(dX);
}
} else {
value += abs(dX);
hDiff = abs(dX);
}
}
@ -78,23 +76,28 @@ void SvKernel::exec(SvPointCloud *pc, SvImage *image, int line)
dY <= _dY && dY < dY_) {
if (dY == _dY) {
vbottom = image->getPixelRGB(x - 1, line + 1);
__dY = rgbDiff(bottom, vbottom);
if (dY > dY_ && _dY > __dY ||
dY < dY_ && _dY < __dY) {
value += abs(dY);
vDiff = abs(dY);
}
} else {
value += abs(dY);
vDiff = abs(dY);
}
}
if (value > 0) {
if (x > 0 && line > 0){
if (hDiff > 0 || vDiff > 0) {
if (x > 1 && line > 1){
lTop = image->getPixelRGB(x - 2, line - 2);
rTop = image->getPixelRGB(x, line - 2);
p.setX(x - 1);
p.setY(line - 1);
int color = value > 255 ? 255 : value;
p.setColor(qRgb(value, value, value));
p.setDiff(hDiff, rgbDiff(center, lTop), vDiff, rgbDiff(center, rTop));
pc->addPoint(p);
}
@ -103,7 +106,7 @@ void SvKernel::exec(SvPointCloud *pc, SvImage *image, int line)
__dX = _dX;
_dX = dX;
dX = dX_;
_xy = right;
center = right;
}
}

View File

@ -7,12 +7,24 @@ SvPoint::SvPoint()
SvPoint::SvPoint(SvPoint &point)
{
m_px = point.x();
m_py = point.y();
m_color = point.color();
(*this) = point;
}
void SvPoint::addCurve(SvCurve *curve)
{
m_curves[m_curveCount++] = curve;
}
int SvPoint::parallelism(SvPoint *p, DiffType type)
{
}
void SvPoint::setDiff(int lDiff, int ltDiff, int tDiff, int rtDiff)
{
m_diff[LEFT] = lDiff;
m_diff[LEFT_TOP] = ltDiff;
m_diff[TOP] = tDiff;
m_diff[RIGHT_TOP] = rtDiff;
}

View File

@ -10,26 +10,19 @@ class SvPoint: public SvSimplePoint
{
public:
enum Sides {
TOP,
BOTTOM,
RIGHT,
LEFT
};
enum FlowType {
HORIZONTAL,
VERTICAL,
SLASH,
BACK_SLASH
enum DiffType {
LEFT = 0,
LEFT_TOP = 1,
TOP = 2,
RIGHT_TOP = 3
};
protected:
uint m_id;
uint m_curveCount;
SvCurve *m_curves[8];
FlowType m_type;
QRgb m_color;
int m_diff[4];
QRgb m_colors[4];
public:
SvPoint();
@ -37,9 +30,12 @@ public:
void addCurve(SvCurve *curve);
uint curveCount() {return m_curveCount; }
QRgb color() { return m_color; }
void setColor(QRgb color) { m_color = color; }
SvCurve *curve(uint index) {return m_curves[index]; }
SvCurve *curve(uint index) { return m_curves[index]; }
int parallelism(SvPoint *p, DiffType type);
int diff(DiffType index) { return m_diff[index]; }
void setDiff(int lDiff, int ltDiff, int tDiff, int rtDiff);
void setColors(QRgb left, QRgb top, QRgb right, QRgb bottom);
};
#endif // SVPOINT_H

View File

@ -31,5 +31,32 @@ SvPointCloud::~SvPointCloud()
void SvPointCloud::addPoint(SvPoint &point)
{
m_pointField[point.y()][point.x()] = new SvPoint(point);
int x = point.x(),
y = point.y();
SvPoint *topLeft, *top, *topRight;
SvPoint *left, *center, *right;
SvPoint *bottomLeft, *bottom, *bottomRight;
center = m_pointField[y][x - 1];
if (y > 1 && y < m_pointFieldHeight - 1 &&
x > 1 && x < m_pointFieldWidth && center) {
topRight = m_pointField[y - 1][x ];
top = m_pointField[y - 1][x - 1];
topLeft = m_pointField[y - 1][x - 2];
right = new SvPoint(point);
left = m_pointField[y ][x - 2];
bottomRight = m_pointField[y + 1][x ];
bottom = m_pointField[y + 1][x - 1];
bottomLeft = m_pointField[y + 1][x - 2];
}
m_pointField[y][x] = right;
}

View File

@ -42,6 +42,8 @@ public:
uint getWidth() { return m_pointFieldWidth; }
uint getHeight() { return m_pointFieldHeight; }
SvPoint *point(uint x, uint y) { return m_pointField[y][x]; }
QList<SvCurve*> &curves() { return m_curves; }
QList<SvFigure*> &figures() { return m_figures; }
};
#endif // SVPOINTCLOUD_H

View File

@ -9,6 +9,8 @@ SvPointCloudViewer::SvPointCloudViewer(QQuickItem *parent) :
setRenderTarget(QQuickPaintedItem::FramebufferObject);
}
void SvPointCloudViewer::paint(QPainter *painter)
{
if (!m_pointCloud) {
@ -23,18 +25,65 @@ void SvPointCloudViewer::paint(QPainter *painter)
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
//glEnable (GL_BLEND);
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLoadIdentity();
glTranslatef(100.0f, height()-10, -40.0f);
glTranslatef(0.0f, height(), -40.0f);
glPointSize(1.0f);
glScalef(1.0f, 1.0f, 1.0f);
foreach (SvFigure *figure, m_pointCloud->figures()) {
glBegin(GL_POLYGON);
glColor3ub(qRed(figure->color()), qGreen(figure->color()), qBlue(figure->color()));
foreach (SvCurve *curve, figure->curves()) {
foreach (SvPoint *point, curve->points()) {
glVertex3i(point->x(), point->y(), 0);
}
}
glEnd();
}
painter->endNativePainting();
}
/*
void SvPointCloudViewer::paint(QPainter *painter)
{
if (!m_pointCloud) {
qDebug() << "point cloud not set!";
return;
}
painter->beginNativePainting();
glViewport(0, 0, width(), height());
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, height(), -40.0f);
glPointSize(1.0f);
glScalef(1.0f, 1.0f, 1.0f);
glBegin(GL_POINTS);
for (int y = 0; y < m_pointCloud->getHeight(); y++) {
for (int x = 0; x < m_pointCloud->getWidth(); x++) {
for (int y = 1; y < m_pointCloud->getHeight(); y++) {
for (int x = 1; x < m_pointCloud->getWidth() - 1; x++) {
SvPoint *lp = m_pointCloud->point(x - 1, y);
SvPoint *tlp = m_pointCloud->point(x - 1, y - 1);
SvPoint *tp = m_pointCloud->point(x, y - 1);
SvPoint *trp = m_pointCloud->point(x + 1, y - 1);
SvPoint *p = m_pointCloud->point(x, y);
if (p) {
glColor3ub(qRed(p->color()), qGreen(p->color()), qBlue(p->color()));
glVertex3i(x, -y, 0);
//glColor3ub(0, 0, 0);
int topRight = abs(p->diff(SvPoint::RIGHT_TOP));
int topLeft = abs(p->diff(SvPoint::LEFT_TOP));
int left = abs(p->diff(SvPoint::LEFT));
int top = abs(p->diff(SvPoint::TOP));
glColor3ub(top * 4 > 255 ? 255 : top * 4, left * 4 > 255 ? 255 : left * 4, 0);
}
}
}
@ -42,4 +91,4 @@ void SvPointCloudViewer::paint(QPainter *painter)
painter->endNativePainting();
}
*/

View File

@ -12,9 +12,9 @@ public:
int y() {return m_py;}
int z() {return m_pz;}
int setX(int px) {m_px = px;}
int setY(int py) {m_py = py;}
int setZ(int pz) {m_pz = pz;}
void setX(int px) {m_px = px;}
void setY(int py) {m_py = py;}
void setZ(int pz) {m_pz = pz;}
SvSimplePoint();
};