Commit 90105169 authored by Balint Cristian's avatar Balint Cristian

Fix LSC crash, guard against invalid label index.

parent 38758066
...@@ -768,22 +768,25 @@ inline void SuperpixelLSCImpl::PostEnforceLabelConnectivity( int threshold ) ...@@ -768,22 +768,25 @@ inline void SuperpixelLSCImpl::PostEnforceLabelConnectivity( int threshold )
double W = W1 + W2; double W = W1 + W2;
for ( int b = 0; b < m_nr_channels; b++ ) if ( (Label1 > 0) && (Label2 > 0) )
{ {
centerC1[b][Label2] = float((W2*centerC1[b][Label2] + W1*centerC1[b][Label1]) / W); for ( int b = 0; b < m_nr_channels; b++ )
centerC2[b][Label2] = float((W2*centerC2[b][Label2] + W1*centerC2[b][Label1]) / W); {
} centerC1[b][Label2] = float((W2*centerC1[b][Label2] + W1*centerC1[b][Label1]) / W);
centerX1[Label2] = float((W2*centerX1[Label2] + W1*centerX1[Label1]) / W); centerC2[b][Label2] = float((W2*centerC2[b][Label2] + W1*centerC2[b][Label1]) / W);
centerX2[Label2] = float((W2*centerX2[Label2] + W1*centerX2[Label1]) / W); }
centerY1[Label2] = float((W2*centerY1[Label2] + W1*centerY1[Label1]) / W); centerX1[Label2] = float((W2*centerX1[Label2] + W1*centerX1[Label1]) / W);
centerY2[Label2] = float((W2*centerY2[Label2] + W1*centerY2[Label1]) / W); centerX2[Label2] = float((W2*centerX2[Label2] + W1*centerX2[Label1]) / W);
centerY1[Label2] = float((W2*centerY1[Label2] + W1*centerY1[Label1]) / W);
centerY2[Label2] = float((W2*centerY2[Label2] + W1*centerY2[Label1]) / W);
centerW[Label2] = (float)W; centerW[Label2] = (float)W;
for( size_t i = 0; i < (*S).xLoc.size(); i++ ) for( size_t i = 0; i < (*S).xLoc.size(); i++ )
{ {
int x = (*S).xLoc[i]; int x = (*S).xLoc[i];
int y = (*S).yLoc[i]; int y = (*S).yLoc[i];
m_klabels.at<int>(y,x) = Label2; m_klabels.at<int>(y,x) = Label2;
}
} }
vector<Superpixel>::iterator Stmp; vector<Superpixel>::iterator Stmp;
......
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