Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Houghlines detects incorrectly

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

click to hide/show revision 2
No.2 Revision

Houghlines detects incorrectly

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 );