我正在尝试使用opencv制作一种波长图像。在大多数情况下,我都做对了,除了一些会在图像中产生条纹的平滑性问题
这是代码
#make ChroMAX torus
#diametre of torus
dia = 1000
#size of steps to circle torus
degstepsize = 360 / dia * pi
#number of steps
degstepno = int(360 / degstepsize)
#a third of degstepno
third = int(degstepno / 3)
#number of steps for 255 in a third
colstep = 255 / third
#making base colour ring
baseCol = []
#blue to green sector
for i in range(third):
baseCol.append((int(colstep * (third - i)),int(colstep * i),0))
#green to red
for i in range(third):
baseCol.append((0,int(colstep * (third - i)),int(colstep * i)))
#red to blue
for i in range(third):
baseCol.append((int(colstep * i),0,int(colstep * (third - i))))
baseCol = tuple(baseCol)
torus = np.ones((degstepno,100,3), np.uint8) * 30
for i in range(len(torus)):
for y in range(100):
torus[i,y] = baseCol[i]
gui.add(cv2imgload(torus),'Torus')
gui.update()
这是图片:
最终,图像将被包裹成甜甜圈。我用圆环的周长而不是360度划分圆环的原因是,我可以确保填充每个像素,因为圆环将从中心抽出(我不确定您是否会理解)