# 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(..)
{

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 close merge delete

Sort by » oldest newest most voted
// 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;

more

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?

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;

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 121 times

Last updated: Dec 05 '13