You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

891 lines
20 KiB

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