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->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]; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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.
 | ||||
|  |  | |||
|  | @ -48,10 +48,10 @@ std::string GetFullPath(absl::string_view file_name) { | |||
|   return JoinPath("./", kTestDataDirectory, file_name); | ||||
| } | ||||
| 
 | ||||
| void MatchesFaceLandmarkerResult(FaceLandmarkerResult* result, | ||||
|                                  const float blendshapes_precision, | ||||
|                                  const float landmark_precision, | ||||
|                                  const float matrix_precison) { | ||||
| void ExpectFaceLandmarkerResultCorrect(FaceLandmarkerResult* result, | ||||
|                                        const float blendshapes_precision, | ||||
|                                        const float landmark_precision, | ||||
|                                        const float matrix_precison) { | ||||
|   // Expects to have the same number of faces detected.
 | ||||
|   EXPECT_EQ(result->face_blendshapes_count, 1); | ||||
| 
 | ||||
|  | @ -115,9 +115,9 @@ TEST(FaceLandmarkerTest, ImageModeTest) { | |||
|   FaceLandmarkerResult result; | ||||
|   face_landmarker_detect_image(landmarker, mp_image, &result, | ||||
|                                /* error_msg */ nullptr); | ||||
|   MatchesFaceLandmarkerResult(&result, kBlendshapesPrecision, | ||||
|                               kLandmarksPrecision, | ||||
|                               kFacialTransformationMatrixPrecision); | ||||
|   ExpectFaceLandmarkerResultCorrect(&result, kBlendshapesPrecision, | ||||
|                                     kLandmarksPrecision, | ||||
|                                     kFacialTransformationMatrixPrecision); | ||||
|   face_landmarker_close_result(&result); | ||||
|   face_landmarker_close(landmarker, /* error_msg */ nullptr); | ||||
| } | ||||
|  | @ -157,9 +157,9 @@ TEST(FaceLandmarkerTest, VideoModeTest) { | |||
|     face_landmarker_detect_for_video(landmarker, mp_image, i, &result, | ||||
|                                      /* error_msg */ nullptr); | ||||
| 
 | ||||
|     MatchesFaceLandmarkerResult(&result, kBlendshapesPrecision, | ||||
|                                 kLandmarksPrecision, | ||||
|                                 kFacialTransformationMatrixPrecision); | ||||
|     ExpectFaceLandmarkerResultCorrect(&result, kBlendshapesPrecision, | ||||
|                                       kLandmarksPrecision, | ||||
|                                       kFacialTransformationMatrixPrecision); | ||||
|     face_landmarker_close_result(&result); | ||||
|   } | ||||
|   face_landmarker_close(landmarker, /* error_msg */ nullptr); | ||||
|  | @ -176,9 +176,9 @@ struct LiveStreamModeCallback { | |||
|                  int64_t timestamp, char* error_msg) { | ||||
|     ASSERT_NE(landmarker_result, nullptr); | ||||
|     ASSERT_EQ(error_msg, nullptr); | ||||
|     MatchesFaceLandmarkerResult(landmarker_result, kBlendshapesPrecision, | ||||
|                                 kLandmarksPrecision, | ||||
|                                 kFacialTransformationMatrixPrecision); | ||||
|     ExpectFaceLandmarkerResultCorrect(landmarker_result, kBlendshapesPrecision, | ||||
|                                       kLandmarksPrecision, | ||||
|                                       kFacialTransformationMatrixPrecision); | ||||
|     EXPECT_GT(image.image_frame.width, 0); | ||||
|     EXPECT_GT(image.image_frame.height, 0); | ||||
|     EXPECT_GT(timestamp, last_timestamp); | ||||
|  |  | |||
|  | @ -47,9 +47,9 @@ std::string GetFullPath(absl::string_view file_name) { | |||
|   return JoinPath("./", kTestDataDirectory, file_name); | ||||
| } | ||||
| 
 | ||||
| void MatchesHandLandmarkerResult(HandLandmarkerResult* result, | ||||
|                                  const float score_precision, | ||||
|                                  const float landmark_precision) { | ||||
| void ExpectHandLandmarkerResultCorrect(HandLandmarkerResult* result, | ||||
|                                        const float score_precision, | ||||
|                                        const float landmark_precision) { | ||||
|   // Expects to have the same number of hands detected.
 | ||||
|   EXPECT_EQ(result->handedness_count, 1); | ||||
| 
 | ||||
|  | @ -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,8 +160,8 @@ struct LiveStreamModeCallback { | |||
|                  int64_t timestamp, char* error_msg) { | ||||
|     ASSERT_NE(landmarker_result, nullptr); | ||||
|     ASSERT_EQ(error_msg, nullptr); | ||||
|     MatchesHandLandmarkerResult(landmarker_result, kScorePrecision, | ||||
|                                 kLandmarkPrecision); | ||||
|     ExpectHandLandmarkerResultCorrect(landmarker_result, kScorePrecision, | ||||
|                                       kLandmarkPrecision); | ||||
|     EXPECT_GT(image.image_frame.width, 0); | ||||
|     EXPECT_GT(image.image_frame.height, 0); | ||||
|     EXPECT_GT(timestamp, last_timestamp); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user