xmrt commited on
Commit
cafc721
1 Parent(s): 010189f

file display

Browse files
Files changed (1) hide show
  1. main.py +10 -39
main.py CHANGED
@@ -5,6 +5,7 @@ from mmpose.apis import MMPoseInferencer
5
  import gradio as gr
6
  import numpy as np
7
  import cv2
 
8
 
9
  print("[INFO]: Imported modules!")
10
  human = MMPoseInferencer("human")
@@ -31,54 +32,24 @@ print("[INFO]: Downloaded models!")
31
 
32
  def poses(photo, check):
33
  # Selecting the specific inferencer
34
- print(check)
35
  inferencer = inferencers[check[0]] # 'hand', 'human , device='cuda'
36
 
37
  print("[INFO]: Running inference!")
38
- #vis_out_dir
 
 
39
  result_generator = inferencer(photo,
40
- vis_out_dir =".",
41
  return_vis=True,
42
  thickness=2,
43
  rebase_keypoint_height=True)
44
 
45
- result = [result for result in result_generator] #next(result_generator)
46
- print(type(result))
47
 
48
- # print(["[INFO] Result from iterator: ", result])
49
-
50
- # for r in result_generator:
51
- # print("[INFO] Single result: ", r)
52
-
53
- # print(type(r))
54
- # # Prepare to save video
55
- # output_file = os.path.join("output.mp4")
56
-
57
- # fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for MP4 video
58
- # fps = 32
59
- # height = 480
60
- # width = 640
61
- # size = (width,height)
62
-
63
- # out_writer = cv2.VideoWriter(output_file, fourcc, fps, size)
64
-
65
- # for result in result_generator:
66
- # print("[INFO] Result: ", result)
67
- # frame = result["visualization"]
68
- # out_writer.write(cv2.cvtColor(frame[0], cv2.COLOR_BGR2RGB))
69
-
70
- # print(os.listdir())
71
- # print("[INFO]: Visualizing results!")
72
- # print(os.listdir())
73
- # print()
74
-
75
- # out_writer.release()
76
- # cv2.destroyAllWindows() # Closing window
77
- output_files = glob.glob(os.path.join(".", "*.mp4"))
78
- print(output_files)
79
  # 00000.mp4
80
  # 000000.mp4
81
- print(os.listdir())
82
 
83
  return output_files[0]
84
 
@@ -103,7 +74,7 @@ def run():
103
 
104
  webcam = gr.Interface(
105
  fn=poses,
106
- inputs= [gr.Video(source="webcam"), check_web],
107
  outputs = gr.PlayableVideo(), #file_types=['.mp4'] #gr.Video(),
108
  title = 'Pose estimation',
109
  description = 'Pose estimation on video',
@@ -112,7 +83,7 @@ def run():
112
 
113
  file = gr.Interface(
114
  poses,
115
- inputs = [gr.Video(source="upload"), check_file],
116
  outputs = gr.PlayableVideo(),
117
  allow_flagging=False
118
  )
 
5
  import gradio as gr
6
  import numpy as np
7
  import cv2
8
+ import uuid
9
 
10
  print("[INFO]: Imported modules!")
11
  human = MMPoseInferencer("human")
 
32
 
33
  def poses(photo, check):
34
  # Selecting the specific inferencer
35
+
36
  inferencer = inferencers[check[0]] # 'hand', 'human , device='cuda'
37
 
38
  print("[INFO]: Running inference!")
39
+ # Create out directory
40
+ vis_out_dir = str(uuid.uuid4())
41
+
42
  result_generator = inferencer(photo,
43
+ vis_out_dir = vis_out_dir,
44
  return_vis=True,
45
  thickness=2,
46
  rebase_keypoint_height=True)
47
 
48
+ result = [result for result in result_generator] #next(result_generator)
 
49
 
50
+ output_files = glob.glob(os.path.join(vis_out_dir, "*.mp4"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # 00000.mp4
52
  # 000000.mp4
 
53
 
54
  return output_files[0]
55
 
 
74
 
75
  webcam = gr.Interface(
76
  fn=poses,
77
+ inputs= [gr.Video(source="webcam", height=412), check_web],
78
  outputs = gr.PlayableVideo(), #file_types=['.mp4'] #gr.Video(),
79
  title = 'Pose estimation',
80
  description = 'Pose estimation on video',
 
83
 
84
  file = gr.Interface(
85
  poses,
86
+ inputs = [gr.Video(source="upload", height=412), check_file],
87
  outputs = gr.PlayableVideo(),
88
  allow_flagging=False
89
  )