Back to index

salome-geom  6.5.0
ShapeRec_FeatureDetector.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : ShapeRec_FeatureDetector.h
00024 // Author : Renaud NEDELEC, Open CASCADE S.A.S.
00025 
00026 // OpenCV includes
00027 #include <cv.h>
00028 #include <highgui.h>
00029 #include "opencv2/imgproc/imgproc.hpp"
00030 #include "opencv2/highgui/highgui.hpp"
00031 
00032 // Qt
00033 #include <QRect>
00034 
00035 enum              // Method used for contour detection
00036 {
00037   CANNY,
00038   COLORFILTER,
00039   RIDGE_DETECTOR
00040 };
00041 
00042 class ShapeRec_FeatureDetector
00043 {
00044 public:
00045   
00046   typedef std::vector<cv::Point>               CvContour;
00047   typedef std::vector<std::vector<cv::Point> > CvContoursArray;
00048   
00049   ShapeRec_FeatureDetector();                                            // Constructor
00050   
00051   void                    SetPath( const std::string& );                 // Sets the image path
00052   void                    SetROI( const QRect& );                        // Sets a Region Of Interest in the image
00053   CvPoint2D32f*           GetCorners()           { return corners;     };
00054   CvContoursArray         GetContours()          { return contours;    };
00055   std::vector<cv::Vec4i>  GetLines()             { return lines;       };
00056   std::vector<cv::Vec4i>  GetContoursHierarchy() { return hierarchy;   };
00057   int                     GetCornerCount()       { return cornerCount; };
00058   int                     GetImgHeight()         { return imgHeight;   };
00059   int                     GetImgWidth()          { return imgWidth;    };
00060   
00061   std::string             CroppImage();
00062   void                    ComputeCorners();                              // Detects the corners from the image located at imagePath
00063   bool                    ComputeLines();                                // Detects the lines from the image located at imagePath
00064   bool                    ComputeContours( int method );                 // Detects the contours from the image located at imagePath
00065   
00066   
00067 private:
00068   std::string             imagePath;
00069   
00070   CvPoint2D32f*           corners;
00071   int                     cornerCount;
00072   
00073   CvContoursArray         contours;
00074   std::vector<cv::Vec4i>  hierarchy;
00075   std::vector<cv::Vec4i>  lines;
00076   int                     imgHeight;
00077   int                     imgWidth; 
00078   CvRect                  rect;
00079   
00080   void                    _detectAndRetrieveContours( cv::Mat binaryImg );
00081   cv::Mat                 _colorFiltering();
00082 };