Skip to content
Snippets Groups Projects
Commit 49863bbf authored by even's avatar even
Browse files

stats output

parent 1bf4e616
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,6 @@ BSDetectionWidget::BSDetectionWidget (QWidget *parent) ...@@ -37,7 +37,6 @@ BSDetectionWidget::BSDetectionWidget (QWidget *parent)
idetview = NULL; idetview = NULL;
// Sets initial user outputs parameters // Sets initial user outputs parameters
alternate = 0;
verbose = false; verbose = false;
stats = false; stats = false;
background = BACK_IMAGE; background = BACK_IMAGE;
...@@ -331,7 +330,6 @@ void BSDetectionWidget::mouseReleaseEvent (QMouseEvent *event) ...@@ -331,7 +330,6 @@ void BSDetectionWidget::mouseReleaseEvent (QMouseEvent *event)
} }
else else
{ {
alternate = 0;
cerr << "p1 defined: " << p1.x () << " " << p1.y () << endl; cerr << "p1 defined: " << p1.x () << " " << p1.y () << endl;
cerr << "p2 defined: " << p2.x () << " " << p2.y () << endl; cerr << "p2 defined: " << p2.x () << " " << p2.y () << endl;
detector.resetMaxDetections (); detector.resetMaxDetections ();
...@@ -782,6 +780,10 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) ...@@ -782,6 +780,10 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event)
displayDetectionResult (); displayDetectionResult ();
break; break;
case Qt::Key_Dollar :
writeTest ();
break;
case Qt::Key_1 : case Qt::Key_1 :
switchPixelAnalyzer (); switchPixelAnalyzer ();
break; break;
...@@ -955,6 +957,16 @@ void BSDetectionWidget::displayBackground () ...@@ -955,6 +957,16 @@ void BSDetectionWidget::displayBackground ()
} }
void BSDetectionWidget::writeTest ()
{
ofstream outf ("test.txt", ios::out);
outf << p1.x() << " " << p1.y () << endl;
outf << p2.x() << " " << p2.y () << endl;
outf.close ();
cout << "Selection saved in test.txt" << endl;
}
void BSDetectionWidget::writeDetectionResult () void BSDetectionWidget::writeDetectionResult ()
{ {
BlurredSegment *bs = detector.getBlurredSegment (); BlurredSegment *bs = detector.getBlurredSegment ();
...@@ -1099,6 +1111,8 @@ void BSDetectionWidget::clearSavedSegments () ...@@ -1099,6 +1111,8 @@ void BSDetectionWidget::clearSavedSegments ()
void BSDetectionWidget::writeStats () void BSDetectionWidget::writeStats ()
{ {
int longEdgeThreshold = 1600;
vector<BlurredSegment *> bss = detector.getBlurredSegments (); vector<BlurredSegment *> bss = detector.getBlurredSegments ();
if (bss.empty ()) if (bss.empty ())
{ {
...@@ -1123,15 +1137,18 @@ void BSDetectionWidget::writeStats () ...@@ -1123,15 +1137,18 @@ void BSDetectionWidget::writeStats ()
{ {
int nbdssnull = 0; int nbdssnull = 0;
double ltotal = 0.; double ltotal = 0.;
int lcount = 0;
double wtotal = 0.; double wtotal = 0.;
vector<BlurredSegment *>::iterator it = bss.begin (); vector<BlurredSegment *>::iterator it = bss.begin ();
while (it != bss.end ()) while (it != bss.end ())
{ {
Pt2i ptb = (*it)->getLastRight (); Pt2i ptb = (*it)->getLastRight ();
Pt2i ptf = (*it)->getLastLeft (); Pt2i ptf = (*it)->getLastLeft ();
double length = sqrt ((ptb.x () - ptf.x ()) * (ptb.x () - ptf.x ()) int length2 = (ptb.x () - ptf.x ()) * (ptb.x () - ptf.x ())
+ (ptb.y () - ptf.y ()) * (ptb.y () - ptf.y ())); + (ptb.y () - ptf.y ()) * (ptb.y () - ptf.y ());
double length = sqrt (length2);
ltotal += length; ltotal += length;
if (length2 > longEdgeThreshold) lcount ++;
DigitalStraightSegment *dss = (*it)->getSegment (); DigitalStraightSegment *dss = (*it)->getSegment ();
if (dss != NULL) if (dss != NULL)
{ {
...@@ -1144,9 +1161,10 @@ void BSDetectionWidget::writeStats () ...@@ -1144,9 +1161,10 @@ void BSDetectionWidget::writeStats ()
cout << bss.size () << " blurred segments detected on " cout << bss.size () << " blurred segments detected on "
<< detector.countOfTrials () << " trials " << endl; << detector.countOfTrials () << " trials " << endl;
cout << lcount << " long (>40) blurred segments detected" << endl;
cout << "Mean length : " << ltotal / bss.size () << endl; cout << "Mean length : " << ltotal / bss.size () << endl;
cout << "Mean width (per unit length) : " << wtotal / ltotal << endl; cout << "Mean width (per unit length) : " << wtotal / ltotal << endl;
cout << nbdssnull << " DSS null" << endl; if (nbdssnull != 0) cout << nbdssnull << " DSS null" << endl;
} }
} }
...@@ -1223,22 +1241,116 @@ void BSDetectionWidget::extract () ...@@ -1223,22 +1241,116 @@ void BSDetectionWidget::extract ()
void BSDetectionWidget::alternateTest () void BSDetectionWidget::alternateTest ()
{ {
if (p1.equals (p2)) int longEdgeThreshold = 1600;
{ int nbruns = 100;
cout << "Stroke undefined" << endl; double diff1 = 0.;
return; int nbdssnull = 0;
} double ltotal = 0.;
double lltotal = 0.;
if (++alternate == 3) alternate = 0; int lcount = 0;
if (alternate == 0) double wtotal = 0.;
{ double lwtotal = 0.;
} vector<BlurredSegment *> bss;
else if (alternate == 1) vector<BlurredSegment *>::iterator it;
ofstream outf ("perf.txt", ios::out);
outf << nbruns << endl;
outf << width << endl;
outf << height << endl;
if (detector.oldDetectorOn ()) detector.switchDetector ();
cout << "Performance test on "
<< (detector.oldDetectorOn () ? "old" : "new") << " detector" << endl;
clock_t start = clock ();
for (int i = 0; i < nbruns; i++) detector.detectAll ();
diff1 = (clock () - start) / (double) CLOCKS_PER_SEC;
outf << diff1 << endl;
detector.detectAll ();
bss = detector.getBlurredSegments ();
it = bss.begin ();
while (it != bss.end ())
{ {
Pt2i ptb = (*it)->getLastRight ();
Pt2i ptf = (*it)->getLastLeft ();
int length2 = (ptb.x () - ptf.x ()) * (ptb.x () - ptf.x ())
+ (ptb.y () - ptf.y ()) * (ptb.y () - ptf.y ());
double length = sqrt (length2);
ltotal += length;
if (length2 > longEdgeThreshold)
{
lcount ++;
lltotal += length;
}
DigitalStraightSegment *dss = (*it)->getSegment ();
if (dss != NULL)
{
double width = dss->width () / (double) (dss->period ());
wtotal += width * length;
if (length2 > longEdgeThreshold) lwtotal += width * length;
}
else nbdssnull ++;
it ++;
} }
else if (alternate == 2) outf << detector.countOfTrials () << endl;
outf << bss.size () << endl;
outf << lcount << endl;;
outf << ltotal / bss.size () << endl;
outf << wtotal / ltotal << endl;
outf << lwtotal / lltotal << endl;
if (nbdssnull != 0) cout << nbdssnull << " DSS null" << endl;
diff1 = 0.;
nbdssnull = 0;
ltotal = 0.;
lltotal = 0.;
lcount = 0;
wtotal = 0.;
lwtotal = 0.;
detector.switchDetector ();
cout << "Performance test on "
<< (detector.oldDetectorOn () ? "old" : "new") << " detector" << endl;
start = clock ();
for (int i = 0; i < nbruns; i++) detector.detectAll ();
diff1 = (clock () - start) / (double) CLOCKS_PER_SEC;
outf << diff1 << endl;
detector.detectAll ();
bss = detector.getBlurredSegments ();
it = bss.begin ();
while (it != bss.end ())
{ {
Pt2i ptb = (*it)->getLastRight ();
Pt2i ptf = (*it)->getLastLeft ();
int length2 = (ptb.x () - ptf.x ()) * (ptb.x () - ptf.x ())
+ (ptb.y () - ptf.y ()) * (ptb.y () - ptf.y ());
double length = sqrt (length2);
ltotal += length;
if (length2 > longEdgeThreshold)
{
lcount ++;
lltotal += length;
}
DigitalStraightSegment *dss = (*it)->getSegment ();
if (dss != NULL)
{
double width = dss->width () / (double) (dss->period ());
wtotal += width * length;
if (length2 > longEdgeThreshold) lwtotal += width * length;
}
else nbdssnull ++;
it ++;
} }
outf << detector.countOfTrials () << endl;
outf << bss.size () << endl;
outf << lcount << endl;
outf << ltotal / bss.size () << endl;
outf << wtotal / ltotal << endl;
outf << lwtotal / lltotal << endl;
if (nbdssnull != 0) cout << nbdssnull << " DSS null" << endl;
outf.close ();
cout << "Selection saved in perf.txt" << endl;
} }
...@@ -1331,7 +1443,7 @@ QSize BSDetectionWidget::setRandomImage (int type) ...@@ -1331,7 +1443,7 @@ QSize BSDetectionWidget::setRandomImage (int type)
vector<BlurredSegment *> rbs[nbsegs]; vector<BlurredSegment *> rbs[nbsegs];
bool dispEach = false; bool dispEach = false;
int nbruns = 100; int nbruns = 1000;
int nbIniPts[nbruns]; int nbIniPts[nbruns];
int oldTrials[nbruns]; int oldTrials[nbruns];
int newTrials[nbruns]; int newTrials[nbruns];
......
...@@ -222,8 +222,6 @@ private: ...@@ -222,8 +222,6 @@ private:
bool udef; bool udef;
/** Saved user definition flag. */ /** Saved user definition flag. */
bool oldudef; bool oldudef;
/** Activation of alternate comparative tests (F8). */
int alternate;
/** Kind of highlight colors. */ /** Kind of highlight colors. */
bool darkHighlightOn; bool darkHighlightOn;
...@@ -360,6 +358,11 @@ private: ...@@ -360,6 +358,11 @@ private:
*/ */
void writeStats (); void writeStats ();
/**
* \brief Writes the selection stroke in test.txt.
*/
void writeTest ();
/** /**
* \brief Writes the result of the last detection in a file. * \brief Writes the result of the last detection in a file.
*/ */
......
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