24 #include <core/exceptions/software.h> 25 #include <fvclassifiers/multi_color.h> 26 #include <fvmodels/color/colormodel.h> 27 #include <fvmodels/scanlines/scanlinemodel.h> 28 #include <fvutils/color/color_object_map.h> 29 #include <fvutils/color/colorspaces.h> 30 #include <fvutils/color/yuv.h> 34 namespace firevision {
54 unsigned int min_num_points,
55 unsigned int box_extent,
57 unsigned int neighbourhood_min_match,
61 if (scanline_model == NULL) {
65 if (color_model == NULL) {
71 this->scanline_model = scanline_model;
72 this->color_model = color_model;
73 this->min_num_points = min_num_points;
74 this->box_extent = box_extent;
75 this->upward = upward;
76 this->grow_by = grow_by;
77 this->neighbourhood_min_match = neighbourhood_min_match;
81 MultiColorClassifier::consider_neighbourhood(
unsigned int x,
unsigned int y, color_t what)
84 unsigned int num_what = 0;
86 unsigned char yp = 0, up = 0, vp = 0;
87 int start_x = -2, start_y = -2;
88 int end_x = 2, end_y = 2;
90 if (x < (
unsigned int)abs(start_x)) {
93 if (y < (
unsigned int)abs(start_y)) {
104 for (
int dx = start_x; dx <= end_x; dx += 2) {
105 for (
int dy = start_y; dy <= end_y; ++dy) {
106 if ((dx == 0) && (dy == 0)) {
129 return new std::list<ROI>;
132 std::map<color_t, std::list<ROI>> rois;
133 std::map<color_t, std::list<ROI>>::iterator map_it;
134 std::list<ROI>::iterator roi_it, roi_it2;
137 unsigned int x = 0, y = 0;
138 unsigned char yp = 0, up = 0, vp = 0;
139 unsigned int num_what = 0;
143 scanline_model->reset();
144 while (!scanline_model->finished()) {
145 x = (*scanline_model)->
x;
146 y = (*scanline_model)->y;
152 if ((c != C_BACKGROUND) && (c != C_OTHER)) {
158 if (neighbourhood_min_match) {
159 num_what = consider_neighbourhood((*scanline_model)->x, (*scanline_model)->y, c);
161 if (num_what >= neighbourhood_min_match) {
164 for (roi_it = rois[c].begin(); roi_it != rois[c].end(); ++roi_it) {
165 if ((*roi_it).contains(x, y)) {
172 for (roi_it = rois[c].begin(); roi_it != rois[c].end(); ++roi_it) {
173 if ((*roi_it).neighbours(x, y, scanline_model->get_margin())) {
175 (*roi_it).extend(x, y);
184 if (x < box_extent) {
189 if (y < box_extent) {
198 unsigned int to_x = (*scanline_model)->x + box_extent;
199 unsigned int to_y = (*scanline_model)->y + box_extent;
222 rois[c].push_back(r);
232 for (map_it = rois.begin(); map_it != rois.end(); ++map_it) {
233 for (roi_it = map_it->second.begin(); roi_it != map_it->second.end(); ++roi_it) {
234 (*roi_it).grow(grow_by);
240 for (map_it = rois.begin(); map_it != rois.end(); ++map_it) {
241 for (roi_it = map_it->second.begin(); roi_it != map_it->second.end(); ++roi_it) {
245 while (roi_it2 != map_it->second.end()) {
246 if ((roi_it != roi_it2) && roi_it->neighbours(&(*roi_it2), scanline_model->get_margin())) {
248 map_it->second.erase(roi_it2);
249 roi_it2 = map_it->second.begin();
258 for (map_it = rois.begin(); map_it != rois.end(); ++map_it) {
259 for (roi_it = map_it->second.begin(); roi_it != map_it->second.end(); ++roi_it) {
260 while ((roi_it != map_it->second.end()) && ((*roi_it).num_hint_points < min_num_points)) {
261 roi_it = map_it->second.erase(roi_it);
268 std::list<ROI> *rv =
new std::list<ROI>();
269 for (map_it = rois.begin(); map_it != rois.end(); ++map_it) {
270 map_it->second.sort();
271 rv->merge(map_it->second);
284 unsigned int nrOfOrangePixels;
285 nrOfOrangePixels = 0;
301 unsigned char *lyp = yp;
302 unsigned char *lup = up;
303 unsigned char *lvp = vp;
308 for (h = 0; h < roi->
height; ++h) {
309 for (w = 0; w < roi->
width; w += 2) {
311 dcolor = color_model->
determine(*yp++, *up++, *vp++);
314 if (dcolor == roi->
color) {
331 massPoint->
x = (
unsigned int)(
float(massPoint->
x) / float(nrOfOrangePixels));
332 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.