Skip to content

Commit

Permalink
Merge pull request #5052 from kinaryml:c-pose-landmarker-api
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 597978981
  • Loading branch information
copybara-github committed Jan 12, 2024
2 parents 2c1f00e + 2bb717d commit 3ba2cb0
Show file tree
Hide file tree
Showing 17 changed files with 1,192 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct GestureRecognizerOptions {
// true for the lifetime of the callback function.
//
// A caller is responsible for closing gesture recognizer result.
typedef void (*result_callback_fn)(GestureRecognizerResult* result,
typedef void (*result_callback_fn)(const GestureRecognizerResult* result,
const MpImage& image, int64_t timestamp_ms,
char* error_msg);
result_callback_fn result_callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ std::string GetFullPath(absl::string_view file_name) {
return JoinPath("./", kTestDataDirectory, file_name);
}

void MatchesGestureRecognizerResult(GestureRecognizerResult* result,
void MatchesGestureRecognizerResult(const GestureRecognizerResult* result,
const float score_precision,
const float landmark_precision) {
// Expects to have the same number of hands detected.
Expand Down Expand Up @@ -188,7 +188,7 @@ TEST(GestureRecognizerTest, VideoModeTest) {
// timestamp is greater than the previous one.
struct LiveStreamModeCallback {
static int64_t last_timestamp;
static void Fn(GestureRecognizerResult* recognizer_result,
static void Fn(const GestureRecognizerResult* recognizer_result,
const MpImage& image, int64_t timestamp, char* error_msg) {
ASSERT_NE(recognizer_result, nullptr);
ASSERT_EQ(error_msg, nullptr);
Expand Down
1 change: 1 addition & 0 deletions mediapipe/tasks/c/vision/image_classifier/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ cc_test(
"//mediapipe/framework/formats:image",
"//mediapipe/framework/port:gtest",
"//mediapipe/tasks/c/components/containers:category",
"//mediapipe/tasks/c/vision/core:common",
"//mediapipe/tasks/cc/vision/utils:image_utils",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/strings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ImageClassifierOptions {
// true for the lifetime of the callback function.
//
// A caller is responsible for closing image classifier result.
typedef void (*result_callback_fn)(ImageClassifierResult* result,
typedef void (*result_callback_fn)(const ImageClassifierResult* result,
const MpImage& image, int64_t timestamp_ms,
char* error_msg);
result_callback_fn result_callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ limitations under the License.
#include "mediapipe/framework/port/gmock.h"
#include "mediapipe/framework/port/gtest.h"
#include "mediapipe/tasks/c/components/containers/category.h"
#include "mediapipe/tasks/c/vision/core/common.h"
#include "mediapipe/tasks/cc/vision/utils/image_utils.h"

namespace {
Expand Down Expand Up @@ -142,8 +143,8 @@ TEST(ImageClassifierTest, VideoModeTest) {
// timestamp is greater than the previous one.
struct LiveStreamModeCallback {
static int64_t last_timestamp;
static void Fn(ImageClassifierResult* classifier_result, const MpImage& image,
int64_t timestamp, char* error_msg) {
static void Fn(const ImageClassifierResult* classifier_result,
const MpImage& image, int64_t timestamp, char* error_msg) {
ASSERT_NE(classifier_result, nullptr);
ASSERT_EQ(error_msg, nullptr);
EXPECT_EQ(
Expand Down
2 changes: 1 addition & 1 deletion mediapipe/tasks/c/vision/image_embedder/image_embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct ImageEmbedderOptions {
// is true for the lifetime of the callback function.
//
// A caller is responsible for closing image embedder result.
typedef void (*result_callback_fn)(ImageEmbedderResult* result,
typedef void (*result_callback_fn)(const ImageEmbedderResult* result,
const MpImage& image, int64_t timestamp_ms,
char* error_msg);
result_callback_fn result_callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ TEST(ImageEmbedderTest, VideoModeTest) {
// timestamp is greater than the previous one.
struct LiveStreamModeCallback {
static int64_t last_timestamp;
static void Fn(ImageEmbedderResult* embedder_result, const MpImage& image,
int64_t timestamp, char* error_msg) {
static void Fn(const ImageEmbedderResult* embedder_result,
const MpImage& image, int64_t timestamp, char* error_msg) {
ASSERT_NE(embedder_result, nullptr);
ASSERT_EQ(error_msg, nullptr);
CheckMobileNetV3Result(*embedder_result, false);
Expand Down
2 changes: 1 addition & 1 deletion mediapipe/tasks/c/vision/object_detector/object_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct ObjectDetectorOptions {
// true for the lifetime of the callback function.
//
// A caller is responsible for closing object detector result.
typedef void (*result_callback_fn)(ObjectDetectorResult* result,
typedef void (*result_callback_fn)(const ObjectDetectorResult* result,
const MpImage& image, int64_t timestamp_ms,
char* error_msg);
result_callback_fn result_callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ TEST(ObjectDetectorTest, VideoModeTest) {
// timestamp is greater than the previous one.
struct LiveStreamModeCallback {
static int64_t last_timestamp;
static void Fn(ObjectDetectorResult* detector_result, const MpImage& image,
int64_t timestamp, char* error_msg) {
static void Fn(const ObjectDetectorResult* detector_result,
const MpImage& image, int64_t timestamp, char* error_msg) {
ASSERT_NE(detector_result, nullptr);
ASSERT_EQ(error_msg, nullptr);
EXPECT_EQ(detector_result->detections_count, 3);
Expand Down
151 changes: 151 additions & 0 deletions mediapipe/tasks/c/vision/pose_landmarker/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Copyright 2023 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(default_visibility = ["//mediapipe/tasks:internal"])

licenses(["notice"])

cc_library(
name = "pose_landmarker_result",
hdrs = ["pose_landmarker_result.h"],
visibility = ["//visibility:public"],
deps = [
"//mediapipe/tasks/c/components/containers:landmark",
"//mediapipe/tasks/c/vision/core:common",
],
)

cc_library(
name = "pose_landmarker_result_converter",
srcs = ["pose_landmarker_result_converter.cc"],
hdrs = ["pose_landmarker_result_converter.h"],
deps = [
":pose_landmarker_result",
"//mediapipe/tasks/c/components/containers:landmark",
"//mediapipe/tasks/c/components/containers:landmark_converter",
"//mediapipe/tasks/c/vision/core:common",
"//mediapipe/tasks/cc/components/containers:landmark",
"//mediapipe/tasks/cc/vision/pose_landmarker:pose_landmarker_result",
],
)

cc_test(
name = "pose_landmarker_result_converter_test",
srcs = ["pose_landmarker_result_converter_test.cc"],
data = [
"//mediapipe/framework/formats:image_frame_opencv",
"//mediapipe/framework/port:opencv_core",
"//mediapipe/framework/port:opencv_imgproc",
"//mediapipe/tasks/testdata/vision:test_images",
],
linkstatic = 1,
deps = [
":pose_landmarker_result",
":pose_landmarker_result_converter",
"//mediapipe/framework/deps:file_path",
"//mediapipe/framework/formats:image",
"//mediapipe/framework/port:gtest",
"//mediapipe/framework/port:gtest_main",
"//mediapipe/tasks/c/components/containers:landmark",
"//mediapipe/tasks/cc/components/containers:landmark",
"//mediapipe/tasks/cc/vision/pose_landmarker:pose_landmarker_result",
"//mediapipe/tasks/cc/vision/utils:image_utils",
"@com_google_absl//absl/flags:flag",
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "pose_landmarker_lib",
srcs = ["pose_landmarker.cc"],
hdrs = ["pose_landmarker.h"],
visibility = ["//visibility:public"],
deps = [
":pose_landmarker_result",
":pose_landmarker_result_converter",
"//mediapipe/framework/formats:image",
"//mediapipe/framework/formats:image_frame",
"//mediapipe/tasks/c/core:base_options",
"//mediapipe/tasks/c/core:base_options_converter",
"//mediapipe/tasks/c/vision/core:common",
"//mediapipe/tasks/cc/vision/core:running_mode",
"//mediapipe/tasks/cc/vision/pose_landmarker",
"//mediapipe/tasks/cc/vision/pose_landmarker:pose_landmarker_result",
"//mediapipe/tasks/cc/vision/utils:image_utils",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
],
alwayslink = 1,
)

cc_test(
name = "pose_landmarker_test",
srcs = ["pose_landmarker_test.cc"],
data = [
"//mediapipe/framework/formats:image_frame_opencv",
"//mediapipe/framework/port:opencv_core",
"//mediapipe/framework/port:opencv_imgproc",
"//mediapipe/tasks/testdata/vision:test_images",
"//mediapipe/tasks/testdata/vision:test_models",
],
linkstatic = 1,
deps = [
":pose_landmarker_lib",
":pose_landmarker_result",
"//mediapipe/framework/deps:file_path",
"//mediapipe/framework/formats:image",
"//mediapipe/framework/port:gtest",
"//mediapipe/tasks/c/components/containers:landmark",
"//mediapipe/tasks/c/vision/core:common",
"//mediapipe/tasks/cc/vision/utils:image_utils",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest_main",
],
)

# bazel build -c opt --linkopt -s --strip always --define MEDIAPIPE_DISABLE_GPU=1 \
# //mediapipe/tasks/c/vision/pose_landmarker:libpose_landmarker.so
cc_binary(
name = "libpose_landmarker.so",
linkopts = [
"-Wl,-soname=libpose_landmarker.so",
"-fvisibility=hidden",
],
linkshared = True,
tags = [
"manual",
"nobuilder",
"notap",
],
deps = [":pose_landmarker_lib"],
)

# bazel build --config darwin_arm64 -c opt --strip always --define MEDIAPIPE_DISABLE_GPU=1 \
# //mediapipe/tasks/c/vision/pose_landmarker:libpose_landmarker.dylib
cc_binary(
name = "libpose_landmarker.dylib",
linkopts = [
"-Wl,-install_name,libpose_landmarker.dylib",
"-fvisibility=hidden",
],
linkshared = True,
tags = [
"manual",
"nobuilder",
"notap",
],
deps = [":pose_landmarker_lib"],
)
Loading

0 comments on commit 3ba2cb0

Please sign in to comment.