Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I change the code following way, but it gave only outer contour output. I think output should be inner contour because I subtract contour_image from canny_output.

int main (...)
{
Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);
 Mat canny_output= Mat::zeros( image.size(), CV_8UC1);  
 vector<vector<cv::Point> > contours;
 vector<Vec4i> hierarchy;

 Canny(image, canny_output, 50, 200);

 findContours (image,  contours ,  hierarchy ,  cv :: RETR_EXTERNAL ,  cv :: CHAIN_APPROX_SIMPLE );

 Mat contour_image = Mat::zeros( image.size(), CV_8UC1);
for(int k= 0; k < contours.size(); k++)
{
    for(int l= 0; l < contours[k].size();l++)
    {
      contour_image.at<uchar>(contours[k][l])=255; 
    }
}
  Mat difference_image;
 absdiff( canny_output,contour_image, difference_image);

  imshow("Difference_image", difference_image); //Produce output same as contour_image
  cv::waitKey(0);
}