I'm working with game based on Pygame. In the abstract - I need to run it in headless mode. By now, I'm using:
os.environ['SDL_VIDEODRIVER'] = 'dummy'
And the problem is, that I can't take the screen from game to NumPy array. The one solution which I found actually works, but only with saving the image to the file, what totally misses the point - but maybe it is a hint. I've tried things like parsing Surface to string:
pil_string_image = pygame.image.tostring(screen,"RGBA",False)
im = Image.frombytes("RGBA",(400, 400), pil_string_image)
cv2.imshow('screen', np.asarray(im))
but afterall I've got only grey screen and that's all.
The reason is, that I need to prepare the game to run in Collab or in text env because I'm doing ML things using game screen.
Is there any way to take the screen properly? Or maybe I could trigger the headless mode in another way, which lets me take image simply like that?
pygame.surfarray.array3d(pygame.display.get_surface())