24 #include <core/exceptions/software.h>
25 #include <fvclassifiers/simple.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,
60 :
Classifier(
"SimpleColorClassifier"), color(color)
62 if (scanline_model == NULL) {
66 if (color_model == NULL) {
72 this->scanline_model = scanline_model;
73 this->color_model = color_model;
74 this->min_num_points = min_num_points;
75 this->box_extent = box_extent;
76 this->upward = upward;
77 this->grow_by = grow_by;
78 this->neighbourhood_min_match = neighbourhood_min_match;
82 SimpleColorClassifier::consider_neighbourhood(
unsigned int x,
unsigned int y, color_t what)
85 unsigned int num_what = 0;
87 unsigned char yp = 0, up = 0, vp = 0;
88 int start_x = -2, start_y = -2;
89 int end_x = 2, end_y = 2;
91 if (x < (
unsigned int)abs(start_x)) {
94 if (y < (
unsigned int)abs(start_y)) {
105 for (
int dx = start_x; dx <= end_x; dx += 2) {
106 for (
int dy = start_y; dy <= end_y; ++dy) {
107 if ((dx == 0) && (dy == 0)) {
131 return new std::list<ROI>;
134 std::list<ROI> * rv =
new std::list<ROI>();
135 std::list<ROI>::iterator roi_it, roi_it2;
138 unsigned int x = 0, y = 0;
139 unsigned char yp = 0, up = 0, vp = 0;
140 unsigned int num_what = 0;
144 scanline_model->reset();
145 while (!scanline_model->finished()) {
146 x = (*scanline_model)->
x;
147 y = (*scanline_model)->y;
159 if (neighbourhood_min_match) {
160 num_what = consider_neighbourhood((*scanline_model)->x, (*scanline_model)->y, c);
162 if (num_what >= neighbourhood_min_match) {
165 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
166 if ((*roi_it).contains(x, y)) {
173 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
174 if ((*roi_it).neighbours(x, y, scanline_model->get_margin())) {
176 (*roi_it).extend(x, y);
185 if (x < box_extent) {
190 if (y < box_extent) {
199 unsigned int to_x = (*scanline_model)->x + box_extent;
200 unsigned int to_y = (*scanline_model)->y + box_extent;
233 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
234 (*roi_it).grow(grow_by);
239 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
243 while (roi_it2 != rv->end()) {
244 if ((roi_it != roi_it2) && roi_it->neighbours(&(*roi_it2), scanline_model->get_margin())) {
247 roi_it2 = rv->begin();
255 for (roi_it = rv->begin(); roi_it != rv->end(); ++roi_it) {
256 while ((roi_it != rv->end()) && ((*roi_it).num_hint_points < min_num_points)) {
257 roi_it = rv->erase(roi_it);
275 unsigned int nrOfOrangePixels;
276 nrOfOrangePixels = 0;
292 unsigned char *lyp = yp;
293 unsigned char *lup = up;
294 unsigned char *lvp = vp;
299 for (h = 0; h < roi->
height; ++h) {
300 for (w = 0; w < roi->
width; w += 2) {
302 dcolor = color_model->
determine(*yp++, *up++, *vp++);
305 if (color == dcolor) {
322 massPoint->
x = (
unsigned int)(
float(massPoint->
x) / float(nrOfOrangePixels));
323 massPoint->
y = (
unsigned int)(
float(massPoint->
y) / float(nrOfOrangePixels));
A NULL pointer was supplied where not allowed.
Classifier to extract regions of interest.
unsigned int _height
Height in pixels of _src buffer.
unsigned char * _src
Source buffer, encoded as YUV422_PLANAR.
unsigned int _width
Width in pixels of _src buffer.
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine classification of YUV pixel.
unsigned int height
ROI height.
fawkes::upoint_t start
ROI start.
unsigned int line_step
line step
unsigned int width
ROI width.
unsigned int hint
ROI hint.
unsigned int image_width
width of image that contains this ROI
color_t color
ROI primary color.
unsigned int pixel_step
pixel step
unsigned int image_height
height of image that contains this ROI
Scanline model interface.
virtual void get_mass_point_of_color(ROI *roi, fawkes::upoint_t *massPoint)
Get mass point of primary color.
virtual std::list< ROI > * classify()
Classify image.
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.
Point with cartesian coordinates as unsigned integers.
unsigned int x
x coordinate
unsigned int y
y coordinate