Sm0kyWu commited on
Commit
80defc0
·
verified ·
1 Parent(s): 006cb0a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -373,7 +373,7 @@ def draw_points_on_image(image, point, point_type):
373
  """在图像上绘制所有点,points 为 [(x, y, point_type), ...]"""
374
  image_with_points = image.copy()
375
  x, y = point
376
- color = (255, 0, 0) if point_type == "visible" else (0, 255, 0)
377
  cv2.circle(image_with_points, (int(x), int(y)), radius=10, color=color, thickness=-1)
378
  return image_with_points
379
 
@@ -392,7 +392,7 @@ def add_point(x, y, point_type, visible_points, occlusion_points):
392
  add操作:将新点添加到 points 列表中,
393
  并返回更新后的图像和新的点列表。
394
  """
395
- if point_type == "visible":
396
  visible_points.append([x, y])
397
  else:
398
  occlusion_points.append([x, y])
@@ -403,7 +403,7 @@ def delete_point(point_type, visible_points, occlusion_points):
403
  delete操作:删除 points 列表中的最后一个点,
404
  并返回更新后的图像和新的点列表。
405
  """
406
- if point_type == "visible":
407
  visible_points.pop()
408
  else:
409
  occlusion_points.pop()
@@ -437,13 +437,13 @@ def see_occlusion_points(image, occlusion_points):
437
  return updated_image
438
 
439
  def update_all_points(visible_points, occlusion_points):
440
- """
441
- 返回一个文本描述当前两个点列表,以及对应的下拉菜单选项(字符串格式)。
442
- """
443
  text = f"Visible Points: {visible_points}\nOcclusion Points: {occlusion_points}"
444
- visible_dropdown = [f"({p[0]}, {p[1]})" for p in visible_points]
445
- occlusion_dropdown = [f"({p[0]}, {p[1]})" for p in occlusion_points]
446
- return text, visible_dropdown, occlusion_dropdown
 
 
 
447
 
448
  def delete_selected_visible(image, visible_points, occlusion_points, selected_index):
449
  """
@@ -495,15 +495,15 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
495
  with gr.Row():
496
  x_input = gr.Number(label="X Coordinate", value=0)
497
  y_input = gr.Number(label="Y Coordinate", value=0)
498
- point_type = gr.Radio(["vis", "occ"], label="Point Prompt Type")
499
  with gr.Row():
500
  see_button = gr.Button("See Point")
501
  add_button = gr.Button("Add Point")
502
  with gr.Row():
503
  # 新增按钮:Clear、分别查看 visible/occlusion
504
  clear_button = gr.Button("Clear Points")
505
- see_visible_button = gr.Button("See Visible Points")
506
- see_occlusion_button = gr.Button("See Occluded Points")
507
  with gr.Row():
508
  # 新增文本框实时显示点列表
509
  points_text = gr.Textbox(label="Points List", interactive=False)
@@ -587,4 +587,4 @@ if __name__ == "__main__":
587
  pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8)))
588
  except:
589
  pass
590
- demo.launch()
 
373
  """在图像上绘制所有点,points 为 [(x, y, point_type), ...]"""
374
  image_with_points = image.copy()
375
  x, y = point
376
+ color = (255, 0, 0) if point_type == "vis" else (0, 255, 0)
377
  cv2.circle(image_with_points, (int(x), int(y)), radius=10, color=color, thickness=-1)
378
  return image_with_points
379
 
 
392
  add操作:将新点添加到 points 列表中,
393
  并返回更新后的图像和新的点列表。
394
  """
395
+ if point_type == "vis":
396
  visible_points.append([x, y])
397
  else:
398
  occlusion_points.append([x, y])
 
403
  delete操作:删除 points 列表中的最后一个点,
404
  并返回更新后的图像和新的点列表。
405
  """
406
+ if point_type == "vis":
407
  visible_points.pop()
408
  else:
409
  occlusion_points.pop()
 
437
  return updated_image
438
 
439
  def update_all_points(visible_points, occlusion_points):
 
 
 
440
  text = f"Visible Points: {visible_points}\nOcclusion Points: {occlusion_points}"
441
+ visible_dropdown_choices = [f"({p[0]}, {p[1]})" for p in visible_points]
442
+ occlusion_dropdown_choices = [f"({p[0]}, {p[1]})" for p in occlusion_points]
443
+ # 使用 gr.Dropdown.update 明确设置 value=None
444
+ visible_dropdown_update = gr.Dropdown.update(value=None, choices=visible_dropdown_choices)
445
+ occlusion_dropdown_update = gr.Dropdown.update(value=None, choices=occlusion_dropdown_choices)
446
+ return text, visible_dropdown_update, occlusion_dropdown_update
447
 
448
  def delete_selected_visible(image, visible_points, occlusion_points, selected_index):
449
  """
 
495
  with gr.Row():
496
  x_input = gr.Number(label="X Coordinate", value=0)
497
  y_input = gr.Number(label="Y Coordinate", value=0)
498
+ point_type = gr.Radio(["vis", "occ"], label="Point Prompt Type", value="vis")
499
  with gr.Row():
500
  see_button = gr.Button("See Point")
501
  add_button = gr.Button("Add Point")
502
  with gr.Row():
503
  # 新增按钮:Clear、分别查看 visible/occlusion
504
  clear_button = gr.Button("Clear Points")
505
+ see_visible_button = gr.Button("Visible Points")
506
+ see_occlusion_button = gr.Button("Occluded Points")
507
  with gr.Row():
508
  # 新增文本框实时显示点列表
509
  points_text = gr.Textbox(label="Points List", interactive=False)
 
587
  pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8)))
588
  except:
589
  pass
590
+ demo.launch()