-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture.py
126 lines (116 loc) · 3.59 KB
/
capture.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""Script to capture images from object detection."""
import argparse
from utils import video, terminal
from detection import deeplearning, traditional
def parse_argument():
"""Parse arguments for command line."""
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"--method",
help="Two computer vision method: traditional or deeplearning",
required=False,
type=str,
default="deeplearning",
)
parser.add_argument(
"--detectionType",
help="""For traditional method, two types of detection are
provided: color or shape.
For deeplearning, this argument is not needed.""",
required=False,
default="color",
)
parser.add_argument(
"--multipleObject",
help="Whether to detect objects with single or multiple classes.",
required=False,
default=False,
)
parser.add_argument(
"--trueClass",
help="""For single class, name of the object class to be detected.
For multiple, this argument is not needed.""",
required=False,
type=str,
default="yellow_duck",
)
parser.add_argument(
"--collectAll",
help="""Whether to collect all images of detected objects or
only the detections with correct labels.""",
required=False,
default=False,
)
parser.add_argument(
"--model",
help="For deeplearning, path of the object detection model.",
required=False,
default="./model/frogducky2.tflite",
)
parser.add_argument(
"--frameWidth",
help="Width of frame to capture from camera.",
required=False,
type=int,
default=640,
)
parser.add_argument(
"--frameHeight",
help="Height of frame to capture from camera.",
required=False,
type=int,
default=480,
)
parser.add_argument(
"--numThreads",
help="For deeplearning, number of CPU threads to run the model.",
required=False,
type=int,
default=4,
)
parser.add_argument(
"--enableEdgeTPU",
help="For deeplearning, whether to run the model on EdgeTPU.",
action="store_true",
required=False,
default=False,
)
parser.add_argument(
"--videoFilename",
help="Name of the output video file with .mp4 extension",
required=False,
default="Deteksi_Objek.mp4",
)
return parser.parse_args()
def main():
"""Run detection and capture the result."""
args = parse_argument()
if args.method == "deeplearning":
detector = deeplearning.DeepDetector(
bool(args.multipleObject),
args.model,
args.frameWidth,
args.frameHeight,
int(args.numThreads),
bool(args.enableEdgeTPU),
)
detector.capture(
str(args.trueClass), bool(args.collectAll), str(args.videoFilename)
)
elif args.method == "traditional":
if str(args.detectionType) == "category":
args.detectionType = terminal.prompt_type()
detector = traditional.TraditionalDetector(
bool(args.multipleObject), args.frameWidth, args.frameHeight
)
detector.capture(
str(args.detectionType),
str(args.trueClass),
bool(args.collectAll),
str(args.videoFilename),
)
video.move_video(str(args.videoFilename))
if __name__ == "__main__":
main()