Can someone explain me how does Features2DToolbox.VoteForUniqueness work?
This is the source code to use it :
BruteForceMatcher<float> matcher = new BruteForceMatcher<float>(DistanceType.L2);
matcher.Add(modelfeature);
indices = new Matrix<int>(destfeature.Rows, 2);
dist = new Matrix<float>(destfeature.Rows, 2);
matcher.KnnMatch(destfeature, indices, dist, 2, null);
mask = new Matrix<byte>(dist.Rows, 1);
mask.SetValue(255);
Features2DToolbox.VoteForUniqueness(dist, 0.8, mask);
I want to make the manual one :
indices = new Matrix<int>(destfeature.Rows, 2);
dist = new Matrix<float>(destfeature.Rows, 2);
for (int i = 0; i < destfeature.Rows; i++)
{
dist[i, 0] = float.MaxValue;
dist[i, 1] = float.MaxValue;
indices[i, 0] = -1;
indices[i, 1] = -1;
for (int j = 0; j < modelfeature.Rows; j++)
{
float temp = 0;
for (int k = 0; k < 128; k++)
{
temp = temp +(float) Math.Pow(modelfeature[j, k] - destfeature[i, k], 2.0);
}
temp =(float) Math.Sqrt(temp);
if (temp < dist[i, 0])
{
dist[i, 1] = dist[i, 0];
indices[i, 1] = indices[i, 0];
dist[i, 0] = temp;
indices[i, 0] = j;
}
else if (temp < dist[i, 1])
{
dist[i, 1] = temp;
indices[i, 1] = j;
}
}
}
mask = new Matrix<byte>(dist.Rows, 1);
for (int i = 0; i < dist.Rows; i++)
{
if (dist[i, 0] < dist[i, 1] * 0.8)
{
mask[i, 0] = 255;
}
else
{
mask[i, 0] = 0;
}
}
already edited
before my mistake is that i divided dist[i,1] with dist[i,0], if it is more than 0.8, it'true.