24 #include <fvclassifiers/simple.h> 26 #include <fvutils/color/colorspaces.h> 27 #include <fvutils/color/yuv.h> 28 #include <fvutils/color/color_object_map.h> 30 #include <fvmodels/scanlines/scanlinemodel.h> 31 #include <fvmodels/color/colormodel.h> 33 #include <core/exceptions/software.h> 60 unsigned int min_num_points,
61 unsigned int box_extent,
63 unsigned int neighbourhood_min_match,
69 if (scanline_model == NULL) {
73 if (color_model == NULL) {
79 this->scanline_model = scanline_model;
80 this->color_model = color_model;
81 this->min_num_points = min_num_points;
82 this->box_extent = box_extent;
83 this->upward = upward;
84 this->grow_by = grow_by;
85 this->neighbourhood_min_match = neighbourhood_min_match;
90 SimpleColorClassifier::consider_neighbourhood(
unsigned int x,
unsigned int y , color_t what)
93 unsigned int num_what = 0;
95 unsigned char yp = 0, up = 0, vp = 0;
96 int start_x = -2, start_y = -2;
97 int end_x = 2, end_y = 2;
99 if (x < (
unsigned int)abs(start_x)) {
102 if (y < (
unsigned int)abs(start_y)) {
113 for (
int dx = start_x; dx <= end_x ; dx += 2) {
114 for (
int dy = start_y; dy <= end_y; ++dy) {
115 if ((dx == 0) && (dy == 0)) {
140 return new std::list< ROI >;
144 std::list< ROI > *rv =
new std::list< ROI >();
145 std::list< ROI >::iterator roi_it, roi_it2;
148 unsigned int x = 0, y = 0;
149 unsigned char yp = 0, up = 0, vp = 0;
150 unsigned int num_what = 0;
154 scanline_model->reset();
155 while (! scanline_model->finished()) {
157 x = (*scanline_model)->
x;
158 y = (*scanline_model)->y;
170 if (neighbourhood_min_match) {
172 consider_neighbourhood((*scanline_model)->x, (*scanline_model)->y, c);
174 if (num_what >= neighbourhood_min_match) {
177 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
178 if ( (*roi_it).contains(x, y) ) {
185 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
186 if ( (*roi_it).neighbours(x, y, scanline_model->get_margin()) ) {
188 (*roi_it).extend(x, y);
197 if ( x < box_extent ) {
202 if ( y < box_extent ) {
211 unsigned int to_x = (*scanline_model)->x + box_extent;
212 unsigned int to_y = (*scanline_model)->y + box_extent;
243 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
244 (*roi_it).grow( grow_by );
249 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
253 while ( roi_it2 != rv->end() ) {
254 if ((roi_it != roi_it2) &&
255 roi_it->neighbours(&(*roi_it2), scanline_model->get_margin()))
259 roi_it2 = rv->begin();
267 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
268 while ( (roi_it != rv->end()) &&
269 ((*roi_it).num_hint_points < min_num_points ))
271 roi_it = rv->erase( roi_it );
291 unsigned int nrOfOrangePixels;
292 nrOfOrangePixels = 0;
297 register unsigned int h = 0;
298 register unsigned int w = 0;
306 unsigned char *lyp = yp;
307 unsigned char *lup = up;
308 unsigned char *lvp = vp;
313 for (h = 0; h < roi->
height; ++h) {
314 for (w = 0; w < roi->
width; w += 2) {
316 dcolor = color_model->
determine(*yp++, *up++, *vp++);
319 if (color == dcolor) {
336 massPoint->
x = (
unsigned int) (
float(massPoint->
x) / float(nrOfOrangePixels));
337 massPoint->
y = (
unsigned int) (
float(massPoint->
y) / float(nrOfOrangePixels));
virtual void get_mass_point_of_color(ROI *roi, fawkes::upoint_t *massPoint)
Get mass point of primary color.
Scanline model interface.
fawkes::upoint_t start
ROI start.
unsigned int _width
Width in pixels of _src buffer.
unsigned int y
y coordinate
unsigned int x
x coordinate
unsigned int width
ROI width.
A NULL pointer was supplied where not allowed.
SimpleColorClassifier(ScanlineModel *scanline_model, ColorModel *color_model, unsigned int min_num_points=6, unsigned int box_extent=50, bool upward=false, unsigned int neighbourhood_min_match=8, unsigned int grow_by=10, color_t color=C_ORANGE)
Constructor.
unsigned int _height
Height in pixels of _src buffer.
unsigned int image_width
width of image that contains this ROI
unsigned int image_height
height of image that contains this ROI
virtual std::list< ROI > * classify()
Classify image.
Point with cartesian coordinates as unsigned integers.
unsigned int hint
ROI hint.
unsigned int height
ROI height.
unsigned int line_step
line step
Classifier to extract regions of interest.
unsigned int pixel_step
pixel step
unsigned char * _src
Source buffer, encoded as YUV422_PLANAR.
color_t color
ROI primary color.
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.