Im using opencv hough transform to attempt to detect shapes. The longer lines are all very nicely detected using the HoughLines method.but the shorter lines are completely ignored. Is there any way to also detect the shorter lines?
the code I'm using is described on this page http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
I'm more interested in lines such as the corner of the house etc. which parameter should I modify to do this with Hough transform? or is there a different algorithm I should be looking at
On the link you provide look at HoughLinesP
import cv2
import numpy as np
img = cv2.imread('beach.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
minLineLength = 100
maxLineGap = 5
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 50, minLineLength, maxLineGap)
for x1, y1, x2, y2 in lines[0]:
cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.imwrite('canny5.jpg', edges)
cv2.imwrite('houghlines5.jpg', img)
Also look at the edge image generated from Canny. You should only be able to find lines where lines exist in the edge image.
and here is the line detection output overlaid on your image:
Play around with variables minLineLength
and maxLineGap
to get a more desirable output. This method also does not give you the long lines that HoughLines does, but looking at the Canny image, maybe those long lines are not desirable in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With