main
luanhailiang 2023-09-22 12:01:37 +08:00
parent e4eda48b02
commit 943b9dfbc7
3 changed files with 14 additions and 7 deletions

13
app.py
View File

@ -43,6 +43,10 @@ def stop(id):
def show():
# print(request.json)
data = request.json["content"]
info(data)
return 'ok'
def info(data):
balls = data["balls"]
table = data["table"]
text = f"table:{table:>3} "
@ -50,7 +54,6 @@ def show():
ball = "#" if "ball"+str(i) in balls else " "
text += f"| {i} : {ball} "
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'),text)
return 'ok'
def worker(id,source,region=None,stream=False):
if region == None:
@ -111,7 +114,9 @@ def worker(id,source,region=None,stream=False):
names = {}
if count < region:
continue
json_data = json.dumps({"table":id,"balls":balls,"time":int(time.time()*1000)})
data = {"table":id,"balls":balls,"time":int(time.time()*1000)}
info(data)
json_data = json.dumps(data)
balls = {}
count = 0
if not stream:
@ -135,10 +140,10 @@ def workerloop(stop_event,id,source,target=None,region=None):
"Content-Type": "application/json"
}
text = json.dumps({"content":json_data})
print(text)
# print(text)
response = requests.post(target, data=text, headers=headers)
print(response.text)
# print(response.text)
finally:
gen.close()

View File

@ -1,8 +1,8 @@
version: '3'
services:
billiard:
# command: ["python", "./app.py"]
command: ["gunicorn", "app:app", "--bind", "0.0.0.0:5000", "--timeout", "0", "--workers", "1"]
command: ["python", "./app.py"]
# command: ["gunicorn", "app:app", "--bind", "0.0.0.0:5000", "--timeout", "0", "--workers", "1"]
restart: always
build: .
volumes:

View File

@ -1,6 +1,7 @@
import cv2
import json
import time
import logging
import requests
import supervision as sv
@ -23,6 +24,7 @@ def show():
text += f"| {i} : {ball} "
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'),text)
return 'ok'
if __name__ == '__main__':
app.logger.setLevel(logging.ERROR)
app.run("0.0.0.0",threaded=True)