dnn example question.
Hello,
I want to port that application here https://docs.opencv.org/master/d5/d86... to a server app. I managed to read the model and get the embeddings for the pictures, so far so good.
What i dont get it is the following line:
var personVec = persons[name];
var score = vec.dot(personVec);
For me the dot product is always 1 - even when the embeddings have different values. I guess my math is not good enough here to understand.
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/dnn.hpp"
#include <math.h>
#include <iostream>
using namespace cv;
using namespace std;
using namespace dnn;
Mat eval( Net net, Mat face) {
Mat blob = blobFromImage(face, 1.0 / 255, Size(96, 96), Scalar(0,0,0,0), true, false);
net.setInput(blob);
Mat result = net.forward();
return result;
}
int main( int argc, char** argv)
{
Net net = readNetFromTorch("openface.nn4.small2.v1.t7");
net.setPreferableTarget(DNN_TARGET_OPENCL);
cout << "read model" << endl;
Mat face1 = imread("face1.jpeg");
Mat face1Vec = eval(net, face1);
cout << "Face1Vec" << face1Vec << endl;
Mat face2 = imread("face2.jpeg");
Mat face2Vec = eval(net, face2);
cout << "Face2Vec" << face2Vec << endl;
auto s1 = face1Vec.dot(face1Vec);
auto s2 = face1Vec.dot(face2Vec);
cout << "s1: " << s1 << endl;
cout << "s2: " << s2 << endl;
return 0;
}