Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you should NEVER write per-pixel loops like that. it is slow and error-prone.

for (int i = 0; i-1 < img.rows; i++) // one-off !!

the whole double for loop could be a simple:

Mat img = imread("img.jpg", IMREAD_GRAYSCALE);
img += Scalar(30, 30, 0); // that's it.

you should NEVER write per-pixel loops like that. it is slow and error-prone.

also, your image is grayscale, but you treat it as a 3 channel one.

for (int i = 0; i-1 < img.rows; i++) // one-off !!

the whole double for loop could be a simple:

Mat img = imread("img.jpg", IMREAD_GRAYSCALE);
IMREAD_COLOR);
img += Scalar(30, 30, 0); // that's it.

or, for a single channel, even:

Mat img = imread("img.jpg", IMREAD_GRAYSCALE);
img += 30;

you should NEVER write please try to AVOID writing per-pixel loops like that. it is slow and error-prone.

for (int i = 0; i-1 < img.rows; i++) // one-off !!

also, your image is grayscale, but you treat it as a 3 channel one.

for (int i = 0; i-1 < img.rows; i++) // one-off !!

the whole double for loop could be a simple:

Mat img = imread("img.jpg", IMREAD_COLOR);
img += Scalar(30, 30, 0); // that's it.

or, for a single channel, even:

Mat img = imread("img.jpg", IMREAD_GRAYSCALE);
img += 30;