Skip to content

Commit 374f5e2

Browse files
MediaPipe Teamjqtang
MediaPipe Team
authored and
jqtang
committed
Project import generated by Copybara.
GitOrigin-RevId: 65b427572550bd9c5bc5f053eeea0f44340d5673
1 parent 1392370 commit 374f5e2

29 files changed

+175
-27
lines changed

Diff for: WORKSPACE

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ http_archive(
3535

3636
http_archive(
3737
name = "rules_cc",
38-
strip_prefix = "rules_cc-master",
39-
urls = ["https://github.com/bazelbuild/rules_cc/archive/master.zip"],
38+
strip_prefix = "rules_cc-main",
39+
urls = ["https://github.com/bazelbuild/rules_cc/archive/main.zip"],
4040
)
4141

4242
http_archive(

Diff for: mediapipe/calculators/core/BUILD

+17
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,23 @@ cc_library(
419419
alwayslink = 1,
420420
)
421421

422+
cc_test(
423+
name = "make_pair_calculator_test",
424+
size = "small",
425+
srcs = ["make_pair_calculator_test.cc"],
426+
deps = [
427+
":make_pair_calculator",
428+
"//mediapipe/framework:calculator_framework",
429+
"//mediapipe/framework:calculator_runner",
430+
"//mediapipe/framework:timestamp",
431+
"//mediapipe/framework/port:gtest_main",
432+
"//mediapipe/framework/port:status",
433+
"//mediapipe/framework/tool:validate_type",
434+
"//mediapipe/util:packet_test_util",
435+
"//mediapipe/util:time_series_test_util",
436+
],
437+
)
438+
422439
cc_library(
423440
name = "matrix_multiply_calculator",
424441
srcs = ["matrix_multiply_calculator.cc"],
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2021 The MediaPipe Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "mediapipe/framework/calculator_framework.h"
16+
#include "mediapipe/framework/calculator_runner.h"
17+
#include "mediapipe/framework/port/canonical_errors.h"
18+
#include "mediapipe/framework/port/gmock.h"
19+
#include "mediapipe/framework/port/gtest.h"
20+
#include "mediapipe/framework/port/status.h"
21+
#include "mediapipe/framework/port/status_matchers.h"
22+
#include "mediapipe/framework/timestamp.h"
23+
#include "mediapipe/framework/tool/validate_type.h"
24+
#include "mediapipe/util/packet_test_util.h"
25+
#include "mediapipe/util/time_series_test_util.h"
26+
27+
namespace mediapipe {
28+
29+
class MakePairCalculatorTest
30+
: public mediapipe::TimeSeriesCalculatorTest<mediapipe::NoOptions> {
31+
protected:
32+
void SetUp() override {
33+
calculator_name_ = "MakePairCalculator";
34+
num_input_streams_ = 2;
35+
}
36+
};
37+
38+
TEST_F(MakePairCalculatorTest, ProducesExpectedPairs) {
39+
InitializeGraph();
40+
AppendInputPacket(new std::string("first packet"), Timestamp(1),
41+
/* input_index= */ 0);
42+
AppendInputPacket(new std::string("second packet"), Timestamp(5),
43+
/* input_index= */ 0);
44+
AppendInputPacket(new int(10), Timestamp(1), /* input_index= */ 1);
45+
AppendInputPacket(new int(20), Timestamp(5), /* input_index= */ 1);
46+
47+
MP_ASSERT_OK(RunGraph());
48+
49+
EXPECT_THAT(
50+
output().packets,
51+
::testing::ElementsAre(
52+
mediapipe::PacketContainsTimestampAndPayload<
53+
std::pair<Packet, Packet>>(
54+
Timestamp(1),
55+
::testing::Pair(
56+
mediapipe::PacketContainsTimestampAndPayload<std::string>(
57+
Timestamp(1), std::string("first packet")),
58+
mediapipe::PacketContainsTimestampAndPayload<int>(
59+
Timestamp(1), 10))),
60+
mediapipe::PacketContainsTimestampAndPayload<
61+
std::pair<Packet, Packet>>(
62+
Timestamp(5),
63+
::testing::Pair(
64+
mediapipe::PacketContainsTimestampAndPayload<std::string>(
65+
Timestamp(5), std::string("second packet")),
66+
mediapipe::PacketContainsTimestampAndPayload<int>(
67+
Timestamp(5), 20)))));
68+
}
69+
70+
} // namespace mediapipe

Diff for: mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator.cc

+4
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,18 @@ absl::Status ContentZoomingCalculator::Process(
660660
// Prevent box from extending beyond the image after camera smoothing.
661661
if (path_offset_y - ceil(path_height / 2.0) < 0) {
662662
path_offset_y = ceil(path_height / 2.0);
663+
MP_RETURN_IF_ERROR(path_solver_tilt_->SetState(path_offset_y));
663664
} else if (path_offset_y + ceil(path_height / 2.0) > frame_height_) {
664665
path_offset_y = frame_height_ - ceil(path_height / 2.0);
666+
MP_RETURN_IF_ERROR(path_solver_tilt_->SetState(path_offset_y));
665667
}
666668

667669
if (path_offset_x - ceil(path_width / 2.0) < 0) {
668670
path_offset_x = ceil(path_width / 2.0);
671+
MP_RETURN_IF_ERROR(path_solver_pan_->SetState(path_offset_x));
669672
} else if (path_offset_x + ceil(path_width / 2.0) > frame_width_) {
670673
path_offset_x = frame_width_ - ceil(path_width / 2.0);
674+
MP_RETURN_IF_ERROR(path_solver_pan_->SetState(path_offset_x));
671675
}
672676

673677
// Convert to top/bottom borders to remove.

Diff for: mediapipe/examples/desktop/autoflip/calculators/face_box_adjuster_calculator.proto

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,10 @@ message FaceBoxAdjusterCalculatorOptions {
6868

6969
// The max amount of time to use an old eye distance when the face look angle
7070
// is unstable.
71-
optional int32 max_facesize_history_us = 9 [default = 8000000];
71+
optional int32 max_facesize_history_us = 9 [default = 300000000];
72+
73+
// Scale factor of face width to shift based on pan look angle.
74+
optional float pan_position_shift_scale = 15 [default = 0.5];
75+
// Scale factor of face height to shift based on tilt look angle.
76+
optional float tilt_position_shift_scale = 16 [default = 0.5];
7277
}

Diff for: mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.cc

+6
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ absl::Status KinematicPathSolver::GetState(int* position) {
209209
return absl::OkStatus();
210210
}
211211

212+
absl::Status KinematicPathSolver::SetState(const int position) {
213+
RET_CHECK(initialized_) << "SetState called before first observation added.";
214+
current_position_px_ = position;
215+
return absl::OkStatus();
216+
}
217+
212218
absl::Status KinematicPathSolver::GetTargetPosition(int* target_position) {
213219
RET_CHECK(initialized_)
214220
<< "GetTargetPosition called before first observation added.";

Diff for: mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.h

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class KinematicPathSolver {
4848
absl::Status UpdatePrediction(const int64 time_us);
4949
// Get the state at a time.
5050
absl::Status GetState(int* position);
51+
// Overwrite the current state value.
52+
absl::Status SetState(const int position);
5153
// Update PixelPerDegree value.
5254
absl::Status UpdatePixelsPerDegree(const float pixels_per_degree);
5355
// Provide the current target position of the reframe action.

Diff for: mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver_test.cc

+21
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,27 @@ TEST(KinematicPathSolverTest, TimestampSmoothing) {
371371
EXPECT_EQ(state, 701);
372372
}
373373

374+
TEST(KinematicPathSolverTest, PassSetPosition) {
375+
KinematicOptions options;
376+
// Set min motion to 2deg
377+
options.set_min_motion_to_reframe(1.0);
378+
options.set_update_rate_seconds(.0000001);
379+
options.set_max_update_rate(1.0);
380+
options.set_max_velocity(18);
381+
// Set degrees / pixel to 8.3
382+
KinematicPathSolver solver(options, 0, 500, 500.0 / kWidthFieldOfView);
383+
int state;
384+
MP_ASSERT_OK(solver.AddObservation(400, kMicroSecInSec * 0));
385+
// Move target by 10px / 8.3 = 1.2deg
386+
MP_ASSERT_OK(solver.AddObservation(410, kMicroSecInSec * 1));
387+
MP_ASSERT_OK(solver.GetState(&state));
388+
// Expect cam to move.
389+
EXPECT_EQ(state, 410);
390+
MP_ASSERT_OK(solver.SetState(400));
391+
MP_ASSERT_OK(solver.GetState(&state));
392+
EXPECT_EQ(state, 400);
393+
}
394+
374395
} // namespace
375396
} // namespace autoflip
376397
} // namespace mediapipe

Diff for: mediapipe/java/com/google/mediapipe/framework/jni/BUILD

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ cc_library(
7373
],
7474
"//mediapipe/gpu:disable_gpu": [],
7575
}),
76-
features = ["-no_undefined"],
7776
linkopts = select({
7877
"//conditions:default": [],
7978
"//mediapipe:android": [

Diff for: mediapipe/java/com/google/mediapipe/mediapipe_aar.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ def _mediapipe_jni(name, gen_libmediapipe, calculators = []):
243243
"//mediapipe:android_arm64": ["@android_opencv//:libopencv_java3_so_arm64-v8a"],
244244
"//mediapipe:android_armeabi": ["@android_opencv//:libopencv_java3_so_armeabi-v7a"],
245245
"//mediapipe:android_arm": ["@android_opencv//:libopencv_java3_so_armeabi-v7a"],
246+
"//mediapipe:android_x86": ["@android_opencv//:libopencv_java3_so_x86"],
247+
"//mediapipe:android_x86_64": ["@android_opencv//:libopencv_java3_so_x86_64"],
246248
"//conditions:default": [],
247249
}),
248250
alwayslink = 1,

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/BUILD renamed to mediapipe/java/com/google/mediapipe/solutioncore/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ cc_binary(
7575
# TODO: Add more calculators to support other top-level solutions.
7676
deps = [
7777
"//mediapipe/java/com/google/mediapipe/framework/jni:mediapipe_framework_jni",
78+
"//mediapipe/modules/hand_landmark:hand_landmark_tracking_cpu_image",
7879
"//mediapipe/modules/hand_landmark:hand_landmark_tracking_gpu_image",
7980
],
8081
)

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/CameraInput.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/CameraInput.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
import android.app.Activity;
1818
import com.google.mediapipe.components.CameraHelper;

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/ErrorListener.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/ErrorListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
/** Interface for the customizable MediaPipe solution error listener. */
1818
public interface ErrorListener {

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/ImageSolutionBase.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/ImageSolutionBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
import android.content.Context;
1818
import android.graphics.Bitmap;

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/ImageSolutionResult.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/ImageSolutionResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
import android.graphics.Bitmap;
1818
import com.google.mediapipe.framework.AndroidPacketGetter;

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/OutputHandler.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/OutputHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
import android.util.Log;
1818
import com.google.mediapipe.framework.MediaPipeException;

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/ResultGlRenderer.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/ResultGlRenderer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
/** Interface for the customizable MediaPipe solution result OpenGL renderer. */
1818
public interface ResultGlRenderer<T extends ImageSolutionResult> {

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/ResultListener.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/ResultListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
/** Interface for the customizable MediaPipe solution result listener. */
1818
public interface ResultListener<T> {

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/SolutionBase.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/SolutionBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
import static java.util.concurrent.TimeUnit.MICROSECONDS;
1818
import static java.util.concurrent.TimeUnit.MILLISECONDS;

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/SolutionGlSurfaceView.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/SolutionGlSurfaceView.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
import android.content.Context;
1818
import android.opengl.GLES20;

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/SolutionGlSurfaceViewRenderer.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/SolutionGlSurfaceViewRenderer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
import android.graphics.SurfaceTexture;
1818
import com.google.mediapipe.components.GlSurfaceViewRenderer;

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/SolutionInfo.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/SolutionInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
import com.google.auto.value.AutoValue;
1818
import com.google.common.collect.ImmutableList;

Diff for: mediapipe/java/com/google/mediapipe/solutionbase/SolutionResult.java renamed to mediapipe/java/com/google/mediapipe/solutioncore/SolutionResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.mediapipe.solutionbase;
15+
package com.google.mediapipe.solutioncore;
1616

1717
/**
1818
* Interface of the MediaPipe solution result. Any MediaPipe solution-specific result class should
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Keep public members of our public interfaces. This also prevents the
2+
# obfuscation of the corresponding methods in classes implementing them,
3+
# such as implementations of PacketCallback#process.
4+
-keep public interface com.google.mediapipe.solutioncore.* {
5+
public *;
6+
}

Diff for: mediapipe/java/com/google/mediapipe/solutions/hands/BUILD

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ android_library(
2424
],
2525
assets = [
2626
"//mediapipe/modules/hand_landmark:hand_landmark_tracking_gpu_image.binarypb",
27+
"//mediapipe/modules/hand_landmark:hand_landmark_tracking_cpu_image.binarypb",
2728
"//mediapipe/modules/hand_landmark:handedness.txt",
2829
"//mediapipe/modules/hand_landmark:hand_landmark.tflite",
2930
"//mediapipe/modules/palm_detection:palm_detection.tflite",
@@ -36,7 +37,7 @@ android_library(
3637
"//mediapipe/framework/formats:classification_java_proto_lite",
3738
"//mediapipe/framework/formats:landmark_java_proto_lite",
3839
"//mediapipe/java/com/google/mediapipe/framework:android_framework",
39-
"//mediapipe/java/com/google/mediapipe/solutionbase:solution_base",
40+
"//mediapipe/java/com/google/mediapipe/solutioncore:solution_base",
4041
"//third_party:autovalue",
4142
"@maven//:androidx_annotation_annotation",
4243
"@maven//:com_google_code_findbugs_jsr305",

Diff for: mediapipe/java/com/google/mediapipe/solutions/hands/Hands.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import com.google.mediapipe.formats.proto.ClassificationProto.Classification;
2222
import com.google.mediapipe.framework.MediaPipeException;
2323
import com.google.mediapipe.framework.Packet;
24-
import com.google.mediapipe.solutionbase.ErrorListener;
25-
import com.google.mediapipe.solutionbase.ImageSolutionBase;
26-
import com.google.mediapipe.solutionbase.OutputHandler;
27-
import com.google.mediapipe.solutionbase.ResultListener;
28-
import com.google.mediapipe.solutionbase.SolutionInfo;
24+
import com.google.mediapipe.solutioncore.ErrorListener;
25+
import com.google.mediapipe.solutioncore.ImageSolutionBase;
26+
import com.google.mediapipe.solutioncore.OutputHandler;
27+
import com.google.mediapipe.solutioncore.ResultListener;
28+
import com.google.mediapipe.solutioncore.SolutionInfo;
2929
import java.util.HashMap;
3030
import java.util.Map;
3131
import javax.annotation.Nullable;
@@ -41,7 +41,8 @@ public class Hands extends ImageSolutionBase {
4141
private static final String TAG = "Hands";
4242

4343
private static final String NUM_HANDS = "num_hands";
44-
private static final String SOLUTION_GRAPH_NAME = "hand_landmark_tracking_gpu_image.binarypb";
44+
private static final String GPU_GRAPH_NAME = "hand_landmark_tracking_gpu_image.binarypb";
45+
private static final String CPU_GRAPH_NAME = "hand_landmark_tracking_cpu_image.binarypb";
4546
private static final String IMAGE_INPUT_STREAM = "image";
4647
private static final ImmutableList<String> OUTPUT_STREAMS =
4748
ImmutableList.of("multi_hand_landmarks", "multi_handedness", "image");
@@ -82,7 +83,7 @@ public Hands(Context context, HandsOptions options) {
8283

8384
SolutionInfo solutionInfo =
8485
SolutionInfo.builder()
85-
.setBinaryGraphPath(SOLUTION_GRAPH_NAME)
86+
.setBinaryGraphPath(options.runOnGpu() ? GPU_GRAPH_NAME : CPU_GRAPH_NAME)
8687
.setImageInputStreamName(IMAGE_INPUT_STREAM)
8788
.setOutputStreamNames(OUTPUT_STREAMS)
8889
.setStaticImageMode(options.mode() == HandsOptions.STATIC_IMAGE_MODE)

0 commit comments

Comments
 (0)