0

I have a floorplan image. Through opencv houghlines method I want to identify the walls in it. Since the size of the lines of walls is larger than the lines in objects in the image, I want to increase the size of the line to be searched. Generally, the code identifies the lines in objects also even though the threshold value is increased. I am new to this platform. Can somebody help me? This is the floorplan image

When I increase the threshold value some object lines are still there but some lines on the walls are missing. Here is the result when I increase the threshold value This is the result I got

Here is the code:

import cv2
import numpy as np
img = cv2.imread("C:\\Users\\User\\Desktop\\tkinter_codes\\floorplans\\ROBIN\\Dataset_3roomsmall\\Cat1_1.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,900,1000,apertureSize = 5)
cv2.imshow('edges', edges)
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10)
for line in lines:
    x1,y1,x2,y2 = line[0]
    cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imshow('image', img)
k = cv2.waitKey(0)
cv2.destroyAllWindows()
nirmal6353
  • 17
  • 7

1 Answers1

0

Use morphology operations for preprocessing this image. By example:

import cv2

original=cv2.imread('kDA62.jpg', cv2.IMREAD_GRAYSCALE)
se=cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
opening=cv2.dilate(original,se,iterations = 1)
opening=cv2.erode(opening,se,iterations = 1)
cv2.imwrite('out_9.png', opening)

enter image description here

Alex Alex
  • 1,893
  • 1
  • 6
  • 12
  • But eventhough the wall lines are identified as two lines one as outer line and other as the inner one. So I am getting two different coordinates at a point on the wall. But I want as single coordinate. Is it possible? – nirmal6353 May 09 '20 at 09:28
  • Also, we are using the probabilistic hough transform method, so all the walls are not identified. Could you please tell me how can I make it identify all the walls? – nirmal6353 May 09 '20 at 09:47
  • You can try to find a skeleton image. Then the found line will be in the middle between the outer and inner lines. Also try function HoughLines, not HoughLinesP. – Alex Alex May 09 '20 at 10:29
  • Morphology can also split the image of walls into segments without using HoughLinesP What do you want to get as a result? – Alex Alex May 09 '20 at 10:29
  • I want the coordinates of every line segment of the wall. So I can use them for constructing the wall for future purposes. How can I find the skeleton image? – nirmal6353 May 09 '20 at 10:39
  • see https://stackoverflow.com/questions/33095476/is-there-any-build-in-function-can-do-skeletonization-in-opencv/33098888#33098888 May be need invert image.. or use scikit-image skimage.morphology.skeletonize – Alex Alex May 09 '20 at 10:48
  • using the hough lines method it is producing clumsy lines and so it is confusing. That's why I am using probabilistic houghlines. with the given image(image containing walls) Could you please share the houghlines method? I tried but the image was almost full of lines. – nirmal6353 May 09 '20 at 11:28