Skip to content

fix the bug of HoughlinesSDIV#20763

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
Cocoaxx:houghlines_sdiv_bug_fix
Sep 29, 2021
Merged

fix the bug of HoughlinesSDIV#20763
opencv-pushbot merged 1 commit intoopencv:3.4from
Cocoaxx:houghlines_sdiv_bug_fix

Conversation

@Cocoaxx
Copy link
Copy Markdown
Contributor

@Cocoaxx Cocoaxx commented Sep 28, 2021

This PR fix the bug in HoughLinesSDIV reported in #20751.
image
image

Above is a test picture and test code.The results before and after modifying the code are shown in the figure below.

image
image

I also test more pictures and more parameters.The code works just fine.

for( size_t idx = 0; idx < lst.size(); idx++ )
{
if( lst[idx].rho < 0 )
continue;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code assumes items with .rho < 0 anywhere in the list and they are not limited to one.
Added check verifies the last element only, so updated code logic doesn't look similar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
image
Actually, through the sorting process, I think the elements pushed in the vector lst have the member variable rho > 0 expect the pivot with rho = -1. And the pivot is always in the end of the vector lst or poped by the sorting process. So I just check the last element.
This is indeed not consistent with the logic of the source code. Perhaps it is more convincing to remove all rho<0 elements in the vector lst.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Find peaks in maccum...
for( index = 0; index < sfn; index++ )
{
int pos = (int)(lst.size() - 1);
if( pos < 0 || lst[pos].value < mcaccum[index] )
{
hough_index vi(mcaccum[index],
index / stn * srho + ri * rho,
index % stn * stheta + ti * theta - (float)(CV_PI*0.5));
lst.push_back(vi);
for( ; pos >= 0; pos-- )
{
if( lst[pos].value > vi.value )
break;
lst[pos+1] = lst[pos];
}
lst[pos+1] = vi;
if( (int)lst.size() > linesMax )
lst.pop_back();
}
}

Ok

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants