grebtsew / FloorplanToBlender3d

Create 3d rooms in blender from floorplans.
GNU General Public License v3.0
396 stars 103 forks source link

Requesting different way of calculating walls outside of contour. #19

Closed frankkim1108 closed 2 years ago

frankkim1108 commented 2 years ago

Hi @grebtsew !!

I have been testing your project for creating a 3D model of a house with a 2D floor plan image. While I was testing your code, I tried all the example floorplan images that was in your Repo.

However, when I ran the code on example5.png image, the output blender file had some missing wall. I started looking for reasons why the walls were missing. After following every line of code, it seemed like

# remove walls outside of contour
boxes = calculate.remove_walls_not_in_contour(boxes, contour)

was removing some walls close to the outer contour.

The code shown in the remove_walls_not_int_contour is using cv2.pointPolygonTest() to see if the wall is inside the outer contour or not. However, some floorplan's outer contour was too tight for the wall bounding rectangle box that it detected some walls as if it was outside of the outer contour.

So one way I tried fixing this issue was instead of doing a pointPolygonTest with a outer contour of the house , which is an output from

# detect contour
contour, _ = detect.outer_contours(gray)

I tried it with a bounding rectangle box of a outer contour of a house.

the code below is what I did.

# detect contour
contour, _ = detect.outer_contours(gray)

(x, y, w, h) = cv2.boundingRect(contour)
p1 = [x, y]
p2 = [x, y + h]
p3 = [x + w, y + h]
p4 = [x + w, y]
pts = np.array([p1, p2, p3, p4], np.int32)
pts = pts.reshape(-1, 1, 2)

# remove walls outside of contour
boxes = calculate.remove_walls_not_in_contour(boxes, pts)

The image below is before and after the fix Before After

grebtsew commented 2 years ago

Hi @frankkim1108!

Thanks for testing the project.

This is a great contribution! The proposed solution really is an improvement!

Do you want me to make an update when I have time or would you like to create a merge request?

Cheers, @grebtsew

frankkim1108 commented 2 years ago

Thank you for the compliment !

I would like to create a merge request please!

grebtsew commented 2 years ago

Hello,

This issue is solved with pull request #21.

Cheers, @grebtsew