From: rnc Date: Fri, 6 Dec 2013 17:54:22 +0000 (+0000) Subject: BUG: Shape recognition: Fixed some memory leaks X-Git-Tag: V7_3_0~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=50ac82e2bea7ffc46669091d702cccdaaad04ac4;p=modules%2Fgeom.git BUG: Shape recognition: Fixed some memory leaks --- diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx index cbb5645fd..de72d17c3 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx @@ -327,7 +327,7 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom // mainFrame()->GroupBoxName->hide(); // Build an instance of detection used to perform image processing operations - aDetector = new ShapeRec_FeatureDetector(); + myDetector = new ShapeRec_FeatureDetector(); setHelpFileName( "shape_recognition_page.html" ); @@ -341,7 +341,7 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom //================================================================================= EntityGUI_FeatureDetectorDlg::~EntityGUI_FeatureDetectorDlg() { - + delete myDetector; } //================================================================================= @@ -447,9 +447,9 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() return ; // Setting the image caracteristics - aDetector->SetPath( theImgFileName ); - height = aDetector->GetImgHeight(); - width = aDetector->GetImgWidth(); + myDetector->SetPath( theImgFileName ); + height = myDetector->GetImgHeight(); + width = myDetector->GetImgWidth(); pictureLeft = -0.5 * width; // X coordinate of the top left corner of the background image in the view pictureTop = 0.5 * height; // Y coordinate of both top corners @@ -674,7 +674,7 @@ void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt) { myEndPnt = theEndPnt; MESSAGE("myEndPnt = ("<GetImgHeight() > 0) + if (setSelectionRect() && myDetector->GetImgHeight() > 0) showImageSample(); } @@ -705,8 +705,8 @@ bool EntityGUI_FeatureDetectorDlg::setSelectionRect() void EntityGUI_FeatureDetectorDlg::showImageSample() { // Cropp the image to the selection rectangle given by the user - aDetector->SetROI( myRect ); - std::string samplePicturePath = aDetector->CroppImage(); + myDetector->SetROI( myRect ); + std::string samplePicturePath = myDetector->CroppImage(); // Display the result QPixmap pixmap(QString(samplePicturePath.c_str())); @@ -753,9 +753,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) subPictureLeft = pictureLeft; subPictureTop = pictureTop; } - aDetector->ComputeCorners( useROI, parameters ); - CvPoint2D32f* corners = aDetector->GetCorners(); - int cornerCount = aDetector->GetCornerCount(); + myDetector->ComputeCorners( useROI, parameters ); + CvPoint2D32f* corners = myDetector->GetCorners(); + int cornerCount = myDetector->GetCornerCount(); int i; // Build the geom objects associated to the detected corners and returned by execute @@ -794,9 +794,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) { GEOM::GEOM_ICurvesOperations_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() ); - aDetector->ComputeContours( useROI, parameters ); - std::vector< std::vector > contours = aDetector->GetContours(); - std::vector hierarchy = aDetector->GetContoursHierarchy(); + myDetector->ComputeContours( useROI, parameters ); + std::vector< std::vector > contours = myDetector->GetContours(); + std::vector hierarchy = myDetector->GetContoursHierarchy(); std::vector< cv::Point > contour; int idx = 0; @@ -914,8 +914,8 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) // else if(myConstructorId ==LINES) // { -// aDetector->ComputeLines(); -// std::vector lines = aDetector->GetLines(); +// myDetector->ComputeLines(); +// std::vector lines = myDetector->GetLines(); // GEOM::GEOM_Object_var Pnt1; // GEOM::GEOM_Object_var Pnt2; // GEOM::GEOM_Object_var aLine; diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h index fdc850d8d..ca0461d5d 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h @@ -84,7 +84,7 @@ private slots: private: - ShapeRec_FeatureDetector* aDetector; + ShapeRec_FeatureDetector* myDetector; gp_Ax3 myWPlane; gp_Ax3 aGlobalCS; diff --git a/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx b/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx index b61f4bc90..2bf97cb55 100644 --- a/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx +++ b/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx @@ -59,7 +59,8 @@ void ShapeRec_FeatureDetector::SetPath( const std::string& thePath ) { IplImage* src = cvLoadImage(imagePath.c_str(),CV_LOAD_IMAGE_COLOR); imgHeight = src->height; - imgWidth = src->width; + imgWidth = src->width; + cvReleaseImage(&src); } } @@ -227,7 +228,6 @@ bool ShapeRec_FeatureDetector::ComputeContours( bool useROI, ShapeRec_Parameters cvReleaseImage(&sample_h_plane); cvReleaseImage(&sample_s_plane); cvReleaseImage(&input_image); - cvReleaseImage(&input_image); cvReleaseImage(&input_hsv); cvReleaseImage(&input_hplane); cvReleaseImage(&input_splane); @@ -294,6 +294,9 @@ std::string ShapeRec_FeatureDetector::CroppImage() cvSaveImage ("/tmp/cropped_image.bmp", cropped_image); + cvReleaseImage(&src); + cvReleaseImage(&cropped_image); + return "/tmp/cropped_image.bmp"; }