Ask Your Question
0

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

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

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

Comments

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

vps gravatar imagevps ( 2017-08-08 16:34:48 -0600 )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 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
2

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

berak gravatar image

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

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])
edit flag offensive delete link more

Comments

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

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

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

Ziri gravatar image

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

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.

edit flag offensive delete link more

Comments

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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 23,506 times

Last updated: Aug 09 '17