문제

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.

도움이 되었습니까?

해결책

The idea of "VoteForUniqueness" is to filter ambiguous matchings. Lets say you want to match the points of image A with the points of image B.

Here is how it works :

  • "KnnMatch" is looking for 2-Nearest Neighbor for each point of image A in image B.
  • In image B, if the 1st and 2nd neighbors are too similar (the distance ratio is less than 0.8), we consider that we don't know which one is the best matching, so the matching is filtered (deleted).

Be awarded that here, when we speak about nearest neighbor and distance, we talk about the distance between the features of points (not the position).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top