-1

I have a pygame game that is training a Neural Network. I would like to show this process on a web app without any interaction between the user / client and the game. Is it possible to retrieve the pygame video data and stream it to a html canvas or something similar?

  • am currently using flask as a back-end to serve the html pages
Finn Formica
  • 86
  • 1
  • 7

1 Answers1

0

Generally speaking you can use pygame.image.save on your window object inside the loop.

window = pygame.display.set_mode(...)
...
pygame.image.save(window, "window.bmp")

Then you can stream the images to various ends to create or stream video. That video can be shown in a web page with a delay. Also your process will be much slower than usual, of course.

Sanxofon
  • 759
  • 9
  • 20
  • Thank you very much for your answer! This makes a lot of sense, however, how would i pass that "window.bmp" file through the web page in real-time (or with a slight delay) – Finn Formica Jun 08 '22 at 23:34
  • So I have managed to save an image and load it into the web page through flask, however, the web page won't load until the game loop is complete which means that there is no video, do you have any idea how to get around this? any help is greatly appreciated ty :) – Finn Formica Jun 09 '22 at 01:30
  • 1
    @finn-formica Sorry for not answering before, something came up. The thing is that you are trying to overwrite the same image name. Try adding an index number to the image name (if you want to crate many images in a folder) or better yet, try using a server/client logic with **CV2** and **VidGear** to stream each frame to a server. You can learn more and see a working example from [this answer](https://stackoverflow.com/a/57204769/4146962). Hope it helps! – Sanxofon Jun 09 '22 at 21:12