How to find the color at a coordinate?

asked 2019-01-26 15:37:45 -0600

I need to find the colour at a particular coordinate. How could I do this?

For example, I load the image as follows:

import cv2
import math

img = cv2.imread("image.png")

x_ccordinate = math.floor(img.shape[0] / 2)
y_coordinate = math.floor(img.shape[1] / 2)

I need to know the color represented by x_coordinate and y_coordinate. How could I do this?

edit retag flag offensive close merge delete

Comments

BGR in OpenCV

b = img[x_coordinate, y_coordinate, 0]

g = img[x_coordinate, y_coordinate, 1]

r = img[x_coordinate, y_coordinate, 2]
sjhalayka gravatar imagesjhalayka ( 2019-01-26 17:57:55 -0600 )edit
1

^^ wrong. [y,x,c].

berak gravatar imageberak ( 2019-01-26 19:23:15 -0600 )edit
1

Sorry about that.

sjhalayka gravatar imagesjhalayka ( 2019-01-26 19:24:05 -0600 )edit

@Mahajan, wrong, too. img.shape is [h,w,channels]

berak gravatar imageberak ( 2019-01-26 19:25:18 -0600 )edit