我试图通过查看相邻像素从 alpha 通道掩码中删除杂散的白色像素,但一直在获取 TypeEror: 'numpy.ndarray' object is not callable 我使用 pygame.surfarray: 创建了一个数组:
alphachannel3d = pygame.surfarray.pixels3d(alphachannel)
然后尝试逐步通过它并将像素值从白色更改为黑色:
if (alphachannel3d[x] == (0, 0, 0)) & (alphachannel3d[x + 3] == (255, 255, 255)) & (alphachannel3d[x -3]==(255, 255, 255)):
alphachannel3d[x] = (255, 255, 255)
这是循环:
x=1
while 1:
count = x
print 'count is', count
print 'waiting 5 seconds'
pygame.time.wait(5000)
img = cam.get_image()
imgarray = pygame.PixelArray(img)
alphachannelarray = basearray.compare(imgarray, distance=0.09, weights=(0.01, 0.01, 0.01))
alphachannel = alphachannelarray.make_surface()
alphachannel3d = pygame.surfarray.pixels3d(alphachannel)
if (alphachannel3d[x] == (0, 0, 0)) & (alphachannel3d[x + 3] == (255, 255, 255)) & (alphachannel3d[x -3]==(255, 255, 255)):
alphachannel3d[x] = (255, 255, 255)
alphachannel = pygame.surfarray.make_surface(alphachannel3d)
srfcScreen.blit(alphachannel, (0,0))
print 'screen blitted'
pygame.display.flip()
print 'display flipped'
x = x+1