qsitj commited on
Commit
81d3e7f
·
verified ·
1 Parent(s): eec4598

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -21
app.py CHANGED
@@ -45,32 +45,26 @@ fdic = {
45
  "weight" : "bold"
46
  }
47
 
 
48
 
49
- def infer(model, in_pil_img):
50
 
 
51
  results = None
52
  if model == "detr-resnet-101":
53
  results = detector101(in_pil_img)
54
  else:
55
  results = detector50(in_pil_img)
56
-
57
  return results
58
 
59
 
60
- #######################################
61
-
62
-
63
- def query_data(model, in_pil_img: Image.Image):
64
- return infer(model, in_pil_img)
65
-
66
-
67
 
68
  def get_figure(in_pil_img):
69
  plt.figure(figsize=(16, 10))
70
  plt.imshow(in_pil_img)
71
 
72
  ax = plt.gca()
73
-
74
  in_results = query_data(in_pil_img)
75
 
76
  for prediction in in_results:
@@ -88,18 +82,8 @@ def get_figure(in_pil_img):
88
  return plt.gcf()
89
 
90
 
91
- def infer(in_pil_img):
92
- figure = get_figure(in_pil_img)
93
-
94
- buf = io.BytesIO()
95
- figure.savefig(buf, bbox_inches='tight')
96
- buf.seek(0)
97
- output_pil_img = Image.open(buf)
98
-
99
- return output_pil_img
100
-
101
-
102
  def process_single_frame(frame):
 
103
  # 将 BGR 转换为 RGB
104
  rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
105
 
@@ -118,6 +102,7 @@ def process_single_frame(frame):
118
 
119
 
120
  def infer_video(input_video_path):
 
121
  with tempfile.TemporaryDirectory() as tmp_dir:
122
  # output_video_path = Path(tmp_dir) / "output.mp4"
123
  cap = cv2.VideoCapture(input_video_path)
 
45
  "weight" : "bold"
46
  }
47
 
48
+ #######################################
49
 
 
50
 
51
+ def query_data(model, in_pil_img: Image.Image):
52
  results = None
53
  if model == "detr-resnet-101":
54
  results = detector101(in_pil_img)
55
  else:
56
  results = detector50(in_pil_img)
57
+ print(f"检测结果:{results}")
58
  return results
59
 
60
 
 
 
 
 
 
 
 
61
 
62
  def get_figure(in_pil_img):
63
  plt.figure(figsize=(16, 10))
64
  plt.imshow(in_pil_img)
65
 
66
  ax = plt.gca()
67
+ print(f"图像尺寸:{in_pil_img.size}")
68
  in_results = query_data(in_pil_img)
69
 
70
  for prediction in in_results:
 
82
  return plt.gcf()
83
 
84
 
 
 
 
 
 
 
 
 
 
 
 
85
  def process_single_frame(frame):
86
+ print(f"开始处理单帧")
87
  # 将 BGR 转换为 RGB
88
  rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
89
 
 
102
 
103
 
104
  def infer_video(input_video_path):
105
+ print(f"开始处理视频 {input_video_path}")
106
  with tempfile.TemporaryDirectory() as tmp_dir:
107
  # output_video_path = Path(tmp_dir) / "output.mp4"
108
  cap = cv2.VideoCapture(input_video_path)