Ask Your Question

Revision history [back]

You don't have to give the x,y coordinates as Point. Just give the x,y values.

int main()
    {
        int pixel_value1 = 0, pixel_value2 = 0;
        Mat image = Mat(100, 100, CV_8UC1, cv::Scalar(127));

        pixel_value1 = image.at<uchar>(10, 10);//if you know the position of the pixel
        cout << "pixel_value1: " << pixel_value1 << endl;

        for (int x = 0;x < image.rows; x++)//To loop through all the pixels
        {
            for (int y = 0; y < image.cols; y++)
            {
                pixel_value2 = image.at<uchar>(x,y);

                cout << "pixel_value2: " << pixel_value2 << endl;
            }
        }

        return 0;
    }

You don't have to give the x,y coordinates as Point. Just give the x,y values.

int main()
    {
        int pixel_value1 = 0, pixel_value2 = 0;
        Mat image = Mat(100, 100, CV_8UC1, cv::Scalar(127));
Scalar(127));

        pixel_value1 = image.at<uchar>(10, 10);//if you know the position of the pixel
        cout << "pixel_value1: " << pixel_value1 << endl;

        for (int x = 0;x < image.rows; x++)//To loop through all the pixels
        {
            for (int y = 0; y < image.cols; y++)
            {
                pixel_value2 = image.at<uchar>(x,y);

                cout << "pixel_value2: " << pixel_value2 << endl;
            }
        }

        return 0;
    }