Reputation: 713
In my project, I need to detect the roof of a house plan. For that, I have to use the front elevation of the blueprint. I'm planning to use open-cv HoughLines method. Using that I need to detect the roof of the house. Below I have attached the image of the house and my code.
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('lol.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
lines = cv2.HoughLines(edges,1,np.pi/180,100)
count =0
for rho,theta in lines[0]:
a = np.cos(theta)
b = np.sin(theta)
x0 = a*rho
y0 = b*rho
x1 = int(x0 + 1000*(-b))
y1 = int(y0 + 1000*(a))
x2 = int(x0 - 1000*(-b))
y2 = int(y0 - 1000*(a))
if( 20 < 180*theta/np.pi < 88):
cv2.line(img, (x1, y1), (x2, y2), (255, 0, 255), 2)
if (160 > 180 * theta / np.pi > 93):
cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.imwrite('detectP.jpg',img)
plt.imshow(img)
House plan I used.
Result obtained after executing the code,
As you can see the detection go through the entire image. I need it to detect only the line and draw the line on top of the angle line not entire image.
Upvotes: 4
Views: 1855
Reputation: 9
You can use the HoughLinesP() function which is Probabilistic Hough Line Transform. Visit https://docs.opencv.org/3.4/d9/db0/tutorial_hough_lines.html
Upvotes: 1