-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
39 lines (29 loc) · 719 Bytes
/
client.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
import cv2
import requests
from dotenv import load_dotenv
import time
import os
load_dotenv()
ip = os.environ.get("SERVER_IP")
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 640)
cap.set(cv2.CAP_PROP_FPS, 36)
def infer(i):
ret, img = cap.read()
if not ret:
return
img = cv2.rotate(img, cv2.ROTATE_180)
retv, buf = cv2.imencode(".jpg", img)
result = requests.post(f"http://{ip}:8000", files={'file': buf}).json()
try:
if result[0][0]['confidence'] > 0.7:
cv2.imwrite(f"save{i}.jpg", img)
print(i, result)
except:
pass
i = 0
while True:
infer(i)
time.sleep(1)
i += 1