# How to find pixel's (with coordinates specified) color values?

Hello, everyone!

I need to get color values(HEX) of specific pixels from live video capture. I have used simpleBlobDetector to get coordinates with Python. How can I do it?

Note: I am kinda new to opencv and forum. If I had ask question in not a proper way, please warn.

edit retag close merge delete

Do you want to find the pixel value with coordinates by clicking on it?

( 2017-08-08 16:34:48 -0500 )edit

Not by clicking, coordinates come from blob detector as keypoints for x and y axis.

( 2017-08-09 01:52:10 -0500 )edit

Sort by ยป oldest newest most voted

it is probably easier, than you thought:

in python, images are just numpy arrays, so you could access a single pixel at x,y like:

color = image[y,x] # row major, like in opencv


given a bgr image (3 channels), you'll recieve a tuple, such as:

(12,156,222)

to get a single hex value from that:

hex = (color[0] << 16) + (color[1] << 8) + (color[2])

more

It's really easy than my thought. Thank you, it works!

( 2017-08-09 04:47:24 -0500 )edit

If you're using Mat and image is gray

You can use : pixel value = image.at<unsigned char="">(cv::Point(x,y)) ;

if you're dealing with color images

channel1_value = image.at<vec3b>(cv::Point(x, y))[0] ;

Then pass your coordinates to Point(x,y).

Hope it helps.

more

Thanks for your response. I think your answer is valid for C language, I was looking for Python.

( 2017-08-09 04:49:04 -0500 )edit

Official site

GitHub

Wiki

Documentation