Commit 5dc7be6a authored by jexner's avatar jexner

Fix segmentation fault in SuperpixelLSCImpl::PostEnforceLabelConnectivity

See https://github.com/opencv/opencv_contrib/issues/1048
parent 58f7afcb
......@@ -792,10 +792,25 @@ inline void SuperpixelLSCImpl::PostEnforceLabelConnectivity( int threshold )
{
Size[Label2] = Size[Label1] + Size[Label2];
if( Size[Label2] >= threshold )
{
if( S == Stmp )
{
// erasing only one should be sufficient when the iterators are the same
// (maybe the case S == Stmp is not even possible?)
Sarray.erase( S );
}
else if( S < Stmp )
{
// erase the latter element first, so the other iterator is not invalidated
Sarray.erase( Stmp );
Sarray.erase( S );
}
else
{
Sarray.erase( S );
Sarray.erase( Stmp );
}
}
else
{
(*Stmp).xLoc.insert( (*Stmp).xLoc.end(), (*S).xLoc.begin(), (*S).xLoc.end() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment