Python OpenCV像素颜色完全相同
我需要第二只眼睛在我的代码,得到一个圆圈的颜色中心。由于某种未知的原因,它返回的每个中心的值几乎相同,这是远远不正确的。圆圈的结果: 中心颜色: [126 126 126] 指向 x:502 y:440 中心色 [124 124 124] 指向 x:502 y:516 中心色 [133 133 133] 指向 x:502 y:596 中心色 [116 116 116] 指向 x:504 y:306 中心色 [119 119 119] 指向 x:504 y:366 输入图像如下所示。显然,应该有非常不同的值,因为黑圈的平均RBG应该远低于100范围 下图显示代码正确地找到了圆和圆的中心(用绿色标记),但没有找到正确的中心颜色值 代码如下:Python OpenCV像素颜色完全相同,python,opencv,image-processing,Python,Opencv,Image Processing,我需要第二只眼睛在我的代码,得到一个圆圈的颜色中心。由于某种未知的原因,它返回的每个中心的值几乎相同,这是远远不正确的。圆圈的结果: 中心颜色: [126 126 126] 指向 x:502 y:440 中心色 [124 124 124] 指向 x:502 y:516 中心色 [133 133 133] 指向 x:502 y:596 中心色 [116 116 116] 指向 x:504 y:306 中心色 [119 119 119] 指向 x:504 y:366 输入图像如下所示。显然,应该有非
import cv2
import numpy as np
from math import sqrt
# Open
img = cv2.imread('test1.jpg',0)
# Process
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
# Find Interest
circles = cv2.HoughCircles(img,cv2.cv.CV_HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=1,maxRadius=20)
circles = np.uint16(np.around(circles))
# Post Process
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
print "Center Colour"
print cimg[i[0], i[1]]
print "Point"
print "x: "+str(i[0]) + " y: " + str(i[1])
cv2.imwrite('output.png',cimg)
根据我的理解,你应该得到内圈的颜色,因为你是在访问颜色值之前绘制的。但由于返回的值不是0、0、255,因此必须交换坐标 原版印刷品为:
print "Center Colour (orig)", cimg[i[0], i[1]]
print "Center Colour (swapped)", cimg[i[1], i[0]]
交换打印是:
print "Center Colour (orig)", cimg[i[0], i[1]]
print "Center Colour (swapped)", cimg[i[1], i[0]]
绘图后输出:
Center Colour (orig) [126 126 126]
Center Colour (orig) [116 116 116]
...
Center Colour (swapped) [ 0 0 255]
Center Colour (swapped) [ 0 0 255]
...
如果现在在绘制内圈之前使用交换打印,输出将如下所示:
Center Colour (swapped) [128 128 128]
Center Colour (swapped) [27 27 27]
...
这就是你要找的吗?是的。非常感谢你,我知道这一定很简单。非常感谢。