Fix naming in different files

This commit is contained in:
Kinar 2023-12-07 00:25:54 -08:00
parent b5c1c11f6a
commit 6909504ca9
3 changed files with 69 additions and 68 deletions

View File

@ -122,16 +122,17 @@ HandLandmarker* CppHandLandmarkerCreate(const HandLandmarkerOptions& options,
}; };
} }
auto detector = HandLandmarker::Create(std::move(cpp_options)); auto landmarker = HandLandmarker::Create(std::move(cpp_options));
if (!detector.ok()) { if (!landmarker.ok()) {
ABSL_LOG(ERROR) << "Failed to create HandLandmarker: " << detector.status(); ABSL_LOG(ERROR) << "Failed to create HandLandmarker: "
CppProcessError(detector.status(), error_msg); << landmarker.status();
CppProcessError(landmarker.status(), error_msg);
return nullptr; return nullptr;
} }
return detector->release(); return landmarker->release();
} }
int CppHandLandmarkerDetect(void* detector, const MpImage& image, int CppHandLandmarkerDetect(void* landmarker, const MpImage& image,
HandLandmarkerResult* result, char** error_msg) { HandLandmarkerResult* result, char** error_msg) {
if (image.type == MpImage::GPU_BUFFER) { if (image.type == MpImage::GPU_BUFFER) {
const absl::Status status = const absl::Status status =
@ -151,8 +152,8 @@ int CppHandLandmarkerDetect(void* detector, const MpImage& image,
return CppProcessError(img.status(), error_msg); return CppProcessError(img.status(), error_msg);
} }
auto cpp_detector = static_cast<HandLandmarker*>(detector); auto cpp_landmarker = static_cast<HandLandmarker*>(landmarker);
auto cpp_result = cpp_detector->Detect(*img); auto cpp_result = cpp_landmarker->Detect(*img);
if (!cpp_result.ok()) { if (!cpp_result.ok()) {
ABSL_LOG(ERROR) << "Recognition failed: " << cpp_result.status(); ABSL_LOG(ERROR) << "Recognition failed: " << cpp_result.status();
return CppProcessError(cpp_result.status(), error_msg); return CppProcessError(cpp_result.status(), error_msg);
@ -161,7 +162,7 @@ int CppHandLandmarkerDetect(void* detector, const MpImage& image,
return 0; return 0;
} }
int CppHandLandmarkerDetectForVideo(void* detector, const MpImage& image, int CppHandLandmarkerDetectForVideo(void* landmarker, const MpImage& image,
int64_t timestamp_ms, int64_t timestamp_ms,
HandLandmarkerResult* result, HandLandmarkerResult* result,
char** error_msg) { char** error_msg) {
@ -183,8 +184,8 @@ int CppHandLandmarkerDetectForVideo(void* detector, const MpImage& image,
return CppProcessError(img.status(), error_msg); return CppProcessError(img.status(), error_msg);
} }
auto cpp_detector = static_cast<HandLandmarker*>(detector); auto cpp_landmarker = static_cast<HandLandmarker*>(landmarker);
auto cpp_result = cpp_detector->DetectForVideo(*img, timestamp_ms); auto cpp_result = cpp_landmarker->DetectForVideo(*img, timestamp_ms);
if (!cpp_result.ok()) { if (!cpp_result.ok()) {
ABSL_LOG(ERROR) << "Recognition failed: " << cpp_result.status(); ABSL_LOG(ERROR) << "Recognition failed: " << cpp_result.status();
return CppProcessError(cpp_result.status(), error_msg); return CppProcessError(cpp_result.status(), error_msg);
@ -193,7 +194,7 @@ int CppHandLandmarkerDetectForVideo(void* detector, const MpImage& image,
return 0; return 0;
} }
int CppHandLandmarkerDetectAsync(void* detector, const MpImage& image, int CppHandLandmarkerDetectAsync(void* landmarker, const MpImage& image,
int64_t timestamp_ms, char** error_msg) { int64_t timestamp_ms, char** error_msg) {
if (image.type == MpImage::GPU_BUFFER) { if (image.type == MpImage::GPU_BUFFER) {
absl::Status status = absl::Status status =
@ -213,8 +214,8 @@ int CppHandLandmarkerDetectAsync(void* detector, const MpImage& image,
return CppProcessError(img.status(), error_msg); return CppProcessError(img.status(), error_msg);
} }
auto cpp_detector = static_cast<HandLandmarker*>(detector); auto cpp_landmarker = static_cast<HandLandmarker*>(landmarker);
auto cpp_result = cpp_detector->DetectAsync(*img, timestamp_ms); auto cpp_result = cpp_landmarker->DetectAsync(*img, timestamp_ms);
if (!cpp_result.ok()) { if (!cpp_result.ok()) {
ABSL_LOG(ERROR) << "Data preparation for the landmark detection failed: " ABSL_LOG(ERROR) << "Data preparation for the landmark detection failed: "
<< cpp_result; << cpp_result;
@ -227,14 +228,14 @@ void CppHandLandmarkerCloseResult(HandLandmarkerResult* result) {
CppCloseHandLandmarkerResult(result); CppCloseHandLandmarkerResult(result);
} }
int CppHandLandmarkerClose(void* detector, char** error_msg) { int CppHandLandmarkerClose(void* landmarker, char** error_msg) {
auto cpp_detector = static_cast<HandLandmarker*>(detector); auto cpp_landmarker = static_cast<HandLandmarker*>(landmarker);
auto result = cpp_detector->Close(); auto result = cpp_landmarker->Close();
if (!result.ok()) { if (!result.ok()) {
ABSL_LOG(ERROR) << "Failed to close HandLandmarker: " << result; ABSL_LOG(ERROR) << "Failed to close HandLandmarker: " << result;
return CppProcessError(result, error_msg); return CppProcessError(result, error_msg);
} }
delete cpp_detector; delete cpp_landmarker;
return 0; return 0;
} }
@ -248,26 +249,26 @@ void* hand_landmarker_create(struct HandLandmarkerOptions* options,
*options, error_msg); *options, error_msg);
} }
int hand_landmarker_detect_image(void* detector, const MpImage& image, int hand_landmarker_detect_image(void* landmarker, const MpImage& image,
HandLandmarkerResult* result, HandLandmarkerResult* result,
char** error_msg) { char** error_msg) {
return mediapipe::tasks::c::vision::hand_landmarker:: return mediapipe::tasks::c::vision::hand_landmarker::CppHandLandmarkerDetect(
CppHandLandmarkerDetect(detector, image, result, error_msg); landmarker, image, result, error_msg);
} }
int hand_landmarker_detect_for_video(void* detector, const MpImage& image, int hand_landmarker_detect_for_video(void* landmarker, const MpImage& image,
int64_t timestamp_ms, int64_t timestamp_ms,
HandLandmarkerResult* result, HandLandmarkerResult* result,
char** error_msg) { char** error_msg) {
return mediapipe::tasks::c::vision::hand_landmarker:: return mediapipe::tasks::c::vision::hand_landmarker::
CppHandLandmarkerDetectForVideo(detector, image, timestamp_ms, result, CppHandLandmarkerDetectForVideo(landmarker, image, timestamp_ms, result,
error_msg); error_msg);
} }
int hand_landmarker_detect_async(void* detector, const MpImage& image, int hand_landmarker_detect_async(void* landmarker, const MpImage& image,
int64_t timestamp_ms, char** error_msg) { int64_t timestamp_ms, char** error_msg) {
return mediapipe::tasks::c::vision::hand_landmarker:: return mediapipe::tasks::c::vision::hand_landmarker::
CppHandLandmarkerDetectAsync(detector, image, timestamp_ms, error_msg); CppHandLandmarkerDetectAsync(landmarker, image, timestamp_ms, error_msg);
} }
void hand_landmarker_close_result(HandLandmarkerResult* result) { void hand_landmarker_close_result(HandLandmarkerResult* result) {
@ -275,9 +276,9 @@ void hand_landmarker_close_result(HandLandmarkerResult* result) {
result); result);
} }
int hand_landmarker_close(void* detector, char** error_ms) { int hand_landmarker_close(void* landmarker, char** error_ms) {
return mediapipe::tasks::c::vision::hand_landmarker::CppHandLandmarkerClose( return mediapipe::tasks::c::vision::hand_landmarker::CppHandLandmarkerClose(
detector, error_ms); landmarker, error_ms);
} }
} // extern "C" } // extern "C"

View File

@ -82,15 +82,15 @@ struct HandLandmarkerOptions {
MP_EXPORT void* hand_landmarker_create(struct HandLandmarkerOptions* options, MP_EXPORT void* hand_landmarker_create(struct HandLandmarkerOptions* options,
char** error_msg); char** error_msg);
// Performs gesture recognition on the input `image`. Returns `0` on success. // Performs hand landmark detection on the input `image`. Returns `0` on
// If an error occurs, returns an error code and sets the error parameter to an // success. If an error occurs, returns an error code and sets the error
// an error message (if `error_msg` is not `nullptr`). You must free the memory // parameter to an an error message (if `error_msg` is not `nullptr`). You must
// allocated for the error message. // free the memory allocated for the error message.
MP_EXPORT int hand_landmarker_detect_image(void* detector, const MpImage& image, MP_EXPORT int hand_landmarker_detect_image(void* landmarker, const MpImage& image,
HandLandmarkerResult* result, HandLandmarkerResult* result,
char** error_msg); char** error_msg);
// Performs gesture recognition on the provided video frame. // Performs hand landmark detection on the provided video frame.
// Only use this method when the HandLandmarker is created with the video // Only use this method when the HandLandmarker is created with the video
// running mode. // running mode.
// The image can be of any size with format RGB or RGBA. It's required to // The image can be of any size with format RGB or RGBA. It's required to
@ -99,13 +99,13 @@ MP_EXPORT int hand_landmarker_detect_image(void* detector, const MpImage& image,
// If an error occurs, returns an error code and sets the error parameter to an // If an error occurs, returns an error code and sets the error parameter to an
// an error message (if `error_msg` is not `nullptr`). You must free the memory // an error message (if `error_msg` is not `nullptr`). You must free the memory
// allocated for the error message. // allocated for the error message.
MP_EXPORT int hand_landmarker_detect_for_video(void* detector, MP_EXPORT int hand_landmarker_detect_for_video(void* landmarker,
const MpImage& image, const MpImage& image,
int64_t timestamp_ms, int64_t timestamp_ms,
HandLandmarkerResult* result, HandLandmarkerResult* result,
char** error_msg); char** error_msg);
// Sends live image data to gesture recognition, and the results will be // Sends live image data to hand landmark detection, and the results will be
// available via the `result_callback` provided in the HandLandmarkerOptions. // available via the `result_callback` provided in the HandLandmarkerOptions.
// Only use this method when the HandLandmarker is created with the live // Only use this method when the HandLandmarker is created with the live
// stream running mode. // stream running mode.
@ -115,15 +115,15 @@ MP_EXPORT int hand_landmarker_detect_for_video(void* detector,
// increasing. // increasing.
// The `result_callback` provides: // The `result_callback` provides:
// - The recognition results as an HandLandmarkerResult object. // - The recognition results as an HandLandmarkerResult object.
// - The const reference to the corresponding input image that the gesture // - The const reference to the corresponding input image that the hand
// detector runs on. Note that the const reference to the image will no // landmarker runs on. Note that the const reference to the image will no
// longer be valid when the callback returns. To access the image data // longer be valid when the callback returns. To access the image data
// outside of the callback, callers need to make a copy of the image. // outside of the callback, callers need to make a copy of the image.
// - The input timestamp in milliseconds. // - The input timestamp in milliseconds.
// If an error occurs, returns an error code and sets the error parameter to an // If an error occurs, returns an error code and sets the error parameter to an
// an error message (if `error_msg` is not `nullptr`). You must free the memory // an error message (if `error_msg` is not `nullptr`). You must free the memory
// allocated for the error message. // allocated for the error message.
MP_EXPORT int hand_landmarker_detect_async(void* detector, const MpImage& image, MP_EXPORT int hand_landmarker_detect_async(void* landmarker, const MpImage& image,
int64_t timestamp_ms, int64_t timestamp_ms,
char** error_msg); char** error_msg);
@ -135,7 +135,7 @@ MP_EXPORT void hand_landmarker_close_result(HandLandmarkerResult* result);
// If an error occurs, returns an error code and sets the error parameter to an // If an error occurs, returns an error code and sets the error parameter to an
// an error message (if `error_msg` is not `nullptr`). You must free the memory // an error message (if `error_msg` is not `nullptr`). You must free the memory
// allocated for the error message. // allocated for the error message.
MP_EXPORT int hand_landmarker_close(void* detector, char** error_msg); MP_EXPORT int hand_landmarker_close(void* landmarker, char** error_msg);
#ifdef __cplusplus #ifdef __cplusplus
} // extern C } // extern C

View File

@ -90,8 +90,8 @@ TEST(HandLandmarkerTest, ImageModeTest) {
/* min_tracking_confidence= */ 0.5, /* min_tracking_confidence= */ 0.5,
}; };
void* detector = hand_landmarker_create(&options, /* error_msg */ nullptr); void* landmarker = hand_landmarker_create(&options, /* error_msg */ nullptr);
EXPECT_NE(detector, nullptr); EXPECT_NE(landmarker, nullptr);
const auto& image_frame = image->GetImageFrameSharedPtr(); const auto& image_frame = image->GetImageFrameSharedPtr();
const MpImage mp_image = { const MpImage mp_image = {
@ -102,11 +102,11 @@ TEST(HandLandmarkerTest, ImageModeTest) {
.height = image_frame->Height()}}; .height = image_frame->Height()}};
HandLandmarkerResult result; HandLandmarkerResult result;
hand_landmarker_detect_image(detector, mp_image, &result, hand_landmarker_detect_image(landmarker, mp_image, &result,
/* error_msg */ nullptr); /* error_msg */ nullptr);
MatchesHandLandmarkerResult(&result, kScorePrecision, kLandmarkPrecision); MatchesHandLandmarkerResult(&result, kScorePrecision, kLandmarkPrecision);
hand_landmarker_close_result(&result); hand_landmarker_close_result(&result);
hand_landmarker_close(detector, /* error_msg */ nullptr); hand_landmarker_close(landmarker, /* error_msg */ nullptr);
} }
TEST(HandLandmarkerTest, VideoModeTest) { TEST(HandLandmarkerTest, VideoModeTest) {
@ -125,8 +125,8 @@ TEST(HandLandmarkerTest, VideoModeTest) {
/* min_tracking_confidence= */ 0.5, /* min_tracking_confidence= */ 0.5,
}; };
void* detector = hand_landmarker_create(&options, /* error_msg */ nullptr); void* landmarker = hand_landmarker_create(&options, /* error_msg */ nullptr);
EXPECT_NE(detector, nullptr); EXPECT_NE(landmarker, nullptr);
const auto& image_frame = image->GetImageFrameSharedPtr(); const auto& image_frame = image->GetImageFrameSharedPtr();
const MpImage mp_image = { const MpImage mp_image = {
@ -138,13 +138,13 @@ TEST(HandLandmarkerTest, VideoModeTest) {
for (int i = 0; i < kIterations; ++i) { for (int i = 0; i < kIterations; ++i) {
HandLandmarkerResult result; HandLandmarkerResult result;
hand_landmarker_detect_for_video(detector, mp_image, i, &result, hand_landmarker_detect_for_video(landmarker, mp_image, i, &result,
/* error_msg */ nullptr); /* error_msg */ nullptr);
MatchesHandLandmarkerResult(&result, kScorePrecision, kLandmarkPrecision); MatchesHandLandmarkerResult(&result, kScorePrecision, kLandmarkPrecision);
hand_landmarker_close_result(&result); hand_landmarker_close_result(&result);
} }
hand_landmarker_close(detector, /* error_msg */ nullptr); hand_landmarker_close(landmarker, /* error_msg */ nullptr);
} }
// A structure to support LiveStreamModeTest below. This structure holds a // A structure to support LiveStreamModeTest below. This structure holds a
@ -154,16 +154,16 @@ TEST(HandLandmarkerTest, VideoModeTest) {
// timestamp is greater than the previous one. // timestamp is greater than the previous one.
struct LiveStreamModeCallback { struct LiveStreamModeCallback {
static int64_t last_timestamp; static int64_t last_timestamp;
static void Fn(HandLandmarkerResult* detector_result, const MpImage& image, static void Fn(HandLandmarkerResult* landmarker_result, const MpImage& image,
int64_t timestamp, char* error_msg) { int64_t timestamp, char* error_msg) {
ASSERT_NE(detector_result, nullptr); ASSERT_NE(landmarker_result, nullptr);
ASSERT_EQ(error_msg, nullptr); ASSERT_EQ(error_msg, nullptr);
MatchesHandLandmarkerResult(detector_result, kScorePrecision, MatchesHandLandmarkerResult(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);
EXPECT_GT(timestamp, last_timestamp); EXPECT_GT(timestamp, last_timestamp);
last_timestamp++; ++last_timestamp;
} }
}; };
int64_t LiveStreamModeCallback::last_timestamp = -1; int64_t LiveStreamModeCallback::last_timestamp = -1;
@ -186,8 +186,8 @@ TEST(HandLandmarkerTest, LiveStreamModeTest) {
/* result_callback= */ LiveStreamModeCallback::Fn, /* result_callback= */ LiveStreamModeCallback::Fn,
}; };
void* detector = hand_landmarker_create(&options, /* error_msg */ nullptr); void* landmarker = hand_landmarker_create(&options, /* error_msg */ nullptr);
EXPECT_NE(detector, nullptr); EXPECT_NE(landmarker, nullptr);
const auto& image_frame = image->GetImageFrameSharedPtr(); const auto& image_frame = image->GetImageFrameSharedPtr();
const MpImage mp_image = { const MpImage mp_image = {
@ -198,11 +198,11 @@ TEST(HandLandmarkerTest, LiveStreamModeTest) {
.height = image_frame->Height()}}; .height = image_frame->Height()}};
for (int i = 0; i < kIterations; ++i) { for (int i = 0; i < kIterations; ++i) {
EXPECT_GE(hand_landmarker_detect_async(detector, mp_image, i, EXPECT_GE(hand_landmarker_detect_async(landmarker, mp_image, i,
/* error_msg */ nullptr), /* error_msg */ nullptr),
0); 0);
} }
hand_landmarker_close(detector, /* error_msg */ nullptr); hand_landmarker_close(landmarker, /* error_msg */ nullptr);
// Due to the flow limiter, the total of outputs might be smaller than the // Due to the flow limiter, the total of outputs might be smaller than the
// number of iterations. // number of iterations.
@ -224,8 +224,8 @@ TEST(HandLandmarkerTest, InvalidArgumentHandling) {
}; };
char* error_msg; char* error_msg;
void* detector = hand_landmarker_create(&options, &error_msg); void* landmarker = hand_landmarker_create(&options, &error_msg);
EXPECT_EQ(detector, nullptr); EXPECT_EQ(landmarker, nullptr);
EXPECT_THAT(error_msg, HasSubstr("ExternalFile must specify")); EXPECT_THAT(error_msg, HasSubstr("ExternalFile must specify"));
@ -245,17 +245,17 @@ TEST(HandLandmarkerTest, FailedRecognitionHandling) {
/* min_tracking_confidence= */ 0.5, /* min_tracking_confidence= */ 0.5,
}; };
void* detector = hand_landmarker_create(&options, /* error_msg */ void* landmarker = hand_landmarker_create(&options, /* error_msg */
nullptr); nullptr);
EXPECT_NE(detector, nullptr); EXPECT_NE(landmarker, nullptr);
const MpImage mp_image = {.type = MpImage::GPU_BUFFER, .gpu_buffer = {}}; const MpImage mp_image = {.type = MpImage::GPU_BUFFER, .gpu_buffer = {}};
HandLandmarkerResult result; HandLandmarkerResult result;
char* error_msg; char* error_msg;
hand_landmarker_detect_image(detector, mp_image, &result, &error_msg); hand_landmarker_detect_image(landmarker, mp_image, &result, &error_msg);
EXPECT_THAT(error_msg, HasSubstr("GPU Buffer not supported yet")); EXPECT_THAT(error_msg, HasSubstr("GPU Buffer not supported yet"));
free(error_msg); free(error_msg);
hand_landmarker_close(detector, /* error_msg */ nullptr); hand_landmarker_close(landmarker, /* error_msg */ nullptr);
} }
} // namespace } // namespace