Reputation: 1
std::vector<matrix<float,0,1>> face_descriptors = net(faces);
Above is what i was looking for.When I use the following command
std:: cout >> face_descriptors[0] >> endl;
It outputs the whole matrix.But I want to calculate the distance between two such vectors so how do I access each element individually?? I am using this for real time face recognition.
Upvotes: 0
Views: 1851
Reputation: 85
for(uint32_t u=0; u<face_descriptors.size(); u++)
{
cout << face_descriptors[u].nc() << endl;
cout << face_descriptors[u].nr() << endl;
for(uint32_t r=0; r<face_descriptors[u].nr(); r++)
cout << face_descriptors[u](r,0) << endl;
}
Upvotes: -1
Reputation: 101
As I understand, you need to calculate the distance between two face descriptors, which are dlib matrices and packed into std vector. To access each matrix element, follow idurdyev reply. But to calculate euclidean distance between i and j descriptors simply use dlib function:
double distance= length(face_descriptors[i] - face_descriptors[j]);
Upvotes: 1
Reputation: 381
Look at this example file that illustrates how to use matrix object in dlib http://dlib.net/matrix_ex.cpp.html
You can simply access element of dlib matrix by the () operator
matrix<float, 1, 3> mat;
mat = 0.1, 0.2, 0.3;
cout << mat(0) << endl;
matrix<float, 3, 3> mat2;
mat2 = 0.1, 0.2, 0.3,
1.1, 1.2, 1.3,
2.1, 2.2, 2.3;
cout << mat2(1, 1) << endl;
Upvotes: 2