|
@@ -16,6 +16,13 @@
|
|
#include "vislearning/cbaselib/LocalizationResult.h"
|
|
#include "vislearning/cbaselib/LocalizationResult.h"
|
|
#include "core/basics/StringTools.h"
|
|
#include "core/basics/StringTools.h"
|
|
|
|
|
|
|
|
+// use this macro to show labeled images
|
|
|
|
+#undef DEBUG_LOCALIZATIONREAD
|
|
|
|
+
|
|
|
|
+#ifdef DEBUG_LOCALIZATIONREAD
|
|
|
|
+#include <core/imagedisplay/ImageDisplay.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
using namespace OBJREC;
|
|
using namespace OBJREC;
|
|
|
|
|
|
using namespace std;
|
|
using namespace std;
|
|
@@ -141,10 +148,10 @@ LocalizationResult::~LocalizationResult ()
|
|
delete slr;
|
|
delete slr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-#undef DEBUG_LOCALIZATIONREAD
|
|
|
|
LocalizationResult::LocalizationResult ( const ClassNames *_cn, const NICE::Image & img, int classno ) : cn(_cn)
|
|
LocalizationResult::LocalizationResult ( const ClassNames *_cn, const NICE::Image & img, int classno ) : cn(_cn)
|
|
{
|
|
{
|
|
- const int t = 200; // FIXME
|
|
|
|
|
|
+ // FIXME: just a bad predefined threshold !
|
|
|
|
+ const int t = 200;
|
|
NICE::Region reg;
|
|
NICE::Region reg;
|
|
|
|
|
|
#ifdef DEBUG_LOCALIZATIONREAD
|
|
#ifdef DEBUG_LOCALIZATIONREAD
|
|
@@ -158,8 +165,6 @@ LocalizationResult::LocalizationResult ( const ClassNames *_cn, const NICE::Imag
|
|
for ( int y = 0 ; y < img.height(); y++ )
|
|
for ( int y = 0 ; y < img.height(); y++ )
|
|
for ( int x = 0 ; x < img.width(); x++ )
|
|
for ( int x = 0 ; x < img.width(); x++ )
|
|
{
|
|
{
|
|
- // refactor-nice.pl: check this substitution
|
|
|
|
- // old: if ( GetVal(img, x, y) < t )
|
|
|
|
if ( img.getPixel(x,y) < t )
|
|
if ( img.getPixel(x,y) < t )
|
|
{
|
|
{
|
|
#ifdef DEBUG_LOCALIZATIONREAD
|
|
#ifdef DEBUG_LOCALIZATIONREAD
|
|
@@ -191,33 +196,69 @@ LocalizationResult::LocalizationResult ( const ClassNames *_cn, const NICE::Colo
|
|
NICE::Image imgo (xsize,ysize);
|
|
NICE::Image imgo (xsize,ysize);
|
|
imgo.set(0);
|
|
imgo.set(0);
|
|
#endif
|
|
#endif
|
|
-
|
|
|
|
- for ( int y = 0 ; y < ysize ; y++ )
|
|
|
|
- for ( int x = 0 ; x < xsize ; x++ )
|
|
|
|
- {
|
|
|
|
- int r = img.getPixel(x,y,0);
|
|
|
|
- int g = img.getPixel(x,y,1);
|
|
|
|
- int b = img.getPixel(x,y,2);
|
|
|
|
|
|
|
|
- int classno;
|
|
|
|
-
|
|
|
|
- _cn->getClassnoFromColor ( classno, r, g, b );
|
|
|
|
-
|
|
|
|
- if ( classno >= 0 )
|
|
|
|
- regions[classno].add(x,y);
|
|
|
|
- #ifdef DEBUG_LOCALIZATIONREAD
|
|
|
|
- imgo.setPixel(x,y,classno);
|
|
|
|
- #endif
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ for ( int y = 0 ; y < ysize ; y++ )
|
|
|
|
+ {
|
|
|
|
+ int xstart = 0;
|
|
|
|
+ // RGB values of the current pixel
|
|
|
|
+ int r = img.getPixel(0,y,0);
|
|
|
|
+ int g = img.getPixel(0,y,1);
|
|
|
|
+ int b = img.getPixel(0,y,2);
|
|
|
|
+
|
|
|
|
+ for ( int x = 0 ; x < xsize ; x++ )
|
|
|
|
+ {
|
|
|
|
+ int r_next, g_next, b_next;
|
|
|
|
+ if ( x != xsize - 1 ) {
|
|
|
|
+ r_next = img.getPixel(x,y,0);
|
|
|
|
+ g_next = img.getPixel(x,y,1);
|
|
|
|
+ b_next = img.getPixel(x,y,2);
|
|
|
|
+ } else {
|
|
|
|
+ // at the border of the image, we should
|
|
|
|
+ // always have a color change to add the last
|
|
|
|
+ // line segment
|
|
|
|
+ r_next = -1;
|
|
|
|
+ g_next = -1;
|
|
|
|
+ b_next = -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // now the RGB color changes and we have an object boundary
|
|
|
|
+ // therefore we have to add a line segment
|
|
|
|
+ if ( r != r_next || g != g_next || b != b_next )
|
|
|
|
+ {
|
|
|
|
+ int classno;
|
|
|
|
+ // look up class number for the label color
|
|
|
|
+ _cn->getClassnoFromColor ( classno, r, g, b );
|
|
|
|
+
|
|
|
|
+ if ( classno >= 0 ) {
|
|
|
|
+ // add line segment as an rectangular region
|
|
|
|
+ regions[classno].add( xstart, y, x, y );
|
|
|
|
+
|
|
|
|
+ #ifdef DEBUG_LOCALIZATIONREAD
|
|
|
|
+ for ( int z = xstart ; z <= x ; z++ )
|
|
|
|
+ imgo.setPixel(z,y,classno);
|
|
|
|
+ #endif
|
|
|
|
+ xstart = x+1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ r = r_next;
|
|
|
|
+ g = g_next;
|
|
|
|
+ b = b_next;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ #ifdef DEBUG_LOCALIZATIONREAD
|
|
|
|
+ showImageOverlay(imgo, imgo);
|
|
|
|
+ #endif
|
|
|
|
|
|
for ( map<int, NICE::Region>::const_iterator j = regions.begin();
|
|
for ( map<int, NICE::Region>::const_iterator j = regions.begin();
|
|
j != regions.end();
|
|
j != regions.end();
|
|
j++ )
|
|
j++ )
|
|
{
|
|
{
|
|
- int classno = j->first;
|
|
|
|
- ClassificationResult *r = new ClassificationResult (classno, 1.0, _cn->getMaxClassno());
|
|
|
|
- push_back ( new SingleLocalizationResult ( r, j->second ) );
|
|
|
|
|
|
+ int classno = j->first;
|
|
|
|
+ ClassificationResult *r = new ClassificationResult (classno, 1.0, _cn->getMaxClassno());
|
|
|
|
+ push_back ( new SingleLocalizationResult ( r, j->second ) );
|
|
}
|
|
}
|
|
|
|
|
|
hasLabeledImage = false;
|
|
hasLabeledImage = false;
|