Skip to content
Snippets Groups Projects
Commit 4c5d8a99 authored by even's avatar even
Browse files

Code: strokes for ASD

parent 7b938066
No related branches found
No related tags found
No related merge requests found
......@@ -941,6 +941,11 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event)
displayDetectionResult ();
break;
case Qt::Key_Semicolon :
// Stores blurred segments features
writeBStraverse ();
break;
case Qt::Key_Plus :
if (zoom > 1)
{
......@@ -1268,6 +1273,73 @@ void BSDetectionWidget::writeDetectionResult ()
}
void BSDetectionWidget::writeBStraverse ()
{
int xlls = 1939000;
int ylls = 13548000;
int travel = 24;
vector<BlurredSegment *> bss = detector.getBlurredSegments ();
if (bss.empty ())
{
BlurredSegment *bs = detector.getBlurredSegment ();
if (bs != NULL)
{
ofstream outf ("strokes.txt", ios::out);
DigitalStraightSegment *dss = bs->getSegment ();
AbsRat x1r, y1r, x2r, y2r;
dss->naiveLine (x1r, y1r, x2r, y2r);
float x1 = x1r.num () / (float) x1r.den ();
float y1 = y1r.num () / (float) y1r.den ();
float x2 = x2r.num () / (float) x2r.den ();
float y2 = y2r.num () / (float) y2r.den ();
float ln = (float) sqrt ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
float dx = (x2 - x1) / ln;
float dy = (y2 - y1) / ln;
for (float pos = 0.0f; pos <= ln; pos += travel)
{
outf << xlls + (int) (x1 + pos * dx - travel * dy + 0.5f) << " "
<< ylls + (int) (y1 + pos * dy + travel * dx + 0.5f) << " "
<< xlls + (int) (x1 + pos * dx + travel * dy + 0.5f) << " "
<< ylls + (int) (y1 + pos * dy - travel * dx + 0.5f) << endl;
}
outf.close ();
}
}
else
{
DigitalStraightSegment *dss = NULL;
AbsRat x1r, y1r, x2r, y2r;
float x1, y1, x2, y2, ln, dx, dy;
ofstream outf ("strokes.txt", ios::out);
vector<BlurredSegment *>::iterator it = bss.begin ();
while (it != bss.end ())
{
if (*it != NULL)
{
dss = (*it)->getSegment ();
dss->naiveLine (x1r, y1r, x2r, y2r);
x1 = x1r.num () / (float) x1r.den ();
y1 = y1r.num () / (float) y1r.den ();
x2 = x2r.num () / (float) x2r.den ();
y2 = y2r.num () / (float) y2r.den ();
ln = (float) sqrt ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
dx = (x2 - x1) / ln;
dy = (y2 - y1) / ln;
for (float pos = 0.0f; pos <= ln; pos += travel)
{
outf << xlls + (int) (x1 + pos * dx - travel * dy + 0.5f) << " "
<< ylls + (int) (y1 + pos * dy + travel * dx + 0.5f) << " "
<< xlls + (int) (x1 + pos * dx + travel * dy + 0.5f) << " "
<< ylls + (int) (y1 + pos * dy - travel * dx + 0.5f) << endl;
}
}
it ++;
}
outf.close ();
}
}
void BSDetectionWidget::displayDetectionResult ()
{
if (background == BACK_BLACK) augmentedImage.fill (qRgb (0, 0, 0));
......
......@@ -410,6 +410,11 @@ private:
*/
void writeDetectionResult ();
/**
* \brief Computes seeds for ASD (strokes.txt).
*/
void writeBStraverse ();
/**
* \brief Displays the result of the last detection.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment