圆的RGB平均值 [英] RGB average of circles

查看:96
本文介绍了圆的RGB平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python中使用OpenCV和PIL.我检测到96个圆圈,它们的中心 坐标半径.我需要每个圆圈的平均RGB.

I'm using OpenCV and PIL in Python. I have 96 circles detected with their center coordinates and radios. I need the average RGB from each circles.

每个圆圈有6000个像素,所以我认为一遍一遍地迭代效率不高.

Each circle has 6000 pixels, so I thinks iterate one to one it is not efficient.

如何从每个圆中提取平均RGB? 如果适合我的用例,我准备使用其他任何库.

How can I extract the average RGB from each circle? I am ready to use any other library if it suits my use-case.

推荐答案

最后我明白了,这是解决方案:

Finally I get it, this is the solution:

circle_img = np.zeros((color_img.shape[0],color_img.shape[1]), np.uint8) #Creamos mascara (matriz de ceros) del tamano de la imagen original
cv2.circle(circle_img,(x_center,y_center),radio,(255,255,255),-1) #Pintamos los circulos en la mascara
datos_rgb = cv2.mean(color_img, mask=circle_img)[::-1]

这篇关于圆的RGB平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆