'how to access the elements of a dlib matrix / vector?

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.



Solution 1:[1]

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;

Solution 2:[2]

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]);

Solution 3:[3]

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;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 idurdyev
Solution 2 Andyrey
Solution 3 YU Chen Shih