Skip to content

Commit bd619c5

Browse files
committed
Merge pull request #868 from sovrasov:line_descr_crash_fix
2 parents 47fbdd0 + 0cd4ff4 commit bd619c5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

modules/line_descriptor/src/binary_descriptor.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,15 @@ void BinaryDescriptor::detectImpl( const Mat& imageSrc, std::vector<KeyLine>& ke
511511
{
512512
for ( size_t keyCounter = 0; keyCounter < keylines.size(); keyCounter++ )
513513
{
514-
KeyLine kl = keylines[keyCounter];
514+
KeyLine& kl = keylines[keyCounter];
515+
516+
//due to imprecise floating point scaling in the pyramid a little overflow can occur in line coordinates,
517+
//especially on big images. It will be fixed here
518+
kl.startPointX = (float)std::min((int)kl.startPointX, mask.cols - 1);
519+
kl.startPointY = (float)std::min((int)kl.startPointY, mask.rows - 1);
520+
kl.endPointX = (float)std::min((int)kl.endPointX, mask.cols - 1);
521+
kl.endPointY = (float)std::min((int)kl.endPointY, mask.rows - 1);
522+
515523
if( mask.at < uchar > ( (int) kl.startPointY, (int) kl.startPointX ) == 0 && mask.at < uchar > ( (int) kl.endPointY, (int) kl.endPointX ) == 0 )
516524
keylines.erase( keylines.begin() + keyCounter );
517525
}

0 commit comments

Comments
 (0)