3 #include <FL/Fl_Shared_Image.H> 24 for(
int i=0; i<*
argc; i++ )
28 srand48( time(NULL) );
30 if(!setlocale(LC_ALL,
"POSIX"))
31 PRINT_WARN(
"Failed to setlocale(); config file may not be parse correctly\n" );
74 const unsigned int x,
const unsigned int y,
75 const unsigned int rwidth,
const unsigned int rheight,
78 const unsigned int bytes_per_sample = 1;
79 const unsigned int depth = pb->d();
80 const unsigned int width = pb->w();
82 for(
unsigned int a = y; a < y+rheight; a++ )
86 uint8_t* pix = (uint8_t*)(pb->data()[0] + (a*width*depth) + x*depth);
87 memset( pix, val, rwidth * depth * bytes_per_sample );
93 const unsigned int width,
94 const unsigned int depth,
99 return( (pixels + (y*width*depth) + x*depth)[0] > threshold );
103 std::vector<rotrect_t>& rects )
106 const int threshold = 127;
108 Fl_Shared_Image *img = Fl_Shared_Image::get(filename.c_str());
111 std::cerr <<
"failed to open file: " << filename << std::endl;
120 const unsigned int width = img->w();
121 const unsigned height = img->h();
122 const unsigned int depth = img->d();
123 uint8_t* pixels = (uint8_t*)img->data()[0];
125 for(
unsigned int y = 0; y < height; y++)
127 for(
unsigned int x = 0; x < width; x++)
130 if(
pixel_is_set( pixels, width, depth, x, y, threshold) )
134 const unsigned int startx = x;
135 const unsigned int starty = y;
136 unsigned int rheight = height;
139 for( ; x < width && !
pixel_is_set( pixels, width, depth, x, y, threshold); x++ )
144 while( !
pixel_is_set( pixels, width, depth, x, yy, threshold) && (yy < height-1) )
150 if( yy-y < rheight ) rheight = yy-y;
154 pb_set_rect( img, startx, starty, x-startx, rheight, 0xFF );
161 latest.
pose.
x = startx;
162 latest.
pose.
y = height-1 - (starty + rheight);
164 latest.
size.
x = x - startx;
165 latest.
size.
y = rheight;
167 assert( latest.
pose.
x >= 0 );
168 assert( latest.
pose.
y >= 0 );
169 assert( latest.
pose.
x <= width );
170 assert( latest.
pose.
y <= height);
172 rects.push_back( latest );
181 if( img ) img->release();
237 if( val < minval )
return minval;
238 if( val > maxval )
return maxval;
The Stage library uses its own namespace.
static std::vector< std::string > args
static const Color magenta
void Init(int *argc, char **argv[])
static bool pixel_is_set(uint8_t *pixels, const unsigned int width, const unsigned int depth, const unsigned int x, const unsigned int y, uint8_t threshold)
int rotrects_from_image_file(const std::string &filename, std::vector< rotrect_t > &rects)
static void pb_set_rect(Fl_Shared_Image *pb, const unsigned int x, const unsigned int y, const unsigned int rwidth, const unsigned int rheight, const uint8_t val)
double constrain(double val, double minval, double maxval)
static const Color yellow
radians_t a
rotation about the z axis.
point_t * unit_square_points_create()