OPEN CV c++ person Recognition K-nn

128 Views Asked by At

I`m trying to write a simple program for person recognition using k-NN algorithm.I think this problem is a classic one, but I need some help. The k-NN classifier needs to compute some distances ,so my question is ,how to compare,or how to compute the distance between 2 images?(I mention that i have to use L2-norm as the metric distance) Thank you !

1

There are 1 best solutions below

2
On

So, k-NN works like, you first need features, with some values. For example, if you have, say n number of features for an image, you'll make an n-dimensional vector out of those features. Something like: F(x1, x2, x3, x4,....xn), where x1, x2, x3...xn are the values for the features. Now, if you compute the features, convert them into vector form, then you can simple calculate the distance between those vectors by using the iconic distance formula. And once you calculate/store all the distances in a list/array, you sort it, and take out the k top values with the lowest distance, and those will be your calculated k nearest neighbors. Once again, feature extraction is something you're looking for.