BlobOperators.h
Go to the documentation of this file.
00001 #ifndef BLOB_OPERATORS_H_INCLUDED
00002 #define BLOB_OPERATORS_H_INCLUDED
00003 
00004 #include "Blob.h"
00005 
00006 /**************************************************************************
00007                 Definició de les classes per a fer operacions sobre els blobs
00008 
00009                 Helper classes to perform operations on blobs
00010 **************************************************************************/
00011 
00013 #define DEGREE2RAD              (CV_PI / 180.0)
00014 
00015 
00018 class COperadorBlob
00019 {
00020 public:
00021         virtual ~COperadorBlob(){};
00022 
00024         virtual double operator()(CBlob &blob) = 0;
00026         virtual const char *GetNom() = 0;
00027 
00028         operator COperadorBlob*()
00029         {
00030                 return (COperadorBlob*)this;
00031         }
00032 };
00033 
00034 typedef COperadorBlob funcio_calculBlob;
00035 
00036 #ifdef BLOB_OBJECT_FACTORY
00037 
00040         struct functorComparacioIdOperador
00041         {
00042           bool operator()(const char* s1, const char* s2) const
00043           {
00044                 return strcmp(s1, s2) < 0;
00045           }
00046         };
00047 
00049         typedef ObjectFactory<COperadorBlob, const char *, functorComparacioIdOperador > t_OperadorBlobFactory;
00050 
00052         void RegistraTotsOperadors( t_OperadorBlobFactory &fabricaOperadorsBlob );
00053 
00054 #endif
00055 
00056 
00059 class CBlobGetID : public COperadorBlob
00060 {
00061 public:
00062     double operator()(CBlob &blob)
00063         { 
00064                 return blob.GetID(); 
00065         }
00066         const char *GetNom()
00067         {
00068                 return "CBlobGetID";
00069         }
00070 };
00071 
00072 
00075 class CBlobGetArea : public COperadorBlob
00076 {
00077 public:
00078     double operator()(CBlob &blob)
00079         { 
00080                 return blob.Area(); 
00081         }
00082         const char *GetNom()
00083         {
00084                 return "CBlobGetArea";
00085         }
00086 };
00087 
00090 class CBlobGetPerimeter: public COperadorBlob
00091 {
00092 public:
00093     double operator()(CBlob &blob)
00094         { 
00095                 return blob.Perimeter(); 
00096         }
00097         const char *GetNom()
00098         {
00099                 return "CBlobGetPerimeter";
00100         }
00101 };
00102 
00105 class CBlobGetExterior: public COperadorBlob
00106 {
00107 public:
00108         CBlobGetExterior()
00109         {
00110                 m_mask = NULL;
00111                 m_xBorder = false;
00112                 m_yBorder = false;
00113         }
00114         CBlobGetExterior(IplImage *mask, bool xBorder = true, bool yBorder = true)
00115         {
00116                 m_mask = mask;
00117                 m_xBorder = xBorder;
00118                 m_yBorder = yBorder;
00119         }
00120     double operator()(CBlob &blob)
00121         { 
00122                 return blob.Exterior(m_mask, m_xBorder, m_yBorder); 
00123         }
00124         const char *GetNom()
00125         {
00126                 return "CBlobGetExterior";
00127         }
00128 private:
00129         IplImage *m_mask;
00130         bool m_xBorder, m_yBorder;
00131 };
00132 
00135 class CBlobGetMean: public COperadorBlob
00136 {
00137 public:
00138         CBlobGetMean()
00139         {
00140                 m_image = NULL;
00141         }
00142         CBlobGetMean( IplImage *image )
00143         {
00144                 m_image = image;
00145         };
00146 
00147     double operator()(CBlob &blob)
00148         { 
00149                 return blob.Mean(m_image); 
00150         }
00151         const char *GetNom()
00152         {
00153                 return "CBlobGetMean";
00154         }
00155 private:
00156 
00157         IplImage *m_image;
00158 };
00159 
00162 class CBlobGetStdDev: public COperadorBlob
00163 {
00164 public:
00165         CBlobGetStdDev()
00166         {
00167                 m_image = NULL;
00168         }
00169         CBlobGetStdDev( IplImage *image )
00170         {
00171                 m_image = image;
00172         };
00173     double operator()(CBlob &blob)
00174         { 
00175                 return blob.StdDev(m_image); 
00176         }
00177         const char *GetNom()
00178         {
00179                 return "CBlobGetStdDev";
00180         }
00181 private:
00182 
00183         IplImage *m_image;
00184 
00185 };
00186 
00189 class CBlobGetCompactness: public COperadorBlob
00190 {
00191 public:
00192     double operator()(CBlob &blob);
00193         const char *GetNom()
00194         {
00195                 return "CBlobGetCompactness";
00196         }
00197 };
00198 
00201 class CBlobGetLength: public COperadorBlob
00202 {
00203 public:
00204     double operator()(CBlob &blob);
00205         const char *GetNom()
00206         {
00207                 return "CBlobGetLength";
00208         }
00209 };
00210 
00213 class CBlobGetBreadth: public COperadorBlob
00214 {
00215 public:
00216     double operator()(CBlob &blob);
00217         const char *GetNom()
00218         {
00219                 return "CBlobGetBreadth";
00220         }
00221 };
00222 
00224 class CBlobGetDiffX: public COperadorBlob
00225 {
00226 public:
00227     double operator()(CBlob &blob)
00228         {
00229                 return blob.GetBoundingBox().width;
00230         }
00231         const char *GetNom()
00232         {
00233                 return "CBlobGetDiffX";
00234         }
00235 };
00236 
00238 class CBlobGetDiffY: public COperadorBlob
00239 {
00240 public:
00241     double operator()(CBlob &blob)
00242         {
00243                 return blob.GetBoundingBox().height;
00244         }
00245         const char *GetNom()
00246         {
00247                 return "CBlobGetDiffY";
00248         }
00249 };
00250 
00253 class CBlobGetMoment: public COperadorBlob
00254 {
00255 public:
00258         CBlobGetMoment()
00259         {
00260                 m_p = m_q = 0;
00261         }
00264         CBlobGetMoment( int p, int q )
00265         {
00266                 m_p = p;
00267                 m_q = q;
00268         };
00269         double operator()(CBlob &blob);
00270         const char *GetNom()
00271         {
00272                 return "CBlobGetMoment";
00273         }
00274 
00275 private:
00277         int m_p, m_q;
00278 };
00279 
00282 class CBlobGetHullPerimeter: public COperadorBlob
00283 {
00284 public:
00285     double operator()(CBlob &blob);
00286         const char *GetNom()
00287         {
00288                 return "CBlobGetHullPerimeter";
00289         }
00290 };
00291 
00294 class CBlobGetHullArea: public COperadorBlob
00295 {
00296 public:
00297     double operator()(CBlob &blob);
00298         const char *GetNom()
00299         {
00300                 return "CBlobGetHullArea";
00301         }
00302 };
00303 
00306 class CBlobGetMinXatMinY: public COperadorBlob
00307 {
00308 public:
00309     double operator()(CBlob &blob);
00310         const char *GetNom()
00311         {
00312                 return "CBlobGetMinXatMinY";
00313         }
00314 };
00315 
00318 class CBlobGetMinYatMaxX: public COperadorBlob
00319 {
00320 public:
00321     double operator()(CBlob &blob);
00322         const char *GetNom()
00323         {
00324                 return "CBlobGetMinYatMaxX";
00325         }
00326 };
00327 
00330 class CBlobGetMaxXatMaxY: public COperadorBlob
00331 {
00332 public:
00333     double operator()(CBlob &blob);
00334         const char *GetNom()
00335         {
00336                 return "CBlobGetMaxXatMaxY";
00337         }
00338 };
00339 
00342 class CBlobGetMaxYatMinX: public COperadorBlob
00343 {
00344 public:
00345     double operator()(CBlob &blob);
00346         const char *GetNom()
00347         {
00348                 return "CBlobGetMaxYatMinX";
00349         }
00350 };
00351 
00354 class CBlobGetMinX: public COperadorBlob
00355 {
00356 public:
00357     double operator()(CBlob &blob)
00358         {
00359                 return blob.MinX();
00360         }
00361         const char *GetNom()
00362         {
00363                 return "CBlobGetMinX";
00364         }
00365 };
00366 
00369 class CBlobGetMaxX: public COperadorBlob
00370 {
00371 public:
00372     double operator()(CBlob &blob)
00373         {
00374                 return blob.MaxX();
00375         }
00376         const char *GetNom()
00377         {
00378                 return "CBlobGetMaxX";
00379         }
00380 };
00381 
00384 class CBlobGetMinY: public COperadorBlob
00385 {
00386 public:
00387     double operator()(CBlob &blob)
00388         {
00389                 return blob.MinY();
00390         }
00391         const char *GetNom()
00392         {
00393                 return "CBlobGetMinY";
00394         }
00395 };
00396 
00399 class CBlobGetMaxY: public COperadorBlob
00400 {
00401 public:
00402     double operator()(CBlob &blob)
00403         {
00404                 return blob.MaxY();
00405         }
00406         const char *GetNom()
00407         {
00408                 return "CBlobGetMaxY";
00409         }
00410 };
00411 
00412 
00415 class CBlobGetElongation: public COperadorBlob
00416 {
00417 public:
00418     double operator()(CBlob &blob);
00419         const char *GetNom()
00420         {
00421                 return "CBlobGetElongation";
00422         }
00423 };
00424 
00427 class CBlobGetRoughness: public COperadorBlob
00428 {
00429 public:
00430     double operator()(CBlob &blob);
00431         const char *GetNom()
00432         {
00433                 return "CBlobGetRoughness";
00434         }
00435 };
00436 
00439 class CBlobGetDistanceFromPoint: public COperadorBlob
00440 {
00441 public:
00443         CBlobGetDistanceFromPoint()
00444         {
00445                 m_x = m_y = 0.0;
00446         }
00448         CBlobGetDistanceFromPoint( const double x, const double y )
00449         {
00450                 m_x = x;
00451                 m_y = y;
00452         }
00453 
00454     double operator()(CBlob &blob);
00455         const char *GetNom()
00456         {
00457                 return "CBlobGetDistanceFromPoint";
00458         }
00459 
00460 private:
00461         // coordenades del punt on volem calcular la distŕncia
00462         double m_x, m_y;
00463 };
00464 
00467 class CBlobGetExternPerimeter: public COperadorBlob
00468 {
00469 public:
00470         CBlobGetExternPerimeter()
00471         {
00472                 m_mask = NULL;
00473                 m_xBorder = false;
00474                 m_yBorder = false;
00475         }
00476         CBlobGetExternPerimeter( IplImage *mask, bool xBorder = true, bool yBorder = true )
00477         {
00478                 m_mask = mask;
00479                 m_xBorder = xBorder;
00480                 m_yBorder = yBorder;
00481         }
00482     double operator()(CBlob &blob)
00483         {
00484                 return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder);
00485         }
00486         const char *GetNom()
00487         {
00488                 return "CBlobGetExternPerimeter";
00489         }
00490 private:
00491         IplImage *m_mask;
00492         bool m_xBorder, m_yBorder;
00493 };
00494 
00499 class CBlobGetExternPerimeterRatio: public COperadorBlob
00500 {
00501 public:
00502         CBlobGetExternPerimeterRatio()
00503         {
00504                 m_mask = NULL;
00505                 m_xBorder = false;
00506                 m_yBorder = false;
00507         }
00508         CBlobGetExternPerimeterRatio( IplImage *mask, bool xBorder = true, bool yBorder = true )
00509         {
00510                 m_mask = mask;
00511                 m_xBorder = xBorder;
00512                 m_yBorder = yBorder;
00513         }
00514     double operator()(CBlob &blob)
00515         {
00516                 if( blob.Perimeter() != 0 )
00517                         return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder) / blob.Perimeter();
00518                 else
00519                         return blob.ExternPerimeter(m_mask,  m_xBorder, m_yBorder);
00520         }
00521         const char *GetNom()
00522         {
00523                 return "CBlobGetExternPerimeterRatio";
00524         }
00525 private:
00526         IplImage *m_mask;
00527         bool  m_xBorder, m_yBorder;
00528 };
00529 
00534 class CBlobGetExternHullPerimeterRatio: public COperadorBlob
00535 {
00536 public:
00537         CBlobGetExternHullPerimeterRatio()
00538         {
00539                 m_mask = NULL;
00540                 m_xBorder = false;
00541                 m_yBorder = false;
00542         }
00543         CBlobGetExternHullPerimeterRatio( IplImage *mask, bool xBorder = true, bool yBorder = true )
00544         {
00545                 m_mask = mask;
00546                 m_xBorder = xBorder;
00547                 m_yBorder = yBorder;
00548         }
00549     double operator()(CBlob &blob)
00550         {
00551                 CBlobGetHullPerimeter getHullPerimeter;
00552                 double hullPerimeter;
00553 
00554                 if( (hullPerimeter = getHullPerimeter( blob ) ) != 0 )
00555                         return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder) / hullPerimeter;
00556                 else
00557                         return blob.ExternPerimeter(m_mask, m_xBorder, m_yBorder);
00558         }
00559         const char *GetNom()
00560         {
00561                 return "CBlobGetExternHullPerimeterRatio";
00562         }
00563 private:
00564         IplImage *m_mask;
00565         bool  m_xBorder, m_yBorder;
00566 
00567 };
00568 
00571 class CBlobGetXCenter: public COperadorBlob
00572 {
00573 public:
00574     double operator()(CBlob &blob)
00575         {
00576                 return blob.MinX() + (( blob.MaxX() - blob.MinX() ) / 2.0);
00577         }
00578         const char *GetNom()
00579         {
00580                 return "CBlobGetXCenter";
00581         }
00582 };
00583 
00586 class CBlobGetYCenter: public COperadorBlob
00587 {
00588 public:
00589     double operator()(CBlob &blob)
00590         {
00591                 return blob.MinY() + (( blob.MaxY() - blob.MinY() ) / 2.0);
00592         }
00593         const char *GetNom()
00594         {
00595                 return "CBlobGetYCenter";
00596         }
00597 };
00598 
00601 class CBlobGetMajorAxisLength: public COperadorBlob
00602 {
00603 public:
00604     double operator()(CBlob &blob)
00605         {
00606                 CvBox2D elipse = blob.GetEllipse();
00607 
00608                 return elipse.size.width;
00609         }
00610         const char *GetNom()
00611         {
00612                 return "CBlobGetMajorAxisLength";
00613         }
00614 };
00615 
00618 class CBlobGetAreaElipseRatio: public COperadorBlob
00619 {
00620 public:
00621     double operator()(CBlob &blob)
00622         {
00623                 if( blob.Area()==0.0 ) return 0.0;
00624 
00625                 CvBox2D elipse = blob.GetEllipse();
00626                 double ratioAreaElipseAreaTaca = ( (elipse.size.width/2.0)
00627                                                                                    *
00628                                                                                    (elipse.size.height/2.0)
00629                                                                        *CV_PI
00630                                                                  )
00631                                                                              /
00632                                                                              blob.Area();
00633 
00634                 return ratioAreaElipseAreaTaca;
00635         }
00636         const char *GetNom()
00637         {
00638                 return "CBlobGetAreaElipseRatio";
00639         }
00640 };
00641 
00644 class CBlobGetMinorAxisLength: public COperadorBlob
00645 {
00646 public:
00647     double operator()(CBlob &blob)
00648         {
00649                 CvBox2D elipse = blob.GetEllipse();
00650 
00651                 return elipse.size.height;
00652         }
00653         const char *GetNom()
00654         {
00655                 return "CBlobGetMinorAxisLength";
00656         }
00657 };
00658 
00661 class CBlobGetOrientation: public COperadorBlob
00662 {
00663 public:
00664     double operator()(CBlob &blob)
00665         {
00666                 CvBox2D elipse = blob.GetEllipse();
00667 /*
00668                 if( elipse.angle > 180.0 )
00669                         return (( elipse.angle - 180.0 )* DEGREE2RAD);
00670                 else
00671                         return ( elipse.angle * DEGREE2RAD);
00672 */
00673                 return elipse.angle;
00674         }
00675         const char *GetNom()
00676         {
00677                 return "CBlobGetOrientation";
00678         }
00679 };
00680 
00683 class CBlobGetOrientationCos: public COperadorBlob
00684 {
00685 public:
00686     double operator()(CBlob &blob)
00687         {
00688                 CBlobGetOrientation getOrientation;
00689                 return fabs( cos( getOrientation(blob)*DEGREE2RAD ));
00690         }
00691         const char *GetNom()
00692         {
00693                 return "CBlobGetOrientationCos";
00694         }
00695 };
00696 
00697 
00700 class CBlobGetAxisRatio: public COperadorBlob
00701 {
00702 public:
00703     double operator()(CBlob &blob)
00704         {
00705                 double major,minor;
00706                 CBlobGetMajorAxisLength getMajor;
00707                 CBlobGetMinorAxisLength getMinor;
00708 
00709                 major = getMajor(blob);
00710                 minor = getMinor(blob);
00711 
00712                 if( major != 0 )
00713                         return minor / major;
00714                 else
00715                         return 0;
00716         }
00717         const char *GetNom()
00718         {
00719                 return "CBlobGetAxisRatio";
00720         }
00721 };
00722 
00723 
00726 class CBlobGetXYInside: public COperadorBlob
00727 {
00728 public:
00731         CBlobGetXYInside()
00732         {
00733                 m_p.x = 0;
00734                 m_p.y = 0;
00735         }
00738         CBlobGetXYInside( CvPoint2D32f p )
00739         {
00740                 m_p = p;
00741         };
00742         double operator()(CBlob &blob);
00743         const char *GetNom()
00744         {
00745                 return "CBlobGetXYInside";
00746         }
00747 
00748 private:
00751         CvPoint2D32f m_p;
00752 };
00753 
00754 #endif  //!BLOB_OPERATORS_H_INCLUDED


hrl_cvblobslib
Author(s): kelsey
autogenerated on Wed Nov 27 2013 11:32:58