tori29umai commited on
Commit
bc1181d
1 Parent(s): 5a76f92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -55,11 +55,11 @@ import numpy as np
55
  import trimesh
56
  import tempfile
57
 
58
- def generate_point_cloud(color_img):
59
  depth_img = predict_depth(color_img[:, :, ::-1])
60
  # 画像サイズの調整
61
  height, width = color_img.shape[:2]
62
- new_height = 512
63
  new_width = int(width * (new_height / height))
64
 
65
  color_img_resized = np.array(Image.fromarray(color_img).resize((new_width, new_height), Image.LANCZOS))
@@ -73,7 +73,7 @@ def generate_point_cloud(color_img):
73
  # 非線形変換(必要に応じて調整)
74
  adjusted_depth = np.power(normalized_depth, 0.1) # ガンマ補正
75
 
76
- # カメラの内部パラメータ(使用するカメラに基づいて調整)
77
  fx, fy = 300, 300 # 焦点距離
78
  cx, cy = color_img_resized.shape[1] / 2, color_img_resized.shape[0] / 2 # 主点
79
 
@@ -101,9 +101,6 @@ def generate_point_cloud(color_img):
101
  # PointCloudオブジェクトの作成
102
  cloud = trimesh.PointCloud(vertices=points, colors=colors)
103
 
104
- # PointCloudオブジェクトの作成
105
- cloud = trimesh.PointCloud(vertices=points, colors=colors)
106
-
107
  # Z軸周りに180度回転を適用(時計回り)
108
  rotation = trimesh.transformations.rotation_matrix(np.pi, [0, 0, 1])
109
  cloud.apply_transform(rotation)
@@ -125,7 +122,8 @@ with gr.Blocks(css=css) as demo:
125
 
126
  with gr.Row():
127
  input_image = gr.Image(label="Input Image", type='numpy', elem_id='img-display-input')
128
-
 
129
  submit = gr.Button(value="Compute Depth & Generate Point Cloud")
130
 
131
  output_3d = gr.Model3D(
@@ -133,7 +131,7 @@ with gr.Blocks(css=css) as demo:
133
  label="3D Model",
134
  )
135
 
136
- submit.click(fn=generate_point_cloud, inputs=[input_image], outputs=[output_3d])
137
 
138
  if __name__ == '__main__':
139
  demo.queue().launch(share=True)
 
55
  import trimesh
56
  import tempfile
57
 
58
+ def generate_point_cloud(color_img, resolution):
59
  depth_img = predict_depth(color_img[:, :, ::-1])
60
  # 画像サイズの調整
61
  height, width = color_img.shape[:2]
62
+ new_height = resolution
63
  new_width = int(width * (new_height / height))
64
 
65
  color_img_resized = np.array(Image.fromarray(color_img).resize((new_width, new_height), Image.LANCZOS))
 
73
  # 非線形変換(必要に応じて調整)
74
  adjusted_depth = np.power(normalized_depth, 0.1) # ガンマ補正
75
 
76
+ # カメラの内部パラメータ(使用するカメラに基づいて調整)
77
  fx, fy = 300, 300 # 焦点距離
78
  cx, cy = color_img_resized.shape[1] / 2, color_img_resized.shape[0] / 2 # 主点
79
 
 
101
  # PointCloudオブジェクトの作成
102
  cloud = trimesh.PointCloud(vertices=points, colors=colors)
103
 
 
 
 
104
  # Z軸周りに180度回転を適用(時計回り)
105
  rotation = trimesh.transformations.rotation_matrix(np.pi, [0, 0, 1])
106
  cloud.apply_transform(rotation)
 
122
 
123
  with gr.Row():
124
  input_image = gr.Image(label="Input Image", type='numpy', elem_id='img-display-input')
125
+ resolution_slider = gr.Slider(minimum=512, maximum=1600, value=512, step=1, label="Resolution")
126
+
127
  submit = gr.Button(value="Compute Depth & Generate Point Cloud")
128
 
129
  output_3d = gr.Model3D(
 
131
  label="3D Model",
132
  )
133
 
134
+ submit.click(fn=generate_point_cloud, inputs=[input_image, resolution_slider], outputs=[output_3d])
135
 
136
  if __name__ == '__main__':
137
  demo.queue().launch(share=True)