/** - FUNCTION: CBlobGetElongation - FUNCTIONALITY: Calculates the elongation of the blob ( length/breadth ) - PARAMETERS: - RESULT: - RESTRICTIONS: - See below to see how the length and the breadth are aproximated - AUTHOR: Ricard Borr� - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ double CBlobGetElongation::operator()(const CBlob &blob) const { double ampladaC,longitudC,amplada,longitud; ampladaC=(double) (blob.Perimeter()+sqrt(pow(blob.Perimeter(),2)-16*blob.Area()))/4; if(ampladaC<=0.0) return 0; longitudC=(double) blob.Area()/ampladaC; longitud=MAX( longitudC , ampladaC ); amplada=MIN( longitudC , ampladaC ); return (double) longitud/amplada; }
/** - FUNCTION: CBlobGetCompactness - FUNCTIONALITY: Calculates the compactness of the blob ( maximum for circle shaped blobs, minimum for the rest) - PARAMETERS: - RESULT: - RESTRICTIONS: - AUTHOR: Ricard Borràs - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ double CBlobGetCompactness::operator()(CBlob &blob) { if( blob.Area() != 0.0 ) return (double) pow(blob.Perimeter(),2)/(4*CV_PI*blob.Area()); else return 0.0; }
/** - FUNCTION: CBlobGetBreadth - FUNCTIONALITY: Calculates the breadth of the blob (the smallest axis of the blob) - PARAMETERS: - RESULT: - RESTRICTIONS: - The breadth is an aproximation to the real breadth - AUTHOR: Ricard Borràs - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ double CBlobGetBreadth::operator()(CBlob &blob) { double ampladaC,longitudC; double tmp; tmp = blob.Perimeter()*blob.Perimeter() - 16*blob.Area(); if( tmp > 0.0 ) ampladaC = (double) (blob.Perimeter()+sqrt(tmp))/4; // error intrínsec en els càlculs de l'àrea i el perímetre else ampladaC = (double) (blob.Perimeter())/4; if(ampladaC<=0.0) return 0; longitudC = (double) blob.Area()/ampladaC; return MIN( longitudC , ampladaC ); }
/** - FUNCTION: CBlobGetLength - FUNCTIONALITY: Calculates the length of the blob (the biggest axis of the blob) - PARAMETERS: - RESULT: - RESTRICTIONS: - The length is an aproximation to the real length - AUTHOR: Ricard Borr� - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ double CBlobGetLength::operator()(const CBlob &blob) const { double ampladaC,longitudC; double tmp; tmp = blob.Perimeter()*blob.Perimeter() - 16*blob.Area(); if( tmp > 0.0 ) ampladaC = (double) (blob.Perimeter()+sqrt(tmp))/4; // error intr�sec en els c�culs de l'�ea i el per�etre else ampladaC = (double) (blob.Perimeter())/4; if(ampladaC<=0.0) return 0; longitudC=(double) blob.Area()/ampladaC; return MAX( longitudC , ampladaC ); }
double CBlobGetHullArea::operator()(const CBlob &blob) const { if(blob.Edges() != NULL && blob.Edges()->total > 0) { CvSeq *hull = cvConvexHull2( blob.Edges(), 0, CV_CLOCKWISE, 1 ); return fabs(cvContourArea(hull)); } return blob.Perimeter(); }
/** - FUNCTION: CBlobGetHullPerimeter - FUNCTIONALITY: Calculates the convex hull perimeter of the blob - PARAMETERS: - RESULT: - returns the convex hull perimeter of the blob or the perimeter if the blob edges could not be retrieved - RESTRICTIONS: - AUTHOR: Ricard Borr� - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ double CBlobGetHullPerimeter::operator()(const CBlob &blob) const { if(blob.Edges() != NULL && blob.Edges()->total > 0) { CvSeq *hull = cvConvexHull2( blob.Edges(), 0, CV_CLOCKWISE, 1 ); return fabs(cvArcLength(hull,CV_WHOLE_SEQ,1)); } return blob.Perimeter(); }
/** - FUNCTION: CBlobGetRoughness - FUNCTIONALITY: Calculates the roughness of the blob ( ratio between perimeter and convex hull perimeter) - PARAMETERS: - RESULT: - RESTRICTIONS: - AUTHOR: Ricard Borràs - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ double CBlobGetRoughness::operator()(CBlob &blob) { CBlobGetHullPerimeter getHullPerimeter = CBlobGetHullPerimeter(); double hullPerimeter = getHullPerimeter(blob); if( hullPerimeter != 0.0 ) return blob.Perimeter() / hullPerimeter;//HullPerimeter(); return 0.0; }
/** - FUNCTION: CBlob - FUNCTIONALITY: Copy constructor - PARAMETERS: - RESULT: - RESTRICTIONS: - AUTHOR: Ricard Borr� - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ CBlob::CBlob( const CBlob &src ) { // copiem les propietats del blob origen a l'actual etiqueta = src.etiqueta; exterior = src.exterior; area = src.Area(); perimeter = src.Perimeter(); parent = src.parent; minx = src.minx; maxx = src.maxx; miny = src.miny; maxy = src.maxy; sumx = src.sumx; sumy = src.sumy; sumxx = src.sumxx; sumyy = src.sumyy; sumxy = src.sumxy; mean = src.mean; stddev = src.stddev; externPerimeter = src.externPerimeter; // copiem els edges del blob origen a l'actual CvSeqReader reader; CvSeqWriter writer; CvPoint edgeactual; // creem una sequencia buida per als edges m_storage = cvCreateMemStorage(0); edges = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvContour), sizeof(CvPoint),m_storage); cvStartReadSeq( src.Edges(), &reader); cvStartAppendToSeq( edges, &writer ); for( int i=0; i< src.Edges()->total; i++) { CV_READ_SEQ_ELEM( edgeactual ,reader); CV_WRITE_SEQ_ELEM( edgeactual , writer ); } cvEndWriteSeq( &writer ); }