Updated tests in face_landmarker_result_converter_test

This commit is contained in:
Kinar 2023-12-11 16:11:39 -08:00
parent 0200d32285
commit 42b251cb8d

View File

@ -52,8 +52,7 @@ void InitFaceLandmarkerResult(
cpp_result->face_blendshapes = cpp_result->face_blendshapes =
std::vector<mediapipe::tasks::components::containers::Classifications>{ std::vector<mediapipe::tasks::components::containers::Classifications>{
classifications_for_blendshapes}; classifications_for_blendshapes};
// cpp_result->face_blendshapes->push_back( cpp_result->face_blendshapes->push_back(classifications_for_blendshapes);
// classifications_for_blendshapes);
// Initialize facial_transformation_matrixes // Initialize facial_transformation_matrixes
Eigen::MatrixXf cpp_matrix(2, 2); Eigen::MatrixXf cpp_matrix(2, 2);
@ -86,49 +85,43 @@ TEST(FaceLandmarkerResultConverterTest, ConvertsCustomResult) {
} }
// Verify conversion of face_blendshapes // Verify conversion of face_blendshapes
if (cpp_result.face_blendshapes.has_value()) { EXPECT_EQ(c_result.face_blendshapes_count,
EXPECT_EQ(c_result.face_blendshapes_count, cpp_result.face_blendshapes.value().size());
cpp_result.face_blendshapes.value().size()); for (uint32_t i = 0; i < c_result.face_blendshapes_count; ++i) {
for (uint32_t i = 0; i < c_result.face_blendshapes_count; ++i) { const auto& cpp_face_blendshapes = cpp_result.face_blendshapes.value();
const auto& cpp_face_blendshapes = cpp_result.face_blendshapes.value(); EXPECT_EQ(c_result.face_blendshapes[i].categories_count,
EXPECT_EQ(c_result.face_blendshapes[i].categories_count, cpp_face_blendshapes[i].categories.size());
cpp_face_blendshapes[i].categories.size()); for (uint32_t j = 0; j < c_result.face_blendshapes[i].categories_count;
for (uint32_t j = 0; j < c_result.face_blendshapes[i].categories_count; ++j) {
++j) { const auto& cpp_category = cpp_face_blendshapes[i].categories[j];
const auto& cpp_category = cpp_face_blendshapes[i].categories[j]; EXPECT_EQ(c_result.face_blendshapes[i].categories[j].index,
EXPECT_EQ(c_result.face_blendshapes[i].categories[j].index, cpp_category.index);
cpp_category.index); EXPECT_FLOAT_EQ(c_result.face_blendshapes[i].categories[j].score,
EXPECT_FLOAT_EQ(c_result.face_blendshapes[i].categories[j].score, cpp_category.score);
cpp_category.score); EXPECT_EQ(
EXPECT_EQ(std::string( std::string(c_result.face_blendshapes[i].categories[j].category_name),
c_result.face_blendshapes[i].categories[j].category_name), cpp_category.category_name);
cpp_category.category_name);
}
} }
} }
// Verify conversion of facial_transformation_matrixes // Verify conversion of facial_transformation_matrixes
if (cpp_result.facial_transformation_matrixes.has_value()) { EXPECT_EQ(c_result.facial_transformation_matrixes_count,
EXPECT_EQ(c_result.facial_transformation_matrixes_count, cpp_result.facial_transformation_matrixes.value().size());
cpp_result.facial_transformation_matrixes.value().size()); for (uint32_t i = 0; i < c_result.facial_transformation_matrixes_count; ++i) {
for (uint32_t i = 0; i < c_result.facial_transformation_matrixes_count; const auto& cpp_facial_transformation_matrixes =
++i) { cpp_result.facial_transformation_matrixes.value();
const auto& cpp_facial_transformation_matrixes = // Assuming Matrix struct contains data array and dimensions
cpp_result.facial_transformation_matrixes.value(); const auto& cpp_matrix = cpp_facial_transformation_matrixes[i];
// Assuming Matrix struct contains data array and dimensions EXPECT_EQ(c_result.facial_transformation_matrixes[i].rows,
const auto& cpp_matrix = cpp_facial_transformation_matrixes[i]; cpp_matrix.rows());
EXPECT_EQ(c_result.facial_transformation_matrixes[i].rows, EXPECT_EQ(c_result.facial_transformation_matrixes[i].cols,
cpp_matrix.rows()); cpp_matrix.cols());
EXPECT_EQ(c_result.facial_transformation_matrixes[i].cols, // Check each element of the matrix
cpp_matrix.cols()); for (long row = 0; row < cpp_matrix.rows(); ++row) {
// Check each element of the matrix for (long col = 0; col < cpp_matrix.cols(); ++col) {
for (long row = 0; row < cpp_matrix.rows(); ++row) { size_t index = col * cpp_matrix.rows() + row; // Column-major index
for (long col = 0; col < cpp_matrix.cols(); ++col) { EXPECT_FLOAT_EQ(c_result.facial_transformation_matrixes[i].data[index],
size_t index = col * cpp_matrix.rows() + row; // Column-major index cpp_matrix(row, col));
EXPECT_FLOAT_EQ(
c_result.facial_transformation_matrixes[i].data[index],
cpp_matrix(row, col));
}
} }
} }
} }