我已经训练了分割模型并检测了平面图的墙壁。现在我想创建这个遮罩的 3D 网格,并以可以轻松在网络上显示的格式构建墙壁。这是使用 ai 生成的遮罩
现在我想将墙壁拉伸到特定高度并制作 3D 模型。
这是提取墙壁的代码,下一步是用它创建 3D 模型。我怎样才能做到这一点?
import cv2
import os
import numpy as np
import matplotlib.pyplot as plt
# Parameters
wall_height = 150
img_path = 'output_mask.png'
# Load the image
img = cv2.imread(img_path)
# Get the original dimensions of the image
original_height, original_width = img.shape[:2]
# Resize the image while preserving aspect ratio
new_width = 1024
new_height = int((new_width / original_width) * original_height)
img_resized = cv2.resize(img, (new_width, new_height))
# Create a blank mask for the walls
walls = np.zeros(img_resized.shape[:2], dtype=np.uint8)
# Extract the walls (walls are white in the image)
walls[(img_resized == [255, 255, 255]).all(axis=2)] = 255
一种解决方案是: