Strange lines detected by openCV python -


i followed tutorial of python opencv, , trying use houghlinesp() detect lines, here code:

imgloc = '...\lines.jpg'  img = cv2.imread(imgloc) gray = cv2.cvtcolor(img, cv2.color_bgr2gray) edges = cv2.canny(gray, 50, 100) minlinelength = 20; maxlinegap = 5 lines = cv2.houghlinesp(edges, 1, np.pi/180, 100, \     minlinelength, maxlinegap) [[x1, y1, x2, y2]] in lines:     cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 2) cv2.imshow('line', img) cv2.waitkey(); cv2.destroyallwindows() 

and here's get: floatinglines apparently strange. there's many lines in sky never expected, , thought there more vertical lines on building, there's not.

the tutorial doesn't give pictures demonstrating how result should be, have no idea if that's normal or not.

so, is there problem in code lead wired image? if does, can make change let detect more vertical line?

==========update_1============

i followed comment's suggestion, more line can detected:

#minlinelength = 20; maxlinegap = 5 lines = cv2.houghlinesp(edges, 1, np.pi/180, 100, \     minlinelength = 10, maxlinegap = 5) 

linedetection2.0 still vertical lines lacked. , canny() result: canny

in result of canny() there vertical edges, why disappeared after houghlinesp()? (or that's visual error?)

==========update_2============

i added blur , value of minlinelength:

gray = cv2.gaussianblur(gray, (5, 5), 0) ... lines = cv2.houghlinesp(edges, 1, np.pi/180, 100, \         minlinelength = 50, maxlinegap = 5) 

the result clearer, still not vertical lines... edges detected , started wonder these slashes comes from

it might worth starting smoothing before performing canny edge detection.

i suggest higher values minlinelength (and maxlinegap, though should not large). should rid of smaller lines , connect vertical line segments detected. if still not bring out vertical lines, might have in threshold parameter.


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -