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;
+ }
}
/*!
}
}
+/*!
+ 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
// 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);
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; };
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;