Ask Your Question
0

How to Print Pixel Color Value C++

asked 2017-06-30 02:59:01 -0600

jjabaram gravatar image

updated 2017-06-30 03:00:02 -0600

I have image with all value is 127(grey), and I want to try to pick one of coordinate and print pixel value, value must return 127.

printf("%d ", nom1.at<uchar>(Point(0, 0)));

but its give me an error . My purpose is to get each pixel color value and print it.

Thank you.

edit retag flag offensive close merge delete

Comments

What's the pixel type of nom1?

KjMag gravatar imageKjMag ( 2017-06-30 09:31:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-30 04:51:49 -0600

updated 2017-06-30 04:54:21 -0600

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, 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;
    }
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-30 02:59:01 -0600

Seen: 5,671 times

Last updated: Jun 30 '17