I was trying to read red pixel values of an part of the image using opencv

# if it is BGR
b = health_bar[:, :, 0]
g = health_bar[:, :, 1]
r = health_bar[:, :, 2]

ImageGrab (PIL/pillow) returns RGB order data, that you’re (needlessly) converting to BGR for OpenCV’s consumption.

spare the cvtColor, directly get the red channel:

screen_rgb = np.array(ImageGrab.grab(bbox=(0,0,1920,1080))) # RGB order
health_bar_rgb = screen_rgb[970:990, 800:900]
r = health_bar_rgb[:, :, 0]

if you need to show anything using cv.imshow, then yes, cvtColor with cv.COLOR_RGB2BGR makes sense to convert the data you received from ImageGrab.

1 Like