![](/img/trans.png)
[英]How do you move the mouse to all of the blue pixels on the screen's x y values averaged
[英]How to change the color of the x and y pixels to blue?
import numpy as np
import cv2
img = np.ones((400, 400,3),np.uint8)*255
circle = np.ones((400, 400))*255
for theta in np.arange(0, 2*np.pi, 0.01):
for r in np.arange(150, 160, 1):
x = 200 + r * np.cos(theta)
y = 200 + r * np.sin(theta)
circle[int(x)][int(y)] = 0
cv2.imshow('c',circle)
这给出了 output:
如何将这些黑色像素的 colors 更改为蓝色? 如果我做
circle[int(x)][int(y)] = (255,0,0)
它给出了一个错误,说"setting an array element with a sequence."
您的circle
不是 3D 数组,而是二维数组( (400, 400)
),因此没有 RGB 维度。 尝试使其成为 3D 阵列。
circle = np.ones((400, 400, 3))*255
然后,你将能够做到
circle[int(x)][int(y)] = [255,0,0]
因为你的阵列是二维的,所以你的 colors 只能是灰度的。 太修复它,为数组的形状添加另一个维度:
import numpy as np
import cv2
img = np.ones((400, 400, 3), np.uint8) * 255
circle = np.ones((400, 400, 3)) * 255
使用 numpy arrays,您可以使用逗号进行嵌套切片:
for theta in np.arange(0, 2*np.pi, 0.01):
for r in np.arange(150, 160, 1):
x = 200 + r * np.cos(theta)
y = 200 + r * np.sin(theta)
circle[int(x), int(y)] = 255, 0, 0
cv2.imshow('c',circle)
最后,不要做np.ones((400, 400, 3)) * 255
,你可以做np.full((400, 400, 3), 255)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.