Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

python - Floor Plan Edge Detection - Image Processing?

I am a guy from a completely different discipline who need some Image Processing techniques to achieve this goal in a project. I need to derive the edges from an indoor floor plan, as shown below

enter image description here

I have tried this particular Python edge detect snippet:

from PIL import Image, ImageFilter

image = Image.open('L12-ST.jpg')
image = image.filter(ImageFilter.FIND_EDGES)
image.save('new_name.png') 

However, it is returning too much more details than I need. It basically detects all the edges including the room walls. Actaully, what I need are just the corridor walls. So I expect something like this

enter image description here

How may I do this? I am using Python, but any generic or general pointers or even some keywords are very much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

here's an example. you will need to have opencv package to run it.

there's a break there because the image has artifacts. if you use a higher quality image, it's probably going to be better. if you cant have a higher quality image, may be morphological operations can be used to connect the small gaps and remove quarter circle protrusions.

enter image description here

import cv2
import numpy as np

img = cv2.imread('c:/data/floor.jpg')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray=255-gray

contours,hierarchy = cv2.findContours(gray,cv2.RETR_LIST ,cv2.CHAIN_APPROX_NONE )

for cnt in contours:
    area = cv2.contourArea(cnt)
    if area>9000 and area<40000:
        cv2.drawContours(img,[cnt],0,(255,0,0),2)

cv2.imshow('img',img)
cv2.waitKey()

edit

did some preprocessing to fix the break

import cv2
import numpy as np

img = cv2.imread('c:/data/floor.jpg')

img=cv2.resize(img,(1700,700))
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray=255-gray
gray=cv2.threshold(gray,4,255,cv2.THRESH_BINARY)[1]
gray=cv2.blur(gray,(15,1))
contours,hierarchy = cv2.findContours(gray,cv2.RETR_LIST ,cv2.CHAIN_APPROX_NONE )

for cnt in contours:
    area = cv2.contourArea(cnt)
    if area>150000 and area<500000:
        cv2.drawContours(img,[cnt],0,(255,0,0),2)

cv2.imshow('img',img)
cv2.waitKey()

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...