Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
parkpow
GitHub Repository: parkpow/deep-license-plate-recognition
Path: blob/master/stream/video_upload.py
641 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
if args.mask:
21
data = dict(mask_id=args.mask)
22
else:
23
data = None
24
25
with open(image_path, "rb") as fp:
26
response = requests.post(args.sdk_url, files=dict(upload=fp), data=data)
27
if response.status_code < 200 or response.status_code > 300:
28
logging.error(response.text)
29
return None
30
else:
31
return response.json()
32
33
34
@Gooey(program_name="Videos Uploader")
35
def main():
36
parser = GooeyParser(
37
description="Upload Videos from a folder to Stream file-upload"
38
)
39
parser.add_argument(
40
"folder", help="Folder containing videos to process.", widget="DirChooser"
41
)
42
43
parser.add_argument(
44
"-m", "--mask", type=str, help="Camera Mask ID to use in the recognition."
45
)
46
47
parser.add_argument(
48
"-s",
49
"--sdk-url",
50
default="http://localhost:8081",
51
help="Url to Stream File Upload Server",
52
)
53
54
args = parser.parse_args()
55
56
# Process files in folder
57
videos_directory = Path(args.folder)
58
with open("output.jsonl", "a") as outfile:
59
for file in videos_directory.iterdir():
60
if file.is_dir():
61
continue
62
logging.info(f"Processing file: {file}")
63
results = stream_api(file, args)
64
logging.info(f"Results:{results}")
65
if results:
66
json.dump(results, outfile)
67
outfile.write("\n")
68
outfile.flush()
69
70
71
if __name__ == "__main__":
72
main()
73
74