Created
July 13, 2021 16:27
-
-
Save alielbashir/a059aa8999aba2489cee11bdec43e426 to your computer and use it in GitHub Desktop.
Return random image as json frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fastapi import FastAPI | |
| from uvicorn import run | |
| import cv2 | |
| import numpy as np | |
| import base64 | |
| app = FastAPI() | |
| @app.get("/api/video_frame") | |
| async def video_frame(): | |
| buffer = cv2.imencode('.jpg', _get_frame())[1] | |
| frame_as_text = base64.b64encode(buffer) | |
| return {"frame": frame_as_text} | |
| def _get_frame(): | |
| frame = np.random.randint(low=0, high=255, size=(480, 640, 3), dtype='uint8') | |
| return frame | |
| if __name__ == '__main__': | |
| run(app, host="127.0.0.1", port=8001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment