So Im trying to get coordinates of the given 3D floor plan and those coordinates will be used in Javascript program using THREE.JS, THREE.Vector3 and THREE.ExtrudeGeometry.
This is the code I have used:
import cv2 as cv
# Load your image
img = cv.imread("house-drawing.png")
# Convert image to grayscale
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
# Thresholding to binarize the image (adjust threshold values as needed)
ret, thresh = cv.threshold(img_gray, 100, 255, cv.THRESH_BINARY)
# Find contours
contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
# Filter contours based on size or other criteria
filtered_contours = []
for contour in contours:
# Calculate contour area
area = cv.contourArea(contour)
# Filter contours based on area (adjust threshold as needed)
if area > 1000: # Adjust this value based on your image size and requirements
# Approximate the contour to reduce points
epsilon = 0.02 * cv.arcLength(contour, True)
approx = cv.approxPolyDP(contour, epsilon, True)
filtered_contours.append(approx)
# Print the coordinates of the contour
for point in approx:
x, y = point[0]
print(f"{{x: {x}, y: {y}}},")
# Draw contours on the original image
cv.drawContours(img, filtered_contours, -1, (0, 255, 0), 3)
# Save the output image
cv.imwrite("out.png", img)
This is the target picture Im trying to get coordinates of:
Floor map plan
Im trying to get the coordinates like this for my Javascript program using Three JS:
]
{ x: 204, y: 363 },
{ x: 212, y: 48 },
{ x: 212, y: 191 },
{ x: 349, y: 191 },
{ x: 349, y: 49 },
]
Mohammed Mohid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.