I’m trying to display a video stream from my Raspberry Pi camera onto my Anvil webapp.
I can do the following to display a static image from the camera:
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.image_1.source = anvil.server.call('takepic')
What I would instead like to do is something like:
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.image_1.source = anvil.server.call('startmovie')
But of course Anvil is expecting to receive a file from the startmovie() function, rather than a BytesIO object, so I get the following error:
anvil.server.SerializationError: Cannot serialize return value from function. Cannot serialize <class '_io.BytesIO'> object at msg['response']
at Form1, line 12
Did you ever find solution for this ? I am also trying to video stream on anvil but stuck with same error.
If you found a solution to this can you please share code
Thank you for this.
Actually I am trying to make a face recognition app on anvil . I am trying to capture frames using cv2 and then using face recognition library for face comparing and detection and I want to stream those frames in anvil in continuous series but problem I am facing is that it is taking a lot time to switch from one frame to other . It is not displaying as a face detection app but rather displaying those detected frames one by one after some interval.
One of the reasons why open-cv / CV2 is fast is that it is written in C++ and accessible in python through CPython, in your search for a solution keep in mind that:
The more round trips and conversions between physical systems you have, the greater lag your code will experience.
Most browsers only natively run javascript, html, php, and WASM / webassembly . (I’m sure i’m forgetting some less used ones, JAR containers I dunno?)
So if you want to skip sending streaming video back and forth or at least use the browser to draw bounding boxes directly on the screen, I would research implementations of CV2 support in the browser, I think Rust compiles to WASM? Not sure if it has implemented CV2.
Edit:
Maybe this is even an option to be used with anvil: