() {
+ @Override
+ public void onLoadCleared(Drawable placeholder) {}
+
+ @Override
+ public void onResourceReady(
+ GifDrawable resource, Transition super GifDrawable> transition) {
+ try {
+ Object startConstant = resource.getConstantState();
+ Field frameManager = startConstant.getClass().getDeclaredField("frameLoader");
+ frameManager.setAccessible(true);
+ Object frameLoader = frameManager.get(startConstant);
+ Field decoder = frameLoader.getClass().getDeclaredField("gifDecoder");
+ decoder.setAccessible(true);
+
+ Object frameObject = (decoder.get(frameLoader));
+ for (int i = 0; i < resource.getFrameCount(); i++) {
+ frameObject.getClass().getMethod("advance").invoke(frameObject);
+ Bitmap bmp =
+ (Bitmap)
+ frameObject.getClass().getMethod("getNextFrame").invoke(frameObject);
+ gifBitmaps.add(flipHorizontal(bmp));
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "", e);
+ }
+ }
+ });
+ }
+
+ // Bitmaps must be flipped due to native acquisition of frames from Android OS
+ private static Bitmap flipHorizontal(Bitmap bmp) {
+ Matrix matrix = new Matrix();
+ // Flip Bitmap frames horizontally
+ matrix.preScale(-1.0f, 1.0f);
+ return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
+ }
+
+ // Function that is continuously called in order to time GIF frame updates
+ private void updateGIFFrame() {
+ long millisPerFrame = 1000 / GIF_FRAME_RATE;
+ if (System.currentTimeMillis() - gifLastFrameUpdateMS >= millisPerFrame) {
+ // Update GIF timestamp
+ gifLastFrameUpdateMS = System.currentTimeMillis();
+ // Cycle through every possible frame and avoid a divide by 0
+ gifCurrentIndex = gifBitmaps.isEmpty() ? 1 : (gifCurrentIndex + 1) % gifBitmaps.size();
+ }
+ }
+
+ // Called once to popup the Keyboard via Android OS with focus set to editText
+ private void openKeyboard() {
+ editText.requestFocus();
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
+ }
+
+ // Called once to close the Keyboard via Android OS
+ private void closeKeyboard() {
+ View view = this.getCurrentFocus();
+ if (view != null) {
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ }
+ }
+
+ private void prepareDemoAssets() {
+ // We render from raw data with openGL, so disable decoding preprocessing
+ BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
+ decodeOptions.inScaled = false;
+ decodeOptions.inDither = false;
+ decodeOptions.inPremultiplied = false;
+
+ try {
+ InputStream inputStream = getAssets().open(DEFAULT_GIF_TEXTURE);
+ defaultGIFTexture =
+ flipHorizontal(
+ BitmapFactory.decodeStream(inputStream, null /*outPadding*/, decodeOptions));
+ inputStream.close();
+ } catch (Exception e) {
+ Log.e(TAG, "Error parsing object texture; error: ", e);
+ throw new IllegalStateException(e);
+ }
+
+ try {
+ InputStream inputStream = getAssets().open(ASSET_3D_TEXTURE);
+ asset3dTexture = BitmapFactory.decodeStream(inputStream, null /*outPadding*/, decodeOptions);
+ inputStream.close();
+ } catch (Exception e) {
+ Log.e(TAG, "Error parsing object texture; error: ", e);
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private class MediaPipePacketManager implements FrameProcessor.OnWillAddFrameListener {
+ @Override
+ public void onWillAddFrame(long timestamp) {
+ // set current GIF bitmap as default texture
+ Bitmap currentGIFBitmap = defaultGIFTexture;
+ // If current index is in bounds, display current frame
+ if (gifCurrentIndex <= gifBitmaps.size() - 1) {
+ currentGIFBitmap = gifBitmaps.get(gifCurrentIndex);
+ }
+ // Update to next GIF frame based on timing and frame rate
+ updateGIFFrame();
+
+ // Calculate and set the aspect ratio of the GIF
+ float gifAspectRatio =
+ (float) currentGIFBitmap.getWidth() / (float) currentGIFBitmap.getHeight();
+
+ Packet stickerSentinelPacket = processor.getPacketCreator().createInt32(stickerSentinel);
+ // Sticker sentinel value must be reset for next graph iteration
+ stickerSentinel = -1;
+ // Initialize sticker data protobufferpacket information
+ Packet stickerProtoDataPacket =
+ processor
+ .getPacketCreator()
+ .createSerializedProto(StickerManager.getMessageLiteData(stickerArrayList));
+ // Define and set the IMU sensory information float array
+ Packet imuDataPacket = processor.getPacketCreator().createFloat32Array(rotationMatrix);
+ // Communicate GIF textures (dynamic texturing) to graph
+ Packet gifTexturePacket = processor.getPacketCreator().createRgbaImageFrame(currentGIFBitmap);
+ Packet gifAspectRatioPacket = processor.getPacketCreator().createFloat32(gifAspectRatio);
+ processor
+ .getGraph()
+ .addConsumablePacketToInputStream(STICKER_SENTINEL_TAG, stickerSentinelPacket, timestamp);
+ processor
+ .getGraph()
+ .addConsumablePacketToInputStream(STICKER_PROTO_TAG, stickerProtoDataPacket, timestamp);
+ processor
+ .getGraph()
+ .addConsumablePacketToInputStream(IMU_MATRIX_TAG, imuDataPacket, timestamp);
+ processor
+ .getGraph()
+ .addConsumablePacketToInputStream(GIF_TEXTURE_TAG, gifTexturePacket, timestamp);
+ processor
+ .getGraph()
+ .addConsumablePacketToInputStream(GIF_ASPECT_RATIO_TAG, gifAspectRatioPacket, timestamp);
+ stickerSentinelPacket.release();
+ stickerProtoDataPacket.release();
+ imuDataPacket.release();
+ gifTexturePacket.release();
+ gifAspectRatioPacket.release();
+ }
+ }
+}
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/StickerManager.java b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/StickerManager.java
new file mode 100644
index 000000000..e6da53624
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/StickerManager.java
@@ -0,0 +1,191 @@
+// Copyright 2020 Google LLC
+//
+// 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 com.google.mediapipe.apps.instantmotiontracking;
+
+import com.google.mediapipe.graphs.instantmotiontracking.StickerBufferProto.Sticker;
+import com.google.mediapipe.graphs.instantmotiontracking.StickerBufferProto.StickerRoll;
+import java.util.ArrayList;
+
+/**
+ * This class represents a single sticker object placed in the
+ * instantmotiontracking system. StickerManagers represent a unique object to render
+ * and manipulate in an AR scene.
+ * A sticker has a sticker_id (a unique integer identifying a sticker object
+ * to render), x and y normalized anchor coordinates [0.0-1.0], user inputs for
+ * rotation in radians, scaling, and a renderID (another unique integer which
+ * determines what object model to render for this unique sticker).
+ */
+public class StickerManager {
+
+ /** All types of possible objects to render for our application. */
+ public enum Render {
+ // Every possible render for a sticker object
+ GIF,
+ ASSET_3D;
+
+ /**
+ * Once called, will set the value of the current render to the next
+ * possible Render available. If all possible Renders have been iterated
+ * through, the function will loop and set to the first available Render.
+ */
+ public Render iterate() {
+ int newEnumIdx = (this.ordinal() + 1) % Render.values().length;
+ return Render.values()[newEnumIdx];
+ }
+ }
+
+ // Current render of the sticker object
+ private Render currentRender;
+
+ // Normalized X and Y coordinates of anchor
+ // (0,0) lies at top-left corner of screen
+ // (1.0,1.0) lies at bottom-right corner of screen
+ private float anchorX;
+ private float anchorY;
+
+ // Rotation in radians from user
+ private float userRotation = 0f;
+ // Scaling factor as defined by user (defaults to 1.0)
+ private float userScalingFactor = 1f;
+
+ // Unique sticker integer ID
+ private final int stickerId;
+
+ // Used to determine next stickerId
+ private static int globalIDLimit = 1;
+
+ /**
+ * Used to create a StickerManager object with a newly generated stickerId and a
+ * default Render of the first possible render in our Render enum.
+ */
+ public StickerManager() {
+ // Every sticker will have a default render of the first 3D asset
+ this.currentRender = Render.values()[1];
+ // StickerManager will render out of view by default
+ this.setAnchorCoordinate(2.0f, 2.0f);
+ // Set the global sticker ID limit for the next sticker
+ stickerId = StickerManager.globalIDLimit++;
+ }
+
+ /**
+ * Used to create a StickerManager object with a newly generated stickerId.
+ *
+ * @param render initial Render of the new StickerManager object
+ */
+ public StickerManager(Render render) {
+ this.currentRender = render;
+ // StickerManager will render out of view by default
+ this.setAnchorCoordinate(2.0f, 2.0f);
+ // Set the global sticker ID limit for the next sticker
+ stickerId = StickerManager.globalIDLimit++;
+ }
+
+ /**
+ * Used to get the sticker ID of the object.
+ *
+ * @return integer of the unique sticker ID
+ */
+ public int getstickerId() {
+ return this.stickerId;
+ }
+
+ /**
+ * Used to update or reset the anchor positions in normalized [0.0-1.0]
+ * coordinate space for the sticker object.
+ *
+ * @param normalizedX normalized X coordinate for the new anchor position
+ * @param normalizedY normalized Y coordinate for the new anchor position
+ */
+ public void setAnchorCoordinate(float normalizedX, float normalizedY) {
+ this.anchorX = normalizedX;
+ this.anchorY = normalizedY;
+ }
+
+ /** Returns the normalized X anchor coordinate of the sticker object. */
+ public float getAnchorX() {
+ return anchorX;
+ }
+
+ /** Returns the normalized Y anchor coordinate of the sticker object. */
+ public float getAnchorY() {
+ return anchorY;
+ }
+
+ /** Returns current asset to be rendered for this sticker object. */
+ public Render getRender() {
+ return currentRender;
+ }
+
+ /** Set render for this sticker object */
+ public void setRender(Render render) {
+ this.currentRender = render;
+ }
+
+ /**
+ * Sets new user value of rotation radians. This rotation is not cumulative,
+ * and must be set to an absolute value of rotation applied to the object.
+ *
+ * @param radians specified radians to rotate the sticker object by
+ */
+ public void setRotation(float radians) {
+ this.userRotation = radians;
+ }
+
+ /** Returns current user radian rotation setting. */
+ public float getRotation() {
+ return this.userRotation;
+ }
+
+ /**
+ * Sets new user scale factor. This factor will be proportional to the scale
+ * of the sticker object.
+ *
+ * @param scaling scale factor to be applied
+ */
+ public void setScaleFactor(float scaling) {
+ this.userScalingFactor = scaling;
+ }
+
+ /** Returns current user scale factor setting. */
+ public float getScaleFactor() {
+ return this.userScalingFactor;
+ }
+
+ /**
+ * This method converts an ArrayList of stickers to a MessageLite object
+ * which can be passed directly to the MediaPipe graph.
+ *
+ * @param stickerArrayList ArrayList of StickerManager objects to convert to data string
+ * @return MessageLite protobuffer of all sticker data
+ */
+ public static StickerRoll getMessageLiteData(
+ ArrayList stickerArrayList) {
+ StickerRoll.Builder stickerRollBuilder
+ = StickerRoll.newBuilder();
+ for (final StickerManager sticker : stickerArrayList) {
+ Sticker protoSticker =
+ Sticker.newBuilder()
+ .setId(sticker.getstickerId())
+ .setX(sticker.getAnchorX())
+ .setY(sticker.getAnchorY())
+ .setRotation(sticker.getRotation())
+ .setScale(sticker.getScaleFactor())
+ .setRenderId(sticker.getRender().ordinal())
+ .build();
+ stickerRollBuilder.addSticker(protoSticker);
+ }
+ return stickerRollBuilder.build();
+ }
+}
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/BUILD
new file mode 100644
index 000000000..e60b04c30
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/BUILD
@@ -0,0 +1,21 @@
+# Copyright 2020 Google LLC
+#
+# 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.
+
+licenses(["notice"])
+
+package(default_visibility = ["//visibility:public"])
+
+exports_files(
+ srcs = glob(["**"]),
+)
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/gif/default_gif_texture.jpg b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/gif/default_gif_texture.jpg
new file mode 100644
index 000000000..27e86f96e
Binary files /dev/null and b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/gif/default_gif_texture.jpg differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/gif/gif.obj.uuu b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/gif/gif.obj.uuu
new file mode 100644
index 000000000..6e63ae6a5
Binary files /dev/null and b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/gif/gif.obj.uuu differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/robot/robot.obj.uuu.zip b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/robot/robot.obj.uuu.zip
new file mode 100644
index 000000000..00a753dd1
Binary files /dev/null and b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/robot/robot.obj.uuu.zip differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/robot/robot_texture.jpg b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/robot/robot_texture.jpg
new file mode 100644
index 000000000..f41e41a6f
Binary files /dev/null and b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/assets/robot/robot_texture.jpg differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/asset_3d_preview.png b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/asset_3d_preview.png
new file mode 100644
index 000000000..a1242817a
Binary files /dev/null and b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/asset_3d_preview.png differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/asset_gif_preview.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/asset_gif_preview.xml
new file mode 100644
index 000000000..fe7758dd9
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/asset_gif_preview.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_add_24.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_add_24.xml
new file mode 100644
index 000000000..eb232541d
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_add_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_arrow_back_24.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_arrow_back_24.xml
new file mode 100644
index 000000000..bab545a70
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_arrow_back_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_clear_24.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_clear_24.xml
new file mode 100644
index 000000000..16d6d37dd
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_clear_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_clear_all_24.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_clear_all_24.xml
new file mode 100644
index 000000000..dc649f3e2
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_clear_all_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_loop_24.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_loop_24.xml
new file mode 100644
index 000000000..c2f773a17
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_loop_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_search_24.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_search_24.xml
new file mode 100644
index 000000000..07b76d627
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/baseline_search_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/circle_button.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/circle_button.xml
new file mode 100644
index 000000000..067ae1f8b
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/drawable/circle_button.xml
@@ -0,0 +1,7 @@
+
+
+ -
+
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/layout/instant_motion_tracking_activity_main.xml b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/layout/instant_motion_tracking_activity_main.xml
new file mode 100644
index 000000000..c99a3c4a4
--- /dev/null
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/instantmotiontracking/res/layout/instant_motion_tracking_activity_main.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/iristrackinggpu/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/iristrackinggpu/BUILD
index 202cee82d..473404fdd 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/iristrackinggpu/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/iristrackinggpu/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
@@ -57,6 +57,7 @@ android_binary(
deps = [
":mediapipe_jni_lib",
"//mediapipe/examples/android/src/java/com/google/mediapipe/apps/basic:basic_lib",
+ "//mediapipe/framework/formats:landmark_java_proto_lite",
"//mediapipe/java/com/google/mediapipe/framework:android_framework",
],
)
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/iristrackinggpu/MainActivity.java b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/iristrackinggpu/MainActivity.java
index a979e698f..fc4c67755 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/iristrackinggpu/MainActivity.java
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/iristrackinggpu/MainActivity.java
@@ -15,7 +15,13 @@
package com.google.mediapipe.apps.iristrackinggpu;
import android.graphics.SurfaceTexture;
+import android.os.Bundle;
+import android.util.Log;
+import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmark;
+import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList;
import com.google.mediapipe.framework.Packet;
+import com.google.mediapipe.framework.PacketGetter;
+import com.google.protobuf.InvalidProtocolBufferException;
import java.util.HashMap;
import java.util.Map;
@@ -24,6 +30,7 @@ public class MainActivity extends com.google.mediapipe.apps.basic.MainActivity {
private static final String TAG = "MainActivity";
private static final String FOCAL_LENGTH_STREAM_NAME = "focal_length_pixel";
+ private static final String OUTPUT_LANDMARKS_STREAM_NAME = "face_landmarks_with_iris";
@Override
protected void onCameraStarted(SurfaceTexture surfaceTexture) {
@@ -37,4 +44,55 @@ public class MainActivity extends com.google.mediapipe.apps.basic.MainActivity {
processor.setInputSidePackets(inputSidePackets);
}
}
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // To show verbose logging, run:
+ // adb shell setprop log.tag.MainActivity VERBOSE
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ processor.addPacketCallback(
+ OUTPUT_LANDMARKS_STREAM_NAME,
+ (packet) -> {
+ byte[] landmarksRaw = PacketGetter.getProtoBytes(packet);
+ try {
+ NormalizedLandmarkList landmarks = NormalizedLandmarkList.parseFrom(landmarksRaw);
+ if (landmarks == null) {
+ Log.v(TAG, "[TS:" + packet.getTimestamp() + "] No landmarks.");
+ return;
+ }
+ Log.v(
+ TAG,
+ "[TS:"
+ + packet.getTimestamp()
+ + "] #Landmarks for face (including iris): "
+ + landmarks.getLandmarkCount());
+ Log.v(TAG, getLandmarksDebugString(landmarks));
+ } catch (InvalidProtocolBufferException e) {
+ Log.e(TAG, "Couldn't Exception received - " + e);
+ return;
+ }
+ });
+ }
+ }
+
+ private static String getLandmarksDebugString(NormalizedLandmarkList landmarks) {
+ int landmarkIndex = 0;
+ String landmarksString = "";
+ for (NormalizedLandmark landmark : landmarks.getLandmarkList()) {
+ landmarksString +=
+ "\t\tLandmark["
+ + landmarkIndex
+ + "]: ("
+ + landmark.getX()
+ + ", "
+ + landmark.getY()
+ + ", "
+ + landmark.getZ()
+ + ")\n";
+ ++landmarkIndex;
+ }
+ return landmarksString;
+ }
}
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/multihandtrackinggpu/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/multihandtrackinggpu/BUILD
index be6152554..7d4d7418c 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/multihandtrackinggpu/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/multihandtrackinggpu/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/BUILD
index fb0e6835f..f07bc8ebc 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
@@ -72,11 +72,11 @@ android_binary(
] + select({
"//conditions:default": [
"//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker:model.obj.uuu",
- "//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker:texture.bmp",
+ "//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker:texture.jpg",
],
":use_chair_model": [
"//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair:model.obj.uuu",
- "//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair:texture.bmp",
+ "//mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair:texture.jpg",
],
}),
assets_dir = "",
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/MainActivity.java b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/MainActivity.java
index 9f33e4eb6..92f9f55bb 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/MainActivity.java
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/MainActivity.java
@@ -31,7 +31,7 @@ import java.util.Map;
public class MainActivity extends com.google.mediapipe.apps.basic.MainActivity {
private static final String TAG = "MainActivity";
- private static final String OBJ_TEXTURE = "texture.bmp";
+ private static final String OBJ_TEXTURE = "texture.jpg";
private static final String OBJ_FILE = "model.obj.uuu";
private static final String BOX_TEXTURE = "classic_colors.png";
private static final String BOX_FILE = "box.obj.uuu";
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/BUILD
index ef6f88d65..46d164040 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/BUILD
index ef6f88d65..46d164040 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/texture.bmp b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/texture.bmp
deleted file mode 100644
index 0a4d1187d..000000000
Binary files a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/texture.bmp and /dev/null differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/texture.jpg b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/texture.jpg
new file mode 100644
index 000000000..759172f5c
Binary files /dev/null and b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/chair/texture.jpg differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/BUILD
index ef6f88d65..46d164040 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/texture.bmp b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/texture.bmp
deleted file mode 100644
index fa6c85a37..000000000
Binary files a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/texture.bmp and /dev/null differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/texture.jpg b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/texture.jpg
new file mode 100644
index 000000000..58f641bfe
Binary files /dev/null and b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetection3d/assets/sneaker/texture.jpg differ
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectioncpu/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectioncpu/BUILD
index 0f14a48a2..080fe4ced 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectioncpu/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectioncpu/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu/BUILD
index 84d5364b9..56e70c2b6 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objecttrackinggpu/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objecttrackinggpu/BUILD
index 75f9c075e..220d48067 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objecttrackinggpu/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/objecttrackinggpu/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/templatematchingcpu/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/templatematchingcpu/BUILD
index 4ca58d99b..0ceeeee1b 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/templatematchingcpu/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/templatematchingcpu/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/upperbodyposetrackinggpu/BUILD b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/upperbodyposetrackinggpu/BUILD
index 660382c5c..fe2da982c 100644
--- a/mediapipe/examples/android/src/java/com/google/mediapipe/apps/upperbodyposetrackinggpu/BUILD
+++ b/mediapipe/examples/android/src/java/com/google/mediapipe/apps/upperbodyposetrackinggpu/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/examples/coral/BUILD b/mediapipe/examples/coral/BUILD
index 338e38d4a..03d4027e7 100644
--- a/mediapipe/examples/coral/BUILD
+++ b/mediapipe/examples/coral/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = [
"//visibility:public",
diff --git a/mediapipe/examples/desktop/BUILD b/mediapipe/examples/desktop/BUILD
index 0e0335157..7772e21da 100644
--- a/mediapipe/examples/desktop/BUILD
+++ b/mediapipe/examples/desktop/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = [
"//visibility:public",
diff --git a/mediapipe/examples/desktop/autoflip/BUILD b/mediapipe/examples/desktop/autoflip/BUILD
index db4625401..9d84e2bdb 100644
--- a/mediapipe/examples/desktop/autoflip/BUILD
+++ b/mediapipe/examples/desktop/autoflip/BUILD
@@ -14,7 +14,7 @@ load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library"
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/autoflip/calculators/BUILD b/mediapipe/examples/desktop/autoflip/calculators/BUILD
index b645dc69f..688084062 100644
--- a/mediapipe/examples/desktop/autoflip/calculators/BUILD
+++ b/mediapipe/examples/desktop/autoflip/calculators/BUILD
@@ -14,7 +14,7 @@ load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library"
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = [
"//mediapipe/examples:__subpackages__",
diff --git a/mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator_test.cc b/mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator_test.cc
index e20ebba12..818e6b4a1 100644
--- a/mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator_test.cc
+++ b/mediapipe/examples/desktop/autoflip/calculators/content_zooming_calculator_test.cc
@@ -173,6 +173,7 @@ TEST(ContentZoomingCalculatorTest, PanConfig) {
auto* options = config.mutable_options()->MutableExtension(
ContentZoomingCalculatorOptions::ext);
options->mutable_kinematic_options_pan()->set_min_motion_to_reframe(0.0);
+ options->mutable_kinematic_options_pan()->set_update_rate_seconds(2);
options->mutable_kinematic_options_tilt()->set_min_motion_to_reframe(5.0);
options->mutable_kinematic_options_zoom()->set_min_motion_to_reframe(5.0);
auto runner = ::absl::make_unique(config);
@@ -191,6 +192,7 @@ TEST(ContentZoomingCalculatorTest, TiltConfig) {
ContentZoomingCalculatorOptions::ext);
options->mutable_kinematic_options_pan()->set_min_motion_to_reframe(5.0);
options->mutable_kinematic_options_tilt()->set_min_motion_to_reframe(0.0);
+ options->mutable_kinematic_options_tilt()->set_update_rate_seconds(2);
options->mutable_kinematic_options_zoom()->set_min_motion_to_reframe(5.0);
auto runner = ::absl::make_unique(config);
AddDetection(cv::Rect_(.4, .5, .1, .1), 0, runner.get());
@@ -209,6 +211,7 @@ TEST(ContentZoomingCalculatorTest, ZoomConfig) {
options->mutable_kinematic_options_pan()->set_min_motion_to_reframe(5.0);
options->mutable_kinematic_options_tilt()->set_min_motion_to_reframe(5.0);
options->mutable_kinematic_options_zoom()->set_min_motion_to_reframe(0.0);
+ options->mutable_kinematic_options_zoom()->set_update_rate_seconds(2);
auto runner = ::absl::make_unique(config);
AddDetection(cv::Rect_(.4, .5, .1, .1), 0, runner.get());
AddDetection(cv::Rect_(.45, .55, .15, .15), 1000000, runner.get());
@@ -345,8 +348,13 @@ TEST(ContentZoomingCalculatorTest, ZoomTestPairSize) {
}
TEST(ContentZoomingCalculatorTest, ZoomTestNearOutsideBorder) {
- auto runner = ::absl::make_unique(
- ParseTextProtoOrDie(kConfigD));
+ auto config = ParseTextProtoOrDie(kConfigD);
+ auto* options = config.mutable_options()->MutableExtension(
+ ContentZoomingCalculatorOptions::ext);
+ options->mutable_kinematic_options_pan()->set_update_rate_seconds(2);
+ options->mutable_kinematic_options_tilt()->set_update_rate_seconds(2);
+ options->mutable_kinematic_options_zoom()->set_update_rate_seconds(2);
+ auto runner = ::absl::make_unique(config);
AddDetection(cv::Rect_(.95, .95, .05, .05), 0, runner.get());
AddDetection(cv::Rect_(.9, .9, .1, .1), 1000000, runner.get());
MP_ASSERT_OK(runner->Run());
@@ -357,8 +365,13 @@ TEST(ContentZoomingCalculatorTest, ZoomTestNearOutsideBorder) {
}
TEST(ContentZoomingCalculatorTest, ZoomTestNearInsideBorder) {
- auto runner = ::absl::make_unique(
- ParseTextProtoOrDie(kConfigD));
+ auto config = ParseTextProtoOrDie(kConfigD);
+ auto* options = config.mutable_options()->MutableExtension(
+ ContentZoomingCalculatorOptions::ext);
+ options->mutable_kinematic_options_pan()->set_update_rate_seconds(2);
+ options->mutable_kinematic_options_tilt()->set_update_rate_seconds(2);
+ options->mutable_kinematic_options_zoom()->set_update_rate_seconds(2);
+ auto runner = ::absl::make_unique(config);
AddDetection(cv::Rect_(0, 0, .05, .05), 0, runner.get());
AddDetection(cv::Rect_(0, 0, .1, .1), 1000000, runner.get());
MP_ASSERT_OK(runner->Run());
diff --git a/mediapipe/examples/desktop/autoflip/calculators/testdata/BUILD b/mediapipe/examples/desktop/autoflip/calculators/testdata/BUILD
index 361d77d3c..cd99c8244 100644
--- a/mediapipe/examples/desktop/autoflip/calculators/testdata/BUILD
+++ b/mediapipe/examples/desktop/autoflip/calculators/testdata/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
filegroup(
name = "test_images",
diff --git a/mediapipe/examples/desktop/autoflip/quality/BUILD b/mediapipe/examples/desktop/autoflip/quality/BUILD
index 4d79b92de..a6e79c3a3 100644
--- a/mediapipe/examples/desktop/autoflip/quality/BUILD
+++ b/mediapipe/examples/desktop/autoflip/quality/BUILD
@@ -14,7 +14,7 @@ load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library"
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.cc b/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.cc
index 3d37541cf..573c990d7 100644
--- a/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.cc
+++ b/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.cc
@@ -12,6 +12,8 @@ namespace autoflip {
current_velocity_deg_per_s_ = 0;
RET_CHECK_GT(pixels_per_degree_, 0)
<< "pixels_per_degree must be larger than 0.";
+ RET_CHECK_GE(options_.update_rate_seconds(), 0)
+ << "update_rate_seconds must be greater than 0.";
RET_CHECK_GE(options_.min_motion_to_reframe(), options_.reframe_window())
<< "Reframe window cannot exceed min_motion_to_reframe.";
return ::mediapipe::OkStatus();
@@ -41,9 +43,10 @@ namespace autoflip {
// Observed velocity and then weighted update of this velocity.
double observed_velocity = delta_degs / delta_t;
- double updated_velocity =
- current_velocity_deg_per_s_ * (1 - options_.update_rate()) +
- observed_velocity * options_.update_rate();
+ double update_rate = std::min(delta_t / options_.update_rate_seconds(),
+ options_.max_update_rate());
+ double updated_velocity = current_velocity_deg_per_s_ * (1 - update_rate) +
+ observed_velocity * update_rate;
// Limited current velocity.
current_velocity_deg_per_s_ =
updated_velocity > 0 ? fmin(updated_velocity, options_.max_velocity())
diff --git a/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.proto b/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.proto
index 552ead0d9..ac2595328 100644
--- a/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.proto
+++ b/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver.proto
@@ -5,7 +5,7 @@ package mediapipe.autoflip;
message KinematicOptions {
// Weighted update of new camera velocity (measurement) vs current state
// (prediction).
- optional double update_rate = 1 [default = 0.5];
+ optional double update_rate = 1 [default = 0.5, deprecated = true];
// Max velocity (degrees per second) that the camera can move.
optional double max_velocity = 2 [default = 18];
// Min motion (in degrees) to react in pixels.
@@ -15,4 +15,9 @@ message KinematicOptions {
// total reframe distance on average. Value cannot exceed
// min_motion_to_reframe value.
optional float reframe_window = 4 [default = 0];
+ // Calculation of internal velocity state is:
+ // min((delta_time_s / update_rate_seconds), max_update_rate)
+ // where delta_time_s is the time since the last frame.
+ optional double update_rate_seconds = 5 [default = 0.20];
+ optional double max_update_rate = 6 [default = 0.8];
}
diff --git a/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver_test.cc b/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver_test.cc
index d751bd1e3..0bdfb50d2 100644
--- a/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver_test.cc
+++ b/mediapipe/examples/desktop/autoflip/quality/kinematic_path_solver_test.cc
@@ -85,7 +85,8 @@ TEST(KinematicPathSolverTest, PassEnoughMotionLargeImg) {
KinematicOptions options;
// Set min motion to 1deg
options.set_min_motion_to_reframe(1.0);
- options.set_update_rate(1);
+ options.set_update_rate_seconds(.0000001);
+ options.set_max_update_rate(1.0);
options.set_max_velocity(1000);
// Set degrees / pixel to 16.6
KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
@@ -102,7 +103,8 @@ TEST(KinematicPathSolverTest, PassEnoughMotionSmallImg) {
KinematicOptions options;
// Set min motion to 2deg
options.set_min_motion_to_reframe(1.0);
- options.set_update_rate(1);
+ options.set_update_rate_seconds(.0000001);
+ options.set_max_update_rate(1.0);
options.set_max_velocity(18);
// Set degrees / pixel to 8.3
KinematicPathSolver solver(options, 0, 500, 500.0 / kWidthFieldOfView);
@@ -132,7 +134,8 @@ TEST(KinematicPathSolverTest, PassReframeWindow) {
KinematicOptions options;
// Set min motion to 1deg
options.set_min_motion_to_reframe(1.0);
- options.set_update_rate(1);
+ options.set_update_rate_seconds(.0000001);
+ options.set_max_update_rate(1.0);
options.set_max_velocity(1000);
// Set reframe window size to .75 for test.
options.set_reframe_window(0.75);
@@ -147,10 +150,41 @@ TEST(KinematicPathSolverTest, PassReframeWindow) {
EXPECT_EQ(state, 507);
}
+TEST(KinematicPathSolverTest, PassUpdateRate30FPS) {
+ KinematicOptions options;
+ options.set_min_motion_to_reframe(1.0);
+ options.set_update_rate_seconds(.25);
+ options.set_max_update_rate(0.8);
+ options.set_max_velocity(18);
+ KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
+ int state;
+ MP_ASSERT_OK(solver.AddObservation(500, kMicroSecInSec * 0));
+ MP_ASSERT_OK(solver.AddObservation(520, kMicroSecInSec * 1 / 30));
+ MP_ASSERT_OK(solver.GetState(&state));
+ // (0.033 / .25) * 20 =
+ EXPECT_EQ(state, 503);
+}
+
+TEST(KinematicPathSolverTest, PassUpdateRate10FPS) {
+ KinematicOptions options;
+ options.set_min_motion_to_reframe(1.0);
+ options.set_update_rate_seconds(.25);
+ options.set_max_update_rate(0.8);
+ options.set_max_velocity(18);
+ KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
+ int state;
+ MP_ASSERT_OK(solver.AddObservation(500, kMicroSecInSec * 0));
+ MP_ASSERT_OK(solver.AddObservation(520, kMicroSecInSec * 1 / 10));
+ MP_ASSERT_OK(solver.GetState(&state));
+ // (0.1 / .25) * 20 =
+ EXPECT_EQ(state, 508);
+}
+
TEST(KinematicPathSolverTest, PassUpdateRate) {
KinematicOptions options;
options.set_min_motion_to_reframe(1.0);
- options.set_update_rate(0.25);
+ options.set_update_rate_seconds(4);
+ options.set_max_update_rate(1.0);
options.set_max_velocity(18);
KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
int state;
diff --git a/mediapipe/examples/desktop/autoflip/quality/testdata/BUILD b/mediapipe/examples/desktop/autoflip/quality/testdata/BUILD
index 2aff7d6a7..bbfc6340d 100644
--- a/mediapipe/examples/desktop/autoflip/quality/testdata/BUILD
+++ b/mediapipe/examples/desktop/autoflip/quality/testdata/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/examples/desktop/autoflip/subgraph/BUILD b/mediapipe/examples/desktop/autoflip/subgraph/BUILD
index 4fea2fb92..9af7e447b 100644
--- a/mediapipe/examples/desktop/autoflip/subgraph/BUILD
+++ b/mediapipe/examples/desktop/autoflip/subgraph/BUILD
@@ -14,7 +14,7 @@ load("//mediapipe/framework/tool:mediapipe_graph.bzl", "mediapipe_simple_subgrap
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/face_detection/BUILD b/mediapipe/examples/desktop/face_detection/BUILD
index 3d1dbcec8..55c9eb741 100644
--- a/mediapipe/examples/desktop/face_detection/BUILD
+++ b/mediapipe/examples/desktop/face_detection/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/face_mesh/BUILD b/mediapipe/examples/desktop/face_mesh/BUILD
index 268d590ef..c63814804 100644
--- a/mediapipe/examples/desktop/face_mesh/BUILD
+++ b/mediapipe/examples/desktop/face_mesh/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/hair_segmentation/BUILD b/mediapipe/examples/desktop/hair_segmentation/BUILD
index 69948e437..9b799f347 100644
--- a/mediapipe/examples/desktop/hair_segmentation/BUILD
+++ b/mediapipe/examples/desktop/hair_segmentation/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/hand_tracking/BUILD b/mediapipe/examples/desktop/hand_tracking/BUILD
index 1c99b00f6..da6eef456 100644
--- a/mediapipe/examples/desktop/hand_tracking/BUILD
+++ b/mediapipe/examples/desktop/hand_tracking/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/hello_world/BUILD b/mediapipe/examples/desktop/hello_world/BUILD
index ff36a24f0..edf98bf13 100644
--- a/mediapipe/examples/desktop/hello_world/BUILD
+++ b/mediapipe/examples/desktop/hello_world/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/iris_tracking/BUILD b/mediapipe/examples/desktop/iris_tracking/BUILD
index 430922115..29812d21c 100644
--- a/mediapipe/examples/desktop/iris_tracking/BUILD
+++ b/mediapipe/examples/desktop/iris_tracking/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/media_sequence/BUILD b/mediapipe/examples/desktop/media_sequence/BUILD
index 30b37d82a..4e94ebe53 100644
--- a/mediapipe/examples/desktop/media_sequence/BUILD
+++ b/mediapipe/examples/desktop/media_sequence/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/multi_hand_tracking/BUILD b/mediapipe/examples/desktop/multi_hand_tracking/BUILD
index f83133545..a7bd112ff 100644
--- a/mediapipe/examples/desktop/multi_hand_tracking/BUILD
+++ b/mediapipe/examples/desktop/multi_hand_tracking/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/object_detection/BUILD b/mediapipe/examples/desktop/object_detection/BUILD
index 66b6d5698..c7860f09a 100644
--- a/mediapipe/examples/desktop/object_detection/BUILD
+++ b/mediapipe/examples/desktop/object_detection/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/object_tracking/BUILD b/mediapipe/examples/desktop/object_tracking/BUILD
index c4ac24ea0..8a87c5bbc 100644
--- a/mediapipe/examples/desktop/object_tracking/BUILD
+++ b/mediapipe/examples/desktop/object_tracking/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/template_matching/BUILD b/mediapipe/examples/desktop/template_matching/BUILD
index 4525a71d3..6ee07f71b 100644
--- a/mediapipe/examples/desktop/template_matching/BUILD
+++ b/mediapipe/examples/desktop/template_matching/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/upper_body_pose_tracking/BUILD b/mediapipe/examples/desktop/upper_body_pose_tracking/BUILD
index 9e32c5681..6240864a3 100644
--- a/mediapipe/examples/desktop/upper_body_pose_tracking/BUILD
+++ b/mediapipe/examples/desktop/upper_body_pose_tracking/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
diff --git a/mediapipe/examples/desktop/youtube8m/BUILD b/mediapipe/examples/desktop/youtube8m/BUILD
index 16b868bdc..af85e3113 100644
--- a/mediapipe/examples/desktop/youtube8m/BUILD
+++ b/mediapipe/examples/desktop/youtube8m/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
cc_binary(
name = "extract_yt8m_features",
diff --git a/mediapipe/examples/ios/BUILD b/mediapipe/examples/ios/BUILD
index 3cf7f234b..fd611a615 100644
--- a/mediapipe/examples/ios/BUILD
+++ b/mediapipe/examples/ios/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/examples/ios/facedetectioncpu/BUILD b/mediapipe/examples/ios/facedetectioncpu/BUILD
index 69d54d72b..a4ae2cfca 100644
--- a/mediapipe/examples/ios/facedetectioncpu/BUILD
+++ b/mediapipe/examples/ios/facedetectioncpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/facedetectiongpu/BUILD b/mediapipe/examples/ios/facedetectiongpu/BUILD
index b06a0a077..507ac45d8 100644
--- a/mediapipe/examples/ios/facedetectiongpu/BUILD
+++ b/mediapipe/examples/ios/facedetectiongpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/facemeshgpu/BUILD b/mediapipe/examples/ios/facemeshgpu/BUILD
index dbe842285..11bd649bf 100644
--- a/mediapipe/examples/ios/facemeshgpu/BUILD
+++ b/mediapipe/examples/ios/facemeshgpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/handdetectiongpu/BUILD b/mediapipe/examples/ios/handdetectiongpu/BUILD
index 953f80719..e1fbb8bd6 100644
--- a/mediapipe/examples/ios/handdetectiongpu/BUILD
+++ b/mediapipe/examples/ios/handdetectiongpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/handtrackinggpu/BUILD b/mediapipe/examples/ios/handtrackinggpu/BUILD
index 162fa2e7d..b3ac999b6 100644
--- a/mediapipe/examples/ios/handtrackinggpu/BUILD
+++ b/mediapipe/examples/ios/handtrackinggpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/helloworld/BUILD b/mediapipe/examples/ios/helloworld/BUILD
index b1916117d..192996bf3 100644
--- a/mediapipe/examples/ios/helloworld/BUILD
+++ b/mediapipe/examples/ios/helloworld/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/iristrackinggpu/BUILD b/mediapipe/examples/ios/iristrackinggpu/BUILD
index c5d039236..3cf8d14f7 100644
--- a/mediapipe/examples/ios/iristrackinggpu/BUILD
+++ b/mediapipe/examples/ios/iristrackinggpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/multihandtrackinggpu/BUILD b/mediapipe/examples/ios/multihandtrackinggpu/BUILD
index 404a50d9f..5616f12b6 100644
--- a/mediapipe/examples/ios/multihandtrackinggpu/BUILD
+++ b/mediapipe/examples/ios/multihandtrackinggpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/objectdetectioncpu/BUILD b/mediapipe/examples/ios/objectdetectioncpu/BUILD
index 3a18ef89a..5ddd12df6 100644
--- a/mediapipe/examples/ios/objectdetectioncpu/BUILD
+++ b/mediapipe/examples/ios/objectdetectioncpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/ios/upperbodyposetrackinggpu/BUILD b/mediapipe/examples/ios/upperbodyposetrackinggpu/BUILD
index 5b9a08be2..0a2402857 100644
--- a/mediapipe/examples/ios/upperbodyposetrackinggpu/BUILD
+++ b/mediapipe/examples/ios/upperbodyposetrackinggpu/BUILD
@@ -22,7 +22,7 @@ load(
"example_provisioning",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
MIN_IOS_VERSION = "10.0"
diff --git a/mediapipe/examples/python/upper_body_pose_tracker.py b/mediapipe/examples/python/upper_body_pose_tracker.py
index b7a195994..edb1dfe73 100644
--- a/mediapipe/examples/python/upper_body_pose_tracker.py
+++ b/mediapipe/examples/python/upper_body_pose_tracker.py
@@ -38,8 +38,8 @@ import time
from typing import Tuple, Union
import cv2
-import numpy as np
import mediapipe.python as mp
+import numpy as np
# resources dependency
from mediapipe.framework.formats import landmark_pb2
@@ -107,7 +107,7 @@ class UpperBodyPoseTracker:
output_file='/tmp/output.png')
# Read an image and convert the BGR image to RGB.
- input_image = cv2.imread('/tmp/input.png')[:, :, ::-1]
+ input_image = cv2.cvtColor(cv2.imread('/tmp/input.png'), COLOR_BGR2RGB)
pose_landmarks, annotated_image = pose_tracker.run(input_image)
pose_tracker.close()
"""
@@ -150,8 +150,11 @@ class UpperBodyPoseTracker:
success, input_frame = cap.read()
if not success:
break
- _, output_frame = self._run_graph(input_frame[:, :, ::-1])
- cv2.imshow('MediaPipe upper body pose tracker', output_frame[:, :, ::-1])
+ input_frame = cv2.cvtColor(input_frame, cv2.COLOR_BGR2RGB)
+ input_frame.flags.writeable = False
+ _, output_frame = self._run_graph(input_frame)
+ cv2.imshow('MediaPipe upper body pose tracker',
+ cv2.cvtColor(output_frame, cv2.COLOR_RGB2BGR))
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
diff --git a/mediapipe/framework/BUILD b/mediapipe/framework/BUILD
index 2140144cd..a61ee12df 100644
--- a/mediapipe/framework/BUILD
+++ b/mediapipe/framework/BUILD
@@ -16,7 +16,7 @@
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_proto_library")
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/framework/calculator_graph_bounds_test.cc b/mediapipe/framework/calculator_graph_bounds_test.cc
index f44931b32..ebc9ee6c8 100644
--- a/mediapipe/framework/calculator_graph_bounds_test.cc
+++ b/mediapipe/framework/calculator_graph_bounds_test.cc
@@ -92,11 +92,11 @@ class IntAdderCalculator : public CalculatorBase {
cc->Inputs().Index(i).Set();
}
cc->Outputs().Index(0).Set();
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -269,11 +269,11 @@ class Delay20Calculator : public CalculatorBase {
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
cc->Inputs().Index(0).Set();
cc->Outputs().Index(0).Set();
+ cc->SetTimestampOffset(TimestampDiff(20));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(TimestampDiff(20));
cc->Outputs().Index(0).AddPacket(MakePacket(0).At(Timestamp(0)));
return ::mediapipe::OkStatus();
}
@@ -641,11 +641,11 @@ class OffsetBoundCalculator : public CalculatorBase {
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
cc->Inputs().Index(0).Set();
cc->Outputs().Index(0).Set();
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(0);
return ::mediapipe::OkStatus();
}
@@ -1446,10 +1446,10 @@ class OffsetAndBoundCalculator : public CalculatorBase {
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
cc->Inputs().Index(0).Set();
cc->Outputs().Index(0).SetSameAs(&cc->Inputs().Index(0));
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(0);
return ::mediapipe::OkStatus();
}
::mediapipe::Status Process(CalculatorContext* cc) final {
diff --git a/mediapipe/framework/calculator_graph_test.cc b/mediapipe/framework/calculator_graph_test.cc
index a70ee02e1..2b63490a0 100644
--- a/mediapipe/framework/calculator_graph_test.cc
+++ b/mediapipe/framework/calculator_graph_test.cc
@@ -100,11 +100,11 @@ class SquareIntCalculator : public CalculatorBase {
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
cc->Inputs().Index(0).Set();
cc->Outputs().Index(0).SetSameAs(&cc->Inputs().Index(0));
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -134,6 +134,7 @@ class DemuxTimedCalculator : public CalculatorBase {
id < cc->Outputs().EndId("OUTPUT"); ++id) {
cc->Outputs().Get(id).SetSameAs(data_input);
}
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -142,7 +143,6 @@ class DemuxTimedCalculator : public CalculatorBase {
data_input_ = cc->Inputs().GetId("INPUT", 0);
output_base_ = cc->Outputs().GetId("OUTPUT", 0);
num_outputs_ = cc->Outputs().NumEntries("OUTPUT");
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -194,6 +194,7 @@ class MuxTimedCalculator : public CalculatorBase {
}
RET_CHECK_EQ(cc->Outputs().NumEntries(), 1);
cc->Outputs().Tag("OUTPUT").SetSameAs(data_input0);
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -202,7 +203,6 @@ class MuxTimedCalculator : public CalculatorBase {
data_input_base_ = cc->Inputs().GetId("INPUT", 0);
num_data_inputs_ = cc->Inputs().NumEntries("INPUT");
output_ = cc->Outputs().GetId("OUTPUT", 0);
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -232,11 +232,11 @@ class IntAdderCalculator : public CalculatorBase {
cc->Inputs().Index(i).Set();
}
cc->Outputs().Index(0).Set();
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -260,11 +260,11 @@ class FloatAdderCalculator : public CalculatorBase {
cc->Inputs().Index(i).Set();
}
cc->Outputs().Index(0).Set();
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -288,11 +288,11 @@ class IntMultiplierCalculator : public CalculatorBase {
cc->Inputs().Index(i).Set();
}
cc->Outputs().Index(0).Set();
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -316,12 +316,12 @@ class FloatScalarMultiplierCalculator : public CalculatorBase {
cc->Inputs().Index(0).Set();
cc->Outputs().Index(0).Set();
cc->InputSidePackets().Index(0).Set();
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
scalar_ = cc->InputSidePackets().Index(0).Get();
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -343,11 +343,11 @@ class IntToFloatCalculator : public CalculatorBase {
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
cc->Inputs().Index(0).Set();
cc->Outputs().Index(0).Set();
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) final {
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
@@ -937,11 +937,11 @@ class SemaphoreCalculator : public CalculatorBase {
cc->Outputs().Index(0).SetSameAs(&cc->Inputs().Index(0));
cc->InputSidePackets().Tag("POST_SEM").Set();
cc->InputSidePackets().Tag("WAIT_SEM").Set();
+ cc->SetTimestampOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
::mediapipe::Status Open(CalculatorContext* cc) override {
- cc->SetOffset(TimestampDiff(0));
return ::mediapipe::OkStatus();
}
diff --git a/mediapipe/framework/deps/BUILD b/mediapipe/framework/deps/BUILD
index 1cf51ddea..cf2bf46bd 100644
--- a/mediapipe/framework/deps/BUILD
+++ b/mediapipe/framework/deps/BUILD
@@ -17,7 +17,7 @@
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library")
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/framework/formats/BUILD b/mediapipe/framework/formats/BUILD
index b7ea42e48..fb10550b3 100644
--- a/mediapipe/framework/formats/BUILD
+++ b/mediapipe/framework/formats/BUILD
@@ -20,7 +20,7 @@ package(
features = ["-layering_check"],
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
exports_files(["LICENSE"])
diff --git a/mediapipe/framework/formats/annotation/BUILD b/mediapipe/framework/formats/annotation/BUILD
index a754b0250..a74b488e8 100644
--- a/mediapipe/framework/formats/annotation/BUILD
+++ b/mediapipe/framework/formats/annotation/BUILD
@@ -18,7 +18,7 @@ load("//mediapipe/framework/port:build_config.bzl", "mediapipe_proto_library")
package(default_visibility = ["//visibility:private"])
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
exports_files(["LICENSE"])
diff --git a/mediapipe/framework/formats/matrix_data.proto b/mediapipe/framework/formats/matrix_data.proto
index 216d01288..d4aa457a5 100644
--- a/mediapipe/framework/formats/matrix_data.proto
+++ b/mediapipe/framework/formats/matrix_data.proto
@@ -21,6 +21,9 @@ syntax = "proto2";
package mediapipe;
+option java_package = "com.google.mediapipe.formats.proto";
+option java_outer_classname = "MatrixDataProto";
+
// Proto for serializing Matrix data.
// Data are stored in column-major order by default.
message MatrixData {
diff --git a/mediapipe/framework/formats/motion/BUILD b/mediapipe/framework/formats/motion/BUILD
index a77034c50..f91d2cade 100644
--- a/mediapipe/framework/formats/motion/BUILD
+++ b/mediapipe/framework/formats/motion/BUILD
@@ -16,7 +16,7 @@
# Description:
# Working with dense optical flow in mediapipe.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
exports_files(["LICENSE"])
diff --git a/mediapipe/framework/formats/object_detection/BUILD b/mediapipe/framework/formats/object_detection/BUILD
index 4a9f0ca50..39940acdc 100644
--- a/mediapipe/framework/formats/object_detection/BUILD
+++ b/mediapipe/framework/formats/object_detection/BUILD
@@ -17,7 +17,7 @@
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library")
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/framework/output_stream_manager.cc b/mediapipe/framework/output_stream_manager.cc
index d3d9c7a44..fba5ee5a4 100644
--- a/mediapipe/framework/output_stream_manager.cc
+++ b/mediapipe/framework/output_stream_manager.cc
@@ -24,6 +24,7 @@ namespace mediapipe {
const std::string& name, const PacketType* packet_type) {
output_stream_spec_.name = name;
output_stream_spec_.packet_type = packet_type;
+ output_stream_spec_.offset_enabled = false;
PrepareForRun(nullptr);
return ::mediapipe::OkStatus();
}
@@ -33,7 +34,6 @@ void OutputStreamManager::PrepareForRun(
output_stream_spec_.error_callback = std::move(error_callback);
output_stream_spec_.locked_intro_data = false;
- output_stream_spec_.offset_enabled = false;
output_stream_spec_.header = Packet();
{
absl::MutexLock lock(&stream_mutex_);
diff --git a/mediapipe/framework/port/BUILD b/mediapipe/framework/port/BUILD
index 45cd101ba..78fa44739 100644
--- a/mediapipe/framework/port/BUILD
+++ b/mediapipe/framework/port/BUILD
@@ -15,7 +15,7 @@
# Description:
# Port of various libraries and utilities.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(
default_visibility = ["//visibility:private"],
@@ -44,7 +44,10 @@ cc_library(
name = "aligned_malloc_and_free",
hdrs = ["aligned_malloc_and_free.h"],
visibility = ["//visibility:public"],
- deps = ["//mediapipe/framework/deps:aligned_malloc_and_free"],
+ deps = [
+ "//mediapipe/framework/deps:aligned_malloc_and_free",
+ "@com_google_absl//absl/base:core_headers",
+ ],
)
# This proto lib is used by any code that needs to do proto I/O and proto template parsing.
diff --git a/mediapipe/framework/port/opencv_imgproc_inc.h b/mediapipe/framework/port/opencv_imgproc_inc.h
index 5f5de8ff3..d59c9dc39 100644
--- a/mediapipe/framework/port/opencv_imgproc_inc.h
+++ b/mediapipe/framework/port/opencv_imgproc_inc.h
@@ -23,6 +23,9 @@
#include
#else
#include
+#if CV_VERSION_MAJOR == 4
+#include
+#endif
#endif
#endif // MEDIAPIPE_PORT_OPENCV_IMGPROC_INC_H_
diff --git a/mediapipe/framework/profiler/BUILD b/mediapipe/framework/profiler/BUILD
index 86007b016..432746ea9 100644
--- a/mediapipe/framework/profiler/BUILD
+++ b/mediapipe/framework/profiler/BUILD
@@ -13,7 +13,7 @@
# limitations under the License.
#
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe/framework:__subpackages__"])
diff --git a/mediapipe/framework/profiler/reporter/BUILD b/mediapipe/framework/profiler/reporter/BUILD
index 83f3dfe9e..6e97a5f3f 100644
--- a/mediapipe/framework/profiler/reporter/BUILD
+++ b/mediapipe/framework/profiler/reporter/BUILD
@@ -13,7 +13,7 @@
# limitations under the License.
#
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
cc_library(
name = "reporter_lib",
diff --git a/mediapipe/framework/profiler/testing/BUILD b/mediapipe/framework/profiler/testing/BUILD
index 9064473e3..0b0d256e5 100644
--- a/mediapipe/framework/profiler/testing/BUILD
+++ b/mediapipe/framework/profiler/testing/BUILD
@@ -13,7 +13,7 @@
# limitations under the License.
#
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(
default_visibility = ["//mediapipe/framework:__subpackages__"],
diff --git a/mediapipe/framework/stream_handler/BUILD b/mediapipe/framework/stream_handler/BUILD
index 9dacd4d60..a805ed262 100644
--- a/mediapipe/framework/stream_handler/BUILD
+++ b/mediapipe/framework/stream_handler/BUILD
@@ -13,7 +13,7 @@
# limitations under the License.
#
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(
default_visibility = ["//visibility:private"],
diff --git a/mediapipe/framework/testdata/BUILD b/mediapipe/framework/testdata/BUILD
index 0b96502cf..3863baebb 100644
--- a/mediapipe/framework/testdata/BUILD
+++ b/mediapipe/framework/testdata/BUILD
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/framework/tool/BUILD b/mediapipe/framework/tool/BUILD
index 694e2e3a1..24f083dc4 100644
--- a/mediapipe/framework/tool/BUILD
+++ b/mediapipe/framework/tool/BUILD
@@ -23,7 +23,7 @@ load(
"mediapipe_binary_graph",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:private"])
diff --git a/mediapipe/framework/tool/testdata/BUILD b/mediapipe/framework/tool/testdata/BUILD
index 4227b11f9..906688520 100644
--- a/mediapipe/framework/tool/testdata/BUILD
+++ b/mediapipe/framework/tool/testdata/BUILD
@@ -18,7 +18,7 @@ load(
"mediapipe_simple_subgraph",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//mediapipe:__subpackages__"])
diff --git a/mediapipe/gpu/BUILD b/mediapipe/gpu/BUILD
index b92a75e63..4992a3d51 100644
--- a/mediapipe/gpu/BUILD
+++ b/mediapipe/gpu/BUILD
@@ -16,7 +16,7 @@ load("//mediapipe/gpu:metal.bzl", "metal_library")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library")
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/gpu/gl_context.cc b/mediapipe/gpu/gl_context.cc
index 54b538273..58b6aab76 100644
--- a/mediapipe/gpu/gl_context.cc
+++ b/mediapipe/gpu/gl_context.cc
@@ -343,6 +343,7 @@ GlContext::~GlContext() {
#error This file must be built with ARC.
#endif
#endif // __OBJC__
+
if (thread_) {
auto status = thread_->Run([this] {
if (profiling_helper_) {
@@ -350,9 +351,8 @@ GlContext::~GlContext() {
}
return ExitContext(nullptr);
});
- if (!status.ok()) {
- LOG(ERROR) << "Failed to deactivate context on thread: " << status;
- }
+ LOG_IF(ERROR, !status.ok())
+ << "Failed to deactivate context on thread: " << status;
if (thread_->IsCurrentThread()) {
thread_.release()->SelfDestruct();
}
@@ -368,40 +368,38 @@ void GlContext::SetProfilingContext(
}
}
+::mediapipe::Status GlContext::SwitchContextAndRun(GlStatusFunction gl_func) {
+ ContextBinding saved_context;
+ MP_RETURN_IF_ERROR(EnterContext(&saved_context)) << " (entering GL context)";
+ auto status = gl_func();
+ LogUncheckedGlErrors(CheckForGlErrors());
+ MP_RETURN_IF_ERROR(ExitContext(&saved_context)) << " (exiting GL context)";
+ return status;
+}
+
::mediapipe::Status GlContext::Run(GlStatusFunction gl_func, int node_id,
Timestamp input_timestamp) {
::mediapipe::Status status;
- if (thread_) {
- bool had_gl_errors = false;
- status = thread_->Run(
- [this, gl_func, node_id, &input_timestamp, &had_gl_errors] {
- if (profiling_helper_) {
- profiling_helper_->MarkTimestamp(node_id, input_timestamp,
- /*is_finish=*/false);
- }
- auto status = gl_func();
- if (profiling_helper_) {
- profiling_helper_->MarkTimestamp(node_id, input_timestamp,
- /*is_finish=*/true);
- }
- had_gl_errors = CheckForGlErrors();
- return status;
- });
- LogUncheckedGlErrors(had_gl_errors);
- } else {
- ContextBinding saved_context;
- MP_RETURN_IF_ERROR(EnterContext(&saved_context));
- if (profiling_helper_) {
+ if (profiling_helper_) {
+ gl_func = [=] {
profiling_helper_->MarkTimestamp(node_id, input_timestamp,
/*is_finish=*/false);
- }
- status = gl_func();
- if (profiling_helper_) {
+ auto status = gl_func();
profiling_helper_->MarkTimestamp(node_id, input_timestamp,
/*is_finish=*/true);
- }
- LogUncheckedGlErrors(CheckForGlErrors());
- MP_RETURN_IF_ERROR(ExitContext(&saved_context));
+ return status;
+ };
+ }
+ if (thread_) {
+ bool had_gl_errors = false;
+ status = thread_->Run([this, gl_func, &had_gl_errors] {
+ auto status = gl_func();
+ had_gl_errors = CheckForGlErrors();
+ return status;
+ });
+ LogUncheckedGlErrors(had_gl_errors);
+ } else {
+ status = SwitchContextAndRun(gl_func);
}
return status;
}
@@ -416,17 +414,12 @@ void GlContext::RunWithoutWaiting(GlVoidFunction gl_func) {
});
} else {
// TODO: queue up task instead.
- ContextBinding saved_context;
- auto status = EnterContext(&saved_context);
+ auto status = SwitchContextAndRun([gl_func] {
+ gl_func();
+ return ::mediapipe::OkStatus();
+ });
if (!status.ok()) {
- LOG(ERROR) << "Failed to enter context: " << status;
- return;
- }
- gl_func();
- LogUncheckedGlErrors(CheckForGlErrors());
- status = ExitContext(&saved_context);
- if (!status.ok()) {
- LOG(ERROR) << "Failed to exit context: " << status;
+ LOG(ERROR) << "Error in RunWithoutWaiting: " << status;
}
}
}
@@ -589,7 +582,7 @@ class GlFenceSyncPoint : public GlSyncPoint {
void GlMultiSyncPoint::Add(std::shared_ptr new_sync) {
for (auto& sync : syncs_) {
- if (&sync->GetContext() == &new_sync->GetContext()) {
+ if (sync->GetContext() == new_sync->GetContext()) {
sync = std::move(new_sync);
return;
}
diff --git a/mediapipe/gpu/gl_context.h b/mediapipe/gpu/gl_context.h
index b9ca6889c..0e8990470 100644
--- a/mediapipe/gpu/gl_context.h
+++ b/mediapipe/gpu/gl_context.h
@@ -91,7 +91,7 @@ class GlSyncPoint {
// Returns whether the sync point has been reached. Does not block.
virtual bool IsReady() = 0;
- const GlContext& GetContext() { return *gl_context_; }
+ const std::shared_ptr& GetContext() { return gl_context_; }
protected:
std::shared_ptr gl_context_;
@@ -366,6 +366,11 @@ class GlContext : public std::enable_shared_from_this {
::mediapipe::Status GetGlExtensions();
::mediapipe::Status GetGlExtensionsCompat();
+ // Make the context current, run gl_func, and restore the previous context.
+ // Internal helper only; callers should use Run or RunWithoutWaiting instead,
+ // which delegates to the dedicated thread if required.
+ ::mediapipe::Status SwitchContextAndRun(GlStatusFunction gl_func);
+
// The following ContextBinding functions have platform-specific
// implementations.
diff --git a/mediapipe/gpu/gl_context_egl.cc b/mediapipe/gpu/gl_context_egl.cc
index 79f0c30eb..58ab00784 100644
--- a/mediapipe/gpu/gl_context_egl.cc
+++ b/mediapipe/gpu/gl_context_egl.cc
@@ -191,6 +191,18 @@ void GlContext::DestroyContext() {
.IgnoreError();
}
+#ifdef __ANDROID__
+ if (HasContext()) {
+ // Detach the current program to work around b/166322604.
+ if (eglMakeCurrent(display_, surface_, surface_, context_)) {
+ glUseProgram(0);
+ } else {
+ LOG(ERROR) << "eglMakeCurrent() returned error " << std::showbase
+ << std::hex << eglGetError();
+ }
+ }
+#endif // __ANDROID__
+
// Destroy the context and surface.
if (IsCurrent()) {
if (!eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
diff --git a/mediapipe/gpu/gl_context_webgl.cc b/mediapipe/gpu/gl_context_webgl.cc
index 19c0ea506..435f16e59 100644
--- a/mediapipe/gpu/gl_context_webgl.cc
+++ b/mediapipe/gpu/gl_context_webgl.cc
@@ -72,23 +72,23 @@ GlContext::StatusOrGlContext GlContext::Create(
// multithreading options, like the special-case combination of USE_PTHREADS
// and OFFSCREEN_FRAMEBUFFER)
EM_ASM(let init_once = true; if (init_once) {
- const __cachedFindCanvasEventTarget = __findCanvasEventTarget;
+ const cachedFindCanvasEventTarget = findCanvasEventTarget;
- if (typeof __cachedFindCanvasEventTarget != = 'function') {
+ if (typeof cachedFindCanvasEventTarget != = 'function') {
if (typeof console != = 'undefined') {
console.error(
'Expected Emscripten global function ' +
- '"__findCanvasEventTarget" not found. WebGL context creation ' +
+ '"findCanvasEventTarget" not found. WebGL context creation ' +
'may fail.');
}
return;
}
- __findCanvasEventTarget = function(target) {
+ findCanvasEventTarget = function(target) {
if (Module && Module.canvas) {
return Module.canvas;
} else if (Module && Module.canvasCssSelector) {
- return __cachedFindCanvasEventTarget(Module.canvasCssSelector);
+ return cachedFindCanvasEventTarget(Module.canvasCssSelector);
} else {
if (typeof console != = 'undefined') {
console.warn('Module properties canvas and canvasCssSelector not ' +
@@ -97,7 +97,7 @@ GlContext::StatusOrGlContext GlContext::Create(
// We still go through with the find attempt, although for most use
// cases it will not succeed, just in case the user does want to fall-
// back.
- return __cachedFindCanvasEventTarget(target);
+ return cachedFindCanvasEventTarget(target);
}
}; // NOLINT: Necessary semicolon.
init_once = false;
diff --git a/mediapipe/gpu/gl_texture_buffer.cc b/mediapipe/gpu/gl_texture_buffer.cc
index cccb8c0fa..d9ec94f0e 100644
--- a/mediapipe/gpu/gl_texture_buffer.cc
+++ b/mediapipe/gpu/gl_texture_buffer.cc
@@ -23,6 +23,13 @@ std::unique_ptr GlTextureBuffer::Wrap(
deletion_callback);
}
+std::unique_ptr GlTextureBuffer::Wrap(
+ GLenum target, GLuint name, int width, int height, GpuBufferFormat format,
+ std::shared_ptr context, DeletionCallback deletion_callback) {
+ return absl::make_unique(target, name, width, height, format,
+ deletion_callback, context);
+}
+
std::unique_ptr GlTextureBuffer::Create(int width, int height,
GpuBufferFormat format,
const void* data) {
@@ -36,18 +43,22 @@ std::unique_ptr GlTextureBuffer::Create(int width, int height,
GlTextureBuffer::GlTextureBuffer(GLenum target, GLuint name, int width,
int height, GpuBufferFormat format,
- DeletionCallback deletion_callback)
+ DeletionCallback deletion_callback,
+ std::shared_ptr producer_context)
: name_(name),
width_(width),
height_(height),
format_(format),
target_(target),
- deletion_callback_(deletion_callback) {}
+ deletion_callback_(deletion_callback),
+ producer_context_(producer_context) {}
bool GlTextureBuffer::CreateInternal(const void* data) {
auto context = GlContext::GetCurrent();
if (!context) return false;
+ producer_context_ = context; // Save creation GL context.
+
glGenTextures(1, &name_);
if (!name_) return false;
@@ -106,6 +117,7 @@ void GlTextureBuffer::Updated(std::shared_ptr prod_token) {
CHECK(!producer_sync_)
<< "Updated existing texture which had not been marked for reuse!";
producer_sync_ = std::move(prod_token);
+ producer_context_ = producer_sync_->GetContext();
}
void GlTextureBuffer::DidRead(std::shared_ptr cons_token) {
diff --git a/mediapipe/gpu/gl_texture_buffer.h b/mediapipe/gpu/gl_texture_buffer.h
index 9c21571d2..e6c44b6ff 100644
--- a/mediapipe/gpu/gl_texture_buffer.h
+++ b/mediapipe/gpu/gl_texture_buffer.h
@@ -50,6 +50,11 @@ class GlTextureBuffer {
GLenum target, GLuint name, int width, int height, GpuBufferFormat format,
DeletionCallback deletion_callback);
+ // Same as Wrap above, but saves the given context for future use.
+ static std::unique_ptr Wrap(
+ GLenum target, GLuint name, int width, int height, GpuBufferFormat format,
+ std::shared_ptr context, DeletionCallback deletion_callback);
+
// Creates a texture of dimensions width x height and allocates space for it.
// If data is provided, it is uploaded to the texture; otherwise, it can be
// provided later via glTexSubImage2D.
@@ -63,7 +68,8 @@ class GlTextureBuffer {
// The commands producing the texture are assumed to be completed at the
// time of this call. If not, call Updated on the result.
GlTextureBuffer(GLenum target, GLuint name, int width, int height,
- GpuBufferFormat format, DeletionCallback deletion_callback);
+ GpuBufferFormat format, DeletionCallback deletion_callback,
+ std::shared_ptr producer_context = nullptr);
~GlTextureBuffer();
// Included to support nativeGetGpuBuffer* in Java.
@@ -111,6 +117,11 @@ class GlTextureBuffer {
void WaitForConsumers();
void WaitForConsumersOnGpu();
+ // Returns the GL context this buffer was created with.
+ const std::shared_ptr& GetProducerContext() {
+ return producer_context_;
+ }
+
private:
// Creates a texture of dimensions width x height and allocates space for it.
// If data is provided, it is uploaded to the texture; otherwise, it can be
@@ -132,6 +143,7 @@ class GlTextureBuffer {
std::unique_ptr consumer_multi_sync_ ABSL_GUARDED_BY(
consumer_sync_mutex_) = absl::make_unique();
DeletionCallback deletion_callback_;
+ std::shared_ptr producer_context_;
};
using GlTextureBufferSharedPtr = std::shared_ptr;
diff --git a/mediapipe/gpu/gpu_buffer_multi_pool.cc b/mediapipe/gpu/gpu_buffer_multi_pool.cc
index c98a3de75..b334f62a8 100644
--- a/mediapipe/gpu/gpu_buffer_multi_pool.cc
+++ b/mediapipe/gpu/gpu_buffer_multi_pool.cc
@@ -206,10 +206,11 @@ void GpuBufferMultiPool::EntryList::InsertAfter(Entry* entry, Entry* after) {
Prepend(entry);
}
-void GpuBufferMultiPool::Evict() {
+void GpuBufferMultiPool::Evict(std::vector* evicted) {
// Remove excess entries.
while (entry_list_.size() > kMaxPoolCount) {
Entry* victim = entry_list_.tail();
+ evicted->emplace_back(std::move(victim->pool));
entry_list_.Remove(victim);
pools_.erase(victim->spec);
}
@@ -230,6 +231,7 @@ void GpuBufferMultiPool::Evict() {
entry->request_count /= 2;
Entry* next = entry->next;
if (entry->request_count == 0) {
+ evicted->emplace_back(std::move(entry->pool));
entry_list_.Remove(entry);
pools_.erase(entry->spec);
}
@@ -240,36 +242,43 @@ void GpuBufferMultiPool::Evict() {
GpuBufferMultiPool::SimplePool GpuBufferMultiPool::RequestPool(
const BufferSpec& key) {
- absl::MutexLock lock(&mutex_);
- auto pool_it = pools_.find(key);
- Entry* entry;
- if (pool_it == pools_.end()) {
- std::tie(pool_it, std::ignore) =
- pools_.emplace(std::piecewise_construct, std::forward_as_tuple(key),
- std::forward_as_tuple(key));
- entry = &pool_it->second;
- CHECK_EQ(entry->request_count, 0);
- entry->request_count = 1;
- entry_list_.Append(entry);
- if (entry->prev != nullptr) CHECK_GE(entry->prev->request_count, 1);
- } else {
- entry = &pool_it->second;
- ++entry->request_count;
- Entry* larger = entry->prev;
- while (larger != nullptr && larger->request_count < entry->request_count) {
- larger = larger->prev;
+ SimplePool pool;
+ std::vector evicted;
+ {
+ absl::MutexLock lock(&mutex_);
+ auto pool_it = pools_.find(key);
+ Entry* entry;
+ if (pool_it == pools_.end()) {
+ std::tie(pool_it, std::ignore) =
+ pools_.emplace(std::piecewise_construct, std::forward_as_tuple(key),
+ std::forward_as_tuple(key));
+ entry = &pool_it->second;
+ CHECK_EQ(entry->request_count, 0);
+ entry->request_count = 1;
+ entry_list_.Append(entry);
+ if (entry->prev != nullptr) CHECK_GE(entry->prev->request_count, 1);
+ } else {
+ entry = &pool_it->second;
+ ++entry->request_count;
+ Entry* larger = entry->prev;
+ while (larger != nullptr &&
+ larger->request_count < entry->request_count) {
+ larger = larger->prev;
+ }
+ if (larger != entry->prev) {
+ entry_list_.Remove(entry);
+ entry_list_.InsertAfter(entry, larger);
+ }
}
- if (larger != entry->prev) {
- entry_list_.Remove(entry);
- entry_list_.InsertAfter(entry, larger);
+ if (!entry->pool && entry->request_count >= kMinRequestsBeforePool) {
+ entry->pool = MakeSimplePool(key);
}
+ pool = entry->pool;
+ ++total_request_count_;
+ Evict(&evicted);
}
- if (!entry->pool && entry->request_count >= kMinRequestsBeforePool) {
- entry->pool = MakeSimplePool(key);
- }
- SimplePool pool = entry->pool;
- ++total_request_count_;
- Evict();
+ // Evicted pools, and their buffers, will be released without holding the
+ // lock.
return pool;
}
diff --git a/mediapipe/gpu/gpu_buffer_multi_pool.h b/mediapipe/gpu/gpu_buffer_multi_pool.h
index 8039d18a2..a8ee5a197 100644
--- a/mediapipe/gpu/gpu_buffer_multi_pool.h
+++ b/mediapipe/gpu/gpu_buffer_multi_pool.h
@@ -160,7 +160,8 @@ class GpuBufferMultiPool {
SimplePool RequestPool(const BufferSpec& key);
GpuBuffer GetBufferFromSimplePool(BufferSpec spec, const SimplePool& pool);
GpuBuffer GetBufferWithoutPool(const BufferSpec& spec);
- void Evict() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ void Evict(std::vector* evicted)
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
absl::Mutex mutex_;
std::unordered_map pools_
diff --git a/mediapipe/graphs/edge_detection/BUILD b/mediapipe/graphs/edge_detection/BUILD
index 2f47a3dde..fac241106 100644
--- a/mediapipe/graphs/edge_detection/BUILD
+++ b/mediapipe/graphs/edge_detection/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/graphs/face_detection/BUILD b/mediapipe/graphs/face_detection/BUILD
index ccc9995d6..ac54089b2 100644
--- a/mediapipe/graphs/face_detection/BUILD
+++ b/mediapipe/graphs/face_detection/BUILD
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/graphs/face_mesh/BUILD b/mediapipe/graphs/face_mesh/BUILD
index 961f2907b..6926fda72 100644
--- a/mediapipe/graphs/face_mesh/BUILD
+++ b/mediapipe/graphs/face_mesh/BUILD
@@ -17,7 +17,7 @@ load(
"mediapipe_binary_graph",
)
-licenses(["notice"]) # Apache 2.0
+licenses(["notice"])
package(default_visibility = ["//visibility:public"])
diff --git a/mediapipe/graphs/face_mesh/calculators/BUILD b/mediapipe/graphs/face_mesh/calculators/BUILD
new file mode 100644
index 000000000..3bebfc9c8
--- /dev/null
+++ b/mediapipe/graphs/face_mesh/calculators/BUILD
@@ -0,0 +1,37 @@
+# Copyright 2020 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.
+
+licenses(["notice"])
+
+package(default_visibility = ["//visibility:public"])
+
+cc_library(
+ name = "face_landmarks_to_render_data_calculator",
+ srcs = ["face_landmarks_to_render_data_calculator.cc"],
+ visibility = ["//visibility:public"],
+ deps = [
+ "//mediapipe/calculators/util:landmarks_to_render_data_calculator",
+ "//mediapipe/calculators/util:landmarks_to_render_data_calculator_cc_proto",
+ "//mediapipe/framework:calculator_framework",
+ "//mediapipe/framework:calculator_options_cc_proto",
+ "//mediapipe/framework/formats:landmark_cc_proto",
+ "//mediapipe/framework/formats:location_data_cc_proto",
+ "//mediapipe/framework/port:ret_check",
+ "//mediapipe/util:color_cc_proto",
+ "//mediapipe/util:render_data_cc_proto",
+ "@com_google_absl//absl/memory",
+ "@com_google_absl//absl/strings",
+ ],
+ alwayslink = 1,
+)
diff --git a/mediapipe/graphs/face_mesh/calculators/face_landmarks_to_render_data_calculator.cc b/mediapipe/graphs/face_mesh/calculators/face_landmarks_to_render_data_calculator.cc
new file mode 100644
index 000000000..7bbea8574
--- /dev/null
+++ b/mediapipe/graphs/face_mesh/calculators/face_landmarks_to_render_data_calculator.cc
@@ -0,0 +1,101 @@
+// Copyright 2020 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.
+
+#include "absl/memory/memory.h"
+#include "absl/strings/str_cat.h"
+#include "absl/strings/str_join.h"
+#include "mediapipe/calculators/util/landmarks_to_render_data_calculator.h"
+#include "mediapipe/calculators/util/landmarks_to_render_data_calculator.pb.h"
+#include "mediapipe/framework/calculator_framework.h"
+#include "mediapipe/framework/calculator_options.pb.h"
+#include "mediapipe/framework/formats/landmark.pb.h"
+#include "mediapipe/framework/formats/location_data.pb.h"
+#include "mediapipe/framework/port/ret_check.h"
+#include "mediapipe/util/color.pb.h"
+#include "mediapipe/util/render_data.pb.h"
+namespace mediapipe {
+
+namespace {
+
+constexpr int kNumFaceLandmarkConnections = 124;
+// Pairs of landmark indices to be rendered with connections.
+constexpr int kFaceLandmarkConnections[] = {
+ // Lips.
+ 61, 146, 146, 91, 91, 181, 181, 84, 84, 17, 17, 314, 314, 405, 405, 321,
+ 321, 375, 375, 291, 61, 185, 185, 40, 40, 39, 39, 37, 37, 0, 0, 267, 267,
+ 269, 269, 270, 270, 409, 409, 291, 78, 95, 95, 88, 88, 178, 178, 87, 87, 14,
+ 14, 317, 317, 402, 402, 318, 318, 324, 324, 308, 78, 191, 191, 80, 80, 81,
+ 81, 82, 82, 13, 13, 312, 312, 311, 311, 310, 310, 415, 415, 308,
+ // Left eye.
+ 33, 7, 7, 163, 163, 144, 144, 145, 145, 153, 153, 154, 154, 155, 155, 133,
+ 33, 246, 246, 161, 161, 160, 160, 159, 159, 158, 158, 157, 157, 173, 173,
+ 133,
+ // Left eyebrow.
+ 46, 53, 53, 52, 52, 65, 65, 55, 70, 63, 63, 105, 105, 66, 66, 107,
+ // Right eye.
+ 263, 249, 249, 390, 390, 373, 373, 374, 374, 380, 380, 381, 381, 382, 382,
+ 362, 263, 466, 466, 388, 388, 387, 387, 386, 386, 385, 385, 384, 384, 398,
+ 398, 362,
+ // Right eyebrow.
+ 276, 283, 283, 282, 282, 295, 295, 285, 300, 293, 293, 334, 334, 296, 296,
+ 336,
+ // Face oval.
+ 10, 338, 338, 297, 297, 332, 332, 284, 284, 251, 251, 389, 389, 356, 356,
+ 454, 454, 323, 323, 361, 361, 288, 288, 397, 397, 365, 365, 379, 379, 378,
+ 378, 400, 400, 377, 377, 152, 152, 148, 148, 176, 176, 149, 149, 150, 150,
+ 136, 136, 172, 172, 58, 58, 132, 132, 93, 93, 234, 234, 127, 127, 162, 162,
+ 21, 21, 54, 54, 103, 103, 67, 67, 109, 109, 10};
+
+} // namespace
+
+// A calculator that converts face landmarks to RenderData proto for
+// visualization. Ignores landmark_connections specified in
+// LandmarksToRenderDataCalculatorOptions, if any, and always uses a fixed set
+// of landmark connections specific to face landmark (defined in
+// kFaceLandmarkConnections[] above).
+//
+// Example config:
+// node {
+// calculator: "FaceLandmarksToRenderDataCalculator"
+// input_stream: "NORM_LANDMARKS:landmarks"
+// output_stream: "RENDER_DATA:render_data"
+// options {
+// [LandmarksToRenderDataCalculatorOptions.ext] {
+// landmark_color { r: 0 g: 255 b: 0 }
+// connection_color { r: 0 g: 255 b: 0 }
+// thickness: 4.0
+// }
+// }
+// }
+class FaceLandmarksToRenderDataCalculator
+ : public LandmarksToRenderDataCalculator {
+ public:
+ ::mediapipe::Status Open(CalculatorContext* cc) override;
+};
+REGISTER_CALCULATOR(FaceLandmarksToRenderDataCalculator);
+
+::mediapipe::Status FaceLandmarksToRenderDataCalculator::Open(
+ CalculatorContext* cc) {
+ cc->SetOffset(TimestampDiff(0));
+ options_ = cc->Options