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.

648 lines
17 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /************************************************************************
  2. Blob.cpp
  3. - FUNCIONALITAT: Implementaci� de la classe CBlob
  4. - AUTOR: Inspecta S.L.
  5. MODIFICACIONS (Modificaci�, Autor, Data):
  6. FUNCTIONALITY: Implementation of the CBlob class and some helper classes to perform
  7. some calculations on it
  8. AUTHOR: Inspecta S.L.
  9. MODIFICATIONS (Modification, Author, Date):
  10. **************************************************************************/
  11. #include "BlobOperators.h"
  12. #include <iterator>
  13. CBlob::CBlob(){
  14. m_storage = NULL;
  15. };
  16. CBlob::CBlob( t_labelType id, CvPoint startPoint, CvSize originalImageSize ){
  17. m_storage = cvCreateMemStorage();
  18. m_externalContour = CBlobContour(startPoint, m_storage);
  19. m_boundingBox.width = -1;
  20. m_id = id;
  21. m_originalImageSize = originalImageSize;
  22. };
  23. //! Copy constructor
  24. CBlob::CBlob( const CBlob &src ){
  25. m_storage = NULL;
  26. *this = src;
  27. };
  28. CBlob::CBlob( const CBlob *src ){
  29. if (src != NULL ){
  30. m_storage = NULL;
  31. *this = *src;
  32. };
  33. };
  34. CBlob& CBlob::operator=(const CBlob &src ){
  35. if( this != &src ){
  36. m_id = src.m_id;
  37. m_originalImageSize = src.m_originalImageSize;
  38. m_boundingBox = src.m_boundingBox;
  39. // copy all blob properties
  40. m_properties.clear();
  41. std::copy(src.m_properties.begin(), src.m_properties.end(), std::inserter(m_properties, m_properties.begin()));
  42. // clear all current blob contours
  43. ClearContours();
  44. if( m_storage )
  45. cvReleaseMemStorage( &m_storage );
  46. m_storage = cvCreateMemStorage();
  47. m_externalContour = CBlobContour(src.m_externalContour.GetStartPoint(), m_storage );
  48. if( src.m_externalContour.m_contour )
  49. m_externalContour.m_contour = cvCloneSeq( src.m_externalContour.m_contour, m_storage);
  50. m_internalContours.clear();
  51. // copy all internal contours
  52. if( src.m_internalContours.size() ){
  53. m_internalContours = t_contourList( src.m_internalContours.size() );
  54. t_contourList::const_iterator itSrc;
  55. t_contourList::iterator it;
  56. itSrc = src.m_internalContours.begin();
  57. it = m_internalContours.begin();
  58. while (itSrc != src.m_internalContours.end()){
  59. *it = CBlobContour((*itSrc).GetStartPoint(), m_storage);
  60. if( (*itSrc).m_contour )
  61. (*it).m_contour = cvCloneSeq( (*itSrc).m_contour, m_storage);
  62. it++;
  63. itSrc++;
  64. };
  65. };
  66. };
  67. return *this;
  68. };
  69. CBlob::~CBlob(){
  70. ClearContours();
  71. m_properties.clear();
  72. if( m_storage ) cvReleaseMemStorage( &m_storage );
  73. };
  74. void CBlob::ClearContours(){
  75. t_contourList::iterator it;
  76. it = m_internalContours.begin();
  77. while (it != m_internalContours.end()){
  78. (*it).ResetChainCode();
  79. it++;
  80. };
  81. m_internalContours.clear();
  82. m_externalContour.ResetChainCode();
  83. };
  84. void CBlob::AddInternalContour( const CBlobContour &newContour ){
  85. m_internalContours.push_back(newContour);
  86. };
  87. //! Indica si el blob est� buit ( no t� cap info associada )
  88. //! Shows if the blob has associated information
  89. bool CBlob::IsEmpty(){
  90. return GetExternalContour()->m_contour == NULL;
  91. };
  92. /**
  93. - FUNCI�: Area
  94. - FUNCIONALITAT: Get blob area, ie. external contour area minus internal contours area
  95. - PAR�METRES:
  96. -
  97. - RESULTAT:
  98. -
  99. - RESTRICCIONS:
  100. -
  101. - AUTOR: rborras
  102. - DATA DE CREACI�: 2008/04/30
  103. - MODIFICACI�: Data. Autor. Descripci�.
  104. */
  105. float CBlob::Area(){
  106. float area;
  107. t_contourList::iterator itContour;
  108. area = m_externalContour.GetArea();
  109. itContour = m_internalContours.begin();
  110. while (itContour != m_internalContours.end() ){
  111. area -= (*itContour).GetArea();
  112. itContour++;
  113. };
  114. return area;
  115. };
  116. /**
  117. - FUNCI�: Perimeter
  118. - FUNCIONALITAT: Get blob perimeter, ie. sum of the lenght of all the contours
  119. - PAR�METRES:
  120. -
  121. - RESULTAT:
  122. -
  123. - RESTRICCIONS:
  124. -
  125. - AUTOR: rborras
  126. - DATA DE CREACI�: 2008/04/30
  127. - MODIFICACI�: Data. Autor. Descripci�.
  128. */
  129. float CBlob::Perimeter(){
  130. float perimeter;
  131. t_contourList::iterator itContour;
  132. perimeter = m_externalContour.GetPerimeter();
  133. itContour = m_internalContours.begin();
  134. while (itContour != m_internalContours.end() ){
  135. perimeter += (*itContour).GetPerimeter();
  136. itContour++;
  137. };
  138. return perimeter;
  139. };
  140. /**
  141. - FUNCI�: Exterior
  142. - FUNCIONALITAT: Return true for extern blobs
  143. - PAR�METRES:
  144. - xBorder: true to consider blobs touching horizontal borders as extern
  145. - yBorder: true to consider blobs touching vertical borders as extern
  146. - RESULTAT:
  147. -
  148. - RESTRICCIONS:
  149. -
  150. - AUTOR: rborras
  151. - DATA DE CREACI�: 2008/05/06
  152. - MODIFICACI�: Data. Autor. Descripci�.
  153. */
  154. int CBlob::Exterior(IplImage *mask,
  155. bool xBorderLeft /* = true */, bool xBorderRight /* = true */,
  156. bool yBorderTop /* = true */, bool yBorderBottom /* = true */ ){
  157. if (ExternPerimeter(mask, xBorderLeft, xBorderRight, yBorderTop, yBorderBottom ) > 0 ){
  158. return 1;
  159. };
  160. return 0;
  161. };
  162. /**
  163. - FUNCI�: ExternPerimeter
  164. - FUNCIONALITAT: Get extern perimeter (perimeter touching image borders)
  165. - PAR�METRES:
  166. - maskImage: if != NULL, counts maskImage black pixels as external pixels and contour points touching
  167. them are counted as external contour points.
  168. - xBorderLeft: true to consider blobs touching left horizontal borders as extern
  169. - xBorderRight: true to consider blobs touching right horizontal borders as extern
  170. - yBorderTop: true to consider blobs touching vertical top borders as extern
  171. - yBorderBottom: true to consider blobs touching vertical bottom borders as extern
  172. - RESULTAT:
  173. -
  174. - RESTRICCIONS:
  175. -
  176. - AUTOR: rborras
  177. - DATA DE CREACI�: 2008/05/05
  178. - MODIFICACI�: Data. Autor. Descripci�.
  179. - NOTA: If CBlobContour::GetContourPoints aproximates contours with a method different that NONE,
  180. this function will not give correct results
  181. */
  182. float CBlob::ExternPerimeter( IplImage *maskImage,
  183. bool xBorderLeft /* = true */, bool xBorderRight /* = true */,
  184. bool yBorderTop /* = true */, bool yBorderBottom /* = true */ ){
  185. t_PointList externContour, externalPoints;
  186. CvSeqReader reader;
  187. CvSeqWriter writer;
  188. CvPoint actualPoint, previousPoint;
  189. bool find = false;
  190. int i,j;
  191. int delta = 0;
  192. float externPerimeter;
  193. // get contour pixels
  194. externContour = m_externalContour.GetContourPoints();
  195. externPerimeter = 0;
  196. // there are contour pixels?
  197. if( externContour == NULL ){
  198. return 0;
  199. };
  200. cvStartReadSeq( externContour, &reader);
  201. // create a sequence with the external points of the blob
  202. externalPoints = cvCreateSeq( externContour->flags, externContour->header_size, externContour->elem_size,
  203. m_storage );
  204. cvStartAppendToSeq( externalPoints, &writer );
  205. previousPoint.x = -1;
  206. // which contour pixels touch border?
  207. for( j=0; j< externContour->total; j++){
  208. CV_READ_SEQ_ELEM( actualPoint, reader);
  209. find = false;
  210. // pixel is touching border?
  211. if ( (xBorderLeft && (actualPoint.x == 0)) ||
  212. (xBorderRight && (actualPoint.x == m_originalImageSize.width - 1 )) ||
  213. (yBorderTop && (actualPoint.y == 0)) ||
  214. (yBorderBottom && (actualPoint.y == m_originalImageSize.height - 1 ))
  215. ){
  216. find = true;
  217. } else {
  218. if( maskImage != NULL ){
  219. // verify if some of 8-connected neighbours is black in mask
  220. char *pMask;
  221. pMask = (maskImage->imageData + actualPoint.x - 1 + (actualPoint.y - 1) * maskImage->widthStep);
  222. for ( i = 0; i < 3; i++, pMask++ ){
  223. if(*pMask == 0 && !find ){
  224. find = true;
  225. break;
  226. };
  227. };
  228. if(!find){
  229. pMask = (maskImage->imageData + actualPoint.x - 1 + (actualPoint.y ) * maskImage->widthStep);
  230. for ( i = 0; i < 3; i++, pMask++ ){
  231. if(*pMask == 0 && !find ){
  232. find = true;
  233. break;
  234. };
  235. };
  236. };
  237. if( !find ){
  238. pMask = (maskImage->imageData + actualPoint.x - 1 + (actualPoint.y + 1) * maskImage->widthStep);
  239. for ( i = 0; i < 3; i++, pMask++ ){
  240. if(*pMask == 0 && !find ){
  241. find = true;
  242. break;
  243. };
  244. };
  245. };
  246. };
  247. };
  248. if( find ){
  249. if( previousPoint.x > 0 )
  250. delta = abs(previousPoint.x - actualPoint.x) + abs(previousPoint.y - actualPoint.y);
  251. // calculate separately each external contour segment
  252. if( delta > 2 ){
  253. cvEndWriteSeq( &writer );
  254. externPerimeter += cvArcLength( externalPoints, CV_WHOLE_SEQ, 0 );
  255. cvClearSeq( externalPoints );
  256. cvStartAppendToSeq( externalPoints, &writer );
  257. delta = 0;
  258. previousPoint.x = -1;
  259. };
  260. CV_WRITE_SEQ_ELEM( actualPoint, writer );
  261. previousPoint = actualPoint;
  262. };
  263. };
  264. cvEndWriteSeq( &writer );
  265. cvSeqSort(externalPoints, cmp_func, 0);
  266. externPerimeter += cvArcLength( externalPoints, CV_WHOLE_SEQ, 0 );
  267. cvClearSeq( externalPoints );
  268. // divide by two because external points have one side inside the blob and the other outside
  269. // Perimeter of external points counts both sides, so it must be divided
  270. externPerimeter /= 2.0;
  271. return externPerimeter;
  272. };
  273. //! Compute blob's moment (p,q up to MAX_CALCULATED_MOMENTS)
  274. float CBlob::Moment( int p, int q ){
  275. float moment;
  276. t_contourList::iterator itContour;
  277. moment = m_externalContour.GetMoment(p,q);
  278. itContour = m_internalContours.begin();
  279. while (itContour != m_internalContours.end() ){
  280. moment -= (*itContour).GetMoment(p,q);
  281. itContour++;
  282. };
  283. return moment;
  284. };
  285. /**
  286. - FUNCI�: Mean
  287. - FUNCIONALITAT: Get blob mean color in input image
  288. - PAR�METRES:
  289. - image: image from gray color are extracted
  290. - RESULTAT:
  291. -
  292. - RESTRICCIONS:
  293. -
  294. - AUTOR: rborras
  295. - DATA DE CREACI�: 2008/05/06
  296. - MODIFICACI�: Data. Autor. Descripci�.
  297. */
  298. float CBlob::Mean( IplImage *image ){
  299. float mean, stddev;
  300. // call mean calculation (where also standard deviation is calculated)
  301. GetMeanAndStdDev( image, mean, stddev );
  302. return mean;
  303. };
  304. float CBlob::StdDev( IplImage *image ){
  305. float mean, stddev;
  306. // call mean calculation (where also standard deviation is calculated)
  307. GetMeanAndStdDev( image, mean, stddev );
  308. return stddev;
  309. };
  310. //! Calculates mean and std deviation of blob in input image
  311. void CBlob::GetMeanAndStdDev( IplImage *image, float &mean, float &stddev ){
  312. IplImage *mask;
  313. CvScalar meanscalar, stdscalar;
  314. CvPoint offset;
  315. // Create a mask with same size as blob bounding box
  316. GetBoundingBox();
  317. if (m_boundingBox.height <= 0 ||m_boundingBox.width <= 0 || !CV_IS_IMAGE( image ) ||
  318. m_boundingBox.height > image->height || m_boundingBox.width > image->width ){
  319. mean = 0;
  320. stddev = 0;
  321. return;
  322. };
  323. // apply ROI and mask to input image to compute mean gray and standard deviation
  324. mask = cvCreateImage( cvSize(m_boundingBox.width, m_boundingBox.height), IPL_DEPTH_8U, 1);
  325. cvSetZero(mask);
  326. offset.x = -m_boundingBox.x;
  327. offset.y = -m_boundingBox.y;
  328. // draw contours on mask
  329. cvDrawContours( mask, m_externalContour.GetContourPoints(), CV_RGB(255,255,255), CV_RGB(255,255,255),0, CV_FILLED, 8,
  330. offset );
  331. // draw internal contours
  332. t_contourList::iterator it = m_internalContours.begin();
  333. while(it != m_internalContours.end() ){
  334. cvDrawContours( mask, (*it).GetContourPoints(), CV_RGB(0,0,0), CV_RGB(0,0,0),0, CV_FILLED, 8, offset );
  335. it++;
  336. };
  337. cvSetImageROI( image, m_boundingBox );
  338. cvAvgSdv( image, &meanscalar, &stdscalar, mask );
  339. mean = meanscalar.val[0];
  340. stddev = stdscalar.val[0];
  341. cvReleaseImage( &mask );
  342. cvResetImageROI( image );
  343. };
  344. /**
  345. - FUNCI�: GetBoundingBox
  346. - FUNCIONALITAT: Get bounding box (without rotation) of a blob
  347. - PAR�METRES:
  348. -
  349. - RESULTAT:
  350. -
  351. - RESTRICCIONS:
  352. -
  353. - AUTOR: rborras
  354. - DATA DE CREACI�: 2008/05/06
  355. - MODIFICACI�: Data. Autor. Descripci�.
  356. */
  357. CvRect CBlob::GetBoundingBox(){
  358. // it is calculated?
  359. /* if( m_boundingBox.width != -1 )
  360. {
  361. return m_boundingBox;
  362. }
  363. */
  364. t_PointList externContour;
  365. CvSeqReader reader;
  366. CvPoint actualPoint;
  367. // get contour pixels
  368. externContour = m_externalContour.GetContourPoints();
  369. // it is an empty blob?
  370. if( !externContour ){
  371. m_boundingBox.x = 0;
  372. m_boundingBox.y = 0;
  373. m_boundingBox.width = 0;
  374. m_boundingBox.height = 0;
  375. return m_boundingBox;
  376. };
  377. cvStartReadSeq( externContour, &reader);
  378. m_boundingBox.x = m_originalImageSize.width;
  379. m_boundingBox.y = m_originalImageSize.height;
  380. m_boundingBox.width = 0;
  381. m_boundingBox.height = 0;
  382. for( int i=0; i< externContour->total; i++){
  383. CV_READ_SEQ_ELEM( actualPoint, reader);
  384. m_boundingBox.x = MIN( actualPoint.x, m_boundingBox.x );
  385. m_boundingBox.y = MIN( actualPoint.y, m_boundingBox.y );
  386. m_boundingBox.width = MAX( actualPoint.x, m_boundingBox.width );
  387. m_boundingBox.height = MAX( actualPoint.y, m_boundingBox.height );
  388. };
  389. //m_boundingBox.x = max( m_boundingBox.x , 0 );
  390. //m_boundingBox.y = max( m_boundingBox.y , 0 );
  391. m_boundingBox.width -= m_boundingBox.x + 1;
  392. m_boundingBox.height -= m_boundingBox.y + 1;
  393. return m_boundingBox;
  394. };
  395. /**
  396. - FUNCI�: GetEllipse
  397. - FUNCIONALITAT: Calculates bounding ellipse of external contour points
  398. - PAR�METRES:
  399. -
  400. - RESULTAT:
  401. -
  402. - RESTRICCIONS:
  403. -
  404. - AUTOR: rborras
  405. - DATA DE CREACI�: 2008/05/06
  406. - MODIFICACI�: Data. Autor. Descripci�.
  407. - NOTA: Calculation is made using second order moment aproximation
  408. */
  409. CvBox2D CBlob::GetEllipse(){
  410. CvBox2D elipse;
  411. float u00,u11,u01,u10,u20,u02, delta, temp;
  412. // it is calculated?
  413. if( m_properties.find( CBlobGetMajorAxisLength().GetNom() ) != m_properties.end() ){
  414. // build a ellipse from calculated properties
  415. elipse.size.width = m_properties[CBlobGetMajorAxisLength().GetNom()];
  416. elipse.size.height = m_properties[CBlobGetMinorAxisLength().GetNom()];
  417. elipse.angle = m_properties[CBlobGetOrientation().GetNom()];
  418. elipse.center.x = m_properties[CBlobGetElipseXCenter().GetNom()];
  419. elipse.center.y = m_properties[CBlobGetElipseYCenter().GetNom()];
  420. };
  421. // initialize properties
  422. m_properties[CBlobGetMajorAxisLength().GetNom()] = 0;
  423. m_properties[CBlobGetMinorAxisLength().GetNom()] = 0;
  424. m_properties[CBlobGetOrientation().GetNom()] = 0;
  425. m_properties[CBlobGetElipseXCenter().GetNom()] = 0;
  426. m_properties[CBlobGetElipseYCenter().GetNom()] = 0;
  427. elipse.angle = 0;
  428. elipse.size.height = 0;
  429. elipse.size.width = 0;
  430. elipse.center.x = 0;
  431. elipse.center.y = 0;
  432. // central moments calculation
  433. u00 = Moment(0,0);
  434. // empty blob?
  435. if( u00 <= 0 ){
  436. return elipse;
  437. };
  438. u10 = Moment(1,0) / u00;
  439. u01 = Moment(0,1) / u00;
  440. u11 = -(Moment(1,1) - Moment(1,0) * Moment(0,1) / u00 ) / u00;
  441. u20 = (Moment(2,0) - Moment(1,0) * Moment(1,0) / u00 ) / u00;
  442. u02 = (Moment(0,2) - Moment(0,1) * Moment(0,1) / u00 ) / u00;
  443. // elipse calculation
  444. delta = sqrt( 4*u11*u11 + (u20-u02)*(u20-u02) );
  445. elipse.center.x = u10;
  446. elipse.center.y = u01;
  447. m_properties[CBlobGetElipseXCenter().GetNom()] = elipse.center.x;
  448. m_properties[CBlobGetElipseYCenter().GetNom()] = elipse.center.y;
  449. temp = u20 + u02 + delta;
  450. if( temp > 0 ){
  451. elipse.size.width = sqrt( 2*(u20 + u02 + delta ));
  452. m_properties[CBlobGetMajorAxisLength().GetNom()] = elipse.size.width;
  453. } else {
  454. return elipse;
  455. };
  456. temp = u20 + u02 - delta;
  457. if( temp > 0 ){
  458. elipse.size.height = sqrt( 2*(u20 + u02 - delta ) );
  459. m_properties[CBlobGetMinorAxisLength().GetNom()] = elipse.size.height;
  460. } else {
  461. return elipse;
  462. };
  463. // elipse orientation
  464. elipse.angle = atan2( 2*u11, u20 - u02 + sqrt( (u20 - u02)*(u20 - u02) + (2*u11)*(2*u11)));
  465. if( elipse.angle == 0 && u02 > u20 ) {
  466. elipse.angle = CV_PI/2.0;
  467. };
  468. // convert to degrees
  469. elipse.angle = (180.0 / CV_PI) *elipse.angle;
  470. elipse.angle+=180;
  471. m_properties[CBlobGetOrientation().GetNom()] = elipse.angle;
  472. return elipse;
  473. };
  474. /**
  475. - FUNCTION: FillBlob
  476. - FUNCTIONALITY:
  477. - Fills the blob with a specified colour
  478. - PARAMETERS:
  479. - imatge: where to paint
  480. - color: colour to paint the blob
  481. - RESULT:
  482. - modifies input image and returns the seed point used to fill the blob
  483. - RESTRICTIONS:
  484. - AUTHOR: Ricard Borr�s
  485. - CREATION DATE: 25-05-2005.
  486. - MODIFICATION: Date. Author. Description.
  487. */
  488. void CBlob::FillBlob( IplImage *imatge, CvScalar color ){
  489. cvDrawContours( imatge, m_externalContour.GetContourPoints(), color, color,0, CV_FILLED, 8 );
  490. };
  491. /**
  492. - FUNCTION: GetConvexHull
  493. - FUNCTIONALITY: Calculates the convex hull polygon of the blob
  494. - PARAMETERS:
  495. - dst: where to store the result
  496. - RESULT:
  497. - true if no error ocurred
  498. - RESTRICTIONS:
  499. - AUTHOR: Ricard Borr�s
  500. - CREATION DATE: 25-05-2005.
  501. - MODIFICATION: Date. Author. Description.
  502. */
  503. t_PointList CBlob::GetConvexHull(){
  504. CvSeq *convexHull = NULL;
  505. if( m_externalContour.GetContourPoints() )
  506. convexHull = cvConvexHull2( m_externalContour.GetContourPoints(), m_storage,
  507. CV_COUNTER_CLOCKWISE, 1 );
  508. return convexHull;
  509. };
  510. /**
  511. - FUNCTION: JoinBlob
  512. - FUNCTIONALITY: Add's external contour to current external contour
  513. - PARAMETERS:
  514. - blob: blob from which extract the added external contour
  515. - RESULT:
  516. - true if no error ocurred
  517. - RESTRICTIONS: Only external contours are added
  518. - AUTHOR: Ricard Borr�s
  519. - CREATION DATE: 25-05-2005.
  520. - MODIFICATION: Date. Author. Description.
  521. */
  522. void CBlob::JoinBlob( CBlob *blob ){
  523. CvSeqWriter writer;
  524. CvSeqReader reader;
  525. t_chainCode chainCode;
  526. cvStartAppendToSeq( m_externalContour.GetChainCode(), &writer );
  527. cvStartReadSeq( blob->GetExternalContour()->GetChainCode(), &reader );
  528. for (int i = 0; i < blob->GetExternalContour()->GetChainCode()->total; i++ ){
  529. CV_READ_SEQ_ELEM( chainCode, reader );
  530. CV_WRITE_SEQ_ELEM( chainCode, writer );
  531. };
  532. cvEndWriteSeq( &writer );
  533. // reset stats for the blob
  534. m_properties.clear();
  535. };