Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Image difference

I tried to calculate difference between two images (Canny image and outer contour), but it gave black image. How can I show original difference between two images? Thanks in advance. Here is my code:

int main (...)
{
Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);
 Mat canny_output;  
 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= Mat::zeros( image.size(), CV_8UC1);;
  difference_image=canny_output-contour_image;

  imshow("Difference_image", difference_image); //Produce black image
  cv::waitKey(0);
}