24 #include <fvclassifiers/multi_color.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,
67 if (scanline_model == NULL) {
71 if (color_model == NULL) {
77 this->scanline_model = scanline_model;
78 this->color_model = color_model;
79 this->min_num_points = min_num_points;
80 this->box_extent = box_extent;
81 this->upward = upward;
82 this->grow_by = grow_by;
83 this->neighbourhood_min_match = neighbourhood_min_match;
88 MultiColorClassifier::consider_neighbourhood(
unsigned int x,
unsigned int y , color_t what)
91 unsigned int num_what = 0;
93 unsigned char yp = 0, up = 0, vp = 0;
94 int start_x = -2, start_y = -2;
95 int end_x = 2, end_y = 2;
97 if (x < (
unsigned int)abs(start_x)) {
100 if (y < (
unsigned int)abs(start_y)) {
111 for (
int dx = start_x; dx <= end_x ; dx += 2) {
112 for (
int dy = start_y; dy <= end_y; ++dy) {
113 if ((dx == 0) && (dy == 0)) {
137 return new std::list< ROI >;
140 std::map<color_t, std::list<ROI> > rois;
141 std::map<color_t, std::list<ROI> >::iterator map_it;
142 std::list<ROI>::iterator roi_it, roi_it2;
145 unsigned int x = 0, y = 0;
146 unsigned char yp = 0, up = 0, vp = 0;
147 unsigned int num_what = 0;
151 scanline_model->reset();
152 while (! scanline_model->finished()) {
154 x = (*scanline_model)->
x;
155 y = (*scanline_model)->y;
161 if ((c != C_BACKGROUND) && (c != C_OTHER)) {
167 if (neighbourhood_min_match) {
169 consider_neighbourhood((*scanline_model)->x, (*scanline_model)->y, c);
171 if (num_what >= neighbourhood_min_match) {
174 for (roi_it = rois[c].begin(); roi_it != rois[c].end(); ++roi_it) {
175 if ( (*roi_it).contains(x, y) ) {
182 for (roi_it = rois[c].begin(); roi_it != rois[c].end(); ++roi_it) {
183 if ( (*roi_it).neighbours(x, y, scanline_model->get_margin()) ) {
185 (*roi_it).extend(x, y);
194 if ( x < box_extent ) {
199 if ( y < box_extent ) {
208 unsigned int to_x = (*scanline_model)->x + box_extent;
209 unsigned int to_y = (*scanline_model)->y + box_extent;
230 rois[c].push_back( r );
240 for (map_it = rois.begin(); map_it != rois.end(); ++map_it) {
241 for (roi_it = map_it->second.begin();
242 roi_it != map_it->second.end(); ++roi_it)
244 (*roi_it).grow( grow_by );
250 for (map_it = rois.begin(); map_it != rois.end(); ++map_it) {
251 for (roi_it = map_it->second.begin(); roi_it != map_it->second.end(); ++roi_it)
256 while ( roi_it2 != map_it->second.end() ) {
257 if ((roi_it != roi_it2) &&
258 roi_it->neighbours(&(*roi_it2), scanline_model->get_margin()))
261 map_it->second.erase(roi_it2);
262 roi_it2 = map_it->second.begin();
271 for (map_it = rois.begin(); map_it != rois.end(); ++map_it) {
272 for (roi_it = map_it->second.begin(); roi_it != map_it->second.end(); ++roi_it)
274 while ( (roi_it != map_it->second.end()) &&
275 ((*roi_it).num_hint_points < min_num_points ))
277 roi_it = map_it->second.erase(roi_it);
284 std::list<ROI> *rv =
new std::list<ROI>();
285 for (map_it = rois.begin(); map_it != rois.end(); ++map_it) {
286 map_it->second.sort();
287 rv->merge(map_it->second);
302 unsigned int nrOfOrangePixels;
303 nrOfOrangePixels = 0;
308 register unsigned int h = 0;
309 register unsigned int w = 0;
317 unsigned char *lyp = yp;
318 unsigned char *lup = up;
319 unsigned char *lvp = vp;
324 for (h = 0; h < roi->
height; ++h) {
325 for (w = 0; w < roi->
width; w += 2) {
327 dcolor = color_model->
determine(*yp++, *up++, *vp++);
330 if (dcolor == roi->
color) {
347 massPoint->
x = (
unsigned int) (
float(massPoint->
x) / float(nrOfOrangePixels));
348 massPoint->
y = (
unsigned int) (
float(massPoint->
y) / float(nrOfOrangePixels));
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.
MultiColorClassifier(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)
Constructor.
A NULL pointer was supplied where not allowed.
virtual std::list< ROI > * classify()
Classify image.
unsigned int _height
Height in pixels of _src buffer.
unsigned int image_width
width of image that contains this ROI
virtual void get_mass_point_of_color(ROI *roi, fawkes::upoint_t *massPoint)
Get mass point of primary color.
unsigned int image_height
height of image that contains this ROI
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.