Skip to content

Commit

Permalink
Fix face recognition (opendr-eu#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-daniel authored and Luca Marchionni committed Jun 24, 2022
1 parent 5ff3c6d commit 62242c7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/c_api/face_recognition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,20 @@ void build_database_face_recognition(const char *database_folder, const char *ou
// Write number of persons
int n = person_names.size();

fout.write(static_cast<char *>(&n), sizeof(int));
fout.write(reinterpret_cast<char *>(&n), sizeof(int));
for (int i = 0; i < n; i++) {
// Write the name of the person (along with its size)
int name_length = person_names[i].size() + 1;
fout.write(static_cast<char *>(&name_length), sizeof(int));
fout.write(reinterpret_cast<char *>(&name_length), sizeof(int));
fout.write(person_names[i].c_str(), name_length);
}

cv::Size s = database_out.size();

fout.write(static_cast<char *>(&s.height), sizeof(int));
fout.write(static_cast<char *>(&s.width), sizeof(int));
fout.write(static_cast<char *>(database_out.data), sizeof(float) * s.height * s.width);
fout.write(static_cast<char *>(&database_ids[0]), sizeof(int) * s.height);
fout.write(reinterpret_cast<char *>(&s.height), sizeof(int));
fout.write(reinterpret_cast<char *>(&s.width), sizeof(int));
fout.write(reinterpret_cast<char *>(database_out.data), sizeof(float) * s.height * s.width);
fout.write(reinterpret_cast<char *>(&database_ids[0]), sizeof(int) * s.height);
fout.flush();
fout.close();
}
Expand All @@ -318,14 +318,14 @@ void load_database_face_recognition(const char *database_path, face_recognition_
return;
}
int n;
fin.read(static_cast<char *>(&n), sizeof(int));
fin.read(reinterpret_cast<char *>(&n), sizeof(int));
char **person_names = new char *[n];

for (int i = 0; i < n; i++) {
person_names[i] = new char[512];
// Read person name
int name_length;
fin.read(static_cast<char *>(&name_length), sizeof(int));
fin.read(reinterpret_cast<char *>(&name_length), sizeof(int));
if (name_length > 512) {
std::cerr << "Person name exceeds max number of characters (512)" << std::endl;
return;
Expand All @@ -334,13 +334,13 @@ void load_database_face_recognition(const char *database_path, face_recognition_
}

int height, width;
fin.read(static_cast<char *>(&height), sizeof(int));
fin.read(static_cast<char *>(&width), sizeof(int));
fin.read(reinterpret_cast<char *>(&height), sizeof(int));
fin.read(reinterpret_cast<char *>(&width), sizeof(int));

float *database_buff = new float[height * width];
int *features_ids = new int[height];
fin.read(static_cast<char *>(database_buff), sizeof(float) * height * width);
fin.read(static_cast<char *>(features_ids), sizeof(int) * height);
fin.read(reinterpret_cast<char *>(database_buff), sizeof(float) * height * width);
fin.read(reinterpret_cast<char *>(features_ids), sizeof(int) * height);

fin.close();

Expand Down

0 comments on commit 62242c7

Please sign in to comment.