Ask Your Question

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

asked 2017-08-08 14:59:49 -0500

m3rt gravatar image

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?

Thanks in advance.

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

edit retag flag offensive close merge delete


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

vps gravatar imagevps ( 2017-08-08 16:34:48 -0500 )edit

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

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

2 answers

Sort by ยป oldest newest most voted

answered 2017-08-09 01:28:20 -0500

berak gravatar image

updated 2017-08-09 01:49:23 -0500

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:


to get a single hex value from that:

hex = (color[0] << 16) + (color[1] << 8) + (color[2])
edit flag offensive delete link more


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

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

answered 2017-08-08 21:51:53 -0500

Ziri gravatar image

updated 2017-08-08 22:05:03 -0500

If you're using Mat and image is gray

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

if you're dealing with color images

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

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

Hope it helps.

edit flag offensive delete link more


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

m3rt gravatar imagem3rt ( 2017-08-09 04:49:04 -0500 )edit

Question Tools

1 follower


Asked: 2017-08-08 14:59:49 -0500

Seen: 16,100 times

Last updated: Aug 09 '17