-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
demo-fall-detection-cmd.py
47 lines (37 loc) · 1.44 KB
/
demo-fall-detection-cmd.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
import argparse
from pathlib import Path
from PIL import Image
from fall_prediction import Fall_prediction
import numpy as np
import json
import time
import yaml
class JsonEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
if isinstance(obj, np.floating):
return float(obj)
if isinstance(obj, np.ndarray):
return obj.tolist()
return super(JsonEncoder, self).default(obj)
parser = argparse.ArgumentParser()
parser.add_argument("--image_1", type=Path, help='Path to the First Image', required=True)
parser.add_argument("--image_2", type=Path, help='Path to the Second Image', required=True)
parser.add_argument("--image_3", type=Path, help='Path to the Third Image')
p = parser.parse_args()
img1 = Image.open(p.image_1)
img2 = Image.open(p.image_2)
img3 = Image.open(p.image_3) if p.image_3 else None
response = Fall_prediction(img1, img2, img3)
if response:
print("There is", response['category'])
print("Confidence :", response['confidence'])
print("Angle : ", response['angle'])
print("Keypoint_corr :", response['keypoint_corr'])
time_str = time.strftime("%Y%m%d-%H%M%S")
json_str = json.dumps(response, cls=JsonEncoder)
with open(f"tmp/{time_str}.yaml","w",) as file:
yaml.dump(json.loads(json_str), file)
else:
print("There is no fall detetcion...")