简体   繁体   English

无法获取正确的像素颜色图像python

[英]Cannot get correct pixel color image python

I am using OpenCV 3 on MacOS and all I am trying to get the RGB values of pixels in an image. 我在MacOS上使用的是OpenCV 3,我正在尝试获取图像中像素的RGB值。

For example, I am using the following image: 例如,我正在使用以下图像:

在此处输入图片说明

I've made a program that detects the click of the user in the image and outputs the RGB color using the x,y coordinates of the click, but apparently when I was clicking in some regions of the circles, I was getting an incorrect value. 我已经制作了一个程序,可以检测用户在图像中的点击,并使用点击的x,y坐标输出RGB颜色,但是显然当我在圆圈的某些区域中点击时,我得到的值不正确。 For example: When I click inside the blue circle, let's say on the point (177,340) of the image, it outputs the value (255,255,255), which is definitely incorrect. 例如:当我在蓝色圆圈内单击时,假设在图像的点(177,340)上,它输出的值(255,255,255)绝对不正确。

But when I click a bit to the right or left, it outputs the correct value: (17, 51, 225). 但是,当我单击左右一点时,它会输出正确的值:(17,51,225)。 This happens for the whole image, 整个图片都会这样,

I was suspecting it was something related to the scale, and then I just opened the image on python and got the value of the pixel using the following code: 我怀疑这与比例有关,然后我在python上打开了图像,并使用以下代码获取了像素值:

import cv2
import numpy as np

img = cv2.imread('circles.jpg', 1)
print(img[177,340])

But still, what I get is this: 但是,我得到的是:

array([255, 255, 255], dtype=uint8)

I suspect it's something related to the coordinates system that I am not aware of. 我怀疑这与我不了解的坐标系有关。 Can someone give me a hand about it? 有人可以帮我一下吗?

Thanks in advance. 提前致谢。

I drawed the point [177,340] in magenta (255,0,255) to your image as the code below. 我将紫红色(255,0,255)的点[177,340]到您的图像上,如下所示。

image[175:179,338:342] = (255,0,255) # enlarge a bit for easy viewing

It's clearly showed in the image that the point is located in the white background. 在图像中清楚地显示出该点位于白色背景中。

在此处输入图片说明

Likely, you coded the (row,col) incorrectly as (col,row) so that you get color [17,51,225] which is the "orange and biggest circle" in your image instead of [244,70,18] which is the "blue circle". 可能是,您将(row,col)错误地编码为(col,row)从而使颜色[17,51,225]成为图像中的“橙色和最大圆圈”,而不是[244,70,18] “蓝色圆圈”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM