T
OK ich habe noch einmal GDB benutzt und ich glaube ich weiß was passiert, ich greife wohl auf Indizes zu, die es nicht gibt.
Ich verstehe nur nicht wieso es passiert, denn es klappt bei manchen Bildern.
Vielleicht findet ihr den Fehler... aber nichts desto trotz scheint valgrind mir massive Speicherprobleme zu zeigen, die ich wohl durch schlechte Pointerverwaltung hin bekomme
Ich poste nochmal den Code der diese Probleme verursacht:
CImg<imgType> EyeLocatorPriv::labelImage()
{
CImg<imgType> labels(width,height,1,1);
labels.fill(0);
stack<Position*> st;
Position* pos = 0;
int lab = 1;
labelValues.clear();
for (int y=1; y<height-1; y++)
{
for (int x=1; x<width-1;x++)
{
if (redBinaryMask(x,y) == 0)
continue;
if (labels(x,y) > 0)
continue;
// push the position on the stack and assign label
st.push(new Position(x,y));
labels(x,y) = lab;
setLabelValue(lab);
while (!st.empty())
{
pos = st.top();
st.pop();
int i = pos->x;
int j = pos->y;
if ((redBinaryMask(i-1,j-1) == 255) && (labels(i-1,j-1) == 0))
{
st.push(new Position(i-1,j-1));
labels(i-1,j-1) = lab;
setLabelValue(lab);
}
if ((redBinaryMask(i-1,j) == 255) && (labels(i-1,j) == 0))
{
st.push(new Position(i-1,j));
labels(i-1,j) = lab;
setLabelValue(lab);
}
if ((redBinaryMask(i-1,j+1) == 255) && (labels(i-1,j+1) == 0))
{
st.push(new Position(i-1,j+1));
labels(i-1,j+1) = lab;
setLabelValue(lab);
}
if ((redBinaryMask(i,j-1) == 255) && (labels(i,j-1) == 0))
{
st.push(new Position(i,j-1));
labels(i,j-1) = lab;
setLabelValue(lab);
}
if ((redBinaryMask(i,j+1) == 255) && (labels(i,j+1) == 0))
{
st.push(new Position(i,j+1));
labels(i,j+1) = lab;
setLabelValue(lab);
}
if ((redBinaryMask(i+1,j-1) == 255) && (labels(i+1,j-1) == 0))
{
st.push(new Position(i+1,j-1));
labels(i+1,j-1) = lab;
setLabelValue(lab);
}
if ((redBinaryMask(i+1,j) == 255) && (labels(i+1,j) == 0))
{
st.push(new Position(i+1,j));
labels(i+1,j) = lab;
setLabelValue(lab);
}
if ((redBinaryMask(i+1,j+1) == 255) && (labels(i+1,j+1) == 0))
{
st.push(new Position(i+1,j+1));
labels(i+1,j+1) = lab;
setLabelValue(lab);
}
} // end while
lab++;
}
}
// remove components with less than 25 pixels
for (map<int,int>::iterator it = labelValues.begin(); it != labelValues.end();)
{
if (it->second <= 25)
labelValues.erase(it++);
else
++it;
}
// update labels
cimg_forXY(labels,x,y)
{
if (labelValues.find(labels(x,y)) == labelValues.end())
labels(x,y) = 0;
}
return labels;
}
Irgendwas scheint wohl schief zu laufen beim pushen auf den Stack, denn die for-Schleifen können definitiv nicht über das Ziel hinaus schießen...