Ask Your Question
0

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

asked 2013-12-05 05:22:13 -0600

Nihad gravatar image

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

berak gravatar image

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);

}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-12-05 05:29:09 -0600

berak gravatar image

updated 2013-12-05 05:29:56 -0600

// since the Mat's type is CV_8UC1, you have to use uchar. you can't choose it at will

contour_image.at<uchar>(y1,x1)=255;
edit flag offensive delete link more

Comments

Thanks it works. Novice question: in computer vision, we use contour_image.at<uchar><y,x> where y is row and x is col. So contours[k][l].x is row or col?

Nihad gravatar imageNihad ( 2013-12-05 05:36:06 -0600 )edit

contours[k] is a vector of Points, ( one contour )

contours[k][l] is a Point,

x is col, like you said before. (would 'horizontal' be more helpful ?)

you could also write:

contour_image.at<uchar>( contours[k][l] ) = 255;

berak gravatar imageberak ( 2013-12-05 05:41:26 -0600 )edit

Thanks works fine.

Nihad gravatar imageNihad ( 2013-12-05 05:46:31 -0600 )edit

Question Tools

Stats

Asked: 2013-12-05 05:22:13 -0600

Seen: 206 times

Last updated: Dec 05 '13