root / vision / cvblobs8.3 / testBlobs / BlobOperators.h @ b11b2b30
History | View | Annotate | Download (16.3 KB)
1 | b11b2b30 | Tom Mullins | #ifndef BLOB_OPERATORS_H_INCLUDED
|
---|---|---|---|
2 | #define BLOB_OPERATORS_H_INCLUDED
|
||
3 | |||
4 | #include "blob.h" |
||
5 | |||
6 | /**************************************************************************
|
||
7 | Definici? de les classes per a fer operacions sobre els blobs
|
||
8 | |||
9 | Helper classes to perform operations on blobs
|
||
10 | **************************************************************************/
|
||
11 | |||
12 | //! Factor de conversi? de graus a radians
|
||
13 | #define DEGREE2RAD (CV_PI / 180.0) |
||
14 | |||
15 | |||
16 | //! Classe d'on derivarem totes les operacions sobre els blobs
|
||
17 | //! Interface to derive all blob operations
|
||
18 | class COperadorBlob |
||
19 | { |
||
20 | public:
|
||
21 | virtual ~COperadorBlob(){}; |
||
22 | |||
23 | //! Aply operator to blob
|
||
24 | virtual double operator()(CBlob &blob) = 0; |
||
25 | //! Get operator name
|
||
26 | virtual const char *GetNom() = 0; |
||
27 | |||
28 | operator COperadorBlob*() |
||
29 | { |
||
30 | return (COperadorBlob*)this;
|
||
31 | } |
||
32 | }; |
||
33 | |||
34 | typedef COperadorBlob funcio_calculBlob;
|
||
35 | |||
36 | #ifdef BLOB_OBJECT_FACTORY
|
||
37 | /**
|
||
38 | Funci? per comparar dos identificadors dins de la f?brica de COperadorBlobs
|
||
39 | */
|
||
40 | struct functorComparacioIdOperador
|
||
41 | { |
||
42 | bool operator()(const char* s1, const char* s2) const |
||
43 | { |
||
44 | return strcmp(s1, s2) < 0; |
||
45 | } |
||
46 | }; |
||
47 | |||
48 | //! Definition of Object factory type for COperadorBlob objects
|
||
49 | typedef ObjectFactory<COperadorBlob, const char *, functorComparacioIdOperador > t_OperadorBlobFactory; |
||
50 | |||
51 | //! Funci? global per a registrar tots els operadors definits a blob.h
|
||
52 | void RegistraTotsOperadors( t_OperadorBlobFactory &fabricaOperadorsBlob );
|
||
53 | |||
54 | #endif
|
||
55 | |||
56 | |||
57 | //! Classe per calcular l'etiqueta d'un blob
|
||
58 | //! Class to get ID of a blob
|
||
59 | class CBlobGetID : public COperadorBlob |
||
60 | { |
||
61 | public:
|
||
62 | double operator()(CBlob &blob)
|
||
63 | { |
||
64 | return blob.GetID();
|
||
65 | } |
||
66 | const char *GetNom() |
||
67 | { |
||
68 | return "CBlobGetID"; |
||
69 | } |
||
70 | }; |
||
71 | |||
72 | |||
73 | //! Classe per calcular l'?rea d'un blob
|
||
74 | //! Class to get the area of a blob
|
||
75 | class CBlobGetArea : public COperadorBlob |
||
76 | { |
||
77 | public:
|
||
78 | double operator()(CBlob &blob)
|
||
79 | { |
||
80 | return blob.Area();
|
||
81 | } |
||
82 | const char *GetNom() |
||
83 | { |
||
84 | return "CBlobGetArea"; |
||
85 | } |
||
86 | }; |
||
87 | |||
88 | //! Classe per calcular el perimetre d'un blob
|
||
89 | //! Class to get the perimeter of a blob
|
||
90 | class CBlobGetPerimeter: public COperadorBlob |
||
91 | { |
||
92 | public:
|
||
93 | double operator()(CBlob &blob)
|
||
94 | { |
||
95 | return blob.Perimeter();
|
||
96 | } |
||
97 | const char *GetNom() |
||
98 | { |
||
99 | return "CBlobGetPerimeter"; |
||
100 | } |
||
101 | }; |
||
102 | |||
103 | //! Classe que diu si un blob ?s extern o no
|
||
104 | //! Class to get the extern flag of a blob
|
||
105 | class CBlobGetExterior: public COperadorBlob |
||
106 | { |
||
107 | public:
|
||
108 | CBlobGetExterior() |
||
109 | { |
||
110 | m_mask = NULL;
|
||
111 | m_xBorder = false;
|
||
112 | m_yBorder = false;
|
||
113 | } |
||
114 | CBlobGetExterior(IplImage *mask, bool xBorder = true, bool yBorder = true) |
||
115 | { |
||
116 | m_mask = mask; |
||
117 | m_xBorder = xBorder; |
||
118 | m_yBorder = yBorder; |
||
119 | } |
||
120 | double operator()(CBlob &blob)
|
||
121 | { |
||
122 | return blob.Exterior(m_mask, m_xBorder, m_yBorder);
|
||
123 | } |
||
124 | const char *GetNom() |
||
125 | { |
||
126 | return "CBlobGetExterior"; |
||
127 | } |
||
128 | private:
|
||
129 | IplImage *m_mask; |
||
130 | bool m_xBorder, m_yBorder;
|
||
131 | }; |
||
132 | |||
133 | //! Classe per calcular la mitjana de nivells de gris d'un blob
|
||
134 | //! Class to get the mean grey level of a blob
|
||
135 | class CBlobGetMean: public COperadorBlob |
||
136 | { |
||
137 | public:
|
||
138 | CBlobGetMean() |
||
139 | { |
||
140 | m_image = NULL;
|
||
141 | } |
||
142 | CBlobGetMean( IplImage *image ) |
||
143 | { |
||
144 | m_image = image; |
||
145 | }; |
||
146 | |||
147 | double operator()(CBlob &blob)
|
||
148 | { |
||
149 | return blob.Mean(m_image);
|
||
150 | } |
||
151 | const char *GetNom() |
||
152 | { |
||
153 | return "CBlobGetMean"; |
||
154 | } |
||
155 | private:
|
||
156 | |||
157 | IplImage *m_image; |
||
158 | }; |
||
159 | |||
160 | //! Classe per calcular la desviaci? est?ndard dels nivells de gris d'un blob
|
||
161 | //! Class to get the standard deviation of the grey level values of a blob
|
||
162 | class CBlobGetStdDev: public COperadorBlob |
||
163 | { |
||
164 | public:
|
||
165 | CBlobGetStdDev() |
||
166 | { |
||
167 | m_image = NULL;
|
||
168 | } |
||
169 | CBlobGetStdDev( IplImage *image ) |
||
170 | { |
||
171 | m_image = image; |
||
172 | }; |
||
173 | double operator()(CBlob &blob)
|
||
174 | { |
||
175 | return blob.StdDev(m_image);
|
||
176 | } |
||
177 | const char *GetNom() |
||
178 | { |
||
179 | return "CBlobGetStdDev"; |
||
180 | } |
||
181 | private:
|
||
182 | |||
183 | IplImage *m_image; |
||
184 | |||
185 | }; |
||
186 | |||
187 | //! Classe per calcular la compacitat d'un blob
|
||
188 | //! Class to calculate the compactness of a blob
|
||
189 | class CBlobGetCompactness: public COperadorBlob |
||
190 | { |
||
191 | public:
|
||
192 | double operator()(CBlob &blob);
|
||
193 | const char *GetNom() |
||
194 | { |
||
195 | return "CBlobGetCompactness"; |
||
196 | } |
||
197 | }; |
||
198 | |||
199 | //! Classe per calcular la longitud d'un blob
|
||
200 | //! Class to calculate the length of a blob
|
||
201 | class CBlobGetLength: public COperadorBlob |
||
202 | { |
||
203 | public:
|
||
204 | double operator()(CBlob &blob);
|
||
205 | const char *GetNom() |
||
206 | { |
||
207 | return "CBlobGetLength"; |
||
208 | } |
||
209 | }; |
||
210 | |||
211 | //! Classe per calcular l'amplada d'un blob
|
||
212 | //! Class to calculate the breadth of a blob
|
||
213 | class CBlobGetBreadth: public COperadorBlob |
||
214 | { |
||
215 | public:
|
||
216 | double operator()(CBlob &blob);
|
||
217 | const char *GetNom() |
||
218 | { |
||
219 | return "CBlobGetBreadth"; |
||
220 | } |
||
221 | }; |
||
222 | |||
223 | //! Classe per calcular la difer?ncia en X del blob
|
||
224 | class CBlobGetDiffX: public COperadorBlob |
||
225 | { |
||
226 | public:
|
||
227 | double operator()(CBlob &blob)
|
||
228 | { |
||
229 | return blob.GetBoundingBox().width;
|
||
230 | } |
||
231 | const char *GetNom() |
||
232 | { |
||
233 | return "CBlobGetDiffX"; |
||
234 | } |
||
235 | }; |
||
236 | |||
237 | //! Classe per calcular la difer?ncia en X del blob
|
||
238 | class CBlobGetDiffY: public COperadorBlob |
||
239 | { |
||
240 | public:
|
||
241 | double operator()(CBlob &blob)
|
||
242 | { |
||
243 | return blob.GetBoundingBox().height;
|
||
244 | } |
||
245 | const char *GetNom() |
||
246 | { |
||
247 | return "CBlobGetDiffY"; |
||
248 | } |
||
249 | }; |
||
250 | |||
251 | //! Classe per calcular el moment PQ del blob
|
||
252 | //! Class to calculate the P,Q moment of a blob
|
||
253 | class CBlobGetMoment: public COperadorBlob |
||
254 | { |
||
255 | public:
|
||
256 | //! Constructor est?ndard
|
||
257 | //! Standard constructor (gets the 00 moment)
|
||
258 | CBlobGetMoment() |
||
259 | { |
||
260 | m_p = m_q = 0;
|
||
261 | } |
||
262 | //! Constructor: indiquem el moment p,q a calcular
|
||
263 | //! Constructor: gets the PQ moment
|
||
264 | CBlobGetMoment( int p, int q ) |
||
265 | { |
||
266 | m_p = p; |
||
267 | m_q = q; |
||
268 | }; |
||
269 | double operator()(CBlob &blob);
|
||
270 | const char *GetNom() |
||
271 | { |
||
272 | return "CBlobGetMoment"; |
||
273 | } |
||
274 | |||
275 | private:
|
||
276 | //! moment que volem calcular
|
||
277 | int m_p, m_q;
|
||
278 | }; |
||
279 | |||
280 | //! Classe per calcular el perimetre del poligon convex d'un blob
|
||
281 | //! Class to calculate the convex hull perimeter of a blob
|
||
282 | class CBlobGetHullPerimeter: public COperadorBlob |
||
283 | { |
||
284 | public:
|
||
285 | double operator()(CBlob &blob);
|
||
286 | const char *GetNom() |
||
287 | { |
||
288 | return "CBlobGetHullPerimeter"; |
||
289 | } |
||
290 | }; |
||
291 | |||
292 | //! Classe per calcular l'?rea del poligon convex d'un blob
|
||
293 | //! Class to calculate the convex hull area of a blob
|
||
294 | class CBlobGetHullArea: public COperadorBlob |
||
295 | { |
||
296 | public:
|
||
297 | double operator()(CBlob &blob);
|
||
298 | const char *GetNom() |
||
299 | { |
||
300 | return "CBlobGetHullArea"; |
||
301 | } |
||
302 | }; |
||
303 | |||
304 | //! Classe per calcular la x minima en la y minima
|
||
305 | //! Class to calculate the minimum x on the minimum y
|
||
306 | class CBlobGetMinXatMinY: public COperadorBlob |
||
307 | { |
||
308 | public:
|
||
309 | double operator()(CBlob &blob);
|
||
310 | const char *GetNom() |
||
311 | { |
||
312 | return "CBlobGetMinXatMinY"; |
||
313 | } |
||
314 | }; |
||
315 | |||
316 | //! Classe per calcular la y minima en la x maxima
|
||
317 | //! Class to calculate the minimum y on the maximum x
|
||
318 | class CBlobGetMinYatMaxX: public COperadorBlob |
||
319 | { |
||
320 | public:
|
||
321 | double operator()(CBlob &blob);
|
||
322 | const char *GetNom() |
||
323 | { |
||
324 | return "CBlobGetMinYatMaxX"; |
||
325 | } |
||
326 | }; |
||
327 | |||
328 | //! Classe per calcular la x maxima en la y maxima
|
||
329 | //! Class to calculate the maximum x on the maximum y
|
||
330 | class CBlobGetMaxXatMaxY: public COperadorBlob |
||
331 | { |
||
332 | public:
|
||
333 | double operator()(CBlob &blob);
|
||
334 | const char *GetNom() |
||
335 | { |
||
336 | return "CBlobGetMaxXatMaxY"; |
||
337 | } |
||
338 | }; |
||
339 | |||
340 | //! Classe per calcular la y maxima en la x minima
|
||
341 | //! Class to calculate the maximum y on the minimum y
|
||
342 | class CBlobGetMaxYatMinX: public COperadorBlob |
||
343 | { |
||
344 | public:
|
||
345 | double operator()(CBlob &blob);
|
||
346 | const char *GetNom() |
||
347 | { |
||
348 | return "CBlobGetMaxYatMinX"; |
||
349 | } |
||
350 | }; |
||
351 | |||
352 | //! Classe per a calcular la x m?nima
|
||
353 | //! Class to get the minimum x
|
||
354 | class CBlobGetMinX: public COperadorBlob |
||
355 | { |
||
356 | public:
|
||
357 | double operator()(CBlob &blob)
|
||
358 | { |
||
359 | return blob.MinX();
|
||
360 | } |
||
361 | const char *GetNom() |
||
362 | { |
||
363 | return "CBlobGetMinX"; |
||
364 | } |
||
365 | }; |
||
366 | |||
367 | //! Classe per a calcular la x m?xima
|
||
368 | //! Class to get the maximum x
|
||
369 | class CBlobGetMaxX: public COperadorBlob |
||
370 | { |
||
371 | public:
|
||
372 | double operator()(CBlob &blob)
|
||
373 | { |
||
374 | return blob.MaxX();
|
||
375 | } |
||
376 | const char *GetNom() |
||
377 | { |
||
378 | return "CBlobGetMaxX"; |
||
379 | } |
||
380 | }; |
||
381 | |||
382 | //! Classe per a calcular la y m?nima
|
||
383 | //! Class to get the minimum y
|
||
384 | class CBlobGetMinY: public COperadorBlob |
||
385 | { |
||
386 | public:
|
||
387 | double operator()(CBlob &blob)
|
||
388 | { |
||
389 | return blob.MinY();
|
||
390 | } |
||
391 | const char *GetNom() |
||
392 | { |
||
393 | return "CBlobGetMinY"; |
||
394 | } |
||
395 | }; |
||
396 | |||
397 | //! Classe per a calcular la y m?xima
|
||
398 | //! Class to get the maximum y
|
||
399 | class CBlobGetMaxY: public COperadorBlob |
||
400 | { |
||
401 | public:
|
||
402 | double operator()(CBlob &blob)
|
||
403 | { |
||
404 | return blob.MaxY();
|
||
405 | } |
||
406 | const char *GetNom() |
||
407 | { |
||
408 | return "CBlobGetMaxY"; |
||
409 | } |
||
410 | }; |
||
411 | |||
412 | |||
413 | //! Classe per calcular l'elongacio d'un blob
|
||
414 | //! Class to calculate the elongation of the blob
|
||
415 | class CBlobGetElongation: public COperadorBlob |
||
416 | { |
||
417 | public:
|
||
418 | double operator()(CBlob &blob);
|
||
419 | const char *GetNom() |
||
420 | { |
||
421 | return "CBlobGetElongation"; |
||
422 | } |
||
423 | }; |
||
424 | |||
425 | //! Classe per calcular la rugositat d'un blob
|
||
426 | //! Class to calculate the roughness of the blob
|
||
427 | class CBlobGetRoughness: public COperadorBlob |
||
428 | { |
||
429 | public:
|
||
430 | double operator()(CBlob &blob);
|
||
431 | const char *GetNom() |
||
432 | { |
||
433 | return "CBlobGetRoughness"; |
||
434 | } |
||
435 | }; |
||
436 | |||
437 | //! Classe per calcular la dist?ncia entre el centre del blob i un punt donat
|
||
438 | //! Class to calculate the euclidean distance between the center of a blob and a given point
|
||
439 | class CBlobGetDistanceFromPoint: public COperadorBlob |
||
440 | { |
||
441 | public:
|
||
442 | //! Standard constructor (distance to point 0,0)
|
||
443 | CBlobGetDistanceFromPoint() |
||
444 | { |
||
445 | m_x = m_y = 0.0; |
||
446 | } |
||
447 | //! Constructor (distance to point x,y)
|
||
448 | CBlobGetDistanceFromPoint( const double x, const double y ) |
||
449 | { |
||
450 | m_x = x; |
||
451 | m_y = y; |
||
452 | } |
||
453 | |||
454 | double operator()(CBlob &blob);
|
||
455 | const char *GetNom() |
||
456 | { |
||
457 | return "CBlobGetDistanceFromPoint"; |
||
458 | } |
||
459 | |||
460 | private:
|
||
461 | // coordenades del punt on volem calcular la dist?ncia
|
||
462 | double m_x, m_y;
|
||
463 | }; |
||
464 | |||
465 | //! Classe per calcular el nombre de pixels externs d'un blob
|
||
466 | //! Class to get the number of extern pixels of a blob
|
||
467 | class CBlobGetExternPerimeter: public COperadorBlob |
||
468 | { |
||
469 | public:
|
||
470 | CBlobGetExternPerimeter() |
||
471 | { |
||
472 | m_mask = NULL;
|
||
473 | m_xBorder = false;
|
||
474 | m_yBorder = false;
|
||
475 | } |
||
476 | CBlobGetExternPerimeter( IplImage *mask, bool xBorder = true, bool yBorder = true ) |
||
477 | { |
||
478 | m_mask = mask; |
||
479 | m_xBorder = xBorder; |
||
480 | m_yBorder = yBorder; |
||
481 | } |
||
482 | double operator()(CBlob &blob)
|
||
483 | { |
||
484 | return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder);
|
||
485 | } |
||
486 | const char *GetNom() |
||
487 | { |
||
488 | return "CBlobGetExternPerimeter"; |
||
489 | } |
||
490 | private:
|
||
491 | IplImage *m_mask; |
||
492 | bool m_xBorder, m_yBorder;
|
||
493 | }; |
||
494 | |||
495 | //! Classe per calcular el ratio entre el perimetre i nombre pixels externs
|
||
496 | //! valors propers a 0 indiquen que la majoria del blob ?s intern
|
||
497 | //! valors propers a 1 indiquen que la majoria del blob ?s extern
|
||
498 | //! Class to calculate the ratio between the perimeter and the number of extern pixels
|
||
499 | class CBlobGetExternPerimeterRatio: public COperadorBlob |
||
500 | { |
||
501 | public:
|
||
502 | CBlobGetExternPerimeterRatio() |
||
503 | { |
||
504 | m_mask = NULL;
|
||
505 | m_xBorder = false;
|
||
506 | m_yBorder = false;
|
||
507 | } |
||
508 | CBlobGetExternPerimeterRatio( IplImage *mask, bool xBorder = true, bool yBorder = true ) |
||
509 | { |
||
510 | m_mask = mask; |
||
511 | m_xBorder = xBorder; |
||
512 | m_yBorder = yBorder; |
||
513 | } |
||
514 | double operator()(CBlob &blob)
|
||
515 | { |
||
516 | if( blob.Perimeter() != 0 ) |
||
517 | return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder) / blob.Perimeter();
|
||
518 | else
|
||
519 | return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder);
|
||
520 | } |
||
521 | const char *GetNom() |
||
522 | { |
||
523 | return "CBlobGetExternPerimeterRatio"; |
||
524 | } |
||
525 | private:
|
||
526 | IplImage *m_mask; |
||
527 | bool m_xBorder, m_yBorder;
|
||
528 | }; |
||
529 | |||
530 | //! Classe per calcular el ratio entre el perimetre convex i nombre pixels externs
|
||
531 | //! valors propers a 0 indiquen que la majoria del blob ?s intern
|
||
532 | //! valors propers a 1 indiquen que la majoria del blob ?s extern
|
||
533 | //! Class to calculate the ratio between the perimeter and the number of extern pixels
|
||
534 | class CBlobGetExternHullPerimeterRatio: public COperadorBlob |
||
535 | { |
||
536 | public:
|
||
537 | CBlobGetExternHullPerimeterRatio() |
||
538 | { |
||
539 | m_mask = NULL;
|
||
540 | m_xBorder = false;
|
||
541 | m_yBorder = false;
|
||
542 | } |
||
543 | CBlobGetExternHullPerimeterRatio( IplImage *mask, bool xBorder = true, bool yBorder = true ) |
||
544 | { |
||
545 | m_mask = mask; |
||
546 | m_xBorder = xBorder; |
||
547 | m_yBorder = yBorder; |
||
548 | } |
||
549 | double operator()(CBlob &blob)
|
||
550 | { |
||
551 | CBlobGetHullPerimeter getHullPerimeter; |
||
552 | double hullPerimeter;
|
||
553 | |||
554 | if( (hullPerimeter = getHullPerimeter( blob ) ) != 0 ) |
||
555 | return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder) / hullPerimeter;
|
||
556 | else
|
||
557 | return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder);
|
||
558 | } |
||
559 | const char *GetNom() |
||
560 | { |
||
561 | return "CBlobGetExternHullPerimeterRatio"; |
||
562 | } |
||
563 | private:
|
||
564 | IplImage *m_mask; |
||
565 | bool m_xBorder, m_yBorder;
|
||
566 | |||
567 | }; |
||
568 | |||
569 | //! Classe per calcular el centre en el eix X d'un blob
|
||
570 | //! Class to calculate the center in the X direction
|
||
571 | class CBlobGetXCenter: public COperadorBlob |
||
572 | { |
||
573 | public:
|
||
574 | double operator()(CBlob &blob)
|
||
575 | { |
||
576 | return blob.MinX() + (( blob.MaxX() - blob.MinX() ) / 2.0); |
||
577 | } |
||
578 | const char *GetNom() |
||
579 | { |
||
580 | return "CBlobGetXCenter"; |
||
581 | } |
||
582 | }; |
||
583 | |||
584 | //! Classe per calcular el centre en el eix Y d'un blob
|
||
585 | //! Class to calculate the center in the Y direction
|
||
586 | class CBlobGetYCenter: public COperadorBlob |
||
587 | { |
||
588 | public:
|
||
589 | double operator()(CBlob &blob)
|
||
590 | { |
||
591 | return blob.MinY() + (( blob.MaxY() - blob.MinY() ) / 2.0); |
||
592 | } |
||
593 | const char *GetNom() |
||
594 | { |
||
595 | return "CBlobGetYCenter"; |
||
596 | } |
||
597 | }; |
||
598 | |||
599 | //! Classe per calcular la longitud de l'eix major d'un blob
|
||
600 | //! Class to calculate the length of the major axis of the ellipse that fits the blob edges
|
||
601 | class CBlobGetMajorAxisLength: public COperadorBlob |
||
602 | { |
||
603 | public:
|
||
604 | double operator()(CBlob &blob)
|
||
605 | { |
||
606 | CvBox2D elipse = blob.GetEllipse(); |
||
607 | |||
608 | return elipse.size.width;
|
||
609 | } |
||
610 | const char *GetNom() |
||
611 | { |
||
612 | return "CBlobGetMajorAxisLength"; |
||
613 | } |
||
614 | }; |
||
615 | |||
616 | //! Classe per calcular el ratio entre l'area de la elipse i la de la taca
|
||
617 | //! Class
|
||
618 | class CBlobGetAreaElipseRatio: public COperadorBlob |
||
619 | { |
||
620 | public:
|
||
621 | double operator()(CBlob &blob)
|
||
622 | { |
||
623 | if( blob.Area()==0.0 ) return 0.0; |
||
624 | |||
625 | CvBox2D elipse = blob.GetEllipse(); |
||
626 | double ratioAreaElipseAreaTaca = ( (elipse.size.width/2.0) |
||
627 | * |
||
628 | (elipse.size.height/2.0) |
||
629 | *CV_PI |
||
630 | ) |
||
631 | / |
||
632 | blob.Area(); |
||
633 | |||
634 | return ratioAreaElipseAreaTaca;
|
||
635 | } |
||
636 | const char *GetNom() |
||
637 | { |
||
638 | return "CBlobGetAreaElipseRatio"; |
||
639 | } |
||
640 | }; |
||
641 | |||
642 | //! Classe per calcular la longitud de l'eix menor d'un blob
|
||
643 | //! Class to calculate the length of the minor axis of the ellipse that fits the blob edges
|
||
644 | class CBlobGetMinorAxisLength: public COperadorBlob |
||
645 | { |
||
646 | public:
|
||
647 | double operator()(CBlob &blob)
|
||
648 | { |
||
649 | CvBox2D elipse = blob.GetEllipse(); |
||
650 | |||
651 | return elipse.size.height;
|
||
652 | } |
||
653 | const char *GetNom() |
||
654 | { |
||
655 | return "CBlobGetMinorAxisLength"; |
||
656 | } |
||
657 | }; |
||
658 | |||
659 | //! Classe per calcular l'orientaci? de l'ellipse del blob en radians
|
||
660 | //! Class to calculate the orientation of the ellipse that fits the blob edges in radians
|
||
661 | class CBlobGetOrientation: public COperadorBlob |
||
662 | { |
||
663 | public:
|
||
664 | double operator()(CBlob &blob)
|
||
665 | { |
||
666 | CvBox2D elipse = blob.GetEllipse(); |
||
667 | /*
|
||
668 | if( elipse.angle > 180.0 )
|
||
669 | return (( elipse.angle - 180.0 )* DEGREE2RAD);
|
||
670 | else
|
||
671 | return ( elipse.angle * DEGREE2RAD);
|
||
672 | */
|
||
673 | return elipse.angle;
|
||
674 | } |
||
675 | const char *GetNom() |
||
676 | { |
||
677 | return "CBlobGetOrientation"; |
||
678 | } |
||
679 | }; |
||
680 | |||
681 | //! Classe per calcular el cosinus de l'orientaci? de l'ellipse del blob
|
||
682 | //! Class to calculate the cosinus of the orientation of the ellipse that fits the blob edges
|
||
683 | class CBlobGetOrientationCos: public COperadorBlob |
||
684 | { |
||
685 | public:
|
||
686 | double operator()(CBlob &blob)
|
||
687 | { |
||
688 | CBlobGetOrientation getOrientation; |
||
689 | return fabs( cos( getOrientation(blob)*DEGREE2RAD ));
|
||
690 | } |
||
691 | const char *GetNom() |
||
692 | { |
||
693 | return "CBlobGetOrientationCos"; |
||
694 | } |
||
695 | }; |
||
696 | |||
697 | |||
698 | //! Classe per calcular el ratio entre l'eix major i menor de la el?lipse
|
||
699 | //! Class to calculate the ratio between both axes of the ellipse
|
||
700 | class CBlobGetAxisRatio: public COperadorBlob |
||
701 | { |
||
702 | public:
|
||
703 | double operator()(CBlob &blob)
|
||
704 | { |
||
705 | double major,minor;
|
||
706 | CBlobGetMajorAxisLength getMajor; |
||
707 | CBlobGetMinorAxisLength getMinor; |
||
708 | |||
709 | major = getMajor(blob); |
||
710 | minor = getMinor(blob); |
||
711 | |||
712 | if( major != 0 ) |
||
713 | return minor / major;
|
||
714 | else
|
||
715 | return 0; |
||
716 | } |
||
717 | const char *GetNom() |
||
718 | { |
||
719 | return "CBlobGetAxisRatio"; |
||
720 | } |
||
721 | }; |
||
722 | |||
723 | |||
724 | //! Classe per calcular si un punt cau dins del blob
|
||
725 | //! Class to calculate whether a point is inside a blob
|
||
726 | class CBlobGetXYInside: public COperadorBlob |
||
727 | { |
||
728 | public:
|
||
729 | //! Constructor est?ndard
|
||
730 | //! Standard constructor
|
||
731 | CBlobGetXYInside() |
||
732 | { |
||
733 | m_p.x = 0;
|
||
734 | m_p.y = 0;
|
||
735 | } |
||
736 | //! Constructor: indiquem el punt
|
||
737 | //! Constructor: sets the point
|
||
738 | CBlobGetXYInside( CvPoint2D32f p ) |
||
739 | { |
||
740 | m_p = p; |
||
741 | }; |
||
742 | double operator()(CBlob &blob);
|
||
743 | const char *GetNom() |
||
744 | { |
||
745 | return "CBlobGetXYInside"; |
||
746 | } |
||
747 | |||
748 | private:
|
||
749 | //! punt que considerem
|
||
750 | //! point to be considered
|
||
751 | CvPoint2D32f m_p; |
||
752 | }; |
||
753 | |||
754 | #endif //!BLOB_OPERATORS_H_INCLUDED |