]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
rnc: added a method in FeatureDetector to cropp an image
authorgdd <gdd>
Wed, 23 Nov 2011 14:51:23 +0000 (14:51 +0000)
committergdd <gdd>
Wed, 23 Nov 2011 14:51:23 +0000 (14:51 +0000)
src/ShapeRecognition/ShapeRec_FeatureDetector.cxx
src/ShapeRecognition/ShapeRec_FeatureDetector.hxx

index 532cba0c3d2b934880ac85bdba9da328a120fc58..b9a341e604d78c916b148aa27438996cd1448063 100644 (file)
@@ -38,16 +38,30 @@ using namespace cv;
   Constructor
   \param theFilename - image to process
 */
-ShapeRec_FeatureDetector::ShapeRec_FeatureDetector(const std::string& theFilename): 
+ShapeRec_FeatureDetector::ShapeRec_FeatureDetector(): 
   corners()
 {
   cornerCount = 2000;
   rect=cvRect(0,0,0,0);
-  imagePath = theFilename;
+  imagePath = ""; //theFilename;
   // Store the dimensions of the picture
-  IplImage* bg_img = cvLoadImage (imagePath.c_str(), CV_LOAD_IMAGE_GRAYSCALE);
-  imgHeight = bg_img->height;
-  imgWidth  = bg_img->width; 
+  imgHeight = 0;
+  imgWidth  = 0;
+}
+
+/*!
+  Sets the path of the image file to be proccesed
+  \param thePath - Location of the image file 
+*/
+void ShapeRec_FeatureDetector::SetPath( const std::string& thePath )
+{
+  imagePath = thePath; 
+  if (imagePath != "")
+  {
+    IplImage* src = cvLoadImage(imagePath.c_str(),CV_LOAD_IMAGE_COLOR);
+    imgHeight = src->height;
+    imgWidth = src->width; 
+  }
 }
 
 /*!
@@ -167,6 +181,28 @@ void ShapeRec_FeatureDetector::SetROI( const QRect& theRect )
   }
 }
 
+/*!
+  Crops the image located at imagePath to the region of interest given by the user via SetROI
+  and stores the result in /tmp
+  \param theRect - Region Of Interest of the image located at imagePath 
+*/
+std::string ShapeRec_FeatureDetector::CroppImage()
+{
+  IplImage* src = cvLoadImage(imagePath.c_str(),CV_LOAD_IMAGE_COLOR);
+  cvSetImageROI(src, rect);
+  IplImage* cropped_image = cvCreateImage(cvGetSize(src),
+                                          src->depth,
+                                          src->nChannels);
+  cvCopy(src, cropped_image, NULL);
+  cvResetImageROI(src);
+  
+  cvSaveImage ("/tmp/cropped_image.bmp", cropped_image);
+  
+  return "/tmp/cropped_image.bmp";
+}
+
+
 /*!
   Performs contours detection and store them in contours 
   \param src - src image to find contours of 
@@ -198,8 +234,8 @@ Mat ShapeRec_FeatureDetector::_colorFiltering()
   // Crop the image to build an histogram from the selected part
   cvSetImageROI(find_image, rect);
   IplImage* test_image = cvCreateImage(cvGetSize(find_image),
-                                      find_image->depth,
-                                      find_image->nChannels);
+                                       find_image->depth,
+                                       find_image->nChannels);
   cvCopy(find_image, test_image, NULL);
   cvResetImageROI(find_image);
   
index a56afcbe482a41afd1c6d46735b499da11e8e46a..a3ebeebb24353d56d4a8b1d13425b3e189212908 100644 (file)
@@ -45,12 +45,9 @@ public:
   typedef std::vector<cv::Point>               CvContour;
   typedef std::vector<std::vector<cv::Point> > CvContoursArray;
   
-  ShapeRec_FeatureDetector( const std::string& );                        // Constructor
-  
-  void                    ComputeCorners();                              // Detects the corners from the image located at imagePath
-  bool                    ComputeLines();                                // Detects the lines from the image located at imagePath
-  bool                    ComputeContours( int method );                 // Detects the contours from the image located at imagePath
+  ShapeRec_FeatureDetector();                                            // Constructor
   
+  void                    SetPath( const std::string& );                 // Sets the image path
   void                    SetROI( const QRect& );                        // Sets a Region Of Interest in the image
   CvPoint2D32f*           GetCorners()           { return corners;     };
   CvContoursArray         GetContours()          { return contours;    };
@@ -60,6 +57,11 @@ public:
   int                     GetImgHeight()         { return imgHeight;   };
   int                     GetImgWidth()          { return imgWidth;    };
   
+  std::string             CroppImage();
+  void                    ComputeCorners();                              // Detects the corners from the image located at imagePath
+  bool                    ComputeLines();                                // Detects the lines from the image located at imagePath
+  bool                    ComputeContours( int method );                 // Detects the contours from the image located at imagePath
+  
   
 private:
   std::string             imagePath;