-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (34 loc) · 1.11 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import cv2
import uvicorn
import resvg_python
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
from src.svg.model import Model
from src.tracking.tracking import Tracking
app = FastAPI()
async def fake_video_streamer():
vid = cv2.VideoCapture(0)
try:
with open("tests/models/face.svg", "r") as model_file:
tracking = Tracking()
model = Model(model_file.read())
tracking.set_model(model)
while True:
ret, frame = vid.read()
if not ret:
break
tracking.process(frame)
buffer = resvg_python.svg_to_png(model.tostring())
yield (
b"--frame\r\n"
b"Content-Type: image/png\r\n\r\n" + bytearray(buffer) + b"\r\n"
)
finally:
vid.release()
@app.get("/")
async def video_stream():
return StreamingResponse(
fake_video_streamer(), media_type="multipart/x-mixed-replace;boundary=frame"
)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)