Reputation: 11
I have trained a segmentation model to detect walls from an image of a floorplan. Now, I wish to create a 3D mesh from the obtained masked array. I also need a mesh format that is compatible with a web viewer.
Below is the code that I used to extract the walls in my 2D image and some sample images.
This is the Masked Generated with AI:
These are the walls:
I imagine the next step is to create the 3D model out of it by extruding the footprint of the walls to a given height. How can I do that?
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
Upvotes: 0
Views: 153
Reputation: 133
One solution would be to:
Upvotes: 0