From a4f2ecbf1e3afa8d80c3cee380f3203924877e4f Mon Sep 17 00:00:00 2001 From: Arshad Khan Date: Thu, 29 Feb 2024 10:58:42 +0000 Subject: [PATCH 1/3] fix includes and cvPoint to cv::point --- .gitignore | 1 + library/BlobContour.cpp | 32 ++++++++--------- library/BlobContour.h | 15 ++++---- library/BlobOperators.cpp | 72 +++++++++++++++++++-------------------- library/BlobOperators.h | 4 +-- library/BlobResult.h | 2 +- library/blob.cpp | 4 +-- library/blob.h | 8 +++-- 8 files changed, 70 insertions(+), 68 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/library/BlobContour.cpp b/library/BlobContour.cpp index da620f2..8c74596 100644 --- a/library/BlobContour.cpp +++ b/library/BlobContour.cpp @@ -11,7 +11,7 @@ CBlobContour::CBlobContour() m_moments.m00 = -1; parent=NULL; } -CBlobContour::CBlobContour(CvPoint startPoint, const Size &imageRes):m_contour(1) +CBlobContour::CBlobContour(cv::Point startPoint, const Size &imageRes):m_contour(1) { m_startPoint.x = startPoint.x; @@ -72,17 +72,17 @@ CBlobContour& CBlobContour::operator=( const CBlobContour &source ) /** -- FUNCIÓ: AddChainCode +- FUNCI�: AddChainCode - FUNCIONALITAT: Add chain code to contour -- PARÀMETRES: +- PAR�METRES: - - RESULTAT: - - RESTRICCIONS: - - AUTOR: rborras -- DATA DE CREACIÓ: 2008/05/06 -- MODIFICACIÓ: Data. Autor. Descripció. +- DATA DE CREACI�: 2008/05/06 +- MODIFICACI�: Data. Autor. Descripci�. */ void CBlobContour::AddChainCode(t_chainCode chaincode) { @@ -97,17 +97,17 @@ void CBlobContour::Reset() } /** -- FUNCIÓ: GetPerimeter +- FUNCI�: GetPerimeter - FUNCIONALITAT: Get perimeter from chain code. Diagonals sum sqrt(2) and horizontal and vertical codes 1 -- PARÀMETRES: +- PAR�METRES: - - RESULTAT: - - RESTRICCIONS: - - AUTOR: rborras -- DATA DE CREACIÓ: 2008/04/30 -- MODIFICACIÓ: Data. Autor. Descripció. +- DATA DE CREACI�: 2008/04/30 +- MODIFICACI�: Data. Autor. Descripci�. - NOTA: Algorithm derived from "Methods to estimate area and perimeters of blob-like objects: A comparison", L.Yang */ double CBlobContour::GetPerimeter() @@ -126,17 +126,17 @@ double CBlobContour::GetPerimeter() } /** -- FUNCIÓ: GetArea +- FUNCI�: GetArea - FUNCIONALITAT: Computes area from chain code -- PARÀMETRES: +- PAR�METRES: - - RESULTAT: - May give negative areas for clock wise contours - RESTRICCIONS: - - AUTOR: rborras -- DATA DE CREACIÓ: 2008/04/30 -- MODIFICACIÓ: Data. Autor. Descripció. +- DATA DE CREACI�: 2008/04/30 +- MODIFICACI�: Data. Autor. Descripci�. - NOTA: Algorithm derived from "Properties of contour codes", G.R. Wilson */ double CBlobContour::GetArea() @@ -218,7 +218,7 @@ void CBlobContour::ShiftBlobContour(int x,int y) } -t_chainCode points2ChainCode( CvPoint p1, CvPoint p2 ) +t_chainCode points2ChainCode( cv::Point p1, cv::Point p2 ) { // /* Luca Nardelli & Saverio Murgia // Freeman Chain Code: @@ -246,14 +246,14 @@ t_chainCode points2ChainCode( CvPoint p1, CvPoint p2 ) else return 200; } -CvPoint chainCode2Point(CvPoint origin,t_chainCode code){ +cv::Point chainCode2Point(cv::Point origin,t_chainCode code){ // /* Luca Nardelli & Saverio Murgia // Freeman Chain Code: // 321 Values indicate the chain code used to identify next pixel location. // 4-0 If I join 2 blobs I can't just append the 2nd blob chain codes, since they will still start // 567 from the 1st blob start point // */ - CvPoint pt = origin; + cv::Point pt = origin; switch(code){ case 0:pt.x++;break; case 1:pt.x++;pt.y--;break; diff --git a/library/BlobContour.h b/library/BlobContour.h index 3c361ca..f293b60 100644 --- a/library/BlobContour.h +++ b/library/BlobContour.h @@ -3,9 +3,8 @@ #include "list" -#include "opencv/cv.h" -#include "opencv/cxcore.h" -#include +#include +#include #include #include @@ -35,7 +34,7 @@ class CBlobContour CBlobContour(); //Size is used to empirically reserve internal vectors for contour points. //This can be a help for very small images, where the vector would be too large. - CBlobContour(CvPoint startPoint, const cv::Size &imageRes = cv::Size(-1,-1)); + CBlobContour(cv::Point startPoint, const cv::Size &imageRes = cv::Size(-1,-1)); //! Copy constructor CBlobContour(CBlobContour *source ); //CBlobContour(CBlobContour &source); @@ -66,7 +65,7 @@ class CBlobContour void ShiftBlobContour(int x,int y); - CvPoint GetStartPoint() const + cv::Point GetStartPoint() const { return m_startPoint; } @@ -89,7 +88,7 @@ class CBlobContour private: //! Starting point of the contour - CvPoint m_startPoint; + cv::Point m_startPoint; //! All points from the contour t_contours m_contourPoints; @@ -105,8 +104,8 @@ class CBlobContour CBlob* parent; }; -t_chainCode points2ChainCode(CvPoint p1, CvPoint p2); -CvPoint chainCode2Point(CvPoint origin,t_chainCode code); +t_chainCode points2ChainCode(cv::Point p1, cv::Point p2); +cv::Point chainCode2Point(cv::Point origin,t_chainCode code); #endif //!BLOBCONTOUR_H_INCLUDED diff --git a/library/BlobOperators.cpp b/library/BlobOperators.cpp index 0b9105a..a495688 100644 --- a/library/BlobOperators.cpp +++ b/library/BlobOperators.cpp @@ -2,7 +2,7 @@ #include "BlobOperators.h" using namespace cv; /*************************************************************************** - Implementació de les classes per al càlcul de característiques sobre el blob + Implementaci� de les classes per al c�lcul de caracter�stiques sobre el blob Implementation of the helper classes to perform operations on blobs /**************************************************************************/ @@ -15,7 +15,7 @@ using namespace cv; - returns the pq moment or 0 if the moment it is not implemented - RESTRICTIONS: - Currently, implemented moments up to 3 -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 20-07-2004. - MODIFICATION: Date. Author. Description. */ @@ -25,19 +25,19 @@ double CBlobGetMoment::operator()(CBlob &blob) } /** -- FUNCIÓ: HullPerimeter +- FUNCI�: HullPerimeter - FUNCIONALITAT: Calcula la longitud del perimetre convex del blob. - Fa servir la funció d'OpenCV cvConvexHull2 per a + Fa servir la funci� d'OpenCV cvConvexHull2 per a calcular el perimetre convex. -- PARÀMETRES: +- PAR�METRES: - RESULTAT: - - retorna la longitud del perímetre convex del blob. Si el blob no té coordenades - associades retorna el perímetre normal del blob. + - retorna la longitud del per�metre convex del blob. Si el blob no t� coordenades + associades retorna el per�metre normal del blob. - RESTRICCIONS: -- AUTOR: Ricard Borràs -- DATA DE CREACIÓ: 20-07-2004. -- MODIFICACIÓ: Data. Autor. Descripció. +- AUTOR: Ricard Borr�s +- DATA DE CREACI�: 20-07-2004. +- MODIFICACI�: Data. Autor. Descripci�. */ /** - FUNCTION: CBlobGetHullPerimeter @@ -47,7 +47,7 @@ double CBlobGetMoment::operator()(CBlob &blob) - returns the convex hull perimeter of the blob or the perimeter if the blob edges could not be retrieved - RESTRICTIONS: -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -85,7 +85,7 @@ double CBlobGetHullArea::operator()(CBlob &blob) - PARAMETERS: - RESULT: - RESTRICTIONS: -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -94,7 +94,7 @@ double CBlobGetMinXatMinY::operator()(CBlob &blob) double result = LONG_MAX; //CvSeqReader reader; - //CvPoint actualPoint; + //cv::Point actualPoint; t_PointList externContour; externContour = blob.GetExternalContour()->GetContourPoints(); @@ -119,7 +119,7 @@ double CBlobGetMinXatMinY::operator()(CBlob &blob) - PARAMETERS: - RESULT: - RESTRICTIONS: -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -128,7 +128,7 @@ double CBlobGetMinYatMaxX::operator()(CBlob &blob) double result = LONG_MAX; //CvSeqReader reader; - //CvPoint actualPoint; + //cv::Point actualPoint; t_PointList externContour; externContour = blob.GetExternalContour()->GetContourPoints(); @@ -154,7 +154,7 @@ double CBlobGetMinYatMaxX::operator()(CBlob &blob) - PARAMETERS: - RESULT: - RESTRICTIONS: -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -163,7 +163,7 @@ double CBlobGetMaxXatMaxY::operator()(CBlob &blob) double result = LONG_MIN; //CvSeqReader reader; - //CvPoint actualPoint; + //cv::Point actualPoint; t_PointList externContour; externContour = blob.GetExternalContour()->GetContourPoints(); @@ -189,7 +189,7 @@ double CBlobGetMaxXatMaxY::operator()(CBlob &blob) - PARAMETERS: - RESULT: - RESTRICTIONS: -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -198,7 +198,7 @@ double CBlobGetMaxYatMinX::operator()(CBlob &blob) double result = LONG_MIN; //CvSeqReader reader; - //CvPoint actualPoint; + //cv::Point actualPoint; t_PointList externContour; externContour = blob.GetExternalContour()->GetContourPoints(); @@ -227,7 +227,7 @@ double CBlobGetMaxYatMinX::operator()(CBlob &blob) - RESULT: - RESTRICTIONS: - See below to see how the lenght and the breadth are aproximated -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -241,7 +241,7 @@ double CBlobGetElongation::operator()(CBlob &blob) 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 + // error intr�nsec en els c�lculs de l'�rea i el per�metre else ampladaC = (double) (blob.Perimeter())/4; @@ -264,7 +264,7 @@ double CBlobGetElongation::operator()(CBlob &blob) - PARAMETERS: - RESULT: - RESTRICTIONS: -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -286,7 +286,7 @@ double CBlobGetCompactness::operator()(CBlob &blob) - PARAMETERS: - RESULT: - RESTRICTIONS: -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -312,7 +312,7 @@ double CBlobGetRoughness::operator()(CBlob &blob) - RESULT: - RESTRICTIONS: - The lenght is an aproximation to the real lenght -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -325,7 +325,7 @@ double CBlobGetLength::operator()(CBlob &blob) 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 + // error intr�nsec en els c�lculs de l'�rea i el per�metre else ampladaC = (double) (blob.Perimeter())/4; @@ -345,7 +345,7 @@ double CBlobGetLength::operator()(CBlob &blob) - RESULT: - RESTRICTIONS: - The breadth is an aproximation to the real breadth -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -358,7 +358,7 @@ double CBlobGetBreadth::operator()(CBlob &blob) 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 + // error intr�nsec en els c�lculs de l'�rea i el per�metre else ampladaC = (double) (blob.Perimeter())/4; @@ -369,7 +369,7 @@ double CBlobGetBreadth::operator()(CBlob &blob) } /** - Calcula la distància entre un punt i el centre del blob + Calcula la dist�ncia entre un punt i el centre del blob */ /** - FUNCTION: CBlobGetDistanceFromPoint @@ -378,7 +378,7 @@ double CBlobGetBreadth::operator()(CBlob &blob) - PARAMETERS: - RESULT: - RESTRICTIONS: -- AUTHOR: Ricard Borràs +- AUTHOR: Ricard Borr�s - CREATION DATE: 25-05-2005. - MODIFICATION: Date. Author. Description. */ @@ -419,18 +419,18 @@ double CBlobGetXYInside::operator()(CBlob &blob) #ifdef BLOB_OBJECT_FACTORY /** -- FUNCIÓ: RegistraTotsOperadors +- FUNCI�: RegistraTotsOperadors - FUNCIONALITAT: Registrar tots els operadors definits a blob.h -- PARÀMETRES: - - fabricaOperadorsBlob: fàbrica on es registraran els operadors +- PAR�METRES: + - fabricaOperadorsBlob: f�brica on es registraran els operadors - RESULTAT: - Modifica l'objecte fabricaOperadorsBlob - RESTRICCIONS: - - Només es registraran els operadors de blob.h. Si se'n volen afegir, cal afegir-los amb - el mètode Register de la fàbrica. + - Nom�s es registraran els operadors de blob.h. Si se'n volen afegir, cal afegir-los amb + el m�tode Register de la f�brica. - AUTOR: rborras -- DATA DE CREACIÓ: 2006/05/18 -- MODIFICACIÓ: Data. Autor. Descripció. +- DATA DE CREACI�: 2006/05/18 +- MODIFICACI�: Data. Autor. Descripci�. */ void RegistraTotsOperadors( t_OperadorBlobFactory &fabricaOperadorsBlob ) { diff --git a/library/BlobOperators.h b/library/BlobOperators.h index c94aeb4..5bab637 100644 --- a/library/BlobOperators.h +++ b/library/BlobOperators.h @@ -749,7 +749,7 @@ class CBlobGetXYInside: public COperadorBlob } //! Constructor: indiquem el punt //! Constructor: sets the point - CBlobGetXYInside( CvPoint2D32f p ) + CBlobGetXYInside( cv::Point2D32f p ) { m_p = p; }; @@ -762,7 +762,7 @@ class CBlobGetXYInside: public COperadorBlob private: //! punt que considerem //! point to be considered - CvPoint2D32f m_p; + cv::Point2D32f m_p; }; #endif //!BLOB_OPERATORS_H_INCLUDED diff --git a/library/BlobResult.h b/library/BlobResult.h index 185f323..0811fba 100644 --- a/library/BlobResult.h +++ b/library/BlobResult.h @@ -22,7 +22,7 @@ MODIFICATIONS (Modification, Author, Date): #include "BlobLibraryConfiguration.h" #include "ComponentLabeling.h" #include -#include "opencv/cxcore.h" +#include #include #include #include diff --git a/library/blob.cpp b/library/blob.cpp index fd762ec..9d33c2a 100644 --- a/library/blob.cpp +++ b/library/blob.cpp @@ -32,7 +32,7 @@ CBlob::CBlob() isJoined=false; startPassed=false; } -CBlob::CBlob( t_labelType id, CvPoint startPoint, CvSize originalImageSize ):m_externalContour(startPoint,originalImageSize) +CBlob::CBlob( t_labelType id, cv::Point startPoint, CvSize originalImageSize ):m_externalContour(startPoint,originalImageSize) { m_externalContour.parent=this; m_id = id; @@ -460,7 +460,7 @@ double CBlob::Mean( IplImage *image ) // Create a mask with same size as blob bounding box IplImage *mask; CvScalar mean, std; - CvPoint offset; + cv::Point offset; GetBoundingBox(); diff --git a/library/blob.h b/library/blob.h index cb9cec2..fe8351a 100644 --- a/library/blob.h +++ b/library/blob.h @@ -18,8 +18,10 @@ MODIFICATIONS (Modification, Author, Date): #ifndef CBLOB_INSPECTA_INCLUDED #define CBLOB_INSPECTA_INCLUDED class CBlob; -#include "opencv/cxcore.h" -#include "opencv2/opencv.hpp" + +#include +#include + #include "BlobLibraryConfiguration.h" #include "BlobContour.h" #include @@ -44,7 +46,7 @@ class CBlob friend class myCompLabeler; public: CBlob(); - CBlob( t_labelType id, CvPoint startPoint, CvSize originalImageSize ); + CBlob( t_labelType id, cv::Point startPoint, CvSize originalImageSize ); ~CBlob(); //! Copy constructor From 3e28284f2bff0a5f7f42bc9a8a215dce8abdd9a0 Mon Sep 17 00:00:00 2001 From: Arshad Khan Date: Thu, 29 Feb 2024 12:08:03 +0000 Subject: [PATCH 2/3] replaced all the relevant types that were breaking between 3.2 to 4.2 --- library/BlobContour.cpp | 25 ++-- library/BlobContour.h | 2 +- library/BlobOperators.h | 36 +++--- library/BlobResult.cpp | 9 +- library/BlobResult.h | 3 +- library/blob.cpp | 273 +++++++++++++++++----------------------- library/blob.h | 26 ++-- 7 files changed, 166 insertions(+), 208 deletions(-) diff --git a/library/BlobContour.cpp b/library/BlobContour.cpp index 8c74596..6676610 100644 --- a/library/BlobContour.cpp +++ b/library/BlobContour.cpp @@ -157,23 +157,18 @@ double CBlobContour::GetArea() //! Get contour moment (p,q up to MAX_CALCULATED_MOMENTS) double CBlobContour::GetMoment(int p, int q) { - // is a valid moment? - if ( p < 0 || q < 0 || p > MAX_MOMENTS_ORDER || q > MAX_MOMENTS_ORDER ) - { + // Assuming m_moments is of type cv::Moments and has been calculated earlier + if ( p < 0 || q < 0 || p > MAX_MOMENTS_ORDER || q > MAX_MOMENTS_ORDER ) { return -1; } - - if( IsEmpty() ) - return 0; - - // it is calculated? - if( m_moments.m00 == -1) - { - //cvMoments( GetContourPoints(), &m_moments ); - m_moments = moments(GetContourPoints(),true); - } - - return cvGetSpatialMoment( &m_moments, p, q ); + else if (p == 0 && q == 0) return m_moments.m00; + else if (p == 1 && q == 0) return m_moments.m10; + else if (p == 0 && q == 1) return m_moments.m01; + // Add more conditions for other moments you need + else { + // Handle error or unsupported moments + return -1; + } } diff --git a/library/BlobContour.h b/library/BlobContour.h index f293b60..7c799d2 100644 --- a/library/BlobContour.h +++ b/library/BlobContour.h @@ -97,7 +97,7 @@ class CBlobContour //! Computed perimeter from contour double m_perimeter; //! Computed moments from contour - CvMoments m_moments; + cv::Moments m_moments; static const t_PointList EMPTY_LIST; //This value is actually used mainly in the detection part, for the labels. diff --git a/library/BlobOperators.h b/library/BlobOperators.h index 5bab637..124eba4 100644 --- a/library/BlobOperators.h +++ b/library/BlobOperators.h @@ -125,7 +125,7 @@ class CBlobGetExterior: public COperadorBlob m_xBorder = true; m_yBorder = true; } - CBlobGetExterior(IplImage *mask, bool xBorder = true, bool yBorder = true) + CBlobGetExterior(cv::Mat *mask, bool xBorder = true, bool yBorder = true) { m_mask = mask; m_xBorder = xBorder; @@ -140,7 +140,7 @@ class CBlobGetExterior: public COperadorBlob return "CBlobGetExterior"; } private: - IplImage *m_mask; + cv::Mat *m_mask; bool m_xBorder, m_yBorder; }; @@ -153,7 +153,7 @@ class CBlobGetMean: public COperadorBlob { m_image = NULL; } - CBlobGetMean( IplImage *image ) + CBlobGetMean( cv::Mat *image ) { m_image = image; }; @@ -168,7 +168,7 @@ class CBlobGetMean: public COperadorBlob } private: - IplImage *m_image; + cv::Mat *m_image; }; //! Classe per calcular la desviaci� est�ndard dels nivells de gris d'un blob @@ -180,7 +180,7 @@ class CBlobGetStdDev: public COperadorBlob { m_image = NULL; } - CBlobGetStdDev( IplImage *image ) + CBlobGetStdDev( cv::Mat *image ) { m_image = image; }; @@ -194,7 +194,7 @@ class CBlobGetStdDev: public COperadorBlob } private: - IplImage *m_image; + cv::Mat *m_image; }; @@ -487,7 +487,7 @@ class CBlobGetExternPerimeter: public COperadorBlob m_xBorder = true; m_yBorder = true; } - CBlobGetExternPerimeter( IplImage *mask, bool xBorder = true, bool yBorder = true ) + CBlobGetExternPerimeter( cv::Mat *mask, bool xBorder = true, bool yBorder = true ) { m_mask = mask; m_xBorder = xBorder; @@ -502,7 +502,7 @@ class CBlobGetExternPerimeter: public COperadorBlob return "CBlobGetExternPerimeter"; } private: - IplImage *m_mask; + cv::Mat *m_mask; bool m_xBorder, m_yBorder; }; @@ -519,7 +519,7 @@ class CBlobGetExternPerimeterRatio: public COperadorBlob m_xBorder = false; m_yBorder = false; } - CBlobGetExternPerimeterRatio( IplImage *mask, bool xBorder = true, bool yBorder = true ) + CBlobGetExternPerimeterRatio( cv::Mat *mask, bool xBorder = true, bool yBorder = true ) { m_mask = mask; m_xBorder = xBorder; @@ -537,7 +537,7 @@ class CBlobGetExternPerimeterRatio: public COperadorBlob return "CBlobGetExternPerimeterRatio"; } private: - IplImage *m_mask; + cv::Mat *m_mask; bool m_xBorder, m_yBorder; }; @@ -554,7 +554,7 @@ class CBlobGetExternHullPerimeterRatio: public COperadorBlob m_xBorder = false; m_yBorder = false; } - CBlobGetExternHullPerimeterRatio( IplImage *mask, bool xBorder = true, bool yBorder = true ) + CBlobGetExternHullPerimeterRatio( cv::Mat *mask, bool xBorder = true, bool yBorder = true ) { m_mask = mask; m_xBorder = xBorder; @@ -575,7 +575,7 @@ class CBlobGetExternHullPerimeterRatio: public COperadorBlob return "CBlobGetExternHullPerimeterRatio"; } private: - IplImage *m_mask; + cv::Mat *m_mask; bool m_xBorder, m_yBorder; }; @@ -617,7 +617,7 @@ class CBlobGetMajorAxisLength: public COperadorBlob public: double operator()(CBlob &blob) { - CvBox2D elipse = blob.GetEllipse(); + cv::RotatedRect elipse = blob.GetEllipse(); return elipse.size.width; } @@ -636,7 +636,7 @@ class CBlobGetAreaElipseRatio: public COperadorBlob { if( blob.Area()==0.0 ) return 0.0; - CvBox2D elipse = blob.GetEllipse(); + cv::RotatedRect elipse = blob.GetEllipse(); double ratioAreaElipseAreaTaca = ( (elipse.size.width/2.0) * (elipse.size.height/2.0) @@ -660,7 +660,7 @@ class CBlobGetMinorAxisLength: public COperadorBlob public: double operator()(CBlob &blob) { - CvBox2D elipse = blob.GetEllipse(); + cv::RotatedRect elipse = blob.GetEllipse(); return elipse.size.height; } @@ -677,7 +677,7 @@ class CBlobGetOrientation: public COperadorBlob public: double operator()(CBlob &blob) { - CvBox2D elipse = blob.GetEllipse(); + cv::RotatedRect elipse = blob.GetEllipse(); /* if( elipse.angle > 180.0 ) return (( elipse.angle - 180.0 )* DEGREE2RAD); @@ -749,7 +749,7 @@ class CBlobGetXYInside: public COperadorBlob } //! Constructor: indiquem el punt //! Constructor: sets the point - CBlobGetXYInside( cv::Point2D32f p ) + CBlobGetXYInside( cv::Point2f p ) { m_p = p; }; @@ -762,7 +762,7 @@ class CBlobGetXYInside: public COperadorBlob private: //! punt que considerem //! point to be considered - cv::Point2D32f m_p; + cv::Point2f m_p; }; #endif //!BLOB_OPERATORS_H_INCLUDED diff --git a/library/BlobResult.cpp b/library/BlobResult.cpp index 3ef8dd1..f069406 100644 --- a/library/BlobResult.cpp +++ b/library/BlobResult.cpp @@ -81,16 +81,17 @@ CBlobResult::CBlobResult() - MODIFICATION: Oct-2013. Luca Nardelli and Saverio Murgia. Changed to comply with reimplemented labelling algorithm */ -CBlobResult::CBlobResult(IplImage *source, IplImage *mask,int numThreads) +CBlobResult::CBlobResult(cv::Mat *source, cv::Mat *mask,int numThreads) { if(mask!=NULL){ - Mat temp = Mat::zeros(Size(source->width,source->height),CV_8UC1); - cvarrToMat(source).copyTo(temp,cvarrToMat(mask)); + Mat temp = Mat::zeros(Size(source->cols,source->rows),CV_8UC1); + // cv::cvarrToMat(source).copyTo(temp,cv::cvarrToMat(mask)); + temp = source->clone(); compLabeler.set(numThreads,temp); compLabeler.doLabeling(m_blobs); } else{ - Mat temp = Mat::zeros(Size(source->width,source->height),CV_8UC1); + Mat temp = Mat::zeros(Size(source->cols,source->rows),CV_8UC1); compLabeler.set(numThreads,temp); compLabeler.doLabeling(m_blobs); } diff --git a/library/BlobResult.h b/library/BlobResult.h index 0811fba..9695831 100644 --- a/library/BlobResult.h +++ b/library/BlobResult.h @@ -24,6 +24,7 @@ MODIFICATIONS (Modification, Author, Date): #include #include #include +#include #include #include #include @@ -92,7 +93,7 @@ class CBlobResult //Constructor, opencv 1.0 and 2.0 interfaces. CBlobResult(); - CBlobResult(IplImage *source, IplImage *mask = NULL, int numThreads=1); + CBlobResult(cv::Mat *source, cv::Mat *mask = NULL, int numThreads=1); CBlobResult(cv::Mat &source, const cv::Mat &mask = cv::Mat(),int numThreads=1); CBlobResult( const CBlobResult &source ); //! Destructor diff --git a/library/blob.cpp b/library/blob.cpp index 9d33c2a..6eefaff 100644 --- a/library/blob.cpp +++ b/library/blob.cpp @@ -32,7 +32,7 @@ CBlob::CBlob() isJoined=false; startPassed=false; } -CBlob::CBlob( t_labelType id, cv::Point startPoint, CvSize originalImageSize ):m_externalContour(startPoint,originalImageSize) +CBlob::CBlob( t_labelType id, cv::Point startPoint, cv::Size originalImageSize ):m_externalContour(startPoint,originalImageSize) { m_externalContour.parent=this; m_id = id; @@ -248,7 +248,7 @@ double CBlob::Perimeter() - DATA DE CREACI�: 2008/05/06 - MODIFICACI�: Data. Autor. Descripci�. */ -int CBlob::Exterior(IplImage *mask, bool xBorder /* = true */, bool yBorder /* = true */) +int CBlob::Exterior(cv::Mat *mask, bool xBorder /* = true */, bool yBorder /* = true */) { int result = 0; if (ExternPerimeter(mask, xBorder, yBorder ) > 0 ) @@ -260,7 +260,7 @@ int CBlob::Exterior(IplImage *mask, bool xBorder /* = true */, bool yBorder /* = } int CBlob::Exterior(Mat mask, bool xBorder /* = true */, bool yBorder /* = true */) { - IplImage temp = (IplImage) mask; + cv::Mat temp = (cv::Mat) mask; return Exterior(&temp, xBorder, yBorder); } /** @@ -281,7 +281,7 @@ int CBlob::Exterior(Mat mask, bool xBorder /* = true */, bool yBorder /* = true - NOTA: If CBlobContour::GetContourPoints aproximates contours with a method different that NONE, this function will not give correct results */ -double CBlob::ExternPerimeter( IplImage *maskImage, bool xBorder /* = true */, bool yBorder /* = true */) +double CBlob::ExternPerimeter( cv::Mat *maskImage, bool xBorder /* = true */, bool yBorder /* = true */) { t_PointList externContour, externalPoints; Point actualPoint, previousPoint; @@ -339,9 +339,10 @@ double CBlob::ExternPerimeter( IplImage *maskImage, bool xBorder /* = true */, b if( maskImage != NULL ) { // verify if some of 8-connected neighbours is black in mask - char *pMask; + uchar *pMask; - pMask = (maskImage->imageData + actualPoint.x - 1 + (actualPoint.y - 1) * maskImage->widthStep); + pMask = (maskImage->data + actualPoint.x - 1 + (actualPoint.y - 1) * maskImage->step); + // pMask = maskImage->data + (actualPoint.y - 1) * maskImage->step + (actualPoint.x - 1); for ( int i = 0; i < 3; i++, pMask++ ) { @@ -354,7 +355,7 @@ double CBlob::ExternPerimeter( IplImage *maskImage, bool xBorder /* = true */, b if(!find) { - pMask = (maskImage->imageData + actualPoint.x - 1 + (actualPoint.y ) * maskImage->widthStep); + pMask = (maskImage->data + actualPoint.x - 1 + (actualPoint.y ) * maskImage->step); for ( int i = 0; i < 3; i++, pMask++ ) { @@ -368,7 +369,7 @@ double CBlob::ExternPerimeter( IplImage *maskImage, bool xBorder /* = true */, b if(!find) { - pMask = (maskImage->imageData + actualPoint.x - 1 + (actualPoint.y + 1) * maskImage->widthStep); + pMask = (maskImage->data + actualPoint.x - 1 + (actualPoint.y + 1) * maskImage->step); for ( int i = 0; i < 3; i++, pMask++ ) { @@ -414,7 +415,7 @@ double CBlob::ExternPerimeter( Mat maskImage, bool xBorder /* = true */, bool yB return ExternPerimeter( NULL, xBorder /* = true */, yBorder /* = true */); } else{ - IplImage temp = (IplImage) maskImage; + cv::Mat temp = (cv::Mat) maskImage; return ExternPerimeter( &temp, xBorder /* = true */, yBorder /* = true */); } } @@ -455,84 +456,69 @@ double CBlob::Moment(int p, int q) - DATA DE CREACI�: 2008/05/06 - MODIFICACI�: Data. Autor. Descripci�. */ -double CBlob::Mean( IplImage *image ) +double CBlob::Mean( cv::Mat *image ) { // Create a mask with same size as blob bounding box - IplImage *mask; - CvScalar mean, std; + cv::Mat mask; + cv::Scalar mean, std; cv::Point offset; GetBoundingBox(); - if (m_boundingBox.height == 0 ||m_boundingBox.width == 0 || !CV_IS_IMAGE( image )) + if (m_boundingBox.height == 0 ||m_boundingBox.width == 0 || image->empty()) { m_meanGray = 0; return m_meanGray; } // apply ROI and mask to input image to compute mean gray and standard deviation - mask = cvCreateImage( cvSize(m_boundingBox.width, m_boundingBox.height), IPL_DEPTH_8U, 1); - cvSetZero(mask); + mask = cv::Mat::zeros(cv::Size(m_boundingBox.width, m_boundingBox.height), CV_8UC1); offset.x = -m_boundingBox.x; offset.y = -m_boundingBox.y; - Mat mask_mat = cvarrToMat(mask); + Mat mask_mat = mask.clone() ; // cv::cvarrToMat(mask); //If joined if(isJoined){ list::iterator it,en = joinedBlobs.end(); for(it = joinedBlobs.begin();it!=en;it++){ -// cvDrawContours( mask, (*it)->m_externalContour.GetContourPoints(), CV_RGB(255,255,255), CV_RGB(255,255,255),0, CV_FILLED, 8, -// offset ); -// vector conts; -// conts.push_back((*it)->m_externalContour.GetContourPoints()); - drawContours(mask_mat,(*it)->m_externalContour.GetContours(),-1,CV_RGB(255,255,255),CV_FILLED,8,noArray(),2147483647,offset); + drawContours(mask_mat,(*it)->m_externalContour.GetContours(),-1,CV_RGB(255,255,255),-1,8,noArray(),2147483647,offset); t_CBlobContourList::iterator itint = (*it)->m_internalContours.begin(); while(itint != (*it)->m_internalContours.end() ) { -// cvDrawContours( mask, (*itint).GetContourPoints(), CV_RGB(0,0,0), CV_RGB(0,0,0),0, CV_FILLED, 8, -// offset ); - drawContours(mask_mat,(*itint)->GetContours(),-1,CV_RGB(0,0,0),CV_FILLED,8,noArray(),2147483647,offset); + drawContours(mask_mat,(*itint)->GetContours(),-1,CV_RGB(0,0,0),-1,8,noArray(),2147483647,offset); itint++; } } } - else{ - // draw contours on mask -// cvDrawContours( mask, m_externalContour.GetContourPoints(), CV_RGB(255,255,255), CV_RGB(255,255,255),0, CV_FILLED, 8, -// offset ); -// vector conts; -// conts.push_back(m_externalContour.GetContourPoints()); - drawContours(mask_mat,m_externalContour.GetContours(),-1,CV_RGB(255,255,255),CV_FILLED,8,noArray(),2147483647,offset); + else{ + drawContours(mask_mat,m_externalContour.GetContours(),-1,CV_RGB(255,255,255),-1,8,noArray(),2147483647,offset); // draw internal contours t_CBlobContourList::iterator it = m_internalContours.begin(); while(it != m_internalContours.end() ) { -// cvDrawContours( mask, (*it).GetContourPoints(), CV_RGB(0,0,0), CV_RGB(0,0,0),0, CV_FILLED, 8, -// offset ); - drawContours(mask_mat,(*it)->GetContours(),-1,CV_RGB(0,0,0),CV_FILLED,8,noArray(),2147483647,offset); + drawContours(mask_mat,(*it)->GetContours(),-1,CV_RGB(0,0,0),-1,8,noArray(),2147483647,offset); it++; } } - cvSetImageROI( image, m_boundingBox ); - cvAvgSdv( image, &mean, &std, mask ); + + // cv::Mat imageCrop(&image, m_boundingBox); + cv::Mat imageCrop = (*image)(m_boundingBox); + cv::meanStdDev(imageCrop, mean, std, mask); m_meanGray = mean.val[0]; m_stdDevGray = std.val[0]; - cvReleaseImage( &mask ); - cvResetImageROI( image ); - return m_meanGray; } double CBlob::Mean(Mat image ){ - IplImage temp = (IplImage) image; + cv::Mat temp = (cv::Mat) image; return Mean(&temp); } -double CBlob::StdDev( IplImage *image ) +double CBlob::StdDev( cv::Mat *image ) { // call mean calculation (where also standard deviation is calculated) Mean( image ); @@ -540,13 +526,13 @@ double CBlob::StdDev( IplImage *image ) return m_stdDevGray; } double CBlob::StdDev(Mat image){ - IplImage temp = (IplImage) image; + cv::Mat temp = (cv::Mat) image; return StdDev(&temp); } //void CBlob::MeanStdDev( Mat image, double *mean, double *stddev ) //{ -// IplImage temp = (IplImage) image; +// cv::Mat temp = (cv::Mat) image; // Mean(&temp); // *mean = m_meanGray; // *stddev = m_stdDevGray; @@ -564,23 +550,23 @@ void CBlob::MeanStdDev( Mat image, Scalar &mean, Scalar &stddev ) if(isJoined){ list::iterator it,en = joinedBlobs.end(); for(it = joinedBlobs.begin();it!=en;it++){ - drawContours(mask_mat,(*it)->m_externalContour.GetContours(),-1,CV_RGB(255,255,255),CV_FILLED,8,noArray(),2147483647,offset); + drawContours(mask_mat,(*it)->m_externalContour.GetContours(),-1,CV_RGB(255,255,255),-1,8,noArray(),2147483647,offset); t_CBlobContourList::iterator itint = (*it)->m_internalContours.begin(); while(itint != (*it)->m_internalContours.end() ) { - drawContours(mask_mat,(*itint)->GetContours(),-1,CV_RGB(0,0,0),CV_FILLED,8,noArray(),2147483647,offset); + drawContours(mask_mat,(*itint)->GetContours(),-1,CV_RGB(0,0,0),-1,8,noArray(),2147483647,offset); itint++; } } } else{ // draw contours on mask - drawContours(mask_mat,m_externalContour.GetContours(),-1,CV_RGB(255,255,255),CV_FILLED,8,noArray(),2147483647,offset); + drawContours(mask_mat,m_externalContour.GetContours(),-1,CV_RGB(255,255,255),-1,8,noArray(),2147483647,offset); // draw internal contours t_CBlobContourList::iterator it = m_internalContours.begin(); while(it != m_internalContours.end() ) { - drawContours(mask_mat,(*it)->GetContours(),-1,CV_RGB(0,0,0),CV_FILLED,8,noArray(),2147483647,offset); + drawContours(mask_mat,(*it)->GetContours(),-1,CV_RGB(0,0,0),-1,8,noArray(),2147483647,offset); it++; } } @@ -601,7 +587,7 @@ void CBlob::MeanStdDev( Mat image, Scalar &mean, Scalar &stddev ) - DATA DE CREACI�: 2008/05/06 - MODIFICACI�: Data. Autor. Descripci�. */ -CvRect CBlob::GetBoundingBox() +cv::Rect CBlob::GetBoundingBox() { // it is calculated? if( m_boundingBox.width != -1 ) @@ -610,7 +596,7 @@ CvRect CBlob::GetBoundingBox() } if(isJoined){ - CvRect bigRect; + cv::Rect bigRect; bigRect.x = 1000000; bigRect.y = 1000000; bigRect.height = 0; @@ -618,7 +604,7 @@ CvRect CBlob::GetBoundingBox() list::iterator it,en = joinedBlobs.end(); int maxX=0,maxY=0; for(it = joinedBlobs.begin();it!=en;it++){ - CvRect temp = (*it)->GetBoundingBox(); + cv::Rect temp = (*it)->GetBoundingBox(); if(bigRect.x > temp.x){ bigRect.x = temp.x; } @@ -686,7 +672,7 @@ CvRect CBlob::GetBoundingBox() - MODIFICACI�: Data. Autor. Descripci�. - NOTA: Calculation is made using second order moment aproximation */ -CvBox2D CBlob::GetEllipse() +cv::RotatedRect CBlob::GetEllipse() { // it is calculated? if( m_ellipse.size.width != -1 ) @@ -784,111 +770,86 @@ CvBox2D CBlob::GetEllipse() - MODIFICATION: - sep/2013. Luca Nardelli. Added functionality to consider internal contours when filling the blob. */ -void CBlob::FillBlob( IplImage *image, CvScalar color, int offsetX , int offsetY, bool intContours, const IplImage *srcImage) -{ - if(srcImage==NULL) - FillBlob(cvarrToMat(image),color,offsetX,offsetY,intContours,Mat()); - else - FillBlob(cvarrToMat(image),color,offsetX,offsetY,intContours,cvarrToMat(srcImage)); -} -void CBlob::FillBlob( Mat image, CvScalar color, int offsetX, int offsetY, bool intContours, const Mat srcImage){ - CV_FUNCNAME("CBlob::FillBlob"); - __CV_BEGIN__; - if(srcImage.data && intContours) - CV_ASSERT(image.size()==srcImage.size() && image.type() == srcImage.type()); - { - Rect bbox = GetBoundingBox(); - Point drawOffset(offsetX,offsetY); - Size imSz = image.size(); - if(bbox.x+offsetX+bbox.width >= imSz.width){ - bbox.width = imSz.width - bbox.x-offsetX; - } - else if(bbox.x+offsetX < 0){ - bbox.x = -offsetX; - bbox.width= bbox.width +offsetX; - } - if(bbox.y+offsetY+bbox.height >= imSz.height){ - bbox.height = imSz.height - bbox.y-offsetY; - } - else if(bbox.y+offsetY < 0){ - bbox.y = -offsetY; - bbox.height= bbox.height +offsetY; - } - if(bbox.width <0 || bbox.height <0){ - return; - } - if(bbox.width==0) - bbox.width++; - if(bbox.height==0) - bbox.height++; - if(isJoined){ - list::iterator itBlob=joinedBlobs.begin(),enBlob = joinedBlobs.end(); - for(itBlob = joinedBlobs.begin();itBlob!=enBlob;itBlob++){ - (*itBlob)->FillBlob(image,color,offsetX,offsetY,intContours,srcImage); - } - // if(intContours){ - // Point offset(-bbox.x,-bbox.y); - // Size sz(bbox.width,bbox.height); - // Mat temp(sz,image.type()); - // Mat mask(sz,CV_8UC1); - // mask.setTo(0); - // for(itBlob = joinedBlobs.begin();itBlob!=enBlob;itBlob++){ - // CBlob *curBlob = *itBlob; - // t_CBlobContourList::iterator it = curBlob->m_internalContours.begin(),en = curBlob->m_internalContours.end(); - // for(it;it!=en;it++){ - // drawContours(mask,(*it)->GetContours(),-1,255,CV_FILLED,8,noArray(),2147483647,offset); - // } - // } - // srcImage(bbox).copyTo(temp,mask); - // for(itBlob = joinedBlobs.begin();itBlob!=enBlob;itBlob++){ - // drawContours(image,(*itBlob)->m_externalContour.GetContours(),-1,color,CV_FILLED,8,noArray(),2147483647,drawOffset); - // } - // temp.copyTo(image(bbox+drawOffset),mask); - // for(itBlob = joinedBlobs.begin();itBlob!=enBlob;itBlob++){ - // CBlob *curBlob = *itBlob; - // t_CBlobContourList::const_iterator it = curBlob->m_internalContours.begin(),en = curBlob->m_internalContours.end(); - // for(it;it!=en;it++){ - // drawContours(image,(*it)->GetContours(),-1,color,1,8,noArray(),2147483647,drawOffset); - // } - // } - // } - // else{ - // for(itBlob = joinedBlobs.begin();itBlob!=enBlob;itBlob++){ - // drawContours(image,(*itBlob)->m_externalContour.GetContours(),-1,color,CV_FILLED,8,noArray(),2147483647,drawOffset); - // } - // } - } - else{ - if(intContours){ - Point offset(-bbox.x,-bbox.y); - t_CBlobContourList::iterator it = m_internalContours.begin(),en = m_internalContours.end(); - Mat temp(bbox.height,bbox.width,image.type()); - drawContours(image,m_externalContour.GetContours(),-1,color,CV_FILLED,8,noArray(),2147483647,drawOffset); - if(srcImage.data){ - Mat mask(bbox.height,bbox.width,CV_8UC1); - mask.setTo(0); - for(it;it!=en;it++){ - drawContours(mask,(*it)->GetContours(),-1,255,CV_FILLED,8,noArray(),2147483647,offset); - } - srcImage(bbox).copyTo(temp,mask); - Mat image_roi = image(bbox+drawOffset); - temp.copyTo(image_roi,mask); - } - else{ - for(it;it!=en;it++){ - drawContours(image,(*it)->GetContours(),-1,CV_RGB(0,0,0),CV_FILLED,8,noArray(),2147483647,drawOffset); - } - } - - for(it=m_internalContours.begin();it!=en;it++){ - drawContours(image,(*it)->GetContours(),-1,color,1,8,noArray(),2147483647,drawOffset); - } - } - else - drawContours(image,m_externalContour.GetContours(),-1,color,CV_FILLED,8,noArray(),2147483647,drawOffset); - } - } - __CV_END__; +// void CBlob::FillBlob( cv::Mat image, cv::Scalar color, int offsetX , int offsetY, bool intContours, const cv::Mat srcImage) +// { +// if(srcImage==NULL) +// FillBlob(image,color,offsetX,offsetY,intContours,Mat()); +// else +// FillBlob(image,color,offsetX,offsetY,intContours, srcImage); +// } + +void CBlob::FillBlob( Mat image, cv::Scalar color, int offsetX, int offsetY, bool intContours, const Mat srcImage){ + + try { + if(srcImage.data && intContours) + { + if (!(image.size() == srcImage.size() && image.type() == srcImage.type())) { + throw std::runtime_error("Image sizes or types do not match"); + } + + Rect bbox = GetBoundingBox(); + Point drawOffset(offsetX,offsetY); + Size imSz = image.size(); + if(bbox.x+offsetX+bbox.width >= imSz.width){ + bbox.width = imSz.width - bbox.x-offsetX; + } + else if(bbox.x+offsetX < 0){ + bbox.x = -offsetX; + bbox.width= bbox.width +offsetX; + } + if(bbox.y+offsetY+bbox.height >= imSz.height){ + bbox.height = imSz.height - bbox.y-offsetY; + } + else if(bbox.y+offsetY < 0){ + bbox.y = -offsetY; + bbox.height= bbox.height +offsetY; + } + if(bbox.width <0 || bbox.height <0){ + return; + } + if(bbox.width==0) + bbox.width++; + if(bbox.height==0) + bbox.height++; + if(isJoined){ + list::iterator itBlob=joinedBlobs.begin(),enBlob = joinedBlobs.end(); + for(itBlob = joinedBlobs.begin();itBlob!=enBlob;itBlob++){ + (*itBlob)->FillBlob(image,color,offsetX,offsetY,intContours,srcImage); + } + } + else{ + if(intContours){ + Point offset(-bbox.x,-bbox.y); + t_CBlobContourList::iterator it = m_internalContours.begin(),en = m_internalContours.end(); + Mat temp(bbox.height,bbox.width,image.type()); + drawContours(image,m_externalContour.GetContours(),-1,color,-1,8,noArray(),2147483647,drawOffset); + if(srcImage.data){ + Mat mask(bbox.height,bbox.width,CV_8UC1); + mask.setTo(0); + for(it;it!=en;it++){ + drawContours(mask,(*it)->GetContours(),-1,255,-1,8,noArray(),2147483647,offset); + } + srcImage(bbox).copyTo(temp,mask); + Mat image_roi = image(bbox+drawOffset); + temp.copyTo(image_roi,mask); + } + else{ + for(it;it!=en;it++){ + drawContours(image,(*it)->GetContours(),-1,CV_RGB(0,0,0),-1,8,noArray(),2147483647,drawOffset); + } + } + + for(it=m_internalContours.begin();it!=en;it++){ + drawContours(image,(*it)->GetContours(),-1,color,1,8,noArray(),2147483647,drawOffset); + } + } + else + drawContours(image,m_externalContour.GetContours(),-1,color,-1,8,noArray(),2147483647,drawOffset); + } + } + } catch (const cv::Exception& e) { + // Handle or log the exception + } } /** diff --git a/library/blob.h b/library/blob.h index fe8351a..791acce 100644 --- a/library/blob.h +++ b/library/blob.h @@ -46,7 +46,7 @@ class CBlob friend class myCompLabeler; public: CBlob(); - CBlob( t_labelType id, cv::Point startPoint, CvSize originalImageSize ); + CBlob( t_labelType id, cv::Point startPoint, cv::Size originalImageSize ); ~CBlob(); //! Copy constructor @@ -82,7 +82,7 @@ class CBlob m_id=newID; } //! > 0 for extern blobs, 0 if not - int Exterior( IplImage *mask, bool xBorder = true, bool yBorder = true ); + int Exterior( cv::Mat *mask, bool xBorder = true, bool yBorder = true ); //! opencv2 Interface int Exterior( cv::Mat mask, bool xBorder = true, bool yBorder = true ); //Computes the area of the blob. @@ -96,19 +96,19 @@ class CBlob double Moment(int p, int q); //! Compute extern perimeter - double ExternPerimeter( IplImage *mask, bool xBorder = true, bool yBorder = true ); + double ExternPerimeter( cv::Mat *mask, bool xBorder = true, bool yBorder = true ); //! opencv2 interface double ExternPerimeter( cv::Mat mask, bool xBorder = true, bool yBorder = true ); //! Get mean grey color //(Warning: use MeanStdDev for simultaneous computation of mean and std. dev, and for RGB images). - double Mean( IplImage *image ); + double Mean( cv::Mat *image ); //! opencv2 interface //(Warning: use MeanStdDev for simultaneous computation of mean and std. dev, and for RGB images). double Mean( cv::Mat image ); //! Get standard deviation grey color //(Warning: use MeanStdDev for simultaneous computation of mean and std. dev, and for RGB images). - double StdDev( IplImage *image ); + double StdDev( cv::Mat *image ); //! opencv2 interface //(Warning: use MeanStdDev for simultaneous computation of mean and std. dev, and for RGB images). double StdDev( cv::Mat image ); @@ -132,17 +132,17 @@ class CBlob //! Paints the blob in an image //! intContours - determines wheter to draw the holes of the blob (true) or not (false) //! srcImage - image from where to copy the holes contents. If unassigned and intContours is true, the internal pixels will be set to black. - void FillBlob( IplImage *image, CvScalar color, int offsetX = 0, int offsetY = 0, bool intContours = false, const IplImage *srcImage = NULL ); - void FillBlob( cv::Mat image, CvScalar color, int offsetX = 0, int offsetY = 0, bool intContours = false, const cv::Mat srcImage = cv::Mat() ); + void FillBlob( cv::Mat *image, cv::Scalar color, int offsetX = 0, int offsetY = 0, bool intContours = false, const cv::Mat *srcImage = NULL ); + void FillBlob( cv::Mat image, cv::Scalar color, int offsetX = 0, int offsetY = 0, bool intContours = false, const cv::Mat srcImage = cv::Mat() ); //! Joins a blob to current one //! NOTE: All the data is copied, a new blob is created and joined to the caller one. void JoinBlob( CBlob *blob); //! Get bounding box - CvRect GetBoundingBox(); + cv::Rect GetBoundingBox(); //! Get bounding ellipse - CvBox2D GetEllipse(); + cv::RotatedRect GetEllipse(); //! Minimun X double MinX() @@ -226,13 +226,13 @@ class CBlob //! Standard deviation from gray color blob distribution double m_stdDevGray; //! Bounding box - CvRect m_boundingBox; + cv::Rect m_boundingBox; //! Bounding ellipse - CvBox2D m_ellipse; + cv::RotatedRect m_ellipse; //! Sizes from image where blob is extracted - CvSize m_originalImageSize; - public: CvSize OriginalImageSize() const { return m_originalImageSize; } + cv::Size m_originalImageSize; + public: cv::Size OriginalImageSize() const { return m_originalImageSize; } public: void OriginalImageSize(int width, int height) { m_originalImageSize.width = width; m_originalImageSize.height = height; } From 6adad394651e21f9671a39e6f454c1537d49513e Mon Sep 17 00:00:00 2001 From: Arshad Khan Date: Thu, 29 Feb 2024 12:13:40 +0000 Subject: [PATCH 3/3] updated example to 4.0 and CMakeList package --- CMakeLists.txt | 2 +- example/main.cpp | 91 ++++++++---------------------------------------- 2 files changed, 16 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96b92cc..a20dc7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(CMAKE_DEBUG_POSTFIX "_d") option(BUILD_SHARED_LIBS "build with shared libraries" OFF) -find_package( OpenCV REQUIRED ) +find_package(OpenCV 4.2.0 REQUIRED ) IF(WIN32) set(PTHREADS_INCLUDE_DIR "" CACHE PATH "Pthreads Include Directory") diff --git a/example/main.cpp b/example/main.cpp index ab462e3..9979383 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -3,7 +3,7 @@ #include #include "blob.h" #include "BlobResult.h" -#include "highgui.h" //include it to use GUI functions. +#include const int NUMCORES = 2; using namespace std; @@ -19,94 +19,33 @@ void testJoin(); void testRandomImage(); //Generate a random image and test blobs. int main(){ -// testTimes(500,3000,250,"TempiHR",20); - //testTimes(1000,1000,20,"TempiLR",40); - //testTimes(10,2000,50,"TempiRandom",15); - //opencvLogo(); - //test(); testJoin(); - //testMio(); - //testRandomImage(); cout <<"Press a key to continue..."<