Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
parkpow
GitHub Repository: parkpow/deep-license-plate-recognition
Path: blob/master/stream/video_upload.py
1089 views
1
import json
2
import logging
3
import os
4
import sys
5
from pathlib import Path
6
7
import requests
8
from gooey import Gooey, GooeyParser
9
10
LOG_LEVEL = os.environ.get("LOGGING", "INFO").upper()
11
12
logging.basicConfig(
13
stream=sys.stdout,
14
level=LOG_LEVEL,
15
format="%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s",
16
)
17
18
19
def stream_api(image_path, args):
20
data = dict(mask_id=args.mask) if args.mask else None
21
22
with open(image_path, "rb") as fp:
23
response = requests.post(args.sdk_url, files=dict(upload=fp), data=data)
24
if response.status_code < 200 or response.status_code > 300:
25
logging.error(response.text)
26
return None
27
else:
28
return response.json()
29
30
31
@Gooey(program_name="Videos Uploader")
32
def main():
33
parser = GooeyParser(
34
description="Upload Videos from a folder to Stream file-upload"
35
)
36
parser.add_argument(
37
"folder", help="Folder containing videos to process.", widget="DirChooser"
38
)
39
40
parser.add_argument(
41
"-m", "--mask", type=str, help="Camera Mask ID to use in the recognition."
42
)
43
44
parser.add_argument(
45
"-s",
46
"--sdk-url",
47
default="http://localhost:8081",
48
help="Url to Stream File Upload Server",
49
)
50
51
args = parser.parse_args()
52
53
# Process files in folder
54
videos_directory = Path(args.folder)
55
with open("output.jsonl", "a") as outfile:
56
for file in videos_directory.iterdir():
57
if file.is_dir():
58
continue
59
logging.info(f"Processing file: {file}")
60
results = stream_api(file, args)
61
logging.info(f"Results:{results}")
62
if results:
63
json.dump(results, outfile)
64
outfile.write("\n")
65
outfile.flush()
66
67
68
if __name__ == "__main__":
69
main()
70
71