Houghlines detects incorrectly

asked 2013-04-27 05:22:15 -0500

soheil1365 gravatar image

updated 2013-04-27 08:47:27 -0500

Guanta gravatar image

Hello guys...

I am detecting line with houghlines in opencv/c++.but the result are not logical... how can I improve the results.

for example some of the trivial lines are not detected while some wrong lines will be drawn... you can see in my image why this diagonal line has been detected while it is not really line(look at thresholded image) and in the other hand some trivial lines(edge) which are really line are not detected... thank you vwry much for any help

image description


Edit: Added code from comment:

Mat src_gray, grad_x, grad_y, abs_grad_x, abs_grad_y, grad,temp,dst,cdst; 
vector<Vec2f> lines; 
vector<Vec2f> all; 
noOfLines = 0; 
Point pt1, pt2; 
int scale = 1; 
int delta = 0; 
int ddepth = CV_16S; 
img.copyTo(temp);
GaussianBlur( img, temp, Size(3,3), 0, 0, BORDER_DEFAULT ); 
cvtColor(temp, src_gray, CV_RGB2GRAY ); 
Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
convertScaleAbs( grad_x, abs_grad_x ); 
Sobel( src_gray, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );
convertScaleAbs( grad_y, abs_grad_y ); 
addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad ); 
Canny(img,, dst, 128, 200, 3); 
cvtColor(dst, cdst, CV_GRAY2BGR); 
HoughLines(dst, lines,10 , CV_PI/10, 128, 0,0 );
edit retag flag offensive close merge delete

Comments

I think you have better post your code

wuling gravatar imagewuling ( 2013-04-27 06:25:35 -0500 )edit

Mat src_gray, grad_x, grad_y, abs_grad_x, abs_grad_y, grad,temp,dst,cdst; vector<Vec2f> lines; vector<Vec2f> all; noOfLines = 0; Point pt1, pt2; int scale = 1; int delta = 0; int ddepth = CV_16S; img.copyTo(temp); GaussianBlur( img, temp, Size(3,3), 0, 0, BORDER_DEFAULT ); cvtColor(temp, src_gray, CV_RGB2GRAY ); Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT ); convertScaleAbs( grad_x, abs_grad_x ); Sobel( src_gray, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT ); convertScaleAbs( grad_y, abs_grad_y ); addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad ); Canny(img,, dst, 128, 200, 3); cvtColor(dst, cdst, CV_GRAY2BGR); HoughLines(dst, lines,10 , CV_PI/10, 128, 0,0 );

Then I drew the detected lines

soheil1365 gravatar imagesoheil1365 ( 2013-04-27 07:37:34 -0500 )edit
1

Hi, My suggestion is changing 4th HoughLines parameter CV_PI/10 to CV_PI/180 and try again

wuling gravatar imagewuling ( 2013-04-27 08:41:15 -0500 )edit

again it gives me wrong answer... some additional and useless lines will be detected...I did it right now

soheil1365 gravatar imagesoheil1365 ( 2013-04-27 08:52:06 -0500 )edit

Hi, if you try to change 3th & 4th parameter for Houghlines and result you don't want. I think it's too sad that:)

wuling gravatar imagewuling ( 2013-04-27 11:38:32 -0500 )edit

oh nooo...I do not think so...because all the other people work with houghlines function properly...

soheil1365 gravatar imagesoheil1365 ( 2013-04-28 05:21:12 -0500 )edit