平面图边缘检测 - 图像处理? [英] Floor Plan Edge Detection - Image Processing?

查看:228
本文介绍了平面图边缘检测 - 图像处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个完全不同的学科的人,需要一些图像处理技术才能在项目中实现这一目标。我需要从室内平面图中推导出边缘,如下所示

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

我尝试过这个特殊的Python边缘检测片段:

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

我该怎么做?我正在使用Python,但非常感谢任何通用或通用指针甚至一些关键字。

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

推荐答案

这是一个例子。你需要有opencv包才能运行它。

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.

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()



< h1>编辑

做了一些预处理来修复中断

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()

这篇关于平面图边缘检测 - 图像处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆