Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How can I mark (white/255) in Mat for contour points?

I want to mark (white/255) in Mat for contour points. I tried following way, but get error.

int main(..)
{
 Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);

vector<vector<cv::Point> > contours;
vector<Vec4i> hierarchy;

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++)
   {
       int x1=contours[k][l].x;
       int y1=contours[k][l].y;
       contour_image.at<int>(y1,x1)=255;///error here
   }
}

  imshow("Contour_image", contour_image);
  cv::waitKey(0);

}

How can I mark (white/255) in Mat for contour points?

I want to mark (white/255) in Mat for contour points. I tried following way, but get error.error. How can I do this? Thanks in advance.

int main(..)
{
 Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);

vector<vector<cv::Point> > contours;
vector<Vec4i> hierarchy;

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++)
   {
       int x1=contours[k][l].x;
       int y1=contours[k][l].y;
       contour_image.at<int>(y1,x1)=255;///error here
   }
}

  imshow("Contour_image", contour_image);
  cv::waitKey(0);

}
click to hide/show revision 3
retagged

updated 2013-12-05 11:16:10 -0600

berak gravatar image

How can I mark (white/255) in Mat for contour points?

I want to mark (white/255) in Mat for contour points. I tried following way, but get error. How can I do this? Thanks in advance.

int main(..)
{
 Mat image = imread("test0.png",CV_LOAD_IMAGE_GRAYSCALE);

vector<vector<cv::Point> > contours;
vector<Vec4i> hierarchy;

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++)
   {
       int x1=contours[k][l].x;
       int y1=contours[k][l].y;
       contour_image.at<int>(y1,x1)=255;///error here
   }
}

  imshow("Contour_image", contour_image);
  cv::waitKey(0);

}