1
- """Script to capture images from object detection"""
1
+ """Script to capture images from object detection. """
2
2
3
3
import argparse
4
- from utils import video
4
+ from utils import video , terminal
5
5
from detection import deeplearning , traditional
6
6
7
7
8
8
def parse_argument ():
9
- """Parse arguments for command line"""
9
+ """Parse arguments for command line. """
10
10
parser = argparse .ArgumentParser (
11
- formatter_class = argparse .ArgumentDefaultsHelpFormatter )
11
+ formatter_class = argparse .ArgumentDefaultsHelpFormatter
12
+ )
12
13
parser .add_argument (
13
- ' --method' ,
14
- help = ' Two computer vision method: traditional or deeplearning' ,
14
+ " --method" ,
15
+ help = " Two computer vision method: traditional or deeplearning" ,
15
16
required = False ,
16
17
type = str ,
17
- default = 'deeplearning' )
18
+ default = "deeplearning" ,
19
+ )
18
20
parser .add_argument (
19
- ' --detectionType' ,
20
- help = ' Type of detection for traditional method: color OR shape' ,
21
+ " --detectionType" ,
22
+ help = " Type of detection for traditional method: color OR shape" ,
21
23
required = False ,
22
- default = 'color' )
24
+ default = "color" ,
25
+ )
23
26
parser .add_argument (
24
- ' --multipleObject' ,
25
- help = ' Whether to detect single or multiple types of objects.' ,
27
+ " --multipleObject" ,
28
+ help = " Whether to detect single or multiple types of objects." ,
26
29
required = False ,
27
- default = False )
30
+ default = False ,
31
+ )
28
32
parser .add_argument (
29
- ' --trueClass' ,
30
- help = ' Name of the object class to be detected if it is a single type.' ,
33
+ " --trueClass" ,
34
+ help = " Name of the object class to be detected if it is a single type." ,
31
35
required = False ,
32
36
type = str ,
33
- default = 'yellow_duck' )
37
+ default = "yellow_duck" ,
38
+ )
34
39
parser .add_argument (
35
- ' --collectAll' ,
36
- help = ' Whether to collect all images or only the True Positive one.' ,
40
+ " --collectAll" ,
41
+ help = " Whether to collect all images or only the True Positive one." ,
37
42
required = False ,
38
- default = False )
43
+ default = False ,
44
+ )
39
45
parser .add_argument (
40
- ' --model' ,
41
- help = ' Path of the object detection model.' ,
46
+ " --model" ,
47
+ help = " Path of the object detection model." ,
42
48
required = False ,
43
- default = './model/frogducky2.tflite' )
49
+ default = "./model/frogducky2.tflite" ,
50
+ )
44
51
parser .add_argument (
45
- ' --frameWidth' ,
46
- help = ' Width of frame to capture from camera.' ,
52
+ " --frameWidth" ,
53
+ help = " Width of frame to capture from camera." ,
47
54
required = False ,
48
55
type = int ,
49
- default = 640 )
56
+ default = 640 ,
57
+ )
50
58
parser .add_argument (
51
- ' --frameHeight' ,
52
- help = ' Height of frame to capture from camera.' ,
59
+ " --frameHeight" ,
60
+ help = " Height of frame to capture from camera." ,
53
61
required = False ,
54
62
type = int ,
55
- default = 480 )
63
+ default = 480 ,
64
+ )
56
65
parser .add_argument (
57
- ' --numThreads' ,
58
- help = ' Number of CPU threads to run the model.' ,
66
+ " --numThreads" ,
67
+ help = " Number of CPU threads to run the model." ,
59
68
required = False ,
60
69
type = int ,
61
- default = 4 )
70
+ default = 4 ,
71
+ )
62
72
parser .add_argument (
63
- ' --enableEdgeTPU' ,
64
- help = ' Whether to run the model on EdgeTPU.' ,
65
- action = ' store_true' ,
73
+ " --enableEdgeTPU" ,
74
+ help = " Whether to run the model on EdgeTPU." ,
75
+ action = " store_true" ,
66
76
required = False ,
67
- default = False )
77
+ default = False ,
78
+ )
68
79
parser .add_argument (
69
- ' --videoFilename' ,
70
- help = ' Name of the output video file with .mp4 extension' ,
80
+ " --videoFilename" ,
81
+ help = " Name of the output video file with .mp4 extension" ,
71
82
required = False ,
72
- default = 'Deteksi_Objek.mp4' )
83
+ default = "Deteksi_Objek.mp4" ,
84
+ )
73
85
return parser .parse_args ()
74
86
75
87
76
88
def main ():
77
- """Main function to run detection """
89
+ """Run detection and capture the result. """
78
90
args = parse_argument ()
79
-
80
- if args .method == 'deeplearning' :
81
- detector = deeplearning .DeepDetector (bool (args .multipleObject ), args .model ,
82
- args .frameWidth , args .frameHeight ,
83
- int (args .numThreads ),bool (args .enableEdgeTPU ))
84
- detector .capture (str (args .trueClass ), bool (args .collectAll ), str (args .videoFilename ))
85
-
86
- elif args .method == 'traditional' :
87
- if str (args .detectionType ) == 'category' :
91
+
92
+ if args .method == "deeplearning" :
93
+ detector = deeplearning .DeepDetector (
94
+ bool (args .multipleObject ),
95
+ args .model ,
96
+ args .frameWidth ,
97
+ args .frameHeight ,
98
+ int (args .numThreads ),
99
+ bool (args .enableEdgeTPU ),
100
+ )
101
+ detector .capture (
102
+ str (args .trueClass ), bool (args .collectAll ), str (args .videoFilename )
103
+ )
104
+
105
+ elif args .method == "traditional" :
106
+ if str (args .detectionType ) == "category" :
88
107
args .detectionType = terminal .prompt_type ()
89
- detector = traditional .TraditionalDetector (bool (args .multipleObject ), args .frameWidth ,
90
- args .frameHeight )
91
- detector .capture (str (args .detectionType ), str (args .trueClass ),
92
- bool (args .collectAll ), str (args .videoFilename ))
93
-
108
+ detector = traditional .TraditionalDetector (
109
+ bool (args .multipleObject ), args .frameWidth , args .frameHeight
110
+ )
111
+ detector .capture (
112
+ str (args .detectionType ),
113
+ str (args .trueClass ),
114
+ bool (args .collectAll ),
115
+ str (args .videoFilename ),
116
+ )
117
+
94
118
video .move_video (str (args .videoFilename ))
95
119
96
120
97
- if __name__ == ' __main__' :
98
- main ()
121
+ if __name__ == " __main__" :
122
+ main ()
0 commit comments