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

View File

@ -82,15 +82,15 @@ struct HandLandmarkerOptions {
MP_EXPORT void* hand_landmarker_create(struct HandLandmarkerOptions* options,
char** error_msg);
// Performs gesture recognition on the input `image`. Returns `0` on success.
// 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
// allocated for the error message.
MP_EXPORT int hand_landmarker_detect_image(void* detector, const MpImage& image,
// Performs hand landmark detection on the input `image`. Returns `0` on
// success. 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 allocated for the error message.
MP_EXPORT int hand_landmarker_detect_image(void* landmarker, const MpImage& image,
HandLandmarkerResult* result,
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
// running mode.
// 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
// an error message (if `error_msg` is not `nullptr`). You must free the memory
// 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,
int64_t timestamp_ms,
HandLandmarkerResult* result,
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.
// Only use this method when the HandLandmarker is created with the live
// stream running mode.
@ -115,15 +115,15 @@ MP_EXPORT int hand_landmarker_detect_for_video(void* detector,
// increasing.
// The `result_callback` provides:
// - The recognition results as an HandLandmarkerResult object.
// - The const reference to the corresponding input image that the gesture
// detector runs on. Note that the const reference to the image will no
// - The const reference to the corresponding input image that the hand
// 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
// outside of the callback, callers need to make a copy of the image.
// - The input timestamp in milliseconds.
// 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
// 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,
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
// an error message (if `error_msg` is not `nullptr`). You must free the memory
// 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
} // extern C

View File

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