平面图边缘检测 - 图像处理?

7 python opencv image-processing

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

在此输入图像描述

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

from PIL import Image, ImageFilter

image = Image.open('L12-ST.jpg')
image = image.filter(ImageFilter.FIND_EDGES)
image.save('new_name.png') 
Run Code Online (Sandbox Code Playgroud)

然而,它返回的细节远远超出我的需要.它基本上检测所有边缘,包括房间墙壁.实际上,我需要的只是走廊的墙壁.所以我期待这样的事情

在此输入图像描述

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

Zaw*_*Lin 8

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

那里有一个休息因为图像有文物.如果你使用更高质量的图像,它可能会更好.如果你不能拥有更高质量的图像,可能会采用形态学操作来连接小间隙并去除四分之一圆形突起.

在此输入图像描述

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()
Run Code Online (Sandbox Code Playgroud)

编辑

做了一些预处理来修复休息

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()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Eb *_*adi 0

我想您在使用边缘检测器之前需要进行一些预处理,因为房间墙壁和走廊之间没有看到特别的差异。一种想法是在 cad 文件中选择不同的颜色,然后帮助您的检测器区分您要查找的内容。第二个是提前限制你的加工区域。否则,我不认为有一种直接的技术可以应用并提取走廊。希望有帮助。