Hough transform detects shorter lines
Im using opencv hough transform to try and detect shapes. Longer lines are very well recognized using the HoughLines method. But shorter lines are completely ignored. Is there a way to detect 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 like corner of the house, etc. what parameter should be changed for this using the Hough transform? or is there another algorithm I should be looking at
source to share
In the link provided, see 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 take a look at the edge image created by Canny. You should only be able to find lines in which boundary images exist.
and here is the line output superimposed on your image:
Play with variables minLineLength
and maxLineGap
to get a more desirable result. This method also doesn't give you the long lines that HoughLines does, but looking at Canny's image it might be that those long lines are not desirable in the first place.
source to share