Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

please do not abuse Mat::at to write whole images, it is a random access operator.

you also have to use the correct type, if your image has 3 channels, it needs to be: img.at<Vec3b> (NOT uchar)

better idea here, if you wanted to draw a grid, use builtin drawing functions like line():

for (int i = 0; i < img.rows; i+=20)
    line(img, Point(0,i), Point(img.cols-1, i), Scalar(255,0,0), 1);

for (int j = 0; j < img.cols; j++)
    line(img, Point(j,0), Point(j, img.rows-1), Scalar(255,0,0), 1);

please do not abuse Mat::at to write whole images, it is a random access operator.

you also have to use the correct type, if your image has 3 channels, it needs to be: img.at<Vec3b> (NOT uchar)

better idea here, if you wanted to draw a grid, use builtin drawing functions like line():

for (int i = 0; i < img.rows; i+=20)
    line(img, Point(0,i), Point(img.cols-1, i), Scalar(255,0,0), 1);

for (int j = 0; j < img.cols; j++)
j+=20)
    line(img, Point(j,0), Point(j, img.rows-1), Scalar(255,0,0), 1);