black out everything outside the 2 lines

asked 2014-01-15 01:06:59 -0600

Kumar gravatar image

updated 2020-09-26 15:30:02 -0600

I perform the hough transform on image to detect lines. but I want to blackout everything outside the 2 lines... i get this kind of output

image description

but i want this type of output..

image description

i used this code..

vector<Vec2f> lines;
HoughLines(dst, lines, 1, 2*CV_PI/180, 70, 0, 0 );
for( size_t i = 0; i < lines.size(); i++ )
{
    float rho = lines[i][0], theta = lines[i][1];
    Point pt1, pt2;
    double a = cos(theta), b = sin(theta);
    double x0 = a*rho, y0 = b*rho;
    pt1.x = cvRound(x0 + 1000*(-b));
    pt1.y = cvRound(y0 + 1000*(a));
    pt2.x = cvRound(x0 - 1000*(-b));
    pt2.y = cvRound(y0 - 1000*(a));
    line( src, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}

any suggestion..

edit retag flag offensive close merge delete

Comments

Keep track of the min/max x values. Then black everything less than min_x and vice-versa for max_x ?

Nghia gravatar imageNghia ( 2014-01-15 03:08:30 -0600 )edit

this will blackout everything except lines, but i want SAMPLE kind of display as shown..

Kumar gravatar imageKumar ( 2014-01-15 09:00:15 -0600 )edit

No, if you do if(x < min_x || x > max_x) mark as black, then it will produce the sample above.

Nghia gravatar imageNghia ( 2014-01-15 17:56:24 -0600 )edit