vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
src.copyTo( dst, detected_edges);
imshow( window_name, dst );
imwrite ("Canny.png", dst);
image=imread ("Canny.png");
Mat converted (image.rows, image.cols, CV_8UC1);
Mat dat (image.rows, image.cols, CV_8UC1, Scalar ::all(0));
cvtColor(image, converted, COLOR_BGR2GRAY,1);
dilate(converted, converted, Mat(), Point(-1.5,-1.5));
threshold (converted, converted,25, 255, THRESH_BINARY);
//findContours (converted, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
findContours (converted, contours,hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
// Mat drawing =Mat::zeros (converted.size(), CV_8UC3);
for (int i=0; i<contours.size(); i++)
{
double a= contourArea (contours[i], false);
if(a>largest_area)
{
largest_area=a;
largest_contour_index=i;
bounding_rect=boundingRect (contours[i]);
}
}
Scalar color (255,255,255);
drawContours (dat, contours, largest_contour_index, color, CV_FILLED,8,hierarchy);
rectangle (image, bounding_rect , Scalar (0,255,0),1,8,0);
imshow("dat", image);
imshow ("largestContour", dat);
imwrite("largestContour.png", image);
imwrite("dat.png", dat);