1 | initial version |
first - try to avoid per-pixel loops. opencv is a highly optimized vector/matrix library. kittens will be killed, whenever you attempt something like above. it could be a plain:
Mat image = imread(s);
Mat gray; // NO preallocation.
cvtColor(image, gray, COLOR_BGR2GRAY);
// done.
// gray holds grayscale image of original size.
then : almost anything in your loop construct is illegal. don't try to be smart there, you have to play by the rules first !
for (int r=0; r<image.rows; r++)
for (int c=0; c<image.cols; c++)
{
Vec3b pix = image.at<Vec3b>(r,c); // row,col ! correct type !
gray.at<uchar>(r,c) = some_operation_with(pix);
}
please have a look at the most basic tutorials