2d floor plan to 3d convertor that gives doll house view (top view)
Drop files here
or click to upload
import streamlit as st
import cv2
import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path
st.title("2D Floor Plan to 3D Dollhouse View Converter")
# Add description
st.markdown("""
This app converts 2D floor plans into a simple 3D dollhouse view (top-down perspective).
Upload a floor plan image (preferably with clear walls and rooms) to see the result.
""")
# File uploader
uploaded_file = st.file_uploader("Upload your floor plan image", type=['png', 'jpg', 'jpeg'])
if uploaded_file is not None:
# Read the image
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Display original image
st.subheader("Original Floor Plan")
st.image(image_rgb, use_column_width=True)
# Image processing parameters
wall_height = st.slider("Wall Height", 1, 50, 20, help="Adjust the height of the walls in the 3D view")
threshold = st.slider("Wall Detection Threshold", 0, 255, 127, help="Adjust this value to better detect walls in your floor plan")
# Process the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, binary = cv2.threshold(gray, threshold, 255, cv2.THRESH_BINARY)
# Create 3D effect
def create_3d_view(binary_image, height):
# Create a heightmap where walls are elevated
heightmap = np.zeros_like(binary_image, dtype=float)
heightmap[binary_image == 0] = height # Walls are black in binary image
# Create figure
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
# Create meshgrid for 3D plot
x, y = np.meshgrid(np.arange(heightmap.shape[1]), np.arange(heightmap.shape[0]))
# Plot surface
surf = ax.plot_surface(x, y, heightmap, cmap='viridis',
linewidth=0, antialiased=True)
# Set viewing angle for dollhouse view
ax.view_init(elev=60, azim=45)
# Hide axes
ax.set_axis_off()
return fig
# Create and display 3D view
st.subheader("3D Dollhouse View")
fig = create_3d_view(binary, wall_height)
st.pyplot(fig)
# Add some tips
st.markdown("""
### Tips for better results:
1. Use floor plans with clear, dark walls and light-colored rooms
2. Adjust the Wall Detection Threshold to better identify walls
3. Modify Wall Height to change the 3D effect
4. The dollhouse view shows walls in elevated regions
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?