xmrt commited on
Commit
b8eab7d
1 Parent(s): aa67e27
Files changed (1) hide show
  1. main.py +35 -26
main.py CHANGED
@@ -35,6 +35,25 @@ inferencers = {"Estimate human 2d poses":human, "Estimate human 2d hand poses":h
35
 
36
  print("[INFO]: Downloaded models!")
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  def tracking(video, model, boxes=True):
39
  print("[INFO] Loading model...")
40
  # Load an official or custom model
@@ -82,10 +101,7 @@ def show_tracking(video_content):
82
 
83
 
84
  def pose3d(video):
85
- clip = moviepy.VideoFileClip(video)
86
-
87
- video = video[:-5]+".mp4"
88
- clip.write_videofile(video)
89
 
90
 
91
  # Define new unique folder
@@ -107,12 +123,8 @@ def pose3d(video):
107
  return "".join(out_file)
108
 
109
 
110
- def pose2d(video):
111
-
112
- clip = moviepy.VideoFileClip(video)
113
-
114
- video = video[:-5]+".mp4"
115
- clip.write_videofile(video)
116
 
117
  # Define new unique folder
118
  add_dir = str(uuid.uuid4())
@@ -124,7 +136,7 @@ def pose2d(video):
124
  return_vis=True,
125
  thickness=2,
126
  rebase_keypoint_height=True,
127
- #kpt_thr=kpt_thr,
128
  device="cuda"
129
  )
130
 
@@ -135,12 +147,8 @@ def pose2d(video):
135
  return "".join(out_file)
136
 
137
 
138
- def pose2dhand(video):
139
- clip = moviepy.VideoFileClip(video)
140
-
141
- video = video[:-5]+".mp4"
142
- clip.write_videofile(video)
143
-
144
 
145
  # Define new unique folder
146
  add_dir = str(uuid.uuid4())
@@ -152,6 +160,7 @@ def pose2dhand(video):
152
  return_vis=True,
153
  thickness=2,
154
  rebase_keypoint_height=True,
 
155
  device="cuda")
156
 
157
  result = [result for result in result_generator] #next(result_generator)
@@ -174,11 +183,11 @@ def run_UI():
174
  submit_pose3d_file = gr.Button("Make 3d pose estimation")
175
  submit_hand_file = gr.Button("Make 2d hand estimation")
176
  submit_detect_file = gr.Button("Detect and track objects")
177
-
178
- video_output1 = gr.PlayableVideo(height=512, label = "Estimate human 2d poses", show_label=True)
179
- video_output2 = gr.PlayableVideo(height=512, label = "Estimate human 3d poses", show_label=True)
180
- video_output3 = gr.PlayableVideo(height=512, label = "Estimate human hand poses", show_label=True)
181
- video_output4 = gr.Video(height=512)
182
 
183
  with gr.Tab("Record video with webcam"):
184
  with gr.Row():
@@ -201,7 +210,7 @@ def run_UI():
201
 
202
  # From file
203
  submit_pose_file.click(fn=pose2d,
204
- inputs= video_input,
205
  outputs = video_output1)
206
 
207
  submit_pose3d_file.click(fn=pose3d,
@@ -209,7 +218,7 @@ def run_UI():
209
  outputs = video_output2)
210
 
211
  submit_hand_file.click(fn=pose2dhand,
212
- inputs= video_input,
213
  outputs = video_output3)
214
 
215
  submit_detect_file.click(fn=show_tracking,
@@ -218,7 +227,7 @@ def run_UI():
218
 
219
  # Web
220
  submit_pose_web.click(fn=pose2d,
221
- inputs = webcam_input,
222
  outputs = webcam_output1)
223
 
224
  submit_pose3d_web.click(fn=pose3d,
@@ -226,7 +235,7 @@ def run_UI():
226
  outputs = webcam_output2)
227
 
228
  submit_hand_web.click(fn=pose2dhand,
229
- inputs= webcam_input,
230
  outputs = webcam_output3)
231
 
232
  submit_detect_web.click(fn=show_tracking,
 
35
 
36
  print("[INFO]: Downloaded models!")
37
 
38
+ def check_extension(video):
39
+ split_tup = os.path.splitext(video)
40
+
41
+ # extract the file name and extension
42
+ file_name = split_tup[0]
43
+ file_extension = split_tup[1]
44
+
45
+ if file_extension is not ".mp4":
46
+ clip = moviepy.VideoFileClip(video)
47
+
48
+ video = file_name+".mp4"
49
+ clip.write_videofile(video)
50
+
51
+ return video
52
+
53
+
54
+
55
+
56
+
57
  def tracking(video, model, boxes=True):
58
  print("[INFO] Loading model...")
59
  # Load an official or custom model
 
101
 
102
 
103
  def pose3d(video):
104
+ video = check_extension(video)
 
 
 
105
 
106
 
107
  # Define new unique folder
 
123
  return "".join(out_file)
124
 
125
 
126
+ def pose2d(video, kpt_threshold):
127
+ video = check_extension(video)
 
 
 
 
128
 
129
  # Define new unique folder
130
  add_dir = str(uuid.uuid4())
 
136
  return_vis=True,
137
  thickness=2,
138
  rebase_keypoint_height=True,
139
+ kpt_thr=kpt_threshold,
140
  device="cuda"
141
  )
142
 
 
147
  return "".join(out_file)
148
 
149
 
150
+ def pose2dhand(video, kpt_threshold):
151
+ video = check_extension(video)
 
 
 
 
152
 
153
  # Define new unique folder
154
  add_dir = str(uuid.uuid4())
 
160
  return_vis=True,
161
  thickness=2,
162
  rebase_keypoint_height=True,
163
+ kpt_thr=kpt_threshold,
164
  device="cuda")
165
 
166
  result = [result for result in result_generator] #next(result_generator)
 
183
  submit_pose3d_file = gr.Button("Make 3d pose estimation")
184
  submit_hand_file = gr.Button("Make 2d hand estimation")
185
  submit_detect_file = gr.Button("Detect and track objects")
186
+ with gr.Column():
187
+ video_output1 = gr.PlayableVideo(height=512, label = "Estimate human 2d poses", show_label=True)
188
+ video_output2 = gr.PlayableVideo(height=512, label = "Estimate human 3d poses", show_label=True)
189
+ video_output3 = gr.PlayableVideo(height=512, label = "Estimate human hand poses", show_label=True)
190
+ video_output4 = gr.Video(height=512)
191
 
192
  with gr.Tab("Record video with webcam"):
193
  with gr.Row():
 
210
 
211
  # From file
212
  submit_pose_file.click(fn=pose2d,
213
+ inputs= [video_input, file_kpthr],
214
  outputs = video_output1)
215
 
216
  submit_pose3d_file.click(fn=pose3d,
 
218
  outputs = video_output2)
219
 
220
  submit_hand_file.click(fn=pose2dhand,
221
+ inputs= [video_input, file_kpthr],
222
  outputs = video_output3)
223
 
224
  submit_detect_file.click(fn=show_tracking,
 
227
 
228
  # Web
229
  submit_pose_web.click(fn=pose2d,
230
+ inputs = [webcam_input, web_kpthr],
231
  outputs = webcam_output1)
232
 
233
  submit_pose3d_web.click(fn=pose3d,
 
235
  outputs = webcam_output2)
236
 
237
  submit_hand_web.click(fn=pose2dhand,
238
+ inputs= [webcam_input, web_kpthr],
239
  outputs = webcam_output3)
240
 
241
  submit_detect_web.click(fn=show_tracking,