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
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 );
I think you have better post your code
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
Hi, My suggestion is changing 4th HoughLines parameter CV_PI/10 to CV_PI/180 and try again
again it gives me wrong answer... some additional and useless lines will be detected...I did it right now
Hi, if you try to change 3th & 4th parameter for Houghlines and result you don't want. I think it's too sad that:)
oh nooo...I do not think so...because all the other people work with houghlines function properly...