Simplified copying data from Eigen matrix to C-style matrix and addressed some issues
This commit is contained in:
parent
42b251cb8d
commit
6fab3a8b85
|
@ -27,11 +27,13 @@ void CppConvertToMatrix(const Eigen::MatrixXf& in, ::Matrix* out) {
|
||||||
out->cols = in.cols();
|
out->cols = in.cols();
|
||||||
out->data = new float[out->rows * out->cols];
|
out->data = new float[out->rows * out->cols];
|
||||||
|
|
||||||
// Copy data from Eigen matrix to C matrix in column-major order
|
// Copy data from Eigen matrix to C-style matrix.
|
||||||
for (int col = 0; col < out->cols; ++col) {
|
// This operation copies the elements sequentially as they appear in the Eigen
|
||||||
for (int row = 0; row < out->rows; ++row) {
|
// matrix's internal storage, regardless of whether it's stored in row-major
|
||||||
out->data[col * out->rows + row] = in(row, col);
|
// 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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,19 +33,19 @@ extern "C" {
|
||||||
// The hand landmarker result from HandLandmarker, where each vector
|
// The hand landmarker result from HandLandmarker, where each vector
|
||||||
// element represents a single hand detected in the image.
|
// element represents a single hand detected in the image.
|
||||||
struct FaceLandmarkerResult {
|
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.
|
// Detected face landmarks in normalized image coordinates.
|
||||||
struct NormalizedLandmarks* face_landmarks;
|
struct NormalizedLandmarks* face_landmarks;
|
||||||
|
|
||||||
// The number of elements in the face_landmarks array.
|
// The number of elements in the face_landmarks array.
|
||||||
uint32_t face_landmarks_count;
|
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;
|
struct Matrix* facial_transformation_matrixes;
|
||||||
|
|
||||||
// The number of elements in the facial_transformation_matrixes array.
|
// The number of elements in the facial_transformation_matrixes array.
|
||||||
|
|
|
@ -48,7 +48,7 @@ std::string GetFullPath(absl::string_view file_name) {
|
||||||
return JoinPath("./", kTestDataDirectory, file_name);
|
return JoinPath("./", kTestDataDirectory, file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MatchesFaceLandmarkerResult(FaceLandmarkerResult* result,
|
void ExpectFaceLandmarkerResultCorrect(FaceLandmarkerResult* result,
|
||||||
const float blendshapes_precision,
|
const float blendshapes_precision,
|
||||||
const float landmark_precision,
|
const float landmark_precision,
|
||||||
const float matrix_precison) {
|
const float matrix_precison) {
|
||||||
|
@ -115,7 +115,7 @@ TEST(FaceLandmarkerTest, ImageModeTest) {
|
||||||
FaceLandmarkerResult result;
|
FaceLandmarkerResult result;
|
||||||
face_landmarker_detect_image(landmarker, mp_image, &result,
|
face_landmarker_detect_image(landmarker, mp_image, &result,
|
||||||
/* error_msg */ nullptr);
|
/* error_msg */ nullptr);
|
||||||
MatchesFaceLandmarkerResult(&result, kBlendshapesPrecision,
|
ExpectFaceLandmarkerResultCorrect(&result, kBlendshapesPrecision,
|
||||||
kLandmarksPrecision,
|
kLandmarksPrecision,
|
||||||
kFacialTransformationMatrixPrecision);
|
kFacialTransformationMatrixPrecision);
|
||||||
face_landmarker_close_result(&result);
|
face_landmarker_close_result(&result);
|
||||||
|
@ -157,7 +157,7 @@ TEST(FaceLandmarkerTest, VideoModeTest) {
|
||||||
face_landmarker_detect_for_video(landmarker, mp_image, i, &result,
|
face_landmarker_detect_for_video(landmarker, mp_image, i, &result,
|
||||||
/* error_msg */ nullptr);
|
/* error_msg */ nullptr);
|
||||||
|
|
||||||
MatchesFaceLandmarkerResult(&result, kBlendshapesPrecision,
|
ExpectFaceLandmarkerResultCorrect(&result, kBlendshapesPrecision,
|
||||||
kLandmarksPrecision,
|
kLandmarksPrecision,
|
||||||
kFacialTransformationMatrixPrecision);
|
kFacialTransformationMatrixPrecision);
|
||||||
face_landmarker_close_result(&result);
|
face_landmarker_close_result(&result);
|
||||||
|
@ -176,7 +176,7 @@ struct LiveStreamModeCallback {
|
||||||
int64_t timestamp, char* error_msg) {
|
int64_t timestamp, char* error_msg) {
|
||||||
ASSERT_NE(landmarker_result, nullptr);
|
ASSERT_NE(landmarker_result, nullptr);
|
||||||
ASSERT_EQ(error_msg, nullptr);
|
ASSERT_EQ(error_msg, nullptr);
|
||||||
MatchesFaceLandmarkerResult(landmarker_result, kBlendshapesPrecision,
|
ExpectFaceLandmarkerResultCorrect(landmarker_result, kBlendshapesPrecision,
|
||||||
kLandmarksPrecision,
|
kLandmarksPrecision,
|
||||||
kFacialTransformationMatrixPrecision);
|
kFacialTransformationMatrixPrecision);
|
||||||
EXPECT_GT(image.image_frame.width, 0);
|
EXPECT_GT(image.image_frame.width, 0);
|
||||||
|
|
|
@ -47,7 +47,7 @@ std::string GetFullPath(absl::string_view file_name) {
|
||||||
return JoinPath("./", kTestDataDirectory, file_name);
|
return JoinPath("./", kTestDataDirectory, file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MatchesHandLandmarkerResult(HandLandmarkerResult* result,
|
void ExpectHandLandmarkerResultCorrect(HandLandmarkerResult* result,
|
||||||
const float score_precision,
|
const float score_precision,
|
||||||
const float landmark_precision) {
|
const float landmark_precision) {
|
||||||
// Expects to have the same number of hands detected.
|
// Expects to have the same number of hands detected.
|
||||||
|
@ -104,7 +104,8 @@ TEST(HandLandmarkerTest, ImageModeTest) {
|
||||||
HandLandmarkerResult result;
|
HandLandmarkerResult result;
|
||||||
hand_landmarker_detect_image(landmarker, mp_image, &result,
|
hand_landmarker_detect_image(landmarker, mp_image, &result,
|
||||||
/* error_msg */ nullptr);
|
/* error_msg */ nullptr);
|
||||||
MatchesHandLandmarkerResult(&result, kScorePrecision, kLandmarkPrecision);
|
ExpectHandLandmarkerResultCorrect(&result, kScorePrecision,
|
||||||
|
kLandmarkPrecision);
|
||||||
hand_landmarker_close_result(&result);
|
hand_landmarker_close_result(&result);
|
||||||
hand_landmarker_close(landmarker, /* error_msg */ nullptr);
|
hand_landmarker_close(landmarker, /* error_msg */ nullptr);
|
||||||
}
|
}
|
||||||
|
@ -141,7 +142,8 @@ TEST(HandLandmarkerTest, VideoModeTest) {
|
||||||
hand_landmarker_detect_for_video(landmarker, mp_image, i, &result,
|
hand_landmarker_detect_for_video(landmarker, mp_image, i, &result,
|
||||||
/* error_msg */ nullptr);
|
/* error_msg */ nullptr);
|
||||||
|
|
||||||
MatchesHandLandmarkerResult(&result, kScorePrecision, kLandmarkPrecision);
|
ExpectHandLandmarkerResultCorrect(&result, kScorePrecision,
|
||||||
|
kLandmarkPrecision);
|
||||||
hand_landmarker_close_result(&result);
|
hand_landmarker_close_result(&result);
|
||||||
}
|
}
|
||||||
hand_landmarker_close(landmarker, /* error_msg */ nullptr);
|
hand_landmarker_close(landmarker, /* error_msg */ nullptr);
|
||||||
|
@ -158,7 +160,7 @@ struct LiveStreamModeCallback {
|
||||||
int64_t timestamp, char* error_msg) {
|
int64_t timestamp, char* error_msg) {
|
||||||
ASSERT_NE(landmarker_result, nullptr);
|
ASSERT_NE(landmarker_result, nullptr);
|
||||||
ASSERT_EQ(error_msg, nullptr);
|
ASSERT_EQ(error_msg, nullptr);
|
||||||
MatchesHandLandmarkerResult(landmarker_result, kScorePrecision,
|
ExpectHandLandmarkerResultCorrect(landmarker_result, kScorePrecision,
|
||||||
kLandmarkPrecision);
|
kLandmarkPrecision);
|
||||||
EXPECT_GT(image.image_frame.width, 0);
|
EXPECT_GT(image.image_frame.width, 0);
|
||||||
EXPECT_GT(image.image_frame.height, 0);
|
EXPECT_GT(image.image_frame.height, 0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user