Simplified copying data from Eigen matrix to C-style matrix and addressed some issues

This commit is contained in:
Kinar 2023-12-13 19:59:36 -08:00
parent 42b251cb8d
commit 6fab3a8b85
4 changed files with 36 additions and 32 deletions

View File

@ -27,11 +27,13 @@ void CppConvertToMatrix(const Eigen::MatrixXf& in, ::Matrix* out) {
out->cols = in.cols();
out->data = new float[out->rows * out->cols];
// Copy data from Eigen matrix to C matrix in column-major order
for (int col = 0; col < out->cols; ++col) {
for (int row = 0; row < out->rows; ++row) {
out->data[col * out->rows + row] = in(row, col);
}
// Copy data from Eigen matrix to C-style matrix.
// This operation copies the elements sequentially as they appear in the Eigen
// matrix's internal storage, regardless of whether it's stored in row-major
// or column-major order and ensures the integrity of data during the
// transfer.
for (int i = 0; i < out->rows * out->cols; ++i) {
out->data[i] = in.data()[i];
}
}

View File

@ -33,19 +33,19 @@ extern "C" {
// The hand landmarker result from HandLandmarker, where each vector
// element represents a single hand detected in the image.
struct FaceLandmarkerResult {
// Optional face blendshapes results.
struct Categories* face_blendshapes;
// The number of elements in the face_blendshapes array.
uint32_t face_blendshapes_count;
// Detected face landmarks in normalized image coordinates.
struct NormalizedLandmarks* face_landmarks;
// The number of elements in the face_landmarks array.
uint32_t face_landmarks_count;
// Optional facial transformation matrix.
// Optional face blendshapes results.
struct Categories* face_blendshapes;
// The number of elements in the face_blendshapes array.
uint32_t face_blendshapes_count;
// Optional facial transformation matrixes.
struct Matrix* facial_transformation_matrixes;
// The number of elements in the facial_transformation_matrixes array.

View File

@ -48,7 +48,7 @@ std::string GetFullPath(absl::string_view file_name) {
return JoinPath("./", kTestDataDirectory, file_name);
}
void MatchesFaceLandmarkerResult(FaceLandmarkerResult* result,
void ExpectFaceLandmarkerResultCorrect(FaceLandmarkerResult* result,
const float blendshapes_precision,
const float landmark_precision,
const float matrix_precison) {
@ -115,7 +115,7 @@ TEST(FaceLandmarkerTest, ImageModeTest) {
FaceLandmarkerResult result;
face_landmarker_detect_image(landmarker, mp_image, &result,
/* error_msg */ nullptr);
MatchesFaceLandmarkerResult(&result, kBlendshapesPrecision,
ExpectFaceLandmarkerResultCorrect(&result, kBlendshapesPrecision,
kLandmarksPrecision,
kFacialTransformationMatrixPrecision);
face_landmarker_close_result(&result);
@ -157,7 +157,7 @@ TEST(FaceLandmarkerTest, VideoModeTest) {
face_landmarker_detect_for_video(landmarker, mp_image, i, &result,
/* error_msg */ nullptr);
MatchesFaceLandmarkerResult(&result, kBlendshapesPrecision,
ExpectFaceLandmarkerResultCorrect(&result, kBlendshapesPrecision,
kLandmarksPrecision,
kFacialTransformationMatrixPrecision);
face_landmarker_close_result(&result);
@ -176,7 +176,7 @@ struct LiveStreamModeCallback {
int64_t timestamp, char* error_msg) {
ASSERT_NE(landmarker_result, nullptr);
ASSERT_EQ(error_msg, nullptr);
MatchesFaceLandmarkerResult(landmarker_result, kBlendshapesPrecision,
ExpectFaceLandmarkerResultCorrect(landmarker_result, kBlendshapesPrecision,
kLandmarksPrecision,
kFacialTransformationMatrixPrecision);
EXPECT_GT(image.image_frame.width, 0);

View File

@ -47,7 +47,7 @@ std::string GetFullPath(absl::string_view file_name) {
return JoinPath("./", kTestDataDirectory, file_name);
}
void MatchesHandLandmarkerResult(HandLandmarkerResult* result,
void ExpectHandLandmarkerResultCorrect(HandLandmarkerResult* result,
const float score_precision,
const float landmark_precision) {
// Expects to have the same number of hands detected.
@ -104,7 +104,8 @@ TEST(HandLandmarkerTest, ImageModeTest) {
HandLandmarkerResult result;
hand_landmarker_detect_image(landmarker, mp_image, &result,
/* error_msg */ nullptr);
MatchesHandLandmarkerResult(&result, kScorePrecision, kLandmarkPrecision);
ExpectHandLandmarkerResultCorrect(&result, kScorePrecision,
kLandmarkPrecision);
hand_landmarker_close_result(&result);
hand_landmarker_close(landmarker, /* error_msg */ nullptr);
}
@ -141,7 +142,8 @@ TEST(HandLandmarkerTest, VideoModeTest) {
hand_landmarker_detect_for_video(landmarker, mp_image, i, &result,
/* error_msg */ nullptr);
MatchesHandLandmarkerResult(&result, kScorePrecision, kLandmarkPrecision);
ExpectHandLandmarkerResultCorrect(&result, kScorePrecision,
kLandmarkPrecision);
hand_landmarker_close_result(&result);
}
hand_landmarker_close(landmarker, /* error_msg */ nullptr);
@ -158,7 +160,7 @@ struct LiveStreamModeCallback {
int64_t timestamp, char* error_msg) {
ASSERT_NE(landmarker_result, nullptr);
ASSERT_EQ(error_msg, nullptr);
MatchesHandLandmarkerResult(landmarker_result, kScorePrecision,
ExpectHandLandmarkerResultCorrect(landmarker_result, kScorePrecision,
kLandmarkPrecision);
EXPECT_GT(image.image_frame.width, 0);
EXPECT_GT(image.image_frame.height, 0);