Salome HOME
BUG: Shape recognition: Fixed some memory leaks
authorrnc <rnc@opencascade.com>
Fri, 6 Dec 2013 17:54:22 +0000 (17:54 +0000)
committerrnc <rnc@opencascade.com>
Fri, 6 Dec 2013 17:54:22 +0000 (17:54 +0000)
src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx
src/EntityGUI/EntityGUI_FeatureDetectorDlg.h
src/ShapeRecognition/ShapeRec_FeatureDetector.cxx

index cbb5645fded338fc123f0a8c7a71888c40028e25..de72d17c3dcdd2cf04be5e01580bcfaed5ddb96a 100644 (file)
@@ -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 = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
-  if (setSelectionRect() && aDetector->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<cv::Point> >   contours  = aDetector->GetContours();
-      std::vector<cv::Vec4i>                  hierarchy = aDetector->GetContoursHierarchy();
+      myDetector->ComputeContours( useROI, parameters );
+      std::vector< std::vector<cv::Point> >   contours  = myDetector->GetContours();
+      std::vector<cv::Vec4i>                  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<cv::Vec4i>  lines = aDetector->GetLines();
+//     myDetector->ComputeLines();
+//     std::vector<cv::Vec4i>  lines = myDetector->GetLines();
 //     GEOM::GEOM_Object_var  Pnt1;
 //     GEOM::GEOM_Object_var  Pnt2;
 //     GEOM::GEOM_Object_var  aLine;
index fdc850d8df8a68c733dcbec46953340213ebe19b..ca0461d5d72389da817fc57c2da78bf44bf8b550 100644 (file)
@@ -84,7 +84,7 @@ private slots:
   
   
 private:
-  ShapeRec_FeatureDetector*          aDetector;
+  ShapeRec_FeatureDetector*          myDetector;
   
   gp_Ax3                             myWPlane;
   gp_Ax3                             aGlobalCS;
index b61f4bc905df5426ecab7c578b9b7840a99ca210..2bf97cb55c573af73854cbdb264f9ea6b6a4aa8a 100644 (file)
@@ -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";
 }