-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_server.py
59 lines (44 loc) · 1.26 KB
/
web_server.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from vidgear.gears import VideoGear
from vidgear.gears import NetGear
from vidgear.gears import ScreenGear
from vidgear.gears.asyncio import WebGear
from vidgear.gears.asyncio.helper import reducer
import cv2
import uvicorn
import asyncio
options = {
'copy': False,
'track': False
}
options_webgear = {
'frame_size_reduction': 1,
'frame_jpeg_quality': 100,
'frame_jpeg_optimize': True,
'frame_jpeg_progressive': False
}
client = NetGear(
# address='192.168.11.145', # school network
address='192.168.11.137', # home network
port='5454',
pattern=2,
receive_mode=True,
logging=True,
protocol='tcp',
**options
)
web = WebGear(logging=True, **options_webgear)
async def frame_producer():
stream = ScreenGear().start()
while True:
frame = client.recv()
if frame is None:
break
# frame = await reducer(frame=frame, percentage=30)
encoded_image = cv2.imencode(ext='.jpg', img=frame)[1].tobytes()
yield (b"--frame\r\nContent-Type:video/jpeg2000\r\n\r\n" + encoded_image + b"\r\n")
await asyncio.sleep(0.00001)
stream.stop()
web.config['generator'] = frame_producer
uvicorn.run(app=web(), host='localhost', port=8000)
web.shutdown()
cv2.destroyAllWindows()