-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.py
109 lines (99 loc) · 3.53 KB
/
Main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import sys
import getopt
def showHelp():
print("Usage:")
print("\tMain.py -h | --help")
print(
"\tMain.py [--fps=<fps>] [--complexity=0|1|2] [--data=\"<path to data>\"] [--no-env-check] [--no-env-download]"
)
print()
print("Options:")
print("\t-h --help\t\tshow this help message and exit")
print(
"\t--fps=<fps>\t\ttarget fps when tracking (fps>=0, 0 means unlimited) [default: 8]"
)
print(
"\t--complexity=0|1|2\ttrack model complexity (0 for lite, 1 for medium, 2 for heavy) [default: 2]"
)
print(
"\t--data=\"<path to data>\"\tuse config file in folder <path to data> [default: \"./data\"]"
)
print("\t--no-env-check\t\tdo not check environment")
print("\t--no-env-download\tdo not download when missing package")
if __name__ == "__main__":
fps = 8
complexity = 2
dataDir = r".\data"
envCheck = True
envDownload = True
opts, _ = getopt.getopt(sys.argv[1:], 'h', [
'fps=', 'complexity=', 'help', 'data=', 'no-env-check',
'no-env-download'
])
for name, value in opts:
if name in ['-h', '--help']:
showHelp()
exit(0)
elif name == '--fps':
try:
fps = int(value)
except:
print(f"invalid fps {value}")
exit(0)
if fps < 0:
print(f"invalid fps {value}")
exit(0)
elif name == '--complexity':
try:
complexity = int(value)
except:
print(f"invalid complexity {value}")
exit(0)
if not complexity in [0, 1, 2]:
print(f"invalid complexity {value}")
exit(0)
elif name == '--data':
dataDir = value
elif name == '--no-env-check':
envCheck = False
elif name == '--no-env-download':
envDownload = False
from Utils import testPackages
if envCheck:
res = testPackages(envDownload)
if not (envDownload or res):
exit(0)
from TaskController import TaskController
from ValidateConfig import ValidateConfig
import mediapipe.python.solutions as sol
print(f"working in folder {dataDir}")
if not os.path.exists(dataDir):
os.mkdir(dataDir)
configPath = os.path.join(dataDir, "config.json")
if not os.path.exists(configPath):
with open(configPath, "w") as f:
f.write("[]")
with sol.holistic.Holistic(min_detection_confidence=0.5,
min_tracking_confidence=0.5,
model_complexity=0) as holistic:
pass
with sol.holistic.Holistic(min_detection_confidence=0.5,
min_tracking_confidence=0.5,
model_complexity=1) as holistic:
pass
with sol.holistic.Holistic(min_detection_confidence=0.5,
min_tracking_confidence=0.5,
model_complexity=2) as holistic:
pass
print(f"Now you can modify {configPath} to custom your own task list")
exit(0)
os.chdir(dataDir)
errlog = open("error.log", "w", encoding='utf-8')
sys.stderr = errlog
if not ValidateConfig("config.json"):
exit(0)
print(f"use fps limit {fps}, model complexity {complexity}")
controller = TaskController()
controller.readConfig("config.json")
controller.startListen(fps, complexity)