convert 2d floor plan to 3d plan similar to this type "https://cdn.prod.website-files.com/5dcf94bbedfe6a4a06634ead/6056fdf874af23462f85906c_3DStandard-After.jpg" using image processing
To upload files, please first save the app
import streamlit as st
import cv2
import numpy as np
from PIL import Image
import io
def process_floor_plan(image):
# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply threshold to get binary image
_, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV)
# Find contours
contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Create a blank image for the 3D effect
height, width = image.shape[:2]
result = np.zeros((height + 50, width + 50, 3), dtype=np.uint8)
result.fill(255) # White background
# Draw the original plan shifted down and right (base layer)
result[50:height+50, 50:width+50] = image
# Draw vertical lines for walls (creating 3D effect)
for contour in contours:
if cv2.contourArea(contour) > 100: # Filter small contours
for point in contour:
x, y = point[0]
cv2.line(result, (x+50, y+50), (x, y), (100, 100, 100), 1)
return result
st.title("2D to 3D Floor Plan Converter")
st.write("""
This app creates a simple 3D effect for floor plans by adding perspective lines.
Upload a 2D floor plan image to see the result.
""")
uploaded_file = st.file_uploader("Choose a floor plan image...", type=['jpg', 'jpeg', 'png'])
if uploaded_file is not None:
# Read image
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
# Convert BGR to RGB for display
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Process the image
result = process_floor_plan(image)
result_rgb = cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
# Display original and processed images
col1, col2 = st.columns(2)
with col1:
st.subheader("Original Floor Plan")
st.image(image_rgb, use_column_width=True)
with col2:
st.subheader("3D Effect")
st.image(result_rgb, use_column_width=True)
st.info("""
Note: This is a simplified 3D effect created through image processing.
For professional architectural visualization, specialized CAD software would be recommended.
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?