Compare commits
+1
-1
@@ -1 +1 @@
|
||||
5.2.0
|
||||
6.1.1
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ RUN pip3 install tf_slim
|
||||
RUN ln -s /usr/bin/python3 /usr/bin/python
|
||||
|
||||
# Install bazel
|
||||
ARG BAZEL_VERSION=5.2.0
|
||||
ARG BAZEL_VERSION=6.1.1
|
||||
RUN mkdir /bazel && \
|
||||
wget --no-check-certificate -O /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/b\
|
||||
azel-${BAZEL_VERSION}-installer-linux-x86_64.sh" && \
|
||||
|
||||
@@ -199,3 +199,20 @@
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
For files under tasks/cc/text/language_detector/custom_ops/utils/utf/
|
||||
===========================================================================
|
||||
/*
|
||||
* The authors of this software are Rob Pike and Ken Thompson.
|
||||
* Copyright (c) 2002 by Lucent Technologies.
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose without fee is hereby granted, provided that this entire notice
|
||||
* is included in all copies of any software which is or includes a copy
|
||||
* or modification of this software and in all copies of the supporting
|
||||
* documentation for such software.
|
||||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
||||
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
|
||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
|
||||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,20 @@ nav_order: 1
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
*This notice and web page will be removed on June 1, 2023.*
|
||||
|
||||
----
|
||||
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## Live ML anywhere
|
||||
@@ -21,15 +35,6 @@ ML solutions for live and streaming media.
|
||||
|
||||
----
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We are moving to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation
|
||||
site for MediaPipe starting April 3, 2023.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## ML solutions in MediaPipe
|
||||
|
||||
Face Detection | Face Mesh | Iris | Hands | Pose | Holistic
|
||||
|
||||
@@ -54,6 +54,76 @@ load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependen
|
||||
|
||||
rules_foreign_cc_dependencies()
|
||||
|
||||
http_archive(
|
||||
name = "com_google_protobuf",
|
||||
sha256 = "87407cd28e7a9c95d9f61a098a53cf031109d451a7763e7dd1253abf8b4df422",
|
||||
strip_prefix = "protobuf-3.19.1",
|
||||
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz"],
|
||||
patches = [
|
||||
"@//third_party:com_google_protobuf_fixes.diff"
|
||||
],
|
||||
patch_args = [
|
||||
"-p1",
|
||||
],
|
||||
)
|
||||
|
||||
# Load Zlib before initializing TensorFlow and the iOS build rules to guarantee
|
||||
# that the target @zlib//:mini_zlib is available
|
||||
http_archive(
|
||||
name = "zlib",
|
||||
build_file = "@//third_party:zlib.BUILD",
|
||||
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
|
||||
strip_prefix = "zlib-1.2.11",
|
||||
urls = [
|
||||
"http://mirror.bazel.build/zlib.net/fossils/zlib-1.2.11.tar.gz",
|
||||
"http://zlib.net/fossils/zlib-1.2.11.tar.gz", # 2017-01-15
|
||||
],
|
||||
patches = [
|
||||
"@//third_party:zlib.diff",
|
||||
],
|
||||
patch_args = [
|
||||
"-p1",
|
||||
],
|
||||
)
|
||||
|
||||
# iOS basic build deps.
|
||||
http_archive(
|
||||
name = "build_bazel_rules_apple",
|
||||
sha256 = "3e2c7ae0ddd181c4053b6491dad1d01ae29011bc322ca87eea45957c76d3a0c3",
|
||||
url = "https://github.com/bazelbuild/rules_apple/releases/download/2.1.0/rules_apple.2.1.0.tar.gz",
|
||||
patches = [
|
||||
# Bypass checking ios unit test runner when building MP ios applications.
|
||||
"@//third_party:build_bazel_rules_apple_bypass_test_runner_check.diff"
|
||||
],
|
||||
patch_args = [
|
||||
"-p1",
|
||||
],
|
||||
)
|
||||
|
||||
load(
|
||||
"@build_bazel_rules_apple//apple:repositories.bzl",
|
||||
"apple_rules_dependencies",
|
||||
)
|
||||
apple_rules_dependencies()
|
||||
|
||||
load(
|
||||
"@build_bazel_rules_swift//swift:repositories.bzl",
|
||||
"swift_rules_dependencies",
|
||||
)
|
||||
swift_rules_dependencies()
|
||||
|
||||
load(
|
||||
"@build_bazel_rules_swift//swift:extras.bzl",
|
||||
"swift_rules_extra_dependencies",
|
||||
)
|
||||
swift_rules_extra_dependencies()
|
||||
|
||||
load(
|
||||
"@build_bazel_apple_support//lib:repositories.bzl",
|
||||
"apple_support_dependencies",
|
||||
)
|
||||
apple_support_dependencies()
|
||||
|
||||
# This is used to select all contents of the archives for CMake-based packages to give CMake access to them.
|
||||
all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""
|
||||
|
||||
@@ -133,19 +203,6 @@ http_archive(
|
||||
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "com_google_protobuf",
|
||||
sha256 = "87407cd28e7a9c95d9f61a098a53cf031109d451a7763e7dd1253abf8b4df422",
|
||||
strip_prefix = "protobuf-3.19.1",
|
||||
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz"],
|
||||
patches = [
|
||||
"@//third_party:com_google_protobuf_fixes.diff"
|
||||
],
|
||||
patch_args = [
|
||||
"-p1",
|
||||
],
|
||||
)
|
||||
|
||||
load("@//third_party/flatbuffers:workspace.bzl", flatbuffers = "repo")
|
||||
flatbuffers()
|
||||
|
||||
@@ -155,6 +212,9 @@ http_archive(
|
||||
urls = ["https://github.com/google/multichannel-audio-tools/archive/1f6b1319f13282eda6ff1317be13de67f4723860.zip"],
|
||||
sha256 = "fe346e1aee4f5069c4cbccb88706a9a2b2b4cf98aeb91ec1319be77e07dd7435",
|
||||
repo_mapping = {"@com_github_glog_glog" : "@com_github_glog_glog_no_gflags"},
|
||||
# TODO: Fix this in AudioTools directly
|
||||
patches = ["@//third_party:com_google_audio_tools_fixes.diff"],
|
||||
patch_args = ["-p1"]
|
||||
)
|
||||
|
||||
http_archive(
|
||||
@@ -179,6 +239,16 @@ http_archive(
|
||||
repo_mapping = {"@com_google_glog" : "@com_github_glog_glog_no_gflags"},
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "darts_clone",
|
||||
build_file = "@//third_party:darts_clone.BUILD",
|
||||
sha256 = "c97f55d05c98da6fcaf7f9ecc6a6dc6bc5b18b8564465f77abff8879d446491c",
|
||||
strip_prefix = "darts-clone-e40ce4627526985a7767444b6ed6893ab6ff8983",
|
||||
urls = [
|
||||
"https://github.com/s-yata/darts-clone/archive/e40ce4627526985a7767444b6ed6893ab6ff8983.zip",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "org_tensorflow_text",
|
||||
sha256 = "f64647276f7288d1b1fe4c89581d51404d0ce4ae97f2bcc4c19bd667549adca8",
|
||||
@@ -270,7 +340,7 @@ new_local_repository(
|
||||
# For local MacOS builds, the path should point to an opencv@3 installation.
|
||||
# If you edit the path here, you will also need to update the corresponding
|
||||
# prefix in "opencv_macos.BUILD".
|
||||
path = "/usr/local",
|
||||
path = "/usr/local", # e.g. /usr/local/Cellar for HomeBrew
|
||||
)
|
||||
|
||||
new_local_repository(
|
||||
@@ -319,63 +389,6 @@ http_archive(
|
||||
],
|
||||
)
|
||||
|
||||
# Load Zlib before initializing TensorFlow and the iOS build rules to guarantee
|
||||
# that the target @zlib//:mini_zlib is available
|
||||
http_archive(
|
||||
name = "zlib",
|
||||
build_file = "@//third_party:zlib.BUILD",
|
||||
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
|
||||
strip_prefix = "zlib-1.2.11",
|
||||
urls = [
|
||||
"http://mirror.bazel.build/zlib.net/fossils/zlib-1.2.11.tar.gz",
|
||||
"http://zlib.net/fossils/zlib-1.2.11.tar.gz", # 2017-01-15
|
||||
],
|
||||
patches = [
|
||||
"@//third_party:zlib.diff",
|
||||
],
|
||||
patch_args = [
|
||||
"-p1",
|
||||
],
|
||||
)
|
||||
|
||||
# iOS basic build deps.
|
||||
http_archive(
|
||||
name = "build_bazel_rules_apple",
|
||||
sha256 = "f94e6dddf74739ef5cb30f000e13a2a613f6ebfa5e63588305a71fce8a8a9911",
|
||||
url = "https://github.com/bazelbuild/rules_apple/releases/download/1.1.3/rules_apple.1.1.3.tar.gz",
|
||||
patches = [
|
||||
# Bypass checking ios unit test runner when building MP ios applications.
|
||||
"@//third_party:build_bazel_rules_apple_bypass_test_runner_check.diff"
|
||||
],
|
||||
patch_args = [
|
||||
"-p1",
|
||||
],
|
||||
)
|
||||
|
||||
load(
|
||||
"@build_bazel_rules_apple//apple:repositories.bzl",
|
||||
"apple_rules_dependencies",
|
||||
)
|
||||
apple_rules_dependencies()
|
||||
|
||||
load(
|
||||
"@build_bazel_rules_swift//swift:repositories.bzl",
|
||||
"swift_rules_dependencies",
|
||||
)
|
||||
swift_rules_dependencies()
|
||||
|
||||
load(
|
||||
"@build_bazel_rules_swift//swift:extras.bzl",
|
||||
"swift_rules_extra_dependencies",
|
||||
)
|
||||
swift_rules_extra_dependencies()
|
||||
|
||||
load(
|
||||
"@build_bazel_apple_support//lib:repositories.bzl",
|
||||
"apple_support_dependencies",
|
||||
)
|
||||
apple_support_dependencies()
|
||||
|
||||
# More iOS deps.
|
||||
|
||||
http_archive(
|
||||
@@ -455,9 +468,9 @@ http_archive(
|
||||
)
|
||||
|
||||
# TensorFlow repo should always go after the other external dependencies.
|
||||
# TF on 2023-03-08.
|
||||
_TENSORFLOW_GIT_COMMIT = "24f7ee636d62e1f8d8330357f8bbd65956dfb84d"
|
||||
_TENSORFLOW_SHA256 = "7f8a96dd99215c0cdc77230d3dbce43e60102b64a89203ad04aa09b0a187a4bd"
|
||||
# TF on 2023-04-12.
|
||||
_TENSORFLOW_GIT_COMMIT = "d712c0c9e24519cc8cd3720279666720d1000eee"
|
||||
_TENSORFLOW_SHA256 = "ba98de6ea5f720071246691a1536ecd5e1b1763033e8c82a1e721a06d3dfd4c1"
|
||||
http_archive(
|
||||
name = "org_tensorflow",
|
||||
urls = [
|
||||
@@ -499,8 +512,8 @@ cc_crosstool(name = "crosstool")
|
||||
# Node dependencies
|
||||
http_archive(
|
||||
name = "build_bazel_rules_nodejs",
|
||||
sha256 = "5aae76dced38f784b58d9776e4ab12278bc156a9ed2b1d9fcd3e39921dc88fda",
|
||||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.7.1/rules_nodejs-5.7.1.tar.gz"],
|
||||
sha256 = "94070eff79305be05b7699207fbac5d2608054dd53e6109f7d00d923919ff45a",
|
||||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-5.8.2.tar.gz"],
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
|
||||
@@ -554,32 +567,32 @@ new_local_repository(
|
||||
|
||||
http_archive(
|
||||
name = "linux_halide",
|
||||
sha256 = "f62b2914823d6e33d18693f5b74484f274523bf5402ce51988e24393d123b375",
|
||||
strip_prefix = "Halide-15.0.0-x86-64-linux",
|
||||
urls = ["https://github.com/halide/Halide/releases/download/v15.0.0/Halide-15.0.0-x86-64-linux-d7651f4b32f9dbd764f243134001f7554378d62d.tar.gz"],
|
||||
sha256 = "d290fadf3f358c94aacf43c883de6468bb98883e26116920afd491ec0e440cd2",
|
||||
strip_prefix = "Halide-15.0.1-x86-64-linux",
|
||||
urls = ["https://github.com/halide/Halide/releases/download/v15.0.1/Halide-15.0.1-x86-64-linux-4c63f1befa1063184c5982b11b6a2cc17d4e5815.tar.gz"],
|
||||
build_file = "@//third_party:halide.BUILD",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "macos_x86_64_halide",
|
||||
sha256 = "3d832aed942080ea89aa832462c68fbb906f3055c440b7b6d35093d7c52f6aab",
|
||||
strip_prefix = "Halide-15.0.0-x86-64-osx",
|
||||
urls = ["https://github.com/halide/Halide/releases/download/v15.0.0/Halide-15.0.0-x86-64-osx-d7651f4b32f9dbd764f243134001f7554378d62d.tar.gz"],
|
||||
sha256 = "48ff073ac1aee5c4aca941a4f043cac64b38ba236cdca12567e09d803594a61c",
|
||||
strip_prefix = "Halide-15.0.1-x86-64-osx",
|
||||
urls = ["https://github.com/halide/Halide/releases/download/v15.0.1/Halide-15.0.1-x86-64-osx-4c63f1befa1063184c5982b11b6a2cc17d4e5815.tar.gz"],
|
||||
build_file = "@//third_party:halide.BUILD",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "macos_arm_64_halide",
|
||||
sha256 = "b1fad3c9810122b187303d7031d9e35fb43761f345d18cc4492c00ed5877f641",
|
||||
strip_prefix = "Halide-15.0.0-arm-64-osx",
|
||||
urls = ["https://github.com/halide/Halide/releases/download/v15.0.0/Halide-15.0.0-arm-64-osx-d7651f4b32f9dbd764f243134001f7554378d62d.tar.gz"],
|
||||
sha256 = "db5d20d75fa7463490fcbc79c89f0abec9c23991f787c8e3e831fff411d5395c",
|
||||
strip_prefix = "Halide-15.0.1-arm-64-osx",
|
||||
urls = ["https://github.com/halide/Halide/releases/download/v15.0.1/Halide-15.0.1-arm-64-osx-4c63f1befa1063184c5982b11b6a2cc17d4e5815.tar.gz"],
|
||||
build_file = "@//third_party:halide.BUILD",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "windows_halide",
|
||||
sha256 = "5acf6fe161dd375856a2b43f4bb0a32815ba958b0585ee312c44e008aa7b0b64",
|
||||
strip_prefix = "Halide-15.0.0-x86-64-windows",
|
||||
urls = ["https://github.com/halide/Halide/releases/download/v15.0.0/Halide-15.0.0-x86-64-windows-d7651f4b32f9dbd764f243134001f7554378d62d.zip"],
|
||||
sha256 = "61fd049bd75ee918ac6c30d0693aac6048f63f8d1fc4db31001573e58eae8dae",
|
||||
strip_prefix = "Halide-15.0.1-x86-64-windows",
|
||||
urls = ["https://github.com/halide/Halide/releases/download/v15.0.1/Halide-15.0.1-x86-64-windows-4c63f1befa1063184c5982b11b6a2cc17d4e5815.zip"],
|
||||
build_file = "@//third_party:halide.BUILD",
|
||||
)
|
||||
|
||||
+2
-2
@@ -16,11 +16,11 @@ py_binary(
|
||||
srcs = ["build_java_api_docs.py"],
|
||||
data = [
|
||||
"//third_party/android/sdk:api/26.txt",
|
||||
"//third_party/java/doclava/current:doclava.jar",
|
||||
"//third_party/java/doclava:doclet.jar",
|
||||
"//third_party/java/jsilver:jsilver_jar",
|
||||
],
|
||||
env = {
|
||||
"DOCLAVA_JAR": "$(location //third_party/java/doclava/current:doclava.jar)",
|
||||
"DOCLAVA_JAR": "$(location //third_party/java/doclava:doclet.jar)",
|
||||
"JSILVER_JAR": "$(location //third_party/java/jsilver:jsilver_jar)",
|
||||
},
|
||||
deps = [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/framework/framework_concepts/graphs_cpp
|
||||
title: Building Graphs in C++
|
||||
parent: Graphs
|
||||
nav_order: 1
|
||||
@@ -12,6 +13,12 @@ nav_order: 1
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
C++ graph builder is a powerful tool for:
|
||||
|
||||
* Building complex graphs
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 1
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
Each calculator is a node of a graph. We describe how to create a new
|
||||
calculator, how to initialize a calculator, how to perform its calculations,
|
||||
input and output streams, timestamps, and options. Each node in the graph is
|
||||
|
||||
@@ -14,6 +14,12 @@ has_toc: false
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## The basics
|
||||
|
||||
### Packet
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 5
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
MediaPipe supports calculator nodes for GPU compute and rendering, and allows combining multiple GPU nodes, as well as mixing them with CPU based calculator nodes. There exist several GPU APIs on mobile platforms (eg, OpenGL ES, Metal and Vulkan). MediaPipe does not attempt to offer a single cross-API GPU abstraction. Individual nodes can be written using different APIs, allowing them to take advantage of platform specific features when needed.
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 2
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Graph
|
||||
|
||||
A `CalculatorGraphConfig` proto specifies the topology and functionality of a
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 3
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
Calculators communicate by sending and receiving packets. Typically a single
|
||||
packet is sent along each input stream at each input timestamp. A packet can
|
||||
contain any kind of data, such as a single frame of video or a single integer
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 6
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Real-time timestamps
|
||||
|
||||
MediaPipe calculator graphs are often used to process streams of video or audio
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 4
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Scheduling mechanics
|
||||
|
||||
Data processing in a MediaPipe graph occurs inside processing nodes defined as
|
||||
|
||||
@@ -15,6 +15,12 @@ nav_order: 1
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
Please follow instructions below to build Android example apps in the supported
|
||||
MediaPipe [solutions](../solutions/solutions.md). To learn more about these
|
||||
example apps, start from [Hello World! on Android](./hello_world_android.md).
|
||||
|
||||
@@ -14,6 +14,12 @@ nav_order: 3
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
***Experimental Only***
|
||||
|
||||
The MediaPipe Android Archive (AAR) library is a convenient way to use MediaPipe
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/
|
||||
title: MediaPipe Android Solutions
|
||||
parent: MediaPipe on Android
|
||||
grand_parent: Getting Started
|
||||
@@ -13,14 +14,9 @@ nav_order: 2
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We are moving to
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation
|
||||
site for MediaPipe starting April 3, 2023. This content will not be moved to
|
||||
the new site, but will remain available in the source code repository on an
|
||||
as-is basis.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/
|
||||
title: Building MediaPipe Examples
|
||||
parent: Getting Started
|
||||
nav_exclude: true
|
||||
@@ -12,14 +13,9 @@ nav_exclude: true
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We are moving to
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation
|
||||
site for MediaPipe starting April 3, 2023. This content will not be moved to
|
||||
the new site, but will remain available in the source code repository on an
|
||||
as-is basis.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
|
||||
@@ -15,6 +15,12 @@ nav_order: 5
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
Please follow instructions below to build C++ command-line example apps in the
|
||||
supported MediaPipe [solutions](../solutions/solutions.md). To learn more about
|
||||
these example apps, start from [Hello World! in C++](./hello_world_cpp.md).
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 9
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
### How to convert ImageFrames and GpuBuffers
|
||||
|
||||
The Calculators [`ImageFrameToGpuBufferCalculator`] and
|
||||
@@ -47,7 +53,7 @@ calculators need only to be *thread-compatible* and not *thread-safe*.
|
||||
In order to enable one calculator to process multiple inputs in parallel, there
|
||||
are two possible approaches:
|
||||
|
||||
1. Define multiple calulator nodes and dispatch input packets to all nodes.
|
||||
1. Define multiple calculator nodes and dispatch input packets to all nodes.
|
||||
2. Make the calculator thread-safe and configure its [`max_in_flight`] setting.
|
||||
|
||||
The first approach can be followed using the calculators designed to distribute
|
||||
@@ -89,12 +95,12 @@ while the application is running:
|
||||
The first approach has the advantage of leveraging [`CalculatorGraphConfig`]
|
||||
processing tools such as "subgraphs". The second approach has the advantage of
|
||||
allowing active calculators and packets to remain in-flight while settings
|
||||
change. Mediapipe contributors are currently investigating alternative approaches
|
||||
change. MediaPipe contributors are currently investigating alternative approaches
|
||||
to achieve both of these advantages.
|
||||
|
||||
### How to process realtime input streams
|
||||
|
||||
The mediapipe framework can be used to process data streams either online or
|
||||
The MediaPipe framework can be used to process data streams either online or
|
||||
offline. For offline processing, packets are pushed into the graph as soon as
|
||||
calculators are ready to process those packets. For online processing, one
|
||||
packet for each frame is pushed into the graph as that frame is recorded.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/
|
||||
title: Getting Started
|
||||
nav_order: 2
|
||||
has_children: true
|
||||
@@ -12,13 +13,8 @@ has_children: true
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We are moving to
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation
|
||||
site for MediaPipe starting April 3, 2023. This content will not be moved to
|
||||
the new site, but will remain available in the source code repository on an
|
||||
as-is basis.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 7
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## OpenGL ES Support
|
||||
|
||||
MediaPipe supports OpenGL ES up to version 3.2 on Android/Linux and up to ES 3.0
|
||||
|
||||
@@ -14,6 +14,12 @@ nav_order: 1
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Introduction
|
||||
|
||||
This codelab uses MediaPipe on an Android device.
|
||||
|
||||
@@ -14,6 +14,12 @@ nav_order: 1
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
1. Ensure you have a working version of MediaPipe. See
|
||||
[installation instructions](./install.md).
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ nav_order: 1
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Introduction
|
||||
|
||||
This codelab uses MediaPipe on an iOS device.
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 8
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Technical questions
|
||||
|
||||
For help with technical or algorithmic questions, visit
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 6
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
Note: To interoperate with OpenCV, OpenCV 3.x to 4.1 are preferred. OpenCV
|
||||
2.x currently works but interoperability support may be deprecated in the
|
||||
future.
|
||||
@@ -577,7 +583,7 @@ next section.
|
||||
|
||||
Option 1. Follow
|
||||
[the official Bazel documentation](https://docs.bazel.build/versions/master/install-windows.html)
|
||||
to install Bazel 5.2.0 or higher.
|
||||
to install Bazel 6.1.1 or higher.
|
||||
|
||||
Option 2. Follow the official
|
||||
[Bazel documentation](https://docs.bazel.build/versions/master/install-bazelisk.html)
|
||||
|
||||
@@ -15,6 +15,12 @@ nav_order: 2
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
Please follow instructions below to build iOS example apps in the supported
|
||||
MediaPipe [solutions](../solutions/solutions.md). To learn more about these
|
||||
example apps, start from, start from
|
||||
@@ -114,8 +120,8 @@ allows you to make use of automatic provisioning (see later section).
|
||||
To install applications on an iOS device, you need a provisioning profile. There
|
||||
are two options:
|
||||
|
||||
1. Automatic provisioning. This allows you to build and install an app to your
|
||||
personal device. The provisining profile is managed by Xcode, and has to be
|
||||
1. Automatic provisioning. This allows you to build and install an app on your
|
||||
personal device. The provisioning profile is managed by Xcode, and has to be
|
||||
updated often (it is valid for about a week).
|
||||
|
||||
2. Custom provisioning. This uses a provisioning profile associated with an
|
||||
@@ -180,7 +186,7 @@ Profiles"`. If there are none, generate and download a profile on
|
||||
Note: if you had previously set up automatic provisioning, you should remove the
|
||||
`provisioning_profile.mobileprovision` symlink in each example's directory,
|
||||
since it will take precedence over the common one. You can also overwrite it
|
||||
with you own profile if you need a different profile for different apps.
|
||||
with your own profile if you need a different profile for different apps.
|
||||
|
||||
1. Open `mediapipe/examples/ios/bundle_id.bzl`, and change the
|
||||
`BUNDLE_ID_PREFIX` to a prefix associated with your provisioning profile.
|
||||
@@ -197,7 +203,7 @@ Note: When you ask Xcode to run an app, by default it will use the Debug
|
||||
configuration. Some of our demos are computationally heavy; you may want to use
|
||||
the Release configuration for better performance.
|
||||
|
||||
Note: Due to an imcoptibility caused by one of our dependencies, MediaPipe
|
||||
Note: Due to an incompatibility caused by one of our dependencies, MediaPipe
|
||||
cannot be used for apps running on the iPhone Simulator on Apple Silicon (M1).
|
||||
|
||||
Tip: To switch build configuration in Xcode, click on the target menu, choose
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/
|
||||
title: MediaPipe in JavaScript
|
||||
parent: Getting Started
|
||||
nav_order: 4
|
||||
@@ -14,12 +15,7 @@ nav_order: 4
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We are moving to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation
|
||||
site for MediaPipe starting April 3, 2023. This content will not be moved to
|
||||
the new site, but will remain available in the source code repository on an
|
||||
as-is basis.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
as the primary developer documentation site for MediaPipe starting April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/
|
||||
title: MediaPipe in Python
|
||||
parent: Getting Started
|
||||
has_children: true
|
||||
@@ -14,6 +15,12 @@ nav_order: 3
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Ready-to-use Python Solutions
|
||||
|
||||
MediaPipe offers ready-to-use yet customizable Python solutions as a prebuilt
|
||||
|
||||
@@ -12,6 +12,11 @@ nav_order: 1
|
||||
1. TOC
|
||||
{:toc}
|
||||
---
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
The MediaPipe Python framework grants direct access to the core components of
|
||||
the MediaPipe C++ framework such as Timestamp, Packet, and CalculatorGraph,
|
||||
@@ -76,7 +81,7 @@ np.ndarray | mp::Matrix | create_ma
|
||||
Google Proto Message | Google Proto Message | create_proto(proto) | get_proto(packet)
|
||||
List\[Proto\] | std::vector\<Proto\> | n/a | get_proto_list(packet)
|
||||
|
||||
It's not uncommon that users create custom C++ classes and and send those into
|
||||
It's not uncommon that users create custom C++ classes and send those into
|
||||
the graphs and calculators. To allow the custom classes to be used in Python
|
||||
with MediaPipe, you may extend the Packet API for a new data type in the
|
||||
following steps:
|
||||
@@ -229,7 +234,7 @@ three stages: initialization and setup, graph run, and graph shutdown.
|
||||
output_packets.append(mp.packet_getter.get_str(packet)))
|
||||
```
|
||||
|
||||
Option 2. Initialize a CalculatorGraph with with a binary protobuf file, and
|
||||
Option 2. Initialize a CalculatorGraph with a binary protobuf file, and
|
||||
observe the output stream(s).
|
||||
|
||||
```python
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 10
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Missing Python binary path
|
||||
|
||||
The error message:
|
||||
|
||||
+14
-9
@@ -6,6 +6,20 @@ nav_order: 1
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
*This notice and web page will be removed on June 1, 2023.*
|
||||
|
||||
----
|
||||
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## Live ML anywhere
|
||||
@@ -21,15 +35,6 @@ ML solutions for live and streaming media.
|
||||
|
||||
----
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We are moving to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation
|
||||
site for MediaPipe starting April 3, 2023.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## ML solutions in MediaPipe
|
||||
|
||||
Face Detection | Face Mesh | Iris | Hands | Pose | Holistic
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
MediaPipe
|
||||
=====================================
|
||||
Please see https://docs.mediapipe.dev.
|
||||
Please see https://developers.google.com/mediapipe/
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/guide#legacy
|
||||
title: AutoFlip (Saliency-aware Video Cropping)
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 14
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 14
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
We have ended support for this MediaPipe Legacy Solution as of March 1, 2023.
|
||||
For more information, see the new
|
||||
For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/guide#legacy
|
||||
title: Box Tracking
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 10
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 10
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
We have ended support for this MediaPipe Legacy Solution as of March 1, 2023.
|
||||
For more information, see the new
|
||||
For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/face_detector/
|
||||
title: Face Detection
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 1
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 1
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/face_landmarker/
|
||||
title: Face Mesh
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 2
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 2
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/image_segmenter/
|
||||
title: Hair Segmentation
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 8
|
||||
---
|
||||
|
||||
@@ -19,13 +20,11 @@ nav_order: 8
|
||||
---
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
As of April 4, 2023, this solution was upgraded to a new MediaPipe
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/vision/image_segmenter/)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/hand_landmarker
|
||||
title: Hands
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 4
|
||||
---
|
||||
|
||||
@@ -19,13 +20,11 @@ nav_order: 4
|
||||
---
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
As of March 1, 2023, this solution was upgraded to a new MediaPipe
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/vision/hand_landmarker)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://github.com/google/mediapipe/blob/master/docs/solutions/holistic.md
|
||||
title: Holistic
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 6
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 6
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
@@ -76,7 +75,7 @@ previous frame as a guide to the object region on the current one. However,
|
||||
during fast movements, the tracker can lose the target, which requires the
|
||||
detector to re-localize it in the image. MediaPipe Holistic uses
|
||||
[pose](./pose.md) prediction (on every frame) as an additional ROI prior to
|
||||
reduce the response time of the pipeline when reacting to fast movements. This
|
||||
reducing the response time of the pipeline when reacting to fast movements. This
|
||||
also enables the model to retain semantic consistency across the body and its
|
||||
parts by preventing a mixup between left and right hands or body parts of one
|
||||
person in the frame with another.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/guide#legacy
|
||||
title: Instant Motion Tracking
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 11
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 11
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
We have ended support for this MediaPipe Legacy Solution as of March 1, 2023.
|
||||
For more information, see the new
|
||||
For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/face_landmarker/
|
||||
title: Iris
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 3
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 3
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/guide#legacy
|
||||
title: KNIFT (Template-based Feature Matching)
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 13
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 13
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
We have ended support for this MediaPipe Legacy Solution as of March 1, 2023.
|
||||
For more information, see the new
|
||||
For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/guide#legacy
|
||||
title: Dataset Preparation with MediaSequence
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 15
|
||||
---
|
||||
|
||||
@@ -24,8 +25,6 @@ For more information, see the new
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/guide#legacy
|
||||
title: Models and Model Cards
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 30
|
||||
---
|
||||
|
||||
@@ -22,8 +23,6 @@ MediaPipe Legacy Solutions will continue to be provided on an as-is basis.
|
||||
We encourage you to check out the new MediaPipe Solutions at:
|
||||
[https://developers.google.com/mediapipe/solutions](https://developers.google.com/mediapipe/solutions)*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
### [Face Detection](https://google.github.io/mediapipe/solutions/face_detection)
|
||||
@@ -108,6 +107,8 @@ one over the other.
|
||||
|
||||
* [TFLite model](https://storage.googleapis.com/mediapipe-assets/ssdlite_object_detection.tflite)
|
||||
* [TFLite model quantized for EdgeTPU/Coral](https://github.com/google/mediapipe/tree/master/mediapipe/examples/coral/models/object-detector-quantized_edgetpu.tflite)
|
||||
* [TensorFlow model](https://storage.googleapis.com/mediapipe-assets/object_detection_saved_model/archive.zip)
|
||||
* [Model information](https://storage.googleapis.com/mediapipe-assets/object_detection_saved_model/README.md)
|
||||
|
||||
### [Objectron](https://google.github.io/mediapipe/solutions/objectron)
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/object_detector/
|
||||
title: Object Detection
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 9
|
||||
---
|
||||
|
||||
@@ -19,13 +20,11 @@ nav_order: 9
|
||||
---
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
As of March 1, 2023, this solution was upgraded to a new MediaPipe
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/vision/object_detector/)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||

|
||||
@@ -118,9 +117,9 @@ on how to build MediaPipe examples.
|
||||
* With a TensorFlow Model
|
||||
|
||||
This uses the
|
||||
[TensorFlow model](https://github.com/google/mediapipe/tree/master/mediapipe/models/object_detection_saved_model)
|
||||
[TensorFlow model](https://storage.googleapis.com/mediapipe-assets/object_detection_saved_model/archive.zip)
|
||||
( see also
|
||||
[model info](https://github.com/google/mediapipe/tree/master/mediapipe/models/object_detection_saved_model/README.md)),
|
||||
[model info](https://storage.googleapis.com/mediapipe-assets/object_detection_saved_model/README.md)),
|
||||
and the pipeline is implemented in this
|
||||
[graph](https://github.com/google/mediapipe/tree/master/mediapipe/graphs/object_detection/object_detection_mobile_cpu.pbtxt).
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
---
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/object_detector
|
||||
title: Object Detection
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 9
|
||||
---
|
||||
|
||||
# MediaPipe Object Detection
|
||||
{: .no_toc }
|
||||
|
||||
<details close markdown="block">
|
||||
<summary>
|
||||
Table of contents
|
||||
</summary>
|
||||
{: .text-delta }
|
||||
1. TOC
|
||||
{:toc}
|
||||
</details>
|
||||
---
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution was upgraded to a new MediaPipe
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/vision/object_detector)
|
||||
site.*
|
||||
|
||||
----
|
||||
|
||||
### TensorFlow model
|
||||
|
||||
The model is trained on [MSCOCO 2014](http://cocodataset.org) dataset using [TensorFlow Object Detection API](https://github.com/tensorflow/models/tree/master/research/object_detection). It is a MobileNetV2-based SSD model with 0.5 depth multiplier. Detailed training configuration is in the provided `pipeline.config`. The model is a relatively compact model which has `0.171 mAP` to achieve real-time performance on mobile devices. You can compare it with other models from the [TensorFlow detection model zoo](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf1_detection_zoo.md).
|
||||
|
||||
|
||||
### TFLite model
|
||||
|
||||
The TFLite model is converted from the TensorFlow above. The steps needed to convert the model are similar to [this tutorial](https://medium.com/tensorflow/training-and-serving-a-realtime-mobile-object-detector-in-30-minutes-with-cloud-tpus-b78971cf1193) with minor modifications. Assuming now we have a trained TensorFlow model which includes the checkpoint files and the training configuration file, for example the files provided in this repo:
|
||||
|
||||
* `model.ckpt.index`
|
||||
* `model.ckpt.meta`
|
||||
* `model.ckpt.data-00000-of-00001`
|
||||
* `pipeline.config`
|
||||
|
||||
Make sure you have installed these [python libraries](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf1.md). Then to get the frozen graph, run the `export_tflite_ssd_graph.py` script from the `models/research` directory with this command:
|
||||
|
||||
```bash
|
||||
$ PATH_TO_MODEL=path/to/the/model
|
||||
$ bazel run object_detection:export_tflite_ssd_graph -- \
|
||||
--pipeline_config_path ${PATH_TO_MODEL}/pipeline.config \
|
||||
--trained_checkpoint_prefix ${PATH_TO_MODEL}/model.ckpt \
|
||||
--output_directory ${PATH_TO_MODEL} \
|
||||
--add_postprocessing_op=False
|
||||
```
|
||||
|
||||
The exported model contains two files:
|
||||
|
||||
* `tflite_graph.pb`
|
||||
* `tflite_graph.pbtxt`
|
||||
|
||||
The difference between this step and the one in [the tutorial](https://medium.com/tensorflow/training-and-serving-a-realtime-mobile-object-detector-in-30-minutes-with-cloud-tpus-b78971cf1193) is that we set `add_postprocessing_op` to False. In MediaPipe, we have provided all the calculators needed for post-processing such that we can exclude the custom TFLite ops for post-processing in the original graph, e.g., non-maximum suppression. This enables the flexibility to integrate with different post-processing algorithms and implementations.
|
||||
|
||||
Optional: You can install and use the [graph tool](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms) to inspect the input/output of the exported model:
|
||||
|
||||
```bash
|
||||
$ bazel run graph_transforms:summarize_graph -- \
|
||||
--in_graph=${PATH_TO_MODEL}/tflite_graph.pb
|
||||
```
|
||||
|
||||
You should be able to see the input image size of the model is 320x320 and the outputs of the model are:
|
||||
|
||||
* `raw_outputs/box_encodings`
|
||||
* `raw_outputs/class_predictions`
|
||||
|
||||
The last step is to convert the model to TFLite. You can look at [this guide](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/r1/convert/cmdline_examples.md) for more detail. For this example, you just need to run:
|
||||
|
||||
```bash
|
||||
$ tflite_convert -- \
|
||||
--graph_def_file=${PATH_TO_MODEL}/tflite_graph.pb \
|
||||
--output_file=${PATH_TO_MODEL}/model.tflite \
|
||||
--input_format=TENSORFLOW_GRAPHDEF \
|
||||
--output_format=TFLITE \
|
||||
--inference_type=FLOAT \
|
||||
--input_shapes=1,320,320,3 \
|
||||
--input_arrays=normalized_input_image_tensor \
|
||||
--output_arrays=raw_outputs/box_encodings,raw_outputs/class_predictions
|
||||
|
||||
```
|
||||
|
||||
Now you have the TFLite model `model.tflite` ready to use with MediaPipe Object Detection graphs. Please see the examples for more detail.
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/guide#legacy
|
||||
title: Objectron (3D Object Detection)
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 12
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 12
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
We have ended support for this MediaPipe Legacy Solution as of March 1, 2023.
|
||||
For more information, see the new
|
||||
For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/pose_landmarker/
|
||||
title: Pose
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
has_children: true
|
||||
has_toc: false
|
||||
nav_order: 5
|
||||
@@ -22,12 +23,10 @@ nav_order: 5
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/vision/pose_landmarker/)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
@@ -144,7 +143,7 @@ The landmark model in MediaPipe Pose predicts the location of 33 pose landmarks
|
||||
:----------------------------------------------------------------------------------------------: |
|
||||
*Fig 4. 33 pose landmarks.* |
|
||||
|
||||
Optionally, MediaPipe Pose can predicts a full-body
|
||||
Optionally, MediaPipe Pose can predict a full-body
|
||||
[segmentation mask](#segmentation_mask) represented as a two-class segmentation
|
||||
(human or background).
|
||||
|
||||
@@ -269,6 +268,7 @@ Supported configuration options:
|
||||
```python
|
||||
import cv2
|
||||
import mediapipe as mp
|
||||
import numpy as np
|
||||
mp_drawing = mp.solutions.drawing_utils
|
||||
mp_drawing_styles = mp.solutions.drawing_styles
|
||||
mp_pose = mp.solutions.pose
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/pose_landmarker/
|
||||
title: Pose Classification
|
||||
parent: Pose
|
||||
grand_parent: Solutions
|
||||
grand_parent: MediaPipe Legacy Solutions
|
||||
nav_order: 1
|
||||
---
|
||||
|
||||
@@ -21,12 +22,10 @@ nav_order: 1
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/vision/pose_landmarker/)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/vision/image_segmenter/
|
||||
title: Selfie Segmentation
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 7
|
||||
---
|
||||
|
||||
@@ -19,13 +20,11 @@ nav_order: 7
|
||||
---
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
As of March 1, 2023, this solution is planned to be upgraded to a new MediaPipe
|
||||
Solution. For more information, see the new
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
As of April 4, 2023, this solution was upgraded to a new MediaPipe
|
||||
Solution. For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/vision/image_segmenter/)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
---
|
||||
layout: default
|
||||
title: Solutions
|
||||
title: MediaPipe Legacy Solutions
|
||||
nav_order: 3
|
||||
has_children: true
|
||||
has_toc: false
|
||||
---
|
||||
|
||||
# Solutions
|
||||
# MediaPipe Legacy Solutions
|
||||
{: .no_toc }
|
||||
|
||||
1. TOC
|
||||
@@ -29,6 +29,12 @@ Solutions at:
|
||||
|
||||
----
|
||||
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
<br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
----
|
||||
|
||||
MediaPipe offers open source cross-platform, customizable ML solutions for live
|
||||
and streaming media.
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/solutions/guide#legacy
|
||||
title: YouTube-8M Feature Extraction and Model Inference
|
||||
parent: Solutions
|
||||
parent: MediaPipe Legacy Solutions
|
||||
nav_order: 16
|
||||
---
|
||||
|
||||
@@ -20,12 +21,10 @@ nav_order: 16
|
||||
|
||||
**Attention:** *Thank you for your interest in MediaPipe Solutions.
|
||||
We have ended support for this MediaPipe Legacy Solution as of March 1, 2023.
|
||||
For more information, see the new
|
||||
For more information, see the
|
||||
[MediaPipe Solutions](https://developers.google.com/mediapipe/solutions/guide#legacy)
|
||||
site.*
|
||||
|
||||
*This notice and web page will be removed on April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
MediaPipe is a useful and general framework for media processing that can assist
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/
|
||||
title: Performance Benchmarking
|
||||
parent: Tools
|
||||
nav_order: 3
|
||||
@@ -12,6 +13,12 @@ nav_order: 3
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
---
|
||||
|
||||
*Coming soon.*
|
||||
|
||||
Future mediapipe releases will include tools for visualizing and analysing the
|
||||
|
||||
+8
-1
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/
|
||||
title: Tools
|
||||
nav_order: 4
|
||||
has_children: true
|
||||
@@ -11,3 +12,9 @@ has_children: true
|
||||
1. TOC
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
layout: default
|
||||
layout: forward
|
||||
target: https://developers.google.com/mediapipe/
|
||||
title: Tracing and Profiling
|
||||
parent: Tools
|
||||
nav_order: 2
|
||||
@@ -12,6 +13,12 @@ nav_order: 2
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
----
|
||||
|
||||
The MediaPipe framework includes a built-in tracer and profiler. The tracer
|
||||
records various timing events related to packet processing, including the start
|
||||
and end time of each Calculator::Process call. The tracer writes trace log files
|
||||
|
||||
@@ -13,6 +13,12 @@ nav_order: 1
|
||||
{:toc}
|
||||
---
|
||||
|
||||
**Attention:** *Thanks for your interest in MediaPipe! We have moved to
|
||||
[https://developers.google.com/mediapipe](https://developers.google.com/mediapipe)
|
||||
as the primary developer documentation site for MediaPipe as of April 3, 2023.*
|
||||
|
||||
---
|
||||
|
||||
To help users understand the structure of their calculator graphs and to
|
||||
understand the overall behavior of their machine learning inference pipelines,
|
||||
we have built the [MediaPipe Visualizer](https://viz.mediapipe.dev/)
|
||||
|
||||
@@ -26,10 +26,11 @@
|
||||
namespace mediapipe {
|
||||
namespace {
|
||||
static bool SafeMultiply(int x, int y, int* result) {
|
||||
static_assert(sizeof(int64) >= 2 * sizeof(int),
|
||||
static_assert(sizeof(int64_t) >= 2 * sizeof(int),
|
||||
"Unable to detect overflow after multiplication");
|
||||
const int64 big = static_cast<int64>(x) * static_cast<int64>(y);
|
||||
if (big > static_cast<int64>(INT_MIN) && big < static_cast<int64>(INT_MAX)) {
|
||||
const int64_t big = static_cast<int64_t>(x) * static_cast<int64_t>(y);
|
||||
if (big > static_cast<int64_t>(INT_MIN) &&
|
||||
big < static_cast<int64_t>(INT_MAX)) {
|
||||
if (result != nullptr) *result = static_cast<int>(big);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -182,12 +182,12 @@ class SpectrogramCalculator : public CalculatorBase {
|
||||
int frame_duration_samples_;
|
||||
int frame_overlap_samples_;
|
||||
// How many samples we've been passed, used for checking input time stamps.
|
||||
int64 cumulative_input_samples_;
|
||||
int64_t cumulative_input_samples_;
|
||||
// How many frames we've emitted, used for calculating output time stamps.
|
||||
int64 cumulative_completed_frames_;
|
||||
int64_t cumulative_completed_frames_;
|
||||
// How many frames were emitted last, used for estimating the timestamp on
|
||||
// Close when use_local_timestamp_ is true;
|
||||
int64 last_completed_frames_;
|
||||
int64_t last_completed_frames_;
|
||||
Timestamp initial_input_timestamp_;
|
||||
int num_input_channels_;
|
||||
// How many frequency bins we emit (=N_FFT/2 + 1).
|
||||
|
||||
@@ -92,8 +92,8 @@ class SpectrogramCalculatorTest
|
||||
.cos()
|
||||
.transpose();
|
||||
}
|
||||
int64 input_timestamp = round(packet_start_time_seconds *
|
||||
Timestamp::kTimestampUnitsPerSecond);
|
||||
int64_t input_timestamp = round(packet_start_time_seconds *
|
||||
Timestamp::kTimestampUnitsPerSecond);
|
||||
AppendInputPacket(packet_data, input_timestamp);
|
||||
total_num_input_samples += packet_size_samples;
|
||||
}
|
||||
@@ -116,8 +116,8 @@ class SpectrogramCalculatorTest
|
||||
double packet_start_time_seconds =
|
||||
kInitialTimestampOffsetMicroseconds * 1e-6 +
|
||||
total_num_input_samples / input_sample_rate_;
|
||||
int64 input_timestamp = round(packet_start_time_seconds *
|
||||
Timestamp::kTimestampUnitsPerSecond);
|
||||
int64_t input_timestamp = round(packet_start_time_seconds *
|
||||
Timestamp::kTimestampUnitsPerSecond);
|
||||
std::unique_ptr<Matrix> impulse(
|
||||
new Matrix(Matrix::Zero(1, packet_sizes_samples[i])));
|
||||
(*impulse)(0, impulse_offsets_samples[i]) = 1.0;
|
||||
@@ -157,8 +157,8 @@ class SpectrogramCalculatorTest
|
||||
.cos()
|
||||
.transpose();
|
||||
}
|
||||
int64 input_timestamp = round(packet_start_time_seconds *
|
||||
Timestamp::kTimestampUnitsPerSecond);
|
||||
int64_t input_timestamp = round(packet_start_time_seconds *
|
||||
Timestamp::kTimestampUnitsPerSecond);
|
||||
AppendInputPacket(packet_data, input_timestamp);
|
||||
total_num_input_samples += packet_size_samples;
|
||||
}
|
||||
@@ -218,7 +218,7 @@ class SpectrogramCalculatorTest
|
||||
const double expected_timestamp_seconds =
|
||||
packet_timestamp_offset_seconds +
|
||||
cumulative_output_frames * frame_step_seconds;
|
||||
const int64 expected_timestamp_ticks =
|
||||
const int64_t expected_timestamp_ticks =
|
||||
expected_timestamp_seconds * Timestamp::kTimestampUnitsPerSecond;
|
||||
EXPECT_EQ(expected_timestamp_ticks, packet.Timestamp().Value());
|
||||
// Accept the timestamp of the first packet as the baseline for checking
|
||||
|
||||
@@ -54,7 +54,8 @@ TEST_F(StabilizedLogCalculatorTest, BasicOperation) {
|
||||
|
||||
std::vector<Matrix> input_data_matrices;
|
||||
for (int input_packet = 0; input_packet < kNumPackets; ++input_packet) {
|
||||
const int64 timestamp = input_packet * Timestamp::kTimestampUnitsPerSecond;
|
||||
const int64_t timestamp =
|
||||
input_packet * Timestamp::kTimestampUnitsPerSecond;
|
||||
Matrix input_data_matrix =
|
||||
Matrix::Random(kNumChannels, kNumSamples).array().abs();
|
||||
input_data_matrices.push_back(input_data_matrix);
|
||||
@@ -80,7 +81,8 @@ TEST_F(StabilizedLogCalculatorTest, OutputScaleWorks) {
|
||||
|
||||
std::vector<Matrix> input_data_matrices;
|
||||
for (int input_packet = 0; input_packet < kNumPackets; ++input_packet) {
|
||||
const int64 timestamp = input_packet * Timestamp::kTimestampUnitsPerSecond;
|
||||
const int64_t timestamp =
|
||||
input_packet * Timestamp::kTimestampUnitsPerSecond;
|
||||
Matrix input_data_matrix =
|
||||
Matrix::Random(kNumChannels, kNumSamples).array().abs();
|
||||
input_data_matrices.push_back(input_data_matrix);
|
||||
|
||||
@@ -109,7 +109,7 @@ class TimeSeriesFramerCalculator : public CalculatorBase {
|
||||
// Returns the timestamp of a sample on a base, which is usually the time
|
||||
// stamp of a packet.
|
||||
Timestamp CurrentSampleTimestamp(const Timestamp& timestamp_base,
|
||||
int64 number_of_samples) {
|
||||
int64_t number_of_samples) {
|
||||
return timestamp_base + round(number_of_samples / sample_rate_ *
|
||||
Timestamp::kTimestampUnitsPerSecond);
|
||||
}
|
||||
@@ -118,10 +118,10 @@ class TimeSeriesFramerCalculator : public CalculatorBase {
|
||||
// emitted.
|
||||
int next_frame_step_samples() const {
|
||||
// All numbers are in input samples.
|
||||
const int64 current_output_frame_start = static_cast<int64>(
|
||||
const int64_t current_output_frame_start = static_cast<int64_t>(
|
||||
round(cumulative_output_frames_ * average_frame_step_samples_));
|
||||
CHECK_EQ(current_output_frame_start, cumulative_completed_samples_);
|
||||
const int64 next_output_frame_start = static_cast<int64>(
|
||||
const int64_t next_output_frame_start = static_cast<int64_t>(
|
||||
round((cumulative_output_frames_ + 1) * average_frame_step_samples_));
|
||||
return next_output_frame_start - current_output_frame_start;
|
||||
}
|
||||
@@ -134,11 +134,11 @@ class TimeSeriesFramerCalculator : public CalculatorBase {
|
||||
// emulate_fractional_frame_overlap is true.
|
||||
double average_frame_step_samples_;
|
||||
int samples_still_to_drop_;
|
||||
int64 cumulative_output_frames_;
|
||||
int64_t cumulative_output_frames_;
|
||||
// "Completed" samples are samples that are no longer needed because
|
||||
// the framer has completely stepped past them (taking into account
|
||||
// any overlap).
|
||||
int64 cumulative_completed_samples_;
|
||||
int64_t cumulative_completed_samples_;
|
||||
Timestamp initial_input_timestamp_;
|
||||
// The current timestamp is updated along with the incoming packets.
|
||||
Timestamp current_timestamp_;
|
||||
|
||||
@@ -49,7 +49,7 @@ class TimeSeriesFramerCalculatorTest
|
||||
|
||||
// Returns a float value with the channel and timestamp separated by
|
||||
// an order of magnitude, for easy parsing by humans.
|
||||
float TestValue(int64 timestamp_in_microseconds, int channel) {
|
||||
float TestValue(int64_t timestamp_in_microseconds, int channel) {
|
||||
return timestamp_in_microseconds + channel / 10.0;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class TimeSeriesFramerCalculatorTest
|
||||
auto matrix = new Matrix(num_channels, num_samples);
|
||||
for (int c = 0; c < num_channels; ++c) {
|
||||
for (int i = 0; i < num_samples; ++i) {
|
||||
int64 timestamp = time_series_util::SecondsToSamples(
|
||||
int64_t timestamp = time_series_util::SecondsToSamples(
|
||||
starting_timestamp_seconds + i / input_sample_rate_,
|
||||
Timestamp::kTimestampUnitsPerSecond);
|
||||
(*matrix)(c, i) = TestValue(timestamp, c);
|
||||
@@ -429,7 +429,7 @@ class TimeSeriesFramerCalculatorTimestampingTest
|
||||
num_full_packets -= 1;
|
||||
}
|
||||
|
||||
int64 num_samples = 0;
|
||||
int64_t num_samples = 0;
|
||||
for (int packet_num = 0; packet_num < num_full_packets; ++packet_num) {
|
||||
const Packet& packet = output().packets[packet_num];
|
||||
num_samples += FrameDurationSamples();
|
||||
|
||||
@@ -218,6 +218,7 @@ cc_library(
|
||||
"//mediapipe/framework:collection_item_id",
|
||||
"//mediapipe/framework/formats:classification_cc_proto",
|
||||
"//mediapipe/framework/formats:detection_cc_proto",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/formats:landmark_cc_proto",
|
||||
"//mediapipe/framework/formats:matrix",
|
||||
"//mediapipe/framework/formats:rect_cc_proto",
|
||||
@@ -282,6 +283,7 @@ cc_library(
|
||||
}),
|
||||
deps = [
|
||||
":concatenate_vector_calculator_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/api2:port",
|
||||
"//mediapipe/framework/formats:classification_cc_proto",
|
||||
@@ -290,7 +292,6 @@ cc_library(
|
||||
"//mediapipe/framework/port:integral_types",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/util:render_data_cc_proto",
|
||||
"@org_tensorflow//tensorflow/lite:framework",
|
||||
] + select({
|
||||
@@ -900,12 +901,12 @@ cc_library(
|
||||
}),
|
||||
deps = [
|
||||
":split_vector_calculator_cc_proto",
|
||||
"//mediapipe/framework/formats:detection_cc_proto",
|
||||
"//mediapipe/framework/formats:classification_cc_proto",
|
||||
"//mediapipe/framework/formats:landmark_cc_proto",
|
||||
"//mediapipe/framework/formats:rect_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:classification_cc_proto",
|
||||
"//mediapipe/framework/formats:detection_cc_proto",
|
||||
"//mediapipe/framework/formats:landmark_cc_proto",
|
||||
"//mediapipe/framework/formats:matrix",
|
||||
"//mediapipe/framework/formats:rect_cc_proto",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace mediapipe {
|
||||
typedef ClipVectorSizeCalculator<int> TestClipIntVectorSizeCalculator;
|
||||
REGISTER_CALCULATOR(TestClipIntVectorSizeCalculator);
|
||||
|
||||
void AddInputVector(const std::vector<int>& input, int64 timestamp,
|
||||
void AddInputVector(const std::vector<int>& input, int64_t timestamp,
|
||||
CalculatorRunner* runner) {
|
||||
runner->MutableInputs()->Index(0).packets.push_back(
|
||||
MakePacket<std::vector<int>>(input).At(Timestamp(timestamp)));
|
||||
|
||||
@@ -63,7 +63,7 @@ void ValidateCombinedLandmarks(
|
||||
|
||||
void AddInputLandmarkLists(
|
||||
const std::vector<NormalizedLandmarkList>& input_landmarks_vec,
|
||||
int64 timestamp, CalculatorRunner* runner) {
|
||||
int64_t timestamp, CalculatorRunner* runner) {
|
||||
for (int i = 0; i < input_landmarks_vec.size(); ++i) {
|
||||
runner->MutableInputs()->Index(i).packets.push_back(
|
||||
MakePacket<NormalizedLandmarkList>(input_landmarks_vec[i])
|
||||
@@ -73,7 +73,7 @@ void AddInputLandmarkLists(
|
||||
|
||||
void AddInputClassificationLists(
|
||||
const std::vector<ClassificationList>& input_classifications_vec,
|
||||
int64 timestamp, CalculatorRunner* runner) {
|
||||
int64_t timestamp, CalculatorRunner* runner) {
|
||||
for (int i = 0; i < input_classifications_vec.size(); ++i) {
|
||||
runner->MutableInputs()->Index(i).packets.push_back(
|
||||
MakePacket<ClassificationList>(input_classifications_vec[i])
|
||||
|
||||
@@ -46,10 +46,10 @@ MEDIAPIPE_REGISTER_NODE(ConcatenateFloatVectorCalculator);
|
||||
// input_stream: "int32_vector_2"
|
||||
// output_stream: "concatenated_int32_vector"
|
||||
// }
|
||||
typedef ConcatenateVectorCalculator<int32> ConcatenateInt32VectorCalculator;
|
||||
typedef ConcatenateVectorCalculator<int32_t> ConcatenateInt32VectorCalculator;
|
||||
MEDIAPIPE_REGISTER_NODE(ConcatenateInt32VectorCalculator);
|
||||
|
||||
typedef ConcatenateVectorCalculator<uint64> ConcatenateUInt64VectorCalculator;
|
||||
typedef ConcatenateVectorCalculator<uint64_t> ConcatenateUInt64VectorCalculator;
|
||||
MEDIAPIPE_REGISTER_NODE(ConcatenateUInt64VectorCalculator);
|
||||
|
||||
typedef ConcatenateVectorCalculator<bool> ConcatenateBoolVectorCalculator;
|
||||
|
||||
@@ -30,26 +30,26 @@ namespace mediapipe {
|
||||
typedef ConcatenateVectorCalculator<int> TestConcatenateIntVectorCalculator;
|
||||
MEDIAPIPE_REGISTER_NODE(TestConcatenateIntVectorCalculator);
|
||||
|
||||
void AddInputVector(int index, const std::vector<int>& input, int64 timestamp,
|
||||
void AddInputVector(int index, const std::vector<int>& input, int64_t timestamp,
|
||||
CalculatorRunner* runner) {
|
||||
runner->MutableInputs()->Index(index).packets.push_back(
|
||||
MakePacket<std::vector<int>>(input).At(Timestamp(timestamp)));
|
||||
}
|
||||
|
||||
void AddInputVectors(const std::vector<std::vector<int>>& inputs,
|
||||
int64 timestamp, CalculatorRunner* runner) {
|
||||
int64_t timestamp, CalculatorRunner* runner) {
|
||||
for (int i = 0; i < inputs.size(); ++i) {
|
||||
AddInputVector(i, inputs[i], timestamp, runner);
|
||||
}
|
||||
}
|
||||
|
||||
void AddInputItem(int index, int input, int64 timestamp,
|
||||
void AddInputItem(int index, int input, int64_t timestamp,
|
||||
CalculatorRunner* runner) {
|
||||
runner->MutableInputs()->Index(index).packets.push_back(
|
||||
MakePacket<int>(input).At(Timestamp(timestamp)));
|
||||
}
|
||||
|
||||
void AddInputItems(const std::vector<int>& inputs, int64 timestamp,
|
||||
void AddInputItems(const std::vector<int>& inputs, int64_t timestamp,
|
||||
CalculatorRunner* runner) {
|
||||
for (int i = 0; i < inputs.size(); ++i) {
|
||||
AddInputItem(i, inputs[i], timestamp, runner);
|
||||
@@ -279,7 +279,7 @@ TEST(TestConcatenateIntVectorCalculatorTest, MixedVectorsAndItemsAnother) {
|
||||
}
|
||||
|
||||
void AddInputVectors(const std::vector<std::vector<float>>& inputs,
|
||||
int64 timestamp, CalculatorRunner* runner) {
|
||||
int64_t timestamp, CalculatorRunner* runner) {
|
||||
for (int i = 0; i < inputs.size(); ++i) {
|
||||
runner->MutableInputs()->Index(i).packets.push_back(
|
||||
MakePacket<std::vector<float>>(inputs[i]).At(Timestamp(timestamp)));
|
||||
|
||||
@@ -78,7 +78,7 @@ class ConstantSidePacketCalculator : public CalculatorBase {
|
||||
} else if (packet_options.has_string_value()) {
|
||||
packet.Set<std::string>();
|
||||
} else if (packet_options.has_uint64_value()) {
|
||||
packet.Set<uint64>();
|
||||
packet.Set<uint64_t>();
|
||||
} else if (packet_options.has_classification_list_value()) {
|
||||
packet.Set<ClassificationList>();
|
||||
} else if (packet_options.has_landmark_list_value()) {
|
||||
@@ -112,7 +112,7 @@ class ConstantSidePacketCalculator : public CalculatorBase {
|
||||
} else if (packet_options.has_string_value()) {
|
||||
packet.Set(MakePacket<std::string>(packet_options.string_value()));
|
||||
} else if (packet_options.has_uint64_value()) {
|
||||
packet.Set(MakePacket<uint64>(packet_options.uint64_value()));
|
||||
packet.Set(MakePacket<uint64_t>(packet_options.uint64_value()));
|
||||
} else if (packet_options.has_classification_list_value()) {
|
||||
packet.Set(MakePacket<ClassificationList>(
|
||||
packet_options.classification_list_value()));
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "mediapipe/framework/formats/classification.pb.h"
|
||||
#include "mediapipe/framework/formats/detection.pb.h"
|
||||
#include "mediapipe/framework/formats/image.h"
|
||||
#include "mediapipe/framework/formats/landmark.pb.h"
|
||||
#include "mediapipe/framework/formats/matrix.h"
|
||||
#include "mediapipe/framework/formats/rect.pb.h"
|
||||
@@ -67,4 +68,8 @@ REGISTER_CALCULATOR(EndLoopMatrixCalculator);
|
||||
typedef EndLoopCalculator<std::vector<Tensor>> EndLoopTensorCalculator;
|
||||
REGISTER_CALCULATOR(EndLoopTensorCalculator);
|
||||
|
||||
typedef EndLoopCalculator<std::vector<::mediapipe::Image>>
|
||||
EndLoopImageCalculator;
|
||||
REGISTER_CALCULATOR(EndLoopImageCalculator);
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -61,8 +61,8 @@ class AtomicSemaphore {
|
||||
};
|
||||
|
||||
// Returns the timestamp values for a vector of Packets.
|
||||
std::vector<int64> TimestampValues(const std::vector<Packet>& packets) {
|
||||
std::vector<int64> result;
|
||||
std::vector<int64_t> TimestampValues(const std::vector<Packet>& packets) {
|
||||
std::vector<int64_t> result;
|
||||
for (const Packet& packet : packets) {
|
||||
result.push_back(packet.Timestamp().Value());
|
||||
}
|
||||
@@ -180,9 +180,9 @@ TEST_F(FlowLimiterCalculatorSemaphoreTest, FramesDropped) {
|
||||
InitializeGraph(1);
|
||||
MP_ASSERT_OK(graph_.StartRun({}));
|
||||
|
||||
auto send_packet = [this](const std::string& input_name, int64 n) {
|
||||
auto send_packet = [this](const std::string& input_name, int64_t n) {
|
||||
MP_EXPECT_OK(graph_.AddPacketToInputStream(
|
||||
input_name, MakePacket<int64>(n).At(Timestamp(n))));
|
||||
input_name, MakePacket<int64_t>(n).At(Timestamp(n))));
|
||||
};
|
||||
|
||||
Packet allow_packet;
|
||||
@@ -207,12 +207,12 @@ TEST_F(FlowLimiterCalculatorSemaphoreTest, FramesDropped) {
|
||||
EXPECT_EQ(10, out_1_packets_.size());
|
||||
|
||||
// Timestamps have not been altered.
|
||||
EXPECT_EQ(PacketValues<int64>(out_1_packets_),
|
||||
EXPECT_EQ(PacketValues<int64_t>(out_1_packets_),
|
||||
TimestampValues(out_1_packets_));
|
||||
|
||||
// Extra inputs on in_1 have been dropped.
|
||||
EXPECT_EQ(TimestampValues(out_1_packets_),
|
||||
(std::vector<int64>{0, 10, 20, 30, 40, 50, 60, 70, 80, 90}));
|
||||
(std::vector<int64_t>{0, 10, 20, 30, 40, 50, 60, 70, 80, 90}));
|
||||
}
|
||||
|
||||
// A calculator that sleeps during Process.
|
||||
@@ -221,8 +221,8 @@ class SleepCalculator : public CalculatorBase {
|
||||
static absl::Status GetContract(CalculatorContract* cc) {
|
||||
cc->Inputs().Tag(kPacketTag).SetAny();
|
||||
cc->Outputs().Tag(kPacketTag).SetSameAs(&cc->Inputs().Tag(kPacketTag));
|
||||
cc->InputSidePackets().Tag(kSleepTimeTag).Set<int64>();
|
||||
cc->InputSidePackets().Tag(kWarmupTimeTag).Set<int64>();
|
||||
cc->InputSidePackets().Tag(kSleepTimeTag).Set<int64_t>();
|
||||
cc->InputSidePackets().Tag(kWarmupTimeTag).Set<int64_t>();
|
||||
cc->InputSidePackets().Tag(kClockTag).Set<mediapipe::Clock*>();
|
||||
cc->SetTimestampOffset(0);
|
||||
return absl::OkStatus();
|
||||
@@ -237,8 +237,8 @@ class SleepCalculator : public CalculatorBase {
|
||||
++packet_count;
|
||||
absl::Duration sleep_time = absl::Microseconds(
|
||||
packet_count == 1
|
||||
? cc->InputSidePackets().Tag(kWarmupTimeTag).Get<int64>()
|
||||
: cc->InputSidePackets().Tag(kSleepTimeTag).Get<int64>());
|
||||
? cc->InputSidePackets().Tag(kWarmupTimeTag).Get<int64_t>()
|
||||
: cc->InputSidePackets().Tag(kSleepTimeTag).Get<int64_t>());
|
||||
clock_->Sleep(sleep_time);
|
||||
cc->Outputs()
|
||||
.Tag(kPacketTag)
|
||||
@@ -375,8 +375,8 @@ TEST_F(FlowLimiterCalculatorTest, FinishedTimestamps) {
|
||||
std::map<std::string, Packet> side_packets = {
|
||||
{"limiter_options",
|
||||
MakePacket<FlowLimiterCalculatorOptions>(limiter_options)},
|
||||
{"warmup_time", MakePacket<int64>(22000)},
|
||||
{"sleep_time", MakePacket<int64>(22000)},
|
||||
{"warmup_time", MakePacket<int64_t>(22000)},
|
||||
{"sleep_time", MakePacket<int64_t>(22000)},
|
||||
{"drop_timesamps", MakePacket<bool>(false)},
|
||||
{"clock", MakePacket<mediapipe::Clock*>(clock_)},
|
||||
};
|
||||
@@ -447,8 +447,8 @@ TEST_F(FlowLimiterCalculatorTest, FinishedLost) {
|
||||
std::map<std::string, Packet> side_packets = {
|
||||
{"limiter_options",
|
||||
MakePacket<FlowLimiterCalculatorOptions>(limiter_options)},
|
||||
{"warmup_time", MakePacket<int64>(22000)},
|
||||
{"sleep_time", MakePacket<int64>(22000)},
|
||||
{"warmup_time", MakePacket<int64_t>(22000)},
|
||||
{"sleep_time", MakePacket<int64_t>(22000)},
|
||||
{"drop_timesamps", MakePacket<bool>(true)},
|
||||
{"clock", MakePacket<mediapipe::Clock*>(clock_)},
|
||||
};
|
||||
@@ -511,8 +511,8 @@ TEST_F(FlowLimiterCalculatorTest, FinishedDelayed) {
|
||||
std::map<std::string, Packet> side_packets = {
|
||||
{"limiter_options",
|
||||
MakePacket<FlowLimiterCalculatorOptions>(limiter_options)},
|
||||
{"warmup_time", MakePacket<int64>(500000)},
|
||||
{"sleep_time", MakePacket<int64>(22000)},
|
||||
{"warmup_time", MakePacket<int64_t>(500000)},
|
||||
{"sleep_time", MakePacket<int64_t>(22000)},
|
||||
{"drop_timesamps", MakePacket<bool>(false)},
|
||||
{"clock", MakePacket<mediapipe::Clock*>(clock_)},
|
||||
};
|
||||
@@ -606,8 +606,8 @@ TEST_F(FlowLimiterCalculatorTest, TwoInputStreams) {
|
||||
std::map<std::string, Packet> side_packets = {
|
||||
{"limiter_options",
|
||||
MakePacket<FlowLimiterCalculatorOptions>(limiter_options)},
|
||||
{"warmup_time", MakePacket<int64>(22000)},
|
||||
{"sleep_time", MakePacket<int64>(22000)},
|
||||
{"warmup_time", MakePacket<int64_t>(22000)},
|
||||
{"sleep_time", MakePacket<int64_t>(22000)},
|
||||
{"drop_timesamps", MakePacket<bool>(true)},
|
||||
{"clock", MakePacket<mediapipe::Clock*>(clock_)},
|
||||
};
|
||||
@@ -715,8 +715,8 @@ TEST_F(FlowLimiterCalculatorTest, ZeroQueue) {
|
||||
std::map<std::string, Packet> side_packets = {
|
||||
{"limiter_options",
|
||||
MakePacket<FlowLimiterCalculatorOptions>(limiter_options)},
|
||||
{"warmup_time", MakePacket<int64>(12000)},
|
||||
{"sleep_time", MakePacket<int64>(12000)},
|
||||
{"warmup_time", MakePacket<int64_t>(12000)},
|
||||
{"sleep_time", MakePacket<int64_t>(12000)},
|
||||
{"drop_timesamps", MakePacket<bool>(true)},
|
||||
{"clock", MakePacket<mediapipe::Clock*>(clock_)},
|
||||
};
|
||||
@@ -862,9 +862,9 @@ TEST_F(FlowLimiterCalculatorTest, AuxiliaryInputs) {
|
||||
|
||||
std::map<std::string, Packet> side_packets = {
|
||||
// Fake processing lazy initialization time in microseconds.
|
||||
{"warmup_time", MakePacket<int64>(22000)},
|
||||
{"warmup_time", MakePacket<int64_t>(22000)},
|
||||
// Fake processing duration in microseconds.
|
||||
{"sleep_time", MakePacket<int64>(22000)},
|
||||
{"sleep_time", MakePacket<int64_t>(22000)},
|
||||
// The SimulationClock to count virtual elapsed time.
|
||||
{"clock", MakePacket<mediapipe::Clock*>(clock_)},
|
||||
};
|
||||
|
||||
@@ -125,7 +125,6 @@ class GateCalculator : public CalculatorBase {
|
||||
RET_CHECK_OK(CheckAndInitAllowDisallowInputs(cc));
|
||||
|
||||
const int num_data_streams = cc->Inputs().NumEntries("");
|
||||
RET_CHECK_GE(num_data_streams, 1);
|
||||
RET_CHECK_EQ(cc->Outputs().NumEntries(""), num_data_streams)
|
||||
<< "Number of data output streams must match with data input streams.";
|
||||
|
||||
|
||||
@@ -35,14 +35,14 @@ class GateCalculatorTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
// Use this when ALLOW/DISALLOW input is provided as a side packet.
|
||||
void RunTimeStep(int64 timestamp, bool stream_payload) {
|
||||
void RunTimeStep(int64_t timestamp, bool stream_payload) {
|
||||
runner_->MutableInputs()->Get("", 0).packets.push_back(
|
||||
MakePacket<bool>(stream_payload).At(Timestamp(timestamp)));
|
||||
MP_ASSERT_OK(runner_->Run()) << "Calculator execution failed.";
|
||||
}
|
||||
|
||||
// Use this when ALLOW/DISALLOW input is provided as an input stream.
|
||||
void RunTimeStep(int64 timestamp, const std::string& control_tag,
|
||||
void RunTimeStep(int64_t timestamp, const std::string& control_tag,
|
||||
bool control) {
|
||||
runner_->MutableInputs()->Get("", 0).packets.push_back(
|
||||
MakePacket<bool>(true).At(Timestamp(timestamp)));
|
||||
@@ -52,6 +52,15 @@ class GateCalculatorTest : public ::testing::Test {
|
||||
MP_ASSERT_OK(runner_->Run()) << "Calculator execution failed.";
|
||||
}
|
||||
|
||||
void RunTimeStepWithoutDataStream(int64_t timestamp,
|
||||
const std::string& control_tag,
|
||||
bool control) {
|
||||
runner_->MutableInputs()
|
||||
->Tag(control_tag)
|
||||
.packets.push_back(MakePacket<bool>(control).At(Timestamp(timestamp)));
|
||||
MP_ASSERT_OK(runner_->Run()) << "Calculator execution failed.";
|
||||
}
|
||||
|
||||
void SetRunner(const std::string& proto) {
|
||||
runner_ = absl::make_unique<CalculatorRunner>(
|
||||
ParseTextProtoOrDie<CalculatorGraphConfig::Node>(proto));
|
||||
@@ -125,9 +134,9 @@ TEST_F(GateCalculatorTest, AllowByALLOWOptionToTrue) {
|
||||
}
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -150,9 +159,9 @@ TEST_F(GateCalculatorTest, DisallowByALLOWOptionSetToFalse) {
|
||||
}
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -166,9 +175,9 @@ TEST_F(GateCalculatorTest, DisallowByALLOWOptionNotSet) {
|
||||
output_stream: "test_output"
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -184,9 +193,9 @@ TEST_F(GateCalculatorTest, AllowByALLOWSidePacketSetToTrue) {
|
||||
)");
|
||||
runner()->MutableSidePackets()->Tag(kAllowTag) = Adopt(new bool(true));
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -206,9 +215,9 @@ TEST_F(GateCalculatorTest, AllowByDisallowSidePacketSetToFalse) {
|
||||
)");
|
||||
runner()->MutableSidePackets()->Tag(kDisallowTag) = Adopt(new bool(false));
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -228,9 +237,9 @@ TEST_F(GateCalculatorTest, DisallowByALLOWSidePacketSetToFalse) {
|
||||
)");
|
||||
runner()->MutableSidePackets()->Tag(kAllowTag) = Adopt(new bool(false));
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -246,9 +255,9 @@ TEST_F(GateCalculatorTest, DisallowByDISALLOWSidePacketSetToTrue) {
|
||||
)");
|
||||
runner()->MutableSidePackets()->Tag(kDisallowTag) = Adopt(new bool(true));
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -263,13 +272,13 @@ TEST_F(GateCalculatorTest, Allow) {
|
||||
output_stream: "test_output"
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, "ALLOW", true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, "ALLOW", false);
|
||||
constexpr int64 kTimestampValue2 = 44;
|
||||
constexpr int64_t kTimestampValue2 = 44;
|
||||
RunTimeStep(kTimestampValue2, "ALLOW", true);
|
||||
constexpr int64 kTimestampValue3 = 45;
|
||||
constexpr int64_t kTimestampValue3 = 45;
|
||||
RunTimeStep(kTimestampValue3, "ALLOW", false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -288,13 +297,13 @@ TEST_F(GateCalculatorTest, Disallow) {
|
||||
output_stream: "test_output"
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, "DISALLOW", true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, "DISALLOW", false);
|
||||
constexpr int64 kTimestampValue2 = 44;
|
||||
constexpr int64_t kTimestampValue2 = 44;
|
||||
RunTimeStep(kTimestampValue2, "DISALLOW", true);
|
||||
constexpr int64 kTimestampValue3 = 45;
|
||||
constexpr int64_t kTimestampValue3 = 45;
|
||||
RunTimeStep(kTimestampValue3, "DISALLOW", false);
|
||||
|
||||
const std::vector<Packet>& output = runner()->Outputs().Get("", 0).packets;
|
||||
@@ -314,13 +323,13 @@ TEST_F(GateCalculatorTest, AllowWithStateChange) {
|
||||
output_stream: "STATE_CHANGE:state_changed"
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, "ALLOW", false);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, "ALLOW", true);
|
||||
constexpr int64 kTimestampValue2 = 44;
|
||||
constexpr int64_t kTimestampValue2 = 44;
|
||||
RunTimeStep(kTimestampValue2, "ALLOW", true);
|
||||
constexpr int64 kTimestampValue3 = 45;
|
||||
constexpr int64_t kTimestampValue3 = 45;
|
||||
RunTimeStep(kTimestampValue3, "ALLOW", false);
|
||||
|
||||
const std::vector<Packet>& output =
|
||||
@@ -332,6 +341,35 @@ TEST_F(GateCalculatorTest, AllowWithStateChange) {
|
||||
EXPECT_EQ(false, output[1].Get<bool>()); // Disallow.
|
||||
}
|
||||
|
||||
TEST_F(GateCalculatorTest, AllowWithStateChangeNoDataStreams) {
|
||||
SetRunner(R"(
|
||||
calculator: "GateCalculator"
|
||||
input_stream: "ALLOW:gating_stream"
|
||||
output_stream: "STATE_CHANGE:state_changed"
|
||||
)");
|
||||
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStepWithoutDataStream(kTimestampValue0, "ALLOW", false);
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStepWithoutDataStream(kTimestampValue1, "ALLOW", true);
|
||||
constexpr int64_t kTimestampValue2 = 44;
|
||||
RunTimeStepWithoutDataStream(kTimestampValue2, "ALLOW", true);
|
||||
constexpr int64_t kTimestampValue3 = 45;
|
||||
RunTimeStepWithoutDataStream(kTimestampValue3, "ALLOW", false);
|
||||
LOG(INFO) << "a";
|
||||
const std::vector<Packet>& output =
|
||||
runner()->Outputs().Get("STATE_CHANGE", 0).packets;
|
||||
LOG(INFO) << "s";
|
||||
ASSERT_EQ(2, output.size());
|
||||
LOG(INFO) << "d";
|
||||
EXPECT_EQ(kTimestampValue1, output[0].Timestamp().Value());
|
||||
EXPECT_EQ(kTimestampValue3, output[1].Timestamp().Value());
|
||||
LOG(INFO) << "f";
|
||||
EXPECT_EQ(true, output[0].Get<bool>()); // Allow.
|
||||
EXPECT_EQ(false, output[1].Get<bool>()); // Disallow.
|
||||
LOG(INFO) << "g";
|
||||
}
|
||||
|
||||
TEST_F(GateCalculatorTest, DisallowWithStateChange) {
|
||||
SetRunner(R"(
|
||||
calculator: "GateCalculator"
|
||||
@@ -341,13 +379,13 @@ TEST_F(GateCalculatorTest, DisallowWithStateChange) {
|
||||
output_stream: "STATE_CHANGE:state_changed"
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, "DISALLOW", true);
|
||||
constexpr int64 kTimestampValue1 = 43;
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStep(kTimestampValue1, "DISALLOW", false);
|
||||
constexpr int64 kTimestampValue2 = 44;
|
||||
constexpr int64_t kTimestampValue2 = 44;
|
||||
RunTimeStep(kTimestampValue2, "DISALLOW", false);
|
||||
constexpr int64 kTimestampValue3 = 45;
|
||||
constexpr int64_t kTimestampValue3 = 45;
|
||||
RunTimeStep(kTimestampValue3, "DISALLOW", true);
|
||||
|
||||
const std::vector<Packet>& output =
|
||||
@@ -359,6 +397,31 @@ TEST_F(GateCalculatorTest, DisallowWithStateChange) {
|
||||
EXPECT_EQ(false, output[1].Get<bool>()); // Disallow.
|
||||
}
|
||||
|
||||
TEST_F(GateCalculatorTest, DisallowWithStateChangeNoDataStreams) {
|
||||
SetRunner(R"(
|
||||
calculator: "GateCalculator"
|
||||
input_stream: "DISALLOW:gating_stream"
|
||||
output_stream: "STATE_CHANGE:state_changed"
|
||||
)");
|
||||
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStepWithoutDataStream(kTimestampValue0, "DISALLOW", true);
|
||||
constexpr int64_t kTimestampValue1 = 43;
|
||||
RunTimeStepWithoutDataStream(kTimestampValue1, "DISALLOW", false);
|
||||
constexpr int64_t kTimestampValue2 = 44;
|
||||
RunTimeStepWithoutDataStream(kTimestampValue2, "DISALLOW", false);
|
||||
constexpr int64_t kTimestampValue3 = 45;
|
||||
RunTimeStepWithoutDataStream(kTimestampValue3, "DISALLOW", true);
|
||||
|
||||
const std::vector<Packet>& output =
|
||||
runner()->Outputs().Get("STATE_CHANGE", 0).packets;
|
||||
ASSERT_EQ(2, output.size());
|
||||
EXPECT_EQ(kTimestampValue1, output[0].Timestamp().Value());
|
||||
EXPECT_EQ(kTimestampValue3, output[1].Timestamp().Value());
|
||||
EXPECT_EQ(true, output[0].Get<bool>()); // Allow.
|
||||
EXPECT_EQ(false, output[1].Get<bool>()); // Disallow.
|
||||
}
|
||||
|
||||
// Must not detect disallow value for first timestamp as a state change.
|
||||
TEST_F(GateCalculatorTest, DisallowInitialNoStateTransition) {
|
||||
SetRunner(R"(
|
||||
@@ -369,7 +432,7 @@ TEST_F(GateCalculatorTest, DisallowInitialNoStateTransition) {
|
||||
output_stream: "STATE_CHANGE:state_changed"
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, "DISALLOW", false);
|
||||
|
||||
const std::vector<Packet>& output =
|
||||
@@ -387,7 +450,7 @@ TEST_F(GateCalculatorTest, AllowInitialNoStateTransition) {
|
||||
output_stream: "STATE_CHANGE:state_changed"
|
||||
)");
|
||||
|
||||
constexpr int64 kTimestampValue0 = 42;
|
||||
constexpr int64_t kTimestampValue0 = 42;
|
||||
RunTimeStep(kTimestampValue0, "ALLOW", true);
|
||||
|
||||
const std::vector<Packet>& output =
|
||||
|
||||
@@ -94,17 +94,17 @@ class GraphProfileCalculatorTest : public ::testing::Test {
|
||||
&graph_config_));
|
||||
}
|
||||
|
||||
static Packet PacketAt(int64 ts) {
|
||||
return Adopt(new int64(999)).At(Timestamp(ts));
|
||||
static Packet PacketAt(int64_t ts) {
|
||||
return Adopt(new int64_t(999)).At(Timestamp(ts));
|
||||
}
|
||||
static Packet None() { return Packet().At(Timestamp::OneOverPostStream()); }
|
||||
static bool IsNone(const Packet& packet) {
|
||||
return packet.Timestamp() == Timestamp::OneOverPostStream();
|
||||
}
|
||||
// Return the values of the timestamps of a vector of Packets.
|
||||
static std::vector<int64> TimestampValues(
|
||||
static std::vector<int64_t> TimestampValues(
|
||||
const std::vector<Packet>& packets) {
|
||||
std::vector<int64> result;
|
||||
std::vector<int64_t> result;
|
||||
for (const Packet& p : packets) {
|
||||
result.push_back(p.Timestamp().Value());
|
||||
}
|
||||
|
||||
@@ -191,17 +191,17 @@ class ImmediateMuxCalculatorTest : public ::testing::Test {
|
||||
&graph_config_));
|
||||
}
|
||||
|
||||
static Packet PacketAt(int64 ts) {
|
||||
return Adopt(new int64(999)).At(Timestamp(ts));
|
||||
static Packet PacketAt(int64_t ts) {
|
||||
return Adopt(new int64_t(999)).At(Timestamp(ts));
|
||||
}
|
||||
static Packet None() { return Packet().At(Timestamp::OneOverPostStream()); }
|
||||
static bool IsNone(const Packet& packet) {
|
||||
return packet.Timestamp() == Timestamp::OneOverPostStream();
|
||||
}
|
||||
// Return the values of the timestamps of a vector of Packets.
|
||||
static std::vector<int64> TimestampValues(
|
||||
static std::vector<int64_t> TimestampValues(
|
||||
const std::vector<Packet>& packets) {
|
||||
std::vector<int64> result;
|
||||
std::vector<int64_t> result;
|
||||
for (const Packet& p : packets) {
|
||||
result.push_back(p.Timestamp().Value());
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
namespace {
|
||||
// Reflect an integer against the lower and upper bound of an interval.
|
||||
int64 ReflectBetween(int64 ts, int64 ts_min, int64 ts_max) {
|
||||
int64_t ReflectBetween(int64_t ts, int64_t ts_min, int64_t ts_max) {
|
||||
if (ts < ts_min) return 2 * ts_min - ts - 1;
|
||||
if (ts >= ts_max) return 2 * ts_max - ts - 1;
|
||||
return ts;
|
||||
@@ -47,7 +47,7 @@ constexpr char kOptionsTag[] = "OPTIONS";
|
||||
// Returns a TimestampDiff (assuming microseconds) corresponding to the
|
||||
// given time in seconds.
|
||||
TimestampDiff TimestampDiffFromSeconds(double seconds) {
|
||||
return TimestampDiff(MathUtil::SafeRound<int64, double>(
|
||||
return TimestampDiff(MathUtil::SafeRound<int64_t, double>(
|
||||
seconds * Timestamp::kTimestampUnitsPerSecond));
|
||||
}
|
||||
} // namespace
|
||||
@@ -117,8 +117,8 @@ absl::Status PacketResamplerCalculator::Open(CalculatorContext* cc) {
|
||||
<< "The output frame rate must be smaller than "
|
||||
<< Timestamp::kTimestampUnitsPerSecond;
|
||||
|
||||
frame_time_usec_ = static_cast<int64>(1000000.0 / frame_rate_);
|
||||
jitter_usec_ = static_cast<int64>(1000000.0 * jitter_ / frame_rate_);
|
||||
frame_time_usec_ = static_cast<int64_t>(1000000.0 / frame_rate_);
|
||||
jitter_usec_ = static_cast<int64_t>(1000000.0 * jitter_ / frame_rate_);
|
||||
RET_CHECK_LE(jitter_usec_, frame_time_usec_);
|
||||
|
||||
video_header_.frame_rate = frame_rate_;
|
||||
@@ -198,17 +198,18 @@ PacketResamplerCalculator::GetSamplingStrategy(
|
||||
return absl::make_unique<JitterWithoutReflectionStrategy>(this);
|
||||
}
|
||||
|
||||
Timestamp PacketResamplerCalculator::PeriodIndexToTimestamp(int64 index) const {
|
||||
Timestamp PacketResamplerCalculator::PeriodIndexToTimestamp(
|
||||
int64_t index) const {
|
||||
CHECK_EQ(jitter_, 0.0);
|
||||
CHECK_NE(first_timestamp_, Timestamp::Unset());
|
||||
return first_timestamp_ + TimestampDiffFromSeconds(index / frame_rate_);
|
||||
}
|
||||
|
||||
int64 PacketResamplerCalculator::TimestampToPeriodIndex(
|
||||
int64_t PacketResamplerCalculator::TimestampToPeriodIndex(
|
||||
Timestamp timestamp) const {
|
||||
CHECK_EQ(jitter_, 0.0);
|
||||
CHECK_NE(first_timestamp_, Timestamp::Unset());
|
||||
return MathUtil::SafeRound<int64, double>(
|
||||
return MathUtil::SafeRound<int64_t, double>(
|
||||
(timestamp - first_timestamp_).Seconds() * frame_rate_);
|
||||
}
|
||||
|
||||
@@ -289,11 +290,11 @@ absl::Status LegacyJitterWithReflectionStrategy::Process(
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const int64 last_diff =
|
||||
const int64_t last_diff =
|
||||
(next_output_timestamp_ - calculator_->last_packet_.Timestamp())
|
||||
.Value();
|
||||
RET_CHECK_GT(last_diff, 0);
|
||||
const int64 curr_diff =
|
||||
const int64_t curr_diff =
|
||||
(next_output_timestamp_ - cc->InputTimestamp()).Value();
|
||||
if (curr_diff > 0) {
|
||||
break;
|
||||
@@ -559,11 +560,11 @@ absl::Status JitterWithoutReflectionStrategy::Process(CalculatorContext* cc) {
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const int64 last_diff =
|
||||
const int64_t last_diff =
|
||||
(next_output_timestamp_ - calculator_->last_packet_.Timestamp())
|
||||
.Value();
|
||||
RET_CHECK_GT(last_diff, 0);
|
||||
const int64 curr_diff =
|
||||
const int64_t curr_diff =
|
||||
(next_output_timestamp_ - cc->InputTimestamp()).Value();
|
||||
if (curr_diff > 0) {
|
||||
break;
|
||||
@@ -631,7 +632,7 @@ absl::Status NoJitterStrategy::Process(CalculatorContext* cc) {
|
||||
} else {
|
||||
// Initialize first_timestamp_ with the first packet timestamp
|
||||
// aligned to the base_timestamp_.
|
||||
int64 first_index = MathUtil::SafeRound<int64, double>(
|
||||
int64_t first_index = MathUtil::SafeRound<int64_t, double>(
|
||||
(cc->InputTimestamp() - base_timestamp_).Seconds() *
|
||||
calculator_->frame_rate_);
|
||||
calculator_->first_timestamp_ =
|
||||
@@ -646,7 +647,7 @@ absl::Status NoJitterStrategy::Process(CalculatorContext* cc) {
|
||||
}
|
||||
}
|
||||
const Timestamp received_timestamp = cc->InputTimestamp();
|
||||
const int64 received_timestamp_idx =
|
||||
const int64_t received_timestamp_idx =
|
||||
calculator_->TimestampToPeriodIndex(received_timestamp);
|
||||
// Only consider the received packet if it belongs to the current period
|
||||
// (== period_count_) or to a newer one (> period_count_).
|
||||
|
||||
@@ -97,7 +97,7 @@ class PacketThinnerCalculator : public CalculatorBase {
|
||||
cc->Inputs().Index(0).SetAny();
|
||||
cc->Outputs().Index(0).SetSameAs(&cc->Inputs().Index(0));
|
||||
if (cc->InputSidePackets().HasTag(kPeriodTag)) {
|
||||
cc->InputSidePackets().Tag(kPeriodTag).Set<int64>();
|
||||
cc->InputSidePackets().Tag(kPeriodTag).Set<int64_t>();
|
||||
}
|
||||
return absl::OkStatus();
|
||||
}
|
||||
@@ -173,7 +173,7 @@ absl::Status PacketThinnerCalculator::Open(CalculatorContext* cc) {
|
||||
|
||||
if (cc->InputSidePackets().HasTag(kPeriodTag)) {
|
||||
period_ =
|
||||
TimestampDiff(cc->InputSidePackets().Tag(kPeriodTag).Get<int64>());
|
||||
TimestampDiff(cc->InputSidePackets().Tag(kPeriodTag).Get<int64_t>());
|
||||
} else {
|
||||
period_ = TimestampDiff(options.period());
|
||||
}
|
||||
@@ -300,13 +300,13 @@ Timestamp PacketThinnerCalculator::NearestSyncTimestamp(Timestamp now) const {
|
||||
|
||||
// Computation is done using int64 arithmetic. No easy way to avoid
|
||||
// since Timestamps don't support div and multiply.
|
||||
const int64 now64 = now.Value();
|
||||
const int64 start64 = start_time_.Value();
|
||||
const int64 period64 = period_.Value();
|
||||
const int64_t now64 = now.Value();
|
||||
const int64_t start64 = start_time_.Value();
|
||||
const int64_t period64 = period_.Value();
|
||||
CHECK_LE(0, period64);
|
||||
|
||||
// Round now64 to its closest interval (units of period64).
|
||||
int64 sync64 =
|
||||
int64_t sync64 =
|
||||
(now64 - start64 + period64 / 2) / period64 * period64 + start64;
|
||||
CHECK_LE(abs(now64 - sync64), period64 / 2)
|
||||
<< "start64: " << start64 << "; now64: " << now64
|
||||
|
||||
@@ -61,8 +61,8 @@ class SimpleRunner : public CalculatorRunner {
|
||||
MutableInputs()->Index(0).header = Adopt(video_header.release());
|
||||
}
|
||||
|
||||
std::vector<int64> GetOutputTimestamps() const {
|
||||
std::vector<int64> timestamps;
|
||||
std::vector<int64_t> GetOutputTimestamps() const {
|
||||
std::vector<int64_t> timestamps;
|
||||
for (const Packet& packet : Outputs().Index(0).packets) {
|
||||
timestamps.emplace_back(packet.Timestamp().Value());
|
||||
}
|
||||
@@ -90,7 +90,7 @@ TEST(PacketThinnerCalculatorTest, StartAndEndTimeTest) {
|
||||
runner.SetInput({2, 3, 5, 7, 11, 13, 17, 19, 23, 29});
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {5, 11};
|
||||
const std::vector<int64_t> expected_timestamps = {5, 11};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ TEST(PacketThinnerCalculatorTest, AsyncUniformStreamThinningTest) {
|
||||
runner.SetInput({2, 4, 6, 8, 10, 12, 14});
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {2, 8, 14};
|
||||
const std::vector<int64_t> expected_timestamps = {2, 8, 14};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -123,10 +123,10 @@ TEST(PacketThinnerCalculatorTest, ASyncUniformStreamThinningTestBySidePacket) {
|
||||
|
||||
SimpleRunner runner(node);
|
||||
runner.SetInput({2, 4, 6, 8, 10, 12, 14});
|
||||
runner.MutableSidePackets()->Tag(kPeriodTag) = MakePacket<int64>(5);
|
||||
runner.MutableSidePackets()->Tag(kPeriodTag) = MakePacket<int64_t>(5);
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {2, 8, 14};
|
||||
const std::vector<int64_t> expected_timestamps = {2, 8, 14};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ TEST(PacketThinnerCalculatorTest, SyncUniformStreamThinningTest1) {
|
||||
runner.SetInput({2, 4, 6, 8, 10, 12, 14});
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {2, 6, 10, 14};
|
||||
const std::vector<int64_t> expected_timestamps = {2, 6, 10, 14};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -162,10 +162,10 @@ TEST(PacketThinnerCalculatorTest, SyncUniformStreamThinningTestBySidePacket1) {
|
||||
|
||||
SimpleRunner runner(node);
|
||||
runner.SetInput({2, 4, 6, 8, 10, 12, 14});
|
||||
runner.MutableSidePackets()->Tag(kPeriodTag) = MakePacket<int64>(5);
|
||||
runner.MutableSidePackets()->Tag(kPeriodTag) = MakePacket<int64_t>(5);
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {2, 6, 10, 14};
|
||||
const std::vector<int64_t> expected_timestamps = {2, 6, 10, 14};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ TEST(PacketThinnerCalculatorTest, SyncUniformStreamThinningTest2) {
|
||||
runner.SetInput({2, 4, 6, 8, 10, 12, 14});
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {0, 5, 10, 15};
|
||||
const std::vector<int64_t> expected_timestamps = {0, 5, 10, 15};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ TEST(PacketThinnerCalculatorTest, PrimeStreamThinningTest1) {
|
||||
runner.SetInput({2, 3, 5, 7, 11, 13, 17, 19, 23, 29});
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {2, 7, 13, 19, 29};
|
||||
const std::vector<int64_t> expected_timestamps = {2, 7, 13, 19, 29};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ TEST(PacketThinnerCalculatorTest, PrimeStreamThinningTest2) {
|
||||
runner.SetInput({2, 3, 5, 7, 11, 13, 17, 19, 23, 29});
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {2, 5, 11, 17, 19, 23, 29};
|
||||
const std::vector<int64_t> expected_timestamps = {2, 5, 11, 17, 19, 23, 29};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ TEST(PacketThinnerCalculatorTest, BoundaryTimestampTest1) {
|
||||
runner.SetInput({2, 3});
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {0, 5};
|
||||
const std::vector<int64_t> expected_timestamps = {0, 5};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ TEST(PacketThinnerCalculatorTest, BoundaryTimestampTest2) {
|
||||
runner.SetInput({-4, -3, 8, 9});
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {-6, 0, 6, 12};
|
||||
const std::vector<int64_t> expected_timestamps = {-6, 0, 6, 12};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ TEST(PacketThinnerCalculatorTest, FrameRateTest1) {
|
||||
runner.SetFrameRate(1000000.0 / 2);
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {2, 8, 14};
|
||||
const std::vector<int64_t> expected_timestamps = {2, 8, 14};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
// The true sampling period is 6.
|
||||
EXPECT_DOUBLE_EQ(1000000.0 / 6, runner.GetFrameRate());
|
||||
@@ -287,7 +287,7 @@ TEST(PacketThinnerCalculatorTest, FrameRateTest2) {
|
||||
runner.SetInput({8, 16, 24, 32, 40, 48, 56});
|
||||
runner.SetFrameRate(1000000.0 / 8);
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
const std::vector<int64> expected_timestamps = {8, 16, 24, 32, 40, 48, 56};
|
||||
const std::vector<int64_t> expected_timestamps = {8, 16, 24, 32, 40, 48, 56};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
// The true sampling period is still 8.
|
||||
EXPECT_DOUBLE_EQ(1000000.0 / 8, runner.GetFrameRate());
|
||||
@@ -308,7 +308,7 @@ TEST(PacketThinnerCalculatorTest, FrameRateTest3) {
|
||||
runner.SetFrameRate(1000000.0 / 2);
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {2, 6, 10, 14};
|
||||
const std::vector<int64_t> expected_timestamps = {2, 6, 10, 14};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
// The true (long-run) sampling period is 5.
|
||||
EXPECT_DOUBLE_EQ(1000000.0 / 5, runner.GetFrameRate());
|
||||
@@ -329,7 +329,7 @@ TEST(PacketThinnerCalculatorTest, FrameRateTest4) {
|
||||
runner.SetFrameRate(1000000.0 / 2);
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {0, 5, 10, 15};
|
||||
const std::vector<int64_t> expected_timestamps = {0, 5, 10, 15};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
// The true (long-run) sampling period is 5.
|
||||
EXPECT_DOUBLE_EQ(1000000.0 / 5, runner.GetFrameRate());
|
||||
@@ -349,7 +349,7 @@ TEST(PacketThinnerCalculatorTest, FrameRateTest5) {
|
||||
runner.SetFrameRate(1000000.0 / 8);
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const std::vector<int64> expected_timestamps = {10, 15, 25, 30, 40, 50, 55};
|
||||
const std::vector<int64_t> expected_timestamps = {10, 15, 25, 30, 40, 50, 55};
|
||||
EXPECT_EQ(expected_timestamps, runner.GetOutputTimestamps());
|
||||
// The true (long-run) sampling period is 8.
|
||||
EXPECT_DOUBLE_EQ(1000000.0 / 8, runner.GetFrameRate());
|
||||
|
||||
@@ -52,8 +52,8 @@ class AtomicSemaphore {
|
||||
};
|
||||
|
||||
// Returns the timestamp values for a vector of Packets.
|
||||
std::vector<int64> TimestampValues(const std::vector<Packet>& packets) {
|
||||
std::vector<int64> result;
|
||||
std::vector<int64_t> TimestampValues(const std::vector<Packet>& packets) {
|
||||
std::vector<int64_t> result;
|
||||
for (const Packet& packet : packets) {
|
||||
result.push_back(packet.Timestamp().Value());
|
||||
}
|
||||
@@ -283,9 +283,9 @@ TEST_F(RealTimeFlowLimiterCalculatorTest, BackEdgeCloses) {
|
||||
InitializeGraph(1);
|
||||
MP_ASSERT_OK(graph_.StartRun({}));
|
||||
|
||||
auto send_packet = [this](const std::string& input_name, int64 n) {
|
||||
auto send_packet = [this](const std::string& input_name, int64_t n) {
|
||||
MP_EXPECT_OK(graph_.AddPacketToInputStream(
|
||||
input_name, MakePacket<int64>(n).At(Timestamp(n))));
|
||||
input_name, MakePacket<int64_t>(n).At(Timestamp(n))));
|
||||
};
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
@@ -307,14 +307,14 @@ TEST_F(RealTimeFlowLimiterCalculatorTest, BackEdgeCloses) {
|
||||
EXPECT_EQ(10, out_2_packets_.size());
|
||||
|
||||
// Timestamps have not been messed with.
|
||||
EXPECT_EQ(PacketValues<int64>(out_1_packets_),
|
||||
EXPECT_EQ(PacketValues<int64_t>(out_1_packets_),
|
||||
TimestampValues(out_1_packets_));
|
||||
EXPECT_EQ(PacketValues<int64>(out_2_packets_),
|
||||
EXPECT_EQ(PacketValues<int64_t>(out_2_packets_),
|
||||
TimestampValues(out_2_packets_));
|
||||
|
||||
// Extra inputs on in_1 have been dropped
|
||||
EXPECT_EQ(TimestampValues(out_1_packets_),
|
||||
(std::vector<int64>{0, 10, 20, 30, 40, 50, 60, 70, 80, 90}));
|
||||
(std::vector<int64_t>{0, 10, 20, 30, 40, 50, 60, 70, 80, 90}));
|
||||
EXPECT_EQ(TimestampValues(out_1_packets_), TimestampValues(out_2_packets_));
|
||||
|
||||
// The closing of the stream has been propagated.
|
||||
@@ -339,7 +339,7 @@ TEST_F(RealTimeFlowLimiterCalculatorTest, AllStreamsClose) {
|
||||
|
||||
EXPECT_EQ(TimestampValues(out_1_packets_), TimestampValues(out_2_packets_));
|
||||
EXPECT_EQ(TimestampValues(out_1_packets_),
|
||||
(std::vector<int64>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
|
||||
(std::vector<int64_t>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
|
||||
EXPECT_EQ(1, close_count_);
|
||||
}
|
||||
|
||||
@@ -392,50 +392,50 @@ TEST(RealTimeFlowLimiterCalculator, TwoStreams) {
|
||||
send_packet("in_a", 1);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(allow, false);
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64>{}));
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64_t>{}));
|
||||
|
||||
send_packet("in_a", 2);
|
||||
send_packet("in_b", 1);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(allow, false);
|
||||
|
||||
send_packet("finished", 1);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(allow, true);
|
||||
|
||||
send_packet("in_b", 2);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(allow, true);
|
||||
|
||||
send_packet("in_b", 3);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64>{1, 3}));
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64_t>{1, 3}));
|
||||
EXPECT_EQ(allow, false);
|
||||
|
||||
send_packet("in_b", 4);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64>{1, 3}));
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64_t>{1}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64_t>{1, 3}));
|
||||
EXPECT_EQ(allow, false);
|
||||
|
||||
send_packet("in_a", 3);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64>{1, 3}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64>{1, 3}));
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64_t>{1, 3}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64_t>{1, 3}));
|
||||
EXPECT_EQ(allow, false);
|
||||
|
||||
send_packet("finished", 3);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64>{1, 3}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64>{1, 3}));
|
||||
EXPECT_EQ(TimestampValues(a_passed), (std::vector<int64_t>{1, 3}));
|
||||
EXPECT_EQ(TimestampValues(b_passed), (std::vector<int64_t>{1, 3}));
|
||||
EXPECT_EQ(allow, true);
|
||||
|
||||
MP_EXPECT_OK(graph_.CloseAllInputStreams());
|
||||
@@ -486,7 +486,7 @@ TEST(RealTimeFlowLimiterCalculator, CanConsume) {
|
||||
send_packet("in", 1);
|
||||
MP_EXPECT_OK(graph_.WaitUntilIdle());
|
||||
EXPECT_EQ(allow, false);
|
||||
EXPECT_EQ(TimestampValues(in_sampled_packets_), (std::vector<int64>{1}));
|
||||
EXPECT_EQ(TimestampValues(in_sampled_packets_), (std::vector<int64_t>{1}));
|
||||
|
||||
MP_EXPECT_OK(in_sampled_packets_[0].Consume<int>());
|
||||
|
||||
|
||||
@@ -322,10 +322,10 @@ TEST(SidePacketToStreamCalculator, AtTimestamp) {
|
||||
|
||||
MP_ASSERT_OK(graph.Initialize(graph_config));
|
||||
const int expected_value = 20;
|
||||
const int64 expected_timestamp = 5;
|
||||
const int64_t expected_timestamp = 5;
|
||||
MP_ASSERT_OK(
|
||||
graph.StartRun({{"side_packet", MakePacket<int>(expected_value)},
|
||||
{"timestamp", MakePacket<int64>(expected_timestamp)}}));
|
||||
{"timestamp", MakePacket<int64_t>(expected_timestamp)}}));
|
||||
|
||||
MP_ASSERT_OK(graph.WaitUntilDone());
|
||||
|
||||
@@ -360,11 +360,11 @@ TEST(SidePacketToStreamCalculator, AtTimestamp_MultipleOutputs) {
|
||||
MP_ASSERT_OK(graph.Initialize(graph_config));
|
||||
const int expected_value0 = 20;
|
||||
const int expected_value1 = 15;
|
||||
const int64 expected_timestamp = 5;
|
||||
const int64_t expected_timestamp = 5;
|
||||
MP_ASSERT_OK(
|
||||
graph.StartRun({{"side_packet0", MakePacket<int>(expected_value0)},
|
||||
{"side_packet1", MakePacket<int>(expected_value1)},
|
||||
{"timestamp", MakePacket<int64>(expected_timestamp)}}));
|
||||
{"timestamp", MakePacket<int64_t>(expected_timestamp)}}));
|
||||
|
||||
MP_ASSERT_OK(graph.WaitUntilDone());
|
||||
|
||||
|
||||
@@ -156,9 +156,9 @@ class SplitListsCalculator : public CalculatorBase {
|
||||
virtual ItemType* AddItem(ListType& list) const = 0;
|
||||
|
||||
private:
|
||||
std::vector<std::pair<int32, int32>> ranges_;
|
||||
int32 max_range_end_ = -1;
|
||||
int32 total_elements_ = 0;
|
||||
std::vector<std::pair<int32_t, int32_t>> ranges_;
|
||||
int32_t max_range_end_ = -1;
|
||||
int32_t total_elements_ = 0;
|
||||
bool element_only_ = false;
|
||||
bool combine_outputs_ = false;
|
||||
};
|
||||
|
||||
@@ -64,16 +64,16 @@ REGISTER_CALCULATOR(StringToIntCalculator);
|
||||
using StringToUintCalculator = StringToIntCalculatorTemplate<unsigned int>;
|
||||
REGISTER_CALCULATOR(StringToUintCalculator);
|
||||
|
||||
using StringToInt32Calculator = StringToIntCalculatorTemplate<int32>;
|
||||
using StringToInt32Calculator = StringToIntCalculatorTemplate<int32_t>;
|
||||
REGISTER_CALCULATOR(StringToInt32Calculator);
|
||||
|
||||
using StringToUint32Calculator = StringToIntCalculatorTemplate<uint32>;
|
||||
using StringToUint32Calculator = StringToIntCalculatorTemplate<uint32_t>;
|
||||
REGISTER_CALCULATOR(StringToUint32Calculator);
|
||||
|
||||
using StringToInt64Calculator = StringToIntCalculatorTemplate<int64>;
|
||||
using StringToInt64Calculator = StringToIntCalculatorTemplate<int64_t>;
|
||||
REGISTER_CALCULATOR(StringToInt64Calculator);
|
||||
|
||||
using StringToUint64Calculator = StringToIntCalculatorTemplate<uint64>;
|
||||
using StringToUint64Calculator = StringToIntCalculatorTemplate<uint64_t>;
|
||||
REGISTER_CALCULATOR(StringToUint64Calculator);
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -147,36 +147,9 @@ cc_library(
|
||||
srcs = ["set_alpha_calculator.cc"],
|
||||
deps = [
|
||||
":set_alpha_calculator_cc_proto",
|
||||
"//mediapipe/framework/formats:image_format_cc_proto",
|
||||
"//mediapipe/framework:calculator_options_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/formats:image_frame_opencv",
|
||||
"//mediapipe/framework/port:logging",
|
||||
"//mediapipe/framework/port:opencv_core",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:vector",
|
||||
] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:gl_quad_renderer",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
],
|
||||
}),
|
||||
alwayslink = 1,
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "bilateral_filter_calculator",
|
||||
srcs = ["bilateral_filter_calculator.cc"],
|
||||
deps = [
|
||||
":bilateral_filter_calculator_cc_proto",
|
||||
"//mediapipe/framework/formats:image_format_cc_proto",
|
||||
"//mediapipe/framework:calculator_options_cc_proto",
|
||||
"@com_google_absl//absl/strings",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:image_format_cc_proto",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/formats:image_frame_opencv",
|
||||
"//mediapipe/framework/port:logging",
|
||||
@@ -188,8 +161,55 @@ cc_library(
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:gl_quad_renderer",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
],
|
||||
}),
|
||||
alwayslink = 1,
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "set_alpha_calculator_test",
|
||||
srcs = ["set_alpha_calculator_test.cc"],
|
||||
deps = [
|
||||
":set_alpha_calculator",
|
||||
":set_alpha_calculator_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:calculator_runner",
|
||||
"//mediapipe/framework/formats:image_frame_opencv",
|
||||
"//mediapipe/framework/formats:rect_cc_proto",
|
||||
"//mediapipe/framework/port:gtest_main",
|
||||
"//mediapipe/framework/port:opencv_core",
|
||||
"//mediapipe/framework/port:opencv_imgproc",
|
||||
"//mediapipe/framework/port:parse_text_proto",
|
||||
"//mediapipe/framework/port:status",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "bilateral_filter_calculator",
|
||||
srcs = ["bilateral_filter_calculator.cc"],
|
||||
deps = [
|
||||
":bilateral_filter_calculator_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:calculator_options_cc_proto",
|
||||
"//mediapipe/framework/formats:image_format_cc_proto",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/formats:image_frame_opencv",
|
||||
"//mediapipe/framework/port:logging",
|
||||
"//mediapipe/framework/port:opencv_core",
|
||||
"//mediapipe/framework/port:opencv_imgproc",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:vector",
|
||||
"@com_google_absl//absl/strings",
|
||||
] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_quad_renderer",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
],
|
||||
}),
|
||||
@@ -229,12 +249,11 @@ cc_library(
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = [
|
||||
":rotation_mode_cc_proto",
|
||||
":image_transformation_calculator_cc_proto",
|
||||
":rotation_mode_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:packet",
|
||||
"//mediapipe/framework:timestamp",
|
||||
"//mediapipe/gpu:scale_mode_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/formats:image_frame_opencv",
|
||||
"//mediapipe/framework/formats:video_stream_header",
|
||||
@@ -242,12 +261,13 @@ cc_library(
|
||||
"//mediapipe/framework/port:opencv_imgproc",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/gpu:scale_mode_cc_proto",
|
||||
] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:gl_quad_renderer",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
],
|
||||
}),
|
||||
@@ -273,10 +293,10 @@ cc_library(
|
||||
}),
|
||||
deps = [
|
||||
":image_cropping_calculator_cc_proto",
|
||||
"//mediapipe/framework/formats:rect_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/formats:image_frame_opencv",
|
||||
"//mediapipe/framework/formats:rect_cc_proto",
|
||||
"//mediapipe/framework/port:opencv_core",
|
||||
"//mediapipe/framework/port:opencv_imgproc",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
@@ -285,8 +305,8 @@ cc_library(
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:gl_quad_renderer",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:gpu_buffer",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
],
|
||||
@@ -347,20 +367,20 @@ cc_library(
|
||||
srcs = ["recolor_calculator.cc"],
|
||||
deps = [
|
||||
":recolor_calculator_cc_proto",
|
||||
"//mediapipe/util:color_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/formats:image_frame_opencv",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:opencv_core",
|
||||
"//mediapipe/framework/port:opencv_imgproc",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/util:color_cc_proto",
|
||||
] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:gl_quad_renderer",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
],
|
||||
}),
|
||||
@@ -420,8 +440,8 @@ cc_library(
|
||||
srcs = ["image_clone_calculator.cc"],
|
||||
deps = [
|
||||
":image_clone_calculator_cc_proto",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
@@ -438,8 +458,8 @@ cc_library(
|
||||
name = "image_properties_calculator",
|
||||
srcs = ["image_properties_calculator.cc"],
|
||||
deps = [
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
@@ -600,11 +620,11 @@ cc_library(
|
||||
srcs = ["segmentation_smoothing_calculator.cc"],
|
||||
deps = [
|
||||
":segmentation_smoothing_calculator_cc_proto",
|
||||
"//mediapipe/framework/formats:image_format_cc_proto",
|
||||
"//mediapipe/framework:calculator_options_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework:calculator_options_cc_proto",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/formats:image_format_cc_proto",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/port:logging",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:vector",
|
||||
@@ -612,8 +632,8 @@ cc_library(
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:gl_quad_renderer",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
],
|
||||
}) + select({
|
||||
@@ -708,8 +728,6 @@ cc_library(
|
||||
deps = [
|
||||
":affine_transformation",
|
||||
":warp_affine_calculator_cc_proto",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/api2:port",
|
||||
@@ -717,12 +735,14 @@ cc_library(
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
":affine_transformation_runner_gl",
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gpu_buffer",
|
||||
":affine_transformation_runner_gl",
|
||||
],
|
||||
}) + select({
|
||||
"//mediapipe/framework/port:disable_opencv": [],
|
||||
@@ -748,6 +768,7 @@ cc_test(
|
||||
"//mediapipe/calculators/tensor:testdata/image_to_tensor/medium_sub_rect_keep_aspect_with_rotation_border_zero.png",
|
||||
"//mediapipe/calculators/tensor:testdata/image_to_tensor/medium_sub_rect_with_rotation.png",
|
||||
"//mediapipe/calculators/tensor:testdata/image_to_tensor/medium_sub_rect_with_rotation_border_zero.png",
|
||||
"//mediapipe/calculators/tensor:testdata/image_to_tensor/medium_sub_rect_with_rotation_border_zero_interp_cubic.png",
|
||||
"//mediapipe/calculators/tensor:testdata/image_to_tensor/noop_except_range.png",
|
||||
],
|
||||
tags = ["desktop_only_test"],
|
||||
|
||||
@@ -29,6 +29,9 @@ class AffineTransformation {
|
||||
// pixels will be calculated.
|
||||
enum class BorderMode { kZero, kReplicate };
|
||||
|
||||
// Pixel sampling interpolation method.
|
||||
enum class Interpolation { kLinear, kCubic };
|
||||
|
||||
struct Size {
|
||||
int width;
|
||||
int height;
|
||||
|
||||
@@ -77,8 +77,11 @@ class GlTextureWarpAffineRunner
|
||||
std::unique_ptr<GpuBuffer>> {
|
||||
public:
|
||||
GlTextureWarpAffineRunner(std::shared_ptr<GlCalculatorHelper> gl_helper,
|
||||
GpuOrigin::Mode gpu_origin)
|
||||
: gl_helper_(gl_helper), gpu_origin_(gpu_origin) {}
|
||||
GpuOrigin::Mode gpu_origin,
|
||||
AffineTransformation::Interpolation interpolation)
|
||||
: gl_helper_(gl_helper),
|
||||
gpu_origin_(gpu_origin),
|
||||
interpolation_(interpolation) {}
|
||||
absl::Status Init() {
|
||||
return gl_helper_->RunInGlContext([this]() -> absl::Status {
|
||||
const GLint attr_location[kNumAttributes] = {
|
||||
@@ -103,28 +106,83 @@ class GlTextureWarpAffineRunner
|
||||
}
|
||||
)";
|
||||
|
||||
// TODO Move bicubic code to common shared place.
|
||||
constexpr GLchar kFragShader[] = R"(
|
||||
DEFAULT_PRECISION(highp, float)
|
||||
in vec2 sample_coordinate;
|
||||
uniform sampler2D input_texture;
|
||||
DEFAULT_PRECISION(highp, float)
|
||||
|
||||
#ifdef GL_ES
|
||||
#define fragColor gl_FragColor
|
||||
#else
|
||||
out vec4 fragColor;
|
||||
#endif // defined(GL_ES);
|
||||
in vec2 sample_coordinate;
|
||||
uniform sampler2D input_texture;
|
||||
uniform vec2 input_size;
|
||||
|
||||
void main() {
|
||||
vec4 color = texture2D(input_texture, sample_coordinate);
|
||||
#ifdef CUSTOM_ZERO_BORDER_MODE
|
||||
float out_of_bounds =
|
||||
float(sample_coordinate.x < 0.0 || sample_coordinate.x > 1.0 ||
|
||||
sample_coordinate.y < 0.0 || sample_coordinate.y > 1.0);
|
||||
color = mix(color, vec4(0.0, 0.0, 0.0, 0.0), out_of_bounds);
|
||||
#endif // defined(CUSTOM_ZERO_BORDER_MODE)
|
||||
fragColor = color;
|
||||
}
|
||||
)";
|
||||
#ifdef GL_ES
|
||||
#define fragColor gl_FragColor
|
||||
#else
|
||||
out vec4 fragColor;
|
||||
#endif // defined(GL_ES);
|
||||
|
||||
#ifdef CUBIC_INTERPOLATION
|
||||
vec4 sample(sampler2D tex, vec2 tex_coord, vec2 tex_size) {
|
||||
const vec2 halve = vec2(0.5,0.5);
|
||||
const vec2 one = vec2(1.0,1.0);
|
||||
const vec2 two = vec2(2.0,2.0);
|
||||
const vec2 three = vec2(3.0,3.0);
|
||||
const vec2 six = vec2(6.0,6.0);
|
||||
|
||||
// Calculate the fraction and integer.
|
||||
tex_coord = tex_coord * tex_size - halve;
|
||||
vec2 frac = fract(tex_coord);
|
||||
vec2 index = tex_coord - frac + halve;
|
||||
|
||||
// Calculate weights for Catmull-Rom filter.
|
||||
vec2 w0 = frac * (-halve + frac * (one - halve * frac));
|
||||
vec2 w1 = one + frac * frac * (-(two+halve) + three/two * frac);
|
||||
vec2 w2 = frac * (halve + frac * (two - three/two * frac));
|
||||
vec2 w3 = frac * frac * (-halve + halve * frac);
|
||||
|
||||
// Calculate weights to take advantage of bilinear texture lookup.
|
||||
vec2 w12 = w1 + w2;
|
||||
vec2 offset12 = w2 / (w1 + w2);
|
||||
|
||||
vec2 index_tl = index - one;
|
||||
vec2 index_br = index + two;
|
||||
vec2 index_eq = index + offset12;
|
||||
|
||||
index_tl /= tex_size;
|
||||
index_br /= tex_size;
|
||||
index_eq /= tex_size;
|
||||
|
||||
// 9 texture lookup and linear blending.
|
||||
vec4 color = vec4(0.0);
|
||||
color += texture2D(tex, vec2(index_tl.x, index_tl.y)) * w0.x * w0.y;
|
||||
color += texture2D(tex, vec2(index_eq.x, index_tl.y)) * w12.x *w0.y;
|
||||
color += texture2D(tex, vec2(index_br.x, index_tl.y)) * w3.x * w0.y;
|
||||
|
||||
color += texture2D(tex, vec2(index_tl.x, index_eq.y)) * w0.x * w12.y;
|
||||
color += texture2D(tex, vec2(index_eq.x, index_eq.y)) * w12.x *w12.y;
|
||||
color += texture2D(tex, vec2(index_br.x, index_eq.y)) * w3.x * w12.y;
|
||||
|
||||
color += texture2D(tex, vec2(index_tl.x, index_br.y)) * w0.x * w3.y;
|
||||
color += texture2D(tex, vec2(index_eq.x, index_br.y)) * w12.x *w3.y;
|
||||
color += texture2D(tex, vec2(index_br.x, index_br.y)) * w3.x * w3.y;
|
||||
return color;
|
||||
}
|
||||
#else
|
||||
vec4 sample(sampler2D tex, vec2 tex_coord, vec2 tex_size) {
|
||||
return texture2D(tex, tex_coord);
|
||||
}
|
||||
#endif // defined(CUBIC_INTERPOLATION)
|
||||
|
||||
void main() {
|
||||
vec4 color = sample(input_texture, sample_coordinate, input_size);
|
||||
#ifdef CUSTOM_ZERO_BORDER_MODE
|
||||
float out_of_bounds =
|
||||
float(sample_coordinate.x < 0.0 || sample_coordinate.x > 1.0 ||
|
||||
sample_coordinate.y < 0.0 || sample_coordinate.y > 1.0);
|
||||
color = mix(color, vec4(0.0, 0.0, 0.0, 0.0), out_of_bounds);
|
||||
#endif // defined(CUSTOM_ZERO_BORDER_MODE)
|
||||
fragColor = color;
|
||||
}
|
||||
)";
|
||||
|
||||
// Create program and set parameters.
|
||||
auto create_fn = [&](const std::string& vs,
|
||||
@@ -137,14 +195,28 @@ class GlTextureWarpAffineRunner
|
||||
glUseProgram(program);
|
||||
glUniform1i(glGetUniformLocation(program, "input_texture"), 1);
|
||||
GLint matrix_id = glGetUniformLocation(program, "transform_matrix");
|
||||
return Program{.id = program, .matrix_id = matrix_id};
|
||||
GLint size_id = glGetUniformLocation(program, "input_size");
|
||||
return Program{
|
||||
.id = program, .matrix_id = matrix_id, .size_id = size_id};
|
||||
};
|
||||
|
||||
const std::string vert_src =
|
||||
absl::StrCat(mediapipe::kMediaPipeVertexShaderPreamble, kVertShader);
|
||||
|
||||
const std::string frag_src = absl::StrCat(
|
||||
mediapipe::kMediaPipeFragmentShaderPreamble, kFragShader);
|
||||
std::string interpolation_def;
|
||||
switch (interpolation_) {
|
||||
case AffineTransformation::Interpolation::kCubic:
|
||||
interpolation_def = R"(
|
||||
#define CUBIC_INTERPOLATION
|
||||
)";
|
||||
break;
|
||||
case AffineTransformation::Interpolation::kLinear:
|
||||
break;
|
||||
}
|
||||
|
||||
const std::string frag_src =
|
||||
absl::StrCat(mediapipe::kMediaPipeFragmentShaderPreamble,
|
||||
interpolation_def, kFragShader);
|
||||
|
||||
ASSIGN_OR_RETURN(program_, create_fn(vert_src, frag_src));
|
||||
|
||||
@@ -152,9 +224,9 @@ class GlTextureWarpAffineRunner
|
||||
std::string custom_zero_border_mode_def = R"(
|
||||
#define CUSTOM_ZERO_BORDER_MODE
|
||||
)";
|
||||
const std::string frag_custom_zero_src =
|
||||
absl::StrCat(mediapipe::kMediaPipeFragmentShaderPreamble,
|
||||
custom_zero_border_mode_def, kFragShader);
|
||||
const std::string frag_custom_zero_src = absl::StrCat(
|
||||
mediapipe::kMediaPipeFragmentShaderPreamble,
|
||||
custom_zero_border_mode_def, interpolation_def, kFragShader);
|
||||
return create_fn(vert_src, frag_custom_zero_src);
|
||||
};
|
||||
#if GL_CLAMP_TO_BORDER_MAY_BE_SUPPORTED
|
||||
@@ -256,6 +328,7 @@ class GlTextureWarpAffineRunner
|
||||
}
|
||||
glUseProgram(program->id);
|
||||
|
||||
// uniforms
|
||||
Eigen::Matrix<float, 4, 4, Eigen::RowMajor> eigen_mat(matrix.data());
|
||||
if (IsMatrixVerticalFlipNeeded(gpu_origin_)) {
|
||||
// @matrix describes affine transformation in terms of TOP LEFT origin, so
|
||||
@@ -275,6 +348,10 @@ class GlTextureWarpAffineRunner
|
||||
eigen_mat.transposeInPlace();
|
||||
glUniformMatrix4fv(program->matrix_id, 1, GL_FALSE, eigen_mat.data());
|
||||
|
||||
if (interpolation_ == AffineTransformation::Interpolation::kCubic) {
|
||||
glUniform2f(program->size_id, texture.width(), texture.height());
|
||||
}
|
||||
|
||||
// vao
|
||||
glBindVertexArray(vao_);
|
||||
|
||||
@@ -327,6 +404,7 @@ class GlTextureWarpAffineRunner
|
||||
struct Program {
|
||||
GLuint id;
|
||||
GLint matrix_id;
|
||||
GLint size_id;
|
||||
};
|
||||
std::shared_ptr<GlCalculatorHelper> gl_helper_;
|
||||
GpuOrigin::Mode gpu_origin_;
|
||||
@@ -335,6 +413,8 @@ class GlTextureWarpAffineRunner
|
||||
Program program_;
|
||||
std::optional<Program> program_custom_zero_;
|
||||
GLuint framebuffer_ = 0;
|
||||
AffineTransformation::Interpolation interpolation_ =
|
||||
AffineTransformation::Interpolation::kLinear;
|
||||
};
|
||||
|
||||
#undef GL_CLAMP_TO_BORDER_MAY_BE_SUPPORTED
|
||||
@@ -344,9 +424,10 @@ class GlTextureWarpAffineRunner
|
||||
absl::StatusOr<std::unique_ptr<
|
||||
AffineTransformation::Runner<GpuBuffer, std::unique_ptr<GpuBuffer>>>>
|
||||
CreateAffineTransformationGlRunner(
|
||||
std::shared_ptr<GlCalculatorHelper> gl_helper, GpuOrigin::Mode gpu_origin) {
|
||||
auto runner =
|
||||
absl::make_unique<GlTextureWarpAffineRunner>(gl_helper, gpu_origin);
|
||||
std::shared_ptr<GlCalculatorHelper> gl_helper, GpuOrigin::Mode gpu_origin,
|
||||
AffineTransformation::Interpolation interpolation) {
|
||||
auto runner = absl::make_unique<GlTextureWarpAffineRunner>(
|
||||
gl_helper, gpu_origin, interpolation);
|
||||
MP_RETURN_IF_ERROR(runner->Init());
|
||||
return runner;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ absl::StatusOr<std::unique_ptr<AffineTransformation::Runner<
|
||||
mediapipe::GpuBuffer, std::unique_ptr<mediapipe::GpuBuffer>>>>
|
||||
CreateAffineTransformationGlRunner(
|
||||
std::shared_ptr<mediapipe::GlCalculatorHelper> gl_helper,
|
||||
mediapipe::GpuOrigin::Mode gpu_origin);
|
||||
mediapipe::GpuOrigin::Mode gpu_origin,
|
||||
AffineTransformation::Interpolation interpolation);
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
|
||||
@@ -39,9 +39,22 @@ cv::BorderTypes GetBorderModeForOpenCv(
|
||||
}
|
||||
}
|
||||
|
||||
int GetInterpolationForOpenCv(
|
||||
AffineTransformation::Interpolation interpolation) {
|
||||
switch (interpolation) {
|
||||
case AffineTransformation::Interpolation::kLinear:
|
||||
return cv::INTER_LINEAR;
|
||||
case AffineTransformation::Interpolation::kCubic:
|
||||
return cv::INTER_CUBIC;
|
||||
}
|
||||
}
|
||||
|
||||
class OpenCvRunner
|
||||
: public AffineTransformation::Runner<ImageFrame, ImageFrame> {
|
||||
public:
|
||||
OpenCvRunner(AffineTransformation::Interpolation interpolation)
|
||||
: interpolation_(GetInterpolationForOpenCv(interpolation)) {}
|
||||
|
||||
absl::StatusOr<ImageFrame> Run(
|
||||
const ImageFrame& input, const std::array<float, 16>& matrix,
|
||||
const AffineTransformation::Size& size,
|
||||
@@ -142,19 +155,23 @@ class OpenCvRunner
|
||||
|
||||
cv::warpAffine(in_mat, out_mat, cv_affine_transform,
|
||||
cv::Size(out_mat.cols, out_mat.rows),
|
||||
/*flags=*/cv::INTER_LINEAR | cv::WARP_INVERSE_MAP,
|
||||
/*flags=*/interpolation_ | cv::WARP_INVERSE_MAP,
|
||||
GetBorderModeForOpenCv(border_mode));
|
||||
|
||||
return out_image;
|
||||
}
|
||||
|
||||
private:
|
||||
int interpolation_ = cv::INTER_LINEAR;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
absl::StatusOr<
|
||||
std::unique_ptr<AffineTransformation::Runner<ImageFrame, ImageFrame>>>
|
||||
CreateAffineTransformationOpenCvRunner() {
|
||||
return absl::make_unique<OpenCvRunner>();
|
||||
CreateAffineTransformationOpenCvRunner(
|
||||
AffineTransformation::Interpolation interpolation) {
|
||||
return absl::make_unique<OpenCvRunner>(interpolation);
|
||||
}
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -25,7 +25,8 @@ namespace mediapipe {
|
||||
|
||||
absl::StatusOr<
|
||||
std::unique_ptr<AffineTransformation::Runner<ImageFrame, ImageFrame>>>
|
||||
CreateAffineTransformationOpenCvRunner();
|
||||
CreateAffineTransformationOpenCvRunner(
|
||||
AffineTransformation::Interpolation interpolation);
|
||||
|
||||
} // namespace mediapipe
|
||||
|
||||
|
||||
@@ -81,7 +81,8 @@ class ImageCloneCalculator : public Node {
|
||||
absl::Status Process(CalculatorContext* cc) override {
|
||||
std::unique_ptr<Image> output;
|
||||
const auto& input = *kIn(cc);
|
||||
if (input.UsesGpu()) {
|
||||
bool input_on_gpu = input.UsesGpu();
|
||||
if (input_on_gpu) {
|
||||
#if !MEDIAPIPE_DISABLE_GPU
|
||||
// Create an output Image that co-owns the underlying texture buffer as
|
||||
// the input Image.
|
||||
@@ -97,15 +98,15 @@ class ImageCloneCalculator : public Node {
|
||||
// Image. This ensures a correct life span of the shared pixel data.
|
||||
output = std::make_unique<Image>(std::make_unique<mediapipe::ImageFrame>(
|
||||
input.image_format(), input.width(), input.height(), input.step(),
|
||||
const_cast<uint8*>(input.GetImageFrameSharedPtr()->PixelData()),
|
||||
[packet_copy_ptr](uint8*) { delete packet_copy_ptr; }));
|
||||
const_cast<uint8_t*>(input.GetImageFrameSharedPtr()->PixelData()),
|
||||
[packet_copy_ptr](uint8_t*) { delete packet_copy_ptr; }));
|
||||
}
|
||||
|
||||
if (output_on_gpu_) {
|
||||
if (output_on_gpu_ && !input_on_gpu) {
|
||||
#if !MEDIAPIPE_DISABLE_GPU
|
||||
gpu_helper_.RunInGlContext([&output]() { output->ConvertToGpu(); });
|
||||
#endif // !MEDIAPIPE_DISABLE_GPU
|
||||
} else {
|
||||
} else if (!output_on_gpu_ && input_on_gpu) {
|
||||
output->ConvertToCpu();
|
||||
}
|
||||
kOut(cc).Send(std::move(output));
|
||||
|
||||
@@ -75,16 +75,16 @@ absl::Status FindInterpolationAlgorithm(
|
||||
|
||||
void CropImageFrame(const ImageFrame& original, int col_start, int row_start,
|
||||
int crop_width, int crop_height, ImageFrame* cropped) {
|
||||
const uint8* src = original.PixelData();
|
||||
uint8* dst = cropped->MutablePixelData();
|
||||
const uint8_t* src = original.PixelData();
|
||||
uint8_t* dst = cropped->MutablePixelData();
|
||||
|
||||
int des_y = 0;
|
||||
for (int y = row_start; y < row_start + crop_height; ++y) {
|
||||
const uint8* src_line = src + y * original.WidthStep();
|
||||
const uint8* src_pixel = src_line + col_start *
|
||||
original.NumberOfChannels() *
|
||||
original.ByteDepth();
|
||||
uint8* dst_line = dst + des_y * cropped->WidthStep();
|
||||
const uint8_t* src_line = src + y * original.WidthStep();
|
||||
const uint8_t* src_pixel = src_line + col_start *
|
||||
original.NumberOfChannels() *
|
||||
original.ByteDepth();
|
||||
uint8_t* dst_line = dst + des_y * cropped->WidthStep();
|
||||
std::memcpy(
|
||||
dst_line, src_pixel,
|
||||
crop_width * cropped->NumberOfChannels() * cropped->ByteDepth());
|
||||
@@ -591,9 +591,9 @@ absl::Status ScaleImageCalculator::Process(CalculatorContext* cc) {
|
||||
const int y_size = output_width_ * output_height_;
|
||||
const int uv_size = output_width_ * output_height_ / 4;
|
||||
std::unique_ptr<uint8_t[]> yuv_data(new uint8_t[y_size + uv_size * 2]);
|
||||
uint8* y = yuv_data.get();
|
||||
uint8* u = y + y_size;
|
||||
uint8* v = u + uv_size;
|
||||
uint8_t* y = yuv_data.get();
|
||||
uint8_t* u = y + y_size;
|
||||
uint8_t* v = u + uv_size;
|
||||
RET_CHECK_EQ(0, I420Scale(yuv_image->data(0), yuv_image->stride(0),
|
||||
yuv_image->data(1), yuv_image->stride(1),
|
||||
yuv_image->data(2), yuv_image->stride(2),
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "mediapipe/framework/formats/image_frame_opencv.h"
|
||||
#include "mediapipe/framework/port/logging.h"
|
||||
#include "mediapipe/framework/port/opencv_core_inc.h"
|
||||
#include "mediapipe/framework/port/opencv_imgproc_inc.h"
|
||||
#include "mediapipe/framework/port/status.h"
|
||||
#include "mediapipe/framework/port/vector.h"
|
||||
|
||||
@@ -53,24 +54,16 @@ enum { ATTRIB_VERTEX, ATTRIB_TEXTURE_POSITION, NUM_ATTRIBUTES };
|
||||
// range of [0, 1). Only the first channel of Alpha is used. Input & output Mat
|
||||
// must be uchar.
|
||||
template <typename AlphaType>
|
||||
absl::Status MergeRGBA8Image(const cv::Mat input_mat, const cv::Mat& alpha_mat,
|
||||
cv::Mat& output_mat) {
|
||||
RET_CHECK_EQ(input_mat.rows, alpha_mat.rows);
|
||||
RET_CHECK_EQ(input_mat.cols, alpha_mat.cols);
|
||||
RET_CHECK_EQ(input_mat.rows, output_mat.rows);
|
||||
RET_CHECK_EQ(input_mat.cols, output_mat.cols);
|
||||
absl::Status CopyAlphaImage(const cv::Mat& alpha_mat, cv::Mat& output_mat) {
|
||||
RET_CHECK_EQ(output_mat.rows, alpha_mat.rows);
|
||||
RET_CHECK_EQ(output_mat.cols, alpha_mat.cols);
|
||||
|
||||
for (int i = 0; i < output_mat.rows; ++i) {
|
||||
const uchar* in_ptr = input_mat.ptr<uchar>(i);
|
||||
const AlphaType* alpha_ptr = alpha_mat.ptr<AlphaType>(i);
|
||||
uchar* out_ptr = output_mat.ptr<uchar>(i);
|
||||
for (int j = 0; j < output_mat.cols; ++j) {
|
||||
const int out_idx = j * kNumChannelsRGBA;
|
||||
const int in_idx = j * input_mat.channels();
|
||||
const int alpha_idx = j * alpha_mat.channels();
|
||||
out_ptr[out_idx + 0] = in_ptr[in_idx + 0];
|
||||
out_ptr[out_idx + 1] = in_ptr[in_idx + 1];
|
||||
out_ptr[out_idx + 2] = in_ptr[in_idx + 2];
|
||||
if constexpr (std::is_same<AlphaType, uchar>::value) {
|
||||
out_ptr[out_idx + 3] = alpha_ptr[alpha_idx + 0]; // channel 0 of mask
|
||||
} else {
|
||||
@@ -273,7 +266,7 @@ absl::Status SetAlphaCalculator::RenderCpu(CalculatorContext* cc) {
|
||||
|
||||
// Setup source image
|
||||
const auto& input_frame = cc->Inputs().Tag(kInputFrameTag).Get<ImageFrame>();
|
||||
const cv::Mat input_mat = mediapipe::formats::MatView(&input_frame);
|
||||
const cv::Mat input_mat = formats::MatView(&input_frame);
|
||||
if (!(input_mat.type() == CV_8UC3 || input_mat.type() == CV_8UC4)) {
|
||||
LOG(ERROR) << "Only 3 or 4 channel 8-bit input image supported";
|
||||
}
|
||||
@@ -281,38 +274,38 @@ absl::Status SetAlphaCalculator::RenderCpu(CalculatorContext* cc) {
|
||||
// Setup destination image
|
||||
auto output_frame = absl::make_unique<ImageFrame>(
|
||||
ImageFormat::SRGBA, input_mat.cols, input_mat.rows);
|
||||
cv::Mat output_mat = mediapipe::formats::MatView(output_frame.get());
|
||||
cv::Mat output_mat = formats::MatView(output_frame.get());
|
||||
|
||||
const bool has_alpha_mask = cc->Inputs().HasTag(kInputAlphaTag) &&
|
||||
!cc->Inputs().Tag(kInputAlphaTag).IsEmpty();
|
||||
const bool use_alpha_mask = alpha_value_ < 0 && has_alpha_mask;
|
||||
|
||||
// Setup alpha image and Update image in CPU.
|
||||
// Copy rgb part of the image in CPU
|
||||
if (input_mat.channels() == 3) {
|
||||
cv::cvtColor(input_mat, output_mat, cv::COLOR_RGB2RGBA);
|
||||
} else {
|
||||
input_mat.copyTo(output_mat);
|
||||
}
|
||||
|
||||
// Setup alpha image in CPU.
|
||||
if (use_alpha_mask) {
|
||||
const auto& alpha_mask = cc->Inputs().Tag(kInputAlphaTag).Get<ImageFrame>();
|
||||
cv::Mat alpha_mat = mediapipe::formats::MatView(&alpha_mask);
|
||||
cv::Mat alpha_mat = formats::MatView(&alpha_mask);
|
||||
|
||||
const bool alpha_is_float = CV_MAT_DEPTH(alpha_mat.type()) == CV_32F;
|
||||
RET_CHECK(alpha_is_float || CV_MAT_DEPTH(alpha_mat.type()) == CV_8U);
|
||||
|
||||
if (alpha_is_float) {
|
||||
MP_RETURN_IF_ERROR(
|
||||
MergeRGBA8Image<float>(input_mat, alpha_mat, output_mat));
|
||||
MP_RETURN_IF_ERROR(CopyAlphaImage<float>(alpha_mat, output_mat));
|
||||
} else {
|
||||
MP_RETURN_IF_ERROR(
|
||||
MergeRGBA8Image<uchar>(input_mat, alpha_mat, output_mat));
|
||||
MP_RETURN_IF_ERROR(CopyAlphaImage<uchar>(alpha_mat, output_mat));
|
||||
}
|
||||
} else {
|
||||
const uchar alpha_value = std::min(std::max(0.0f, alpha_value_), 255.0f);
|
||||
for (int i = 0; i < output_mat.rows; ++i) {
|
||||
const uchar* in_ptr = input_mat.ptr<uchar>(i);
|
||||
uchar* out_ptr = output_mat.ptr<uchar>(i);
|
||||
for (int j = 0; j < output_mat.cols; ++j) {
|
||||
const int out_idx = j * kNumChannelsRGBA;
|
||||
const int in_idx = j * input_mat.channels();
|
||||
out_ptr[out_idx + 0] = in_ptr[in_idx + 0];
|
||||
out_ptr[out_idx + 1] = in_ptr[in_idx + 1];
|
||||
out_ptr[out_idx + 2] = in_ptr[in_idx + 2];
|
||||
out_ptr[out_idx + 3] = alpha_value; // use value from options
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "mediapipe/calculators/image/set_alpha_calculator.pb.h"
|
||||
#include "mediapipe/framework/calculator_framework.h"
|
||||
#include "mediapipe/framework/calculator_runner.h"
|
||||
#include "mediapipe/framework/formats/image_frame_opencv.h"
|
||||
#include "mediapipe/framework/formats/rect.pb.h"
|
||||
#include "mediapipe/framework/port/gtest.h"
|
||||
#include "mediapipe/framework/port/opencv_core_inc.h"
|
||||
#include "mediapipe/framework/port/opencv_imgproc_inc.h"
|
||||
#include "mediapipe/framework/port/parse_text_proto.h"
|
||||
#include "mediapipe/framework/port/status_matchers.h"
|
||||
#include "testing/base/public/benchmark.h"
|
||||
|
||||
namespace mediapipe {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int input_width = 100;
|
||||
constexpr int input_height = 100;
|
||||
|
||||
std::unique_ptr<ImageFrame> GetInputFrame(int width, int height, int channel) {
|
||||
const int total_size = width * height * channel;
|
||||
|
||||
ImageFormat::Format image_format;
|
||||
if (channel == 4) {
|
||||
image_format = ImageFormat::SRGBA;
|
||||
} else if (channel == 3) {
|
||||
image_format = ImageFormat::SRGB;
|
||||
} else {
|
||||
image_format = ImageFormat::GRAY8;
|
||||
}
|
||||
|
||||
auto input_frame = std::make_unique<ImageFrame>(image_format, width, height,
|
||||
/*alignment_boundary =*/1);
|
||||
for (int i = 0; i < total_size; ++i) {
|
||||
input_frame->MutablePixelData()[i] = i % 256;
|
||||
}
|
||||
return input_frame;
|
||||
}
|
||||
|
||||
// Test SetAlphaCalculator with RGB IMAGE input.
|
||||
TEST(SetAlphaCalculatorTest, CpuRgb) {
|
||||
auto calculator_node = ParseTextProtoOrDie<CalculatorGraphConfig::Node>(
|
||||
R"pb(
|
||||
calculator: "SetAlphaCalculator"
|
||||
input_stream: "IMAGE:input_frames"
|
||||
input_stream: "ALPHA:masks"
|
||||
output_stream: "IMAGE:output_frames"
|
||||
)pb");
|
||||
CalculatorRunner runner(calculator_node);
|
||||
|
||||
// Input frames.
|
||||
const auto input_frame = GetInputFrame(input_width, input_height, 3);
|
||||
const auto mask_frame = GetInputFrame(input_width, input_height, 1);
|
||||
auto input_frame_packet = MakePacket<ImageFrame>(std::move(*input_frame));
|
||||
auto mask_frame_packet = MakePacket<ImageFrame>(std::move(*mask_frame));
|
||||
runner.MutableInputs()->Tag("IMAGE").packets.push_back(
|
||||
input_frame_packet.At(Timestamp(1)));
|
||||
runner.MutableInputs()->Tag("ALPHA").packets.push_back(
|
||||
mask_frame_packet.At(Timestamp(1)));
|
||||
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const auto& outputs = runner.Outputs();
|
||||
EXPECT_EQ(outputs.NumEntries(), 1);
|
||||
const auto& output_image = outputs.Tag("IMAGE").packets[0].Get<ImageFrame>();
|
||||
|
||||
// Generate ground truth (expected_mat).
|
||||
const auto image = GetInputFrame(input_width, input_height, 3);
|
||||
const auto input_mat = formats::MatView(image.get());
|
||||
const auto mask = GetInputFrame(input_width, input_height, 1);
|
||||
const auto mask_mat = formats::MatView(mask.get());
|
||||
const std::array<cv::Mat, 2> input_mats = {input_mat, mask_mat};
|
||||
cv::Mat expected_mat(input_width, input_height, CV_8UC4);
|
||||
cv::mixChannels(input_mats, {expected_mat}, {0, 0, 1, 1, 2, 2, 3, 3});
|
||||
|
||||
cv::Mat output_mat = formats::MatView(&output_image);
|
||||
double max_diff = cv::norm(expected_mat, output_mat, cv::NORM_INF);
|
||||
EXPECT_FLOAT_EQ(max_diff, 0);
|
||||
} // TEST
|
||||
|
||||
// Test SetAlphaCalculator with RGBA IMAGE input.
|
||||
TEST(SetAlphaCalculatorTest, CpuRgba) {
|
||||
auto calculator_node = ParseTextProtoOrDie<CalculatorGraphConfig::Node>(
|
||||
R"pb(
|
||||
calculator: "SetAlphaCalculator"
|
||||
input_stream: "IMAGE:input_frames"
|
||||
input_stream: "ALPHA:masks"
|
||||
output_stream: "IMAGE:output_frames"
|
||||
)pb");
|
||||
CalculatorRunner runner(calculator_node);
|
||||
|
||||
// Input frames.
|
||||
const auto input_frame = GetInputFrame(input_width, input_height, 4);
|
||||
const auto mask_frame = GetInputFrame(input_width, input_height, 1);
|
||||
auto input_frame_packet = MakePacket<ImageFrame>(std::move(*input_frame));
|
||||
auto mask_frame_packet = MakePacket<ImageFrame>(std::move(*mask_frame));
|
||||
runner.MutableInputs()->Tag("IMAGE").packets.push_back(
|
||||
input_frame_packet.At(Timestamp(1)));
|
||||
runner.MutableInputs()->Tag("ALPHA").packets.push_back(
|
||||
mask_frame_packet.At(Timestamp(1)));
|
||||
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
|
||||
const auto& outputs = runner.Outputs();
|
||||
EXPECT_EQ(outputs.NumEntries(), 1);
|
||||
const auto& output_image = outputs.Tag("IMAGE").packets[0].Get<ImageFrame>();
|
||||
|
||||
// Generate ground truth (expected_mat).
|
||||
const auto image = GetInputFrame(input_width, input_height, 4);
|
||||
const auto input_mat = formats::MatView(image.get());
|
||||
const auto mask = GetInputFrame(input_width, input_height, 1);
|
||||
const auto mask_mat = formats::MatView(mask.get());
|
||||
const std::array<cv::Mat, 2> input_mats = {input_mat, mask_mat};
|
||||
cv::Mat expected_mat(input_width, input_height, CV_8UC4);
|
||||
cv::mixChannels(input_mats, {expected_mat}, {0, 0, 1, 1, 2, 2, 4, 3});
|
||||
|
||||
cv::Mat output_mat = formats::MatView(&output_image);
|
||||
double max_diff = cv::norm(expected_mat, output_mat, cv::NORM_INF);
|
||||
EXPECT_FLOAT_EQ(max_diff, 0);
|
||||
} // TEST
|
||||
|
||||
static void BM_SetAlpha3ChannelImage(benchmark::State& state) {
|
||||
auto calculator_node = ParseTextProtoOrDie<CalculatorGraphConfig::Node>(
|
||||
R"pb(
|
||||
calculator: "SetAlphaCalculator"
|
||||
input_stream: "IMAGE:input_frames"
|
||||
input_stream: "ALPHA:masks"
|
||||
output_stream: "IMAGE:output_frames"
|
||||
)pb");
|
||||
CalculatorRunner runner(calculator_node);
|
||||
|
||||
// Input frames.
|
||||
const auto input_frame = GetInputFrame(input_width, input_height, 3);
|
||||
const auto mask_frame = GetInputFrame(input_width, input_height, 1);
|
||||
auto input_frame_packet = MakePacket<ImageFrame>(std::move(*input_frame));
|
||||
auto mask_frame_packet = MakePacket<ImageFrame>(std::move(*mask_frame));
|
||||
runner.MutableInputs()->Tag("IMAGE").packets.push_back(
|
||||
input_frame_packet.At(Timestamp(1)));
|
||||
runner.MutableInputs()->Tag("ALPHA").packets.push_back(
|
||||
mask_frame_packet.At(Timestamp(1)));
|
||||
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
const auto& outputs = runner.Outputs();
|
||||
ASSERT_EQ(1, outputs.NumEntries());
|
||||
|
||||
for (const auto _ : state) {
|
||||
MP_ASSERT_OK(runner.Run());
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(BM_SetAlpha3ChannelImage);
|
||||
|
||||
} // namespace
|
||||
} // namespace mediapipe
|
||||
@@ -53,6 +53,17 @@ AffineTransformation::BorderMode GetBorderMode(
|
||||
}
|
||||
}
|
||||
|
||||
AffineTransformation::Interpolation GetInterpolation(
|
||||
mediapipe::WarpAffineCalculatorOptions::Interpolation interpolation) {
|
||||
switch (interpolation) {
|
||||
case mediapipe::WarpAffineCalculatorOptions::INTER_UNSPECIFIED:
|
||||
case mediapipe::WarpAffineCalculatorOptions::INTER_LINEAR:
|
||||
return AffineTransformation::Interpolation::kLinear;
|
||||
case mediapipe::WarpAffineCalculatorOptions::INTER_CUBIC:
|
||||
return AffineTransformation::Interpolation::kCubic;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ImageT>
|
||||
class WarpAffineRunnerHolder {};
|
||||
|
||||
@@ -61,16 +72,22 @@ template <>
|
||||
class WarpAffineRunnerHolder<ImageFrame> {
|
||||
public:
|
||||
using RunnerType = AffineTransformation::Runner<ImageFrame, ImageFrame>;
|
||||
absl::Status Open(CalculatorContext* cc) { return absl::OkStatus(); }
|
||||
absl::Status Open(CalculatorContext* cc) {
|
||||
interpolation_ = GetInterpolation(
|
||||
cc->Options<mediapipe::WarpAffineCalculatorOptions>().interpolation());
|
||||
return absl::OkStatus();
|
||||
}
|
||||
absl::StatusOr<RunnerType*> GetRunner() {
|
||||
if (!runner_) {
|
||||
ASSIGN_OR_RETURN(runner_, CreateAffineTransformationOpenCvRunner());
|
||||
ASSIGN_OR_RETURN(runner_,
|
||||
CreateAffineTransformationOpenCvRunner(interpolation_));
|
||||
}
|
||||
return runner_.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<RunnerType> runner_;
|
||||
AffineTransformation::Interpolation interpolation_;
|
||||
};
|
||||
#endif // !MEDIAPIPE_DISABLE_OPENCV
|
||||
|
||||
@@ -85,12 +102,14 @@ class WarpAffineRunnerHolder<mediapipe::GpuBuffer> {
|
||||
gpu_origin_ =
|
||||
cc->Options<mediapipe::WarpAffineCalculatorOptions>().gpu_origin();
|
||||
gl_helper_ = std::make_shared<mediapipe::GlCalculatorHelper>();
|
||||
interpolation_ = GetInterpolation(
|
||||
cc->Options<mediapipe::WarpAffineCalculatorOptions>().interpolation());
|
||||
return gl_helper_->Open(cc);
|
||||
}
|
||||
absl::StatusOr<RunnerType*> GetRunner() {
|
||||
if (!runner_) {
|
||||
ASSIGN_OR_RETURN(
|
||||
runner_, CreateAffineTransformationGlRunner(gl_helper_, gpu_origin_));
|
||||
ASSIGN_OR_RETURN(runner_, CreateAffineTransformationGlRunner(
|
||||
gl_helper_, gpu_origin_, interpolation_));
|
||||
}
|
||||
return runner_.get();
|
||||
}
|
||||
@@ -99,6 +118,7 @@ class WarpAffineRunnerHolder<mediapipe::GpuBuffer> {
|
||||
mediapipe::GpuOrigin::Mode gpu_origin_;
|
||||
std::shared_ptr<mediapipe::GlCalculatorHelper> gl_helper_;
|
||||
std::unique_ptr<RunnerType> runner_;
|
||||
AffineTransformation::Interpolation interpolation_;
|
||||
};
|
||||
#endif // !MEDIAPIPE_DISABLE_GPU
|
||||
|
||||
@@ -146,7 +166,7 @@ class WarpAffineRunnerHolder<mediapipe::Image> {
|
||||
const ImageFrame image_frame(frame_ptr->Format(), frame_ptr->Width(),
|
||||
frame_ptr->Height(), frame_ptr->WidthStep(),
|
||||
const_cast<uint8_t*>(frame_ptr->PixelData()),
|
||||
[](uint8* data){});
|
||||
[](uint8_t* data){});
|
||||
ASSIGN_OR_RETURN(auto result,
|
||||
runner->Run(image_frame, matrix, size, border_mode));
|
||||
return mediapipe::Image(std::make_shared<ImageFrame>(std::move(result)));
|
||||
|
||||
@@ -31,6 +31,13 @@ message WarpAffineCalculatorOptions {
|
||||
BORDER_REPLICATE = 2;
|
||||
}
|
||||
|
||||
// Pixel sampling interpolation methods. See @interpolation.
|
||||
enum Interpolation {
|
||||
INTER_UNSPECIFIED = 0;
|
||||
INTER_LINEAR = 1;
|
||||
INTER_CUBIC = 2;
|
||||
}
|
||||
|
||||
// Pixel extrapolation method.
|
||||
// When converting image to tensor it may happen that tensor needs to read
|
||||
// pixels outside image boundaries. Border mode helps to specify how such
|
||||
@@ -43,4 +50,10 @@ message WarpAffineCalculatorOptions {
|
||||
// to be flipped vertically as tensors are expected to start at top.
|
||||
// (DEFAULT or unset interpreted as CONVENTIONAL.)
|
||||
optional GpuOrigin.Mode gpu_origin = 2;
|
||||
|
||||
// Sampling method for neighboring pixels.
|
||||
// INTER_LINEAR (bilinear) linearly interpolates from the nearest 4 neighbors.
|
||||
// INTER_CUBIC (bicubic) interpolates a small neighborhood with cubic weights.
|
||||
// INTER_UNSPECIFIED or unset interpreted as INTER_LINEAR.
|
||||
optional Interpolation interpolation = 3;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ void RunTest(const std::string& graph_text, const std::string& tag,
|
||||
const cv::Mat& input, cv::Mat expected_result,
|
||||
float similarity_threshold, std::array<float, 16> matrix,
|
||||
int out_width, int out_height,
|
||||
absl::optional<AffineTransformation::BorderMode> border_mode) {
|
||||
std::optional<AffineTransformation::BorderMode> border_mode,
|
||||
std::optional<AffineTransformation::Interpolation> interpolation) {
|
||||
std::string border_mode_str;
|
||||
if (border_mode) {
|
||||
switch (*border_mode) {
|
||||
@@ -75,8 +76,20 @@ void RunTest(const std::string& graph_text, const std::string& tag,
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string interpolation_str;
|
||||
if (interpolation) {
|
||||
switch (*interpolation) {
|
||||
case AffineTransformation::Interpolation::kLinear:
|
||||
interpolation_str = "interpolation: INTER_LINEAR";
|
||||
break;
|
||||
case AffineTransformation::Interpolation::kCubic:
|
||||
interpolation_str = "interpolation: INTER_CUBIC";
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto graph_config = mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(
|
||||
absl::Substitute(graph_text, /*$0=*/border_mode_str));
|
||||
absl::Substitute(graph_text, /*$0=*/border_mode_str,
|
||||
/*$1=*/interpolation_str));
|
||||
|
||||
std::vector<Packet> output_packets;
|
||||
tool::AddVectorSink("output_image", &graph_config, &output_packets);
|
||||
@@ -88,7 +101,7 @@ void RunTest(const std::string& graph_text, const std::string& tag,
|
||||
|
||||
ImageFrame input_image(
|
||||
input.channels() == 4 ? ImageFormat::SRGBA : ImageFormat::SRGB,
|
||||
input.cols, input.rows, input.step, input.data, [](uint8*) {});
|
||||
input.cols, input.rows, input.step, input.data, [](uint8_t*) {});
|
||||
MP_ASSERT_OK(graph.AddPacketToInputStream(
|
||||
"input_image",
|
||||
MakePacket<ImageFrame>(std::move(input_image)).At(Timestamp(0))));
|
||||
@@ -132,7 +145,8 @@ struct SimilarityConfig {
|
||||
void RunTest(cv::Mat input, cv::Mat expected_result,
|
||||
const SimilarityConfig& similarity, std::array<float, 16> matrix,
|
||||
int out_width, int out_height,
|
||||
absl::optional<AffineTransformation::BorderMode> border_mode) {
|
||||
std::optional<AffineTransformation::BorderMode> border_mode,
|
||||
std::optional<AffineTransformation::Interpolation> interpolation) {
|
||||
RunTest(R"(
|
||||
input_stream: "input_image"
|
||||
input_stream: "output_size"
|
||||
@@ -146,12 +160,13 @@ void RunTest(cv::Mat input, cv::Mat expected_result,
|
||||
options {
|
||||
[mediapipe.WarpAffineCalculatorOptions.ext] {
|
||||
$0 # border mode
|
||||
$1 # interpolation
|
||||
}
|
||||
}
|
||||
}
|
||||
)",
|
||||
"cpu", input, expected_result, similarity.threshold_on_cpu, matrix,
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
|
||||
RunTest(R"(
|
||||
input_stream: "input_image"
|
||||
@@ -171,6 +186,7 @@ void RunTest(cv::Mat input, cv::Mat expected_result,
|
||||
options {
|
||||
[mediapipe.WarpAffineCalculatorOptions.ext] {
|
||||
$0 # border mode
|
||||
$1 # interpolation
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +197,7 @@ void RunTest(cv::Mat input, cv::Mat expected_result,
|
||||
}
|
||||
)",
|
||||
"cpu_image", input, expected_result, similarity.threshold_on_cpu,
|
||||
matrix, out_width, out_height, border_mode);
|
||||
matrix, out_width, out_height, border_mode, interpolation);
|
||||
|
||||
RunTest(R"(
|
||||
input_stream: "input_image"
|
||||
@@ -201,6 +217,7 @@ void RunTest(cv::Mat input, cv::Mat expected_result,
|
||||
options {
|
||||
[mediapipe.WarpAffineCalculatorOptions.ext] {
|
||||
$0 # border mode
|
||||
$1 # interpolation
|
||||
gpu_origin: TOP_LEFT
|
||||
}
|
||||
}
|
||||
@@ -212,7 +229,7 @@ void RunTest(cv::Mat input, cv::Mat expected_result,
|
||||
}
|
||||
)",
|
||||
"gpu", input, expected_result, similarity.threshold_on_gpu, matrix,
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
|
||||
RunTest(R"(
|
||||
input_stream: "input_image"
|
||||
@@ -237,6 +254,7 @@ void RunTest(cv::Mat input, cv::Mat expected_result,
|
||||
options {
|
||||
[mediapipe.WarpAffineCalculatorOptions.ext] {
|
||||
$0 # border mode
|
||||
$1 # interpolation
|
||||
gpu_origin: TOP_LEFT
|
||||
}
|
||||
}
|
||||
@@ -253,7 +271,7 @@ void RunTest(cv::Mat input, cv::Mat expected_result,
|
||||
}
|
||||
)",
|
||||
"gpu_image", input, expected_result, similarity.threshold_on_gpu,
|
||||
matrix, out_width, out_height, border_mode);
|
||||
matrix, out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
std::array<float, 16> GetMatrix(cv::Mat input, mediapipe::NormalizedRect roi,
|
||||
@@ -287,10 +305,11 @@ TEST(WarpAffineCalculatorTest, MediumSubRectKeepAspect) {
|
||||
int out_height = 256;
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode = {};
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.82},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, MediumSubRectKeepAspectBorderZero) {
|
||||
@@ -312,10 +331,11 @@ TEST(WarpAffineCalculatorTest, MediumSubRectKeepAspectBorderZero) {
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kZero;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.81},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, MediumSubRectKeepAspectWithRotation) {
|
||||
@@ -337,10 +357,11 @@ TEST(WarpAffineCalculatorTest, MediumSubRectKeepAspectWithRotation) {
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kReplicate;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.77},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, MediumSubRectKeepAspectWithRotationBorderZero) {
|
||||
@@ -362,10 +383,11 @@ TEST(WarpAffineCalculatorTest, MediumSubRectKeepAspectWithRotationBorderZero) {
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kZero;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.75},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, MediumSubRectWithRotation) {
|
||||
@@ -386,10 +408,11 @@ TEST(WarpAffineCalculatorTest, MediumSubRectWithRotation) {
|
||||
bool keep_aspect_ratio = false;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kReplicate;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.81},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, MediumSubRectWithRotationBorderZero) {
|
||||
@@ -411,10 +434,38 @@ TEST(WarpAffineCalculatorTest, MediumSubRectWithRotationBorderZero) {
|
||||
bool keep_aspect_ratio = false;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kZero;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.80},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, MediumSubRectWithRotationBorderZeroInterpCubic) {
|
||||
mediapipe::NormalizedRect roi;
|
||||
roi.set_x_center(0.65f);
|
||||
roi.set_y_center(0.4f);
|
||||
roi.set_width(0.5f);
|
||||
roi.set_height(0.5f);
|
||||
roi.set_rotation(M_PI * -45.0f / 180.0f);
|
||||
auto input = GetRgb(
|
||||
"/mediapipe/calculators/"
|
||||
"tensor/testdata/image_to_tensor/input.jpg");
|
||||
auto expected_output = GetRgb(
|
||||
"/mediapipe/calculators/"
|
||||
"tensor/testdata/image_to_tensor/"
|
||||
"medium_sub_rect_with_rotation_border_zero_interp_cubic.png");
|
||||
int out_width = 256;
|
||||
int out_height = 256;
|
||||
bool keep_aspect_ratio = false;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kZero;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation =
|
||||
AffineTransformation::Interpolation::kCubic;
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.78},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, LargeSubRect) {
|
||||
@@ -435,10 +486,11 @@ TEST(WarpAffineCalculatorTest, LargeSubRect) {
|
||||
bool keep_aspect_ratio = false;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kReplicate;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.95},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, LargeSubRectBorderZero) {
|
||||
@@ -459,10 +511,11 @@ TEST(WarpAffineCalculatorTest, LargeSubRectBorderZero) {
|
||||
bool keep_aspect_ratio = false;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kZero;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.92},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, LargeSubRectKeepAspect) {
|
||||
@@ -483,10 +536,11 @@ TEST(WarpAffineCalculatorTest, LargeSubRectKeepAspect) {
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kReplicate;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.97},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, LargeSubRectKeepAspectBorderZero) {
|
||||
@@ -508,10 +562,11 @@ TEST(WarpAffineCalculatorTest, LargeSubRectKeepAspectBorderZero) {
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kZero;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.97},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, LargeSubRectKeepAspectWithRotation) {
|
||||
@@ -532,10 +587,11 @@ TEST(WarpAffineCalculatorTest, LargeSubRectKeepAspectWithRotation) {
|
||||
int out_height = 128;
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode = {};
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.91},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, LargeSubRectKeepAspectWithRotationBorderZero) {
|
||||
@@ -557,10 +613,11 @@ TEST(WarpAffineCalculatorTest, LargeSubRectKeepAspectWithRotationBorderZero) {
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kZero;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.88},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, NoOp) {
|
||||
@@ -581,10 +638,11 @@ TEST(WarpAffineCalculatorTest, NoOp) {
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kReplicate;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.99},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
TEST(WarpAffineCalculatorTest, NoOpBorderZero) {
|
||||
@@ -605,10 +663,11 @@ TEST(WarpAffineCalculatorTest, NoOpBorderZero) {
|
||||
bool keep_aspect_ratio = true;
|
||||
std::optional<AffineTransformation::BorderMode> border_mode =
|
||||
AffineTransformation::BorderMode::kZero;
|
||||
std::optional<AffineTransformation::Interpolation> interpolation = {};
|
||||
RunTest(input, expected_output,
|
||||
{.threshold_on_cpu = 0.99, .threshold_on_gpu = 0.99},
|
||||
GetMatrix(input, roi, keep_aspect_ratio, out_width, out_height),
|
||||
out_width, out_height, border_mode);
|
||||
out_width, out_height, border_mode, interpolation);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -12,25 +12,20 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_cc_proto_library")
|
||||
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_proto_library")
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
package(default_visibility = ["//visibility:private"])
|
||||
|
||||
proto_library(
|
||||
mediapipe_proto_library(
|
||||
name = "callback_packet_calculator_proto",
|
||||
srcs = ["callback_packet_calculator.proto"],
|
||||
visibility = ["//mediapipe/framework:__subpackages__"],
|
||||
deps = ["//mediapipe/framework:calculator_proto"],
|
||||
)
|
||||
|
||||
mediapipe_cc_proto_library(
|
||||
name = "callback_packet_calculator_cc_proto",
|
||||
srcs = ["callback_packet_calculator.proto"],
|
||||
cc_deps = ["//mediapipe/framework:calculator_cc_proto"],
|
||||
visibility = ["//mediapipe/framework:__subpackages__"],
|
||||
deps = [":callback_packet_calculator_proto"],
|
||||
deps = [
|
||||
"//mediapipe/framework:calculator_options_proto",
|
||||
"//mediapipe/framework:calculator_proto",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
|
||||
@@ -237,7 +237,9 @@ cc_library(
|
||||
cc_test(
|
||||
name = "bert_preprocessor_calculator_test",
|
||||
srcs = ["bert_preprocessor_calculator_test.cc"],
|
||||
data = ["//mediapipe/tasks/testdata/text:bert_text_classifier_models"],
|
||||
data = [
|
||||
"//mediapipe/tasks/testdata/text:bert_text_classifier_models",
|
||||
],
|
||||
linkopts = ["-ldl"],
|
||||
deps = [
|
||||
":bert_preprocessor_calculator",
|
||||
@@ -250,7 +252,7 @@ cc_test(
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_sentencepiece//src:sentencepiece_processor",
|
||||
"@com_google_sentencepiece//src:sentencepiece_processor", # fixdeps: keep
|
||||
],
|
||||
)
|
||||
|
||||
@@ -300,7 +302,7 @@ cc_test(
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_sentencepiece//src:sentencepiece_processor",
|
||||
"@com_google_sentencepiece//src:sentencepiece_processor", # fixdeps: keep
|
||||
],
|
||||
)
|
||||
|
||||
@@ -399,8 +401,8 @@ cc_library_with_tflite(
|
||||
hdrs = ["inference_calculator.h"],
|
||||
tflite_deps = [
|
||||
"//mediapipe/util/tflite:tflite_model_loader",
|
||||
"@org_tensorflow//tensorflow/lite/core/shims:framework_stable",
|
||||
"@org_tensorflow//tensorflow/lite/core/shims:builtin_ops",
|
||||
"@org_tensorflow//tensorflow/lite:framework_stable",
|
||||
"@org_tensorflow//tensorflow/lite/kernels:builtin_ops",
|
||||
],
|
||||
deps = [
|
||||
":inference_calculator_cc_proto",
|
||||
@@ -442,12 +444,12 @@ cc_library(
|
||||
tags = ["nomac"],
|
||||
deps = [
|
||||
":inference_calculator_interface",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"//mediapipe/framework/deps:file_path",
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/util/tflite:tflite_gpu_runner",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@org_tensorflow//tensorflow/lite:framework_stable",
|
||||
] + select({
|
||||
"//conditions:default": [],
|
||||
@@ -465,10 +467,6 @@ cc_library(
|
||||
"-x objective-c++",
|
||||
"-fobjc-arc", # enable reference-counting
|
||||
],
|
||||
linkopts = [
|
||||
"-framework CoreVideo",
|
||||
"-framework MetalKit",
|
||||
],
|
||||
tags = ["ios"],
|
||||
deps = [
|
||||
"inference_calculator_interface",
|
||||
@@ -484,7 +482,13 @@ cc_library(
|
||||
"@org_tensorflow//tensorflow/lite/delegates/gpu:metal_delegate_internal",
|
||||
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:shape",
|
||||
"@org_tensorflow//tensorflow/lite/delegates/gpu/metal:buffer_convert",
|
||||
],
|
||||
] + select({
|
||||
"//mediapipe:apple": [
|
||||
"//third_party/apple_frameworks:CoreVideo",
|
||||
"//third_party/apple_frameworks:MetalKit",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
alwayslink = 1,
|
||||
)
|
||||
|
||||
@@ -502,7 +506,7 @@ cc_library_with_tflite(
|
||||
name = "tflite_delegate_ptr",
|
||||
hdrs = ["tflite_delegate_ptr.h"],
|
||||
tflite_deps = [
|
||||
"@org_tensorflow//tensorflow/lite/core/shims:c_api_types",
|
||||
"@org_tensorflow//tensorflow/lite/c:c_api_types",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -513,8 +517,8 @@ cc_library_with_tflite(
|
||||
tflite_deps = [
|
||||
":tflite_delegate_ptr",
|
||||
"//mediapipe/util/tflite:tflite_model_loader",
|
||||
"@org_tensorflow//tensorflow/lite/core/shims:c_api_types",
|
||||
"@org_tensorflow//tensorflow/lite/core/shims:framework_stable",
|
||||
"@org_tensorflow//tensorflow/lite:framework_stable",
|
||||
"@org_tensorflow//tensorflow/lite/c:c_api_types",
|
||||
],
|
||||
deps = [
|
||||
":inference_runner",
|
||||
@@ -542,8 +546,8 @@ cc_library(
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@org_tensorflow//tensorflow/lite/core/shims:c_api_types",
|
||||
"@org_tensorflow//tensorflow/lite/core/shims:framework_stable",
|
||||
"@org_tensorflow//tensorflow/lite:framework_stable",
|
||||
"@org_tensorflow//tensorflow/lite/c:c_api_types",
|
||||
"@org_tensorflow//tensorflow/lite/delegates/xnnpack:xnnpack_delegate",
|
||||
] + select({
|
||||
"//conditions:default": [],
|
||||
@@ -603,8 +607,8 @@ cc_library(
|
||||
cc_library(
|
||||
name = "inference_calculator",
|
||||
deps = [
|
||||
":inference_calculator_interface",
|
||||
":inference_calculator_cpu",
|
||||
":inference_calculator_interface",
|
||||
] + select({
|
||||
"//conditions:default": [":inference_calculator_gl_if_compute_shader_available"],
|
||||
":platform_ios_with_gpu": [":inference_calculator_metal"],
|
||||
@@ -642,11 +646,11 @@ cc_library(
|
||||
deps = [
|
||||
":tensor_converter_calculator_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:port",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/formats:matrix",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework:port",
|
||||
"//mediapipe/util:resource_util",
|
||||
] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
@@ -664,16 +668,16 @@ cc_library(
|
||||
"//mediapipe/gpu:gpu_buffer",
|
||||
],
|
||||
"//mediapipe:ios": [
|
||||
"//mediapipe/gpu:MPPMetalUtil",
|
||||
"//mediapipe/gpu:MPPMetalHelper",
|
||||
"//mediapipe/gpu:MPPMetalUtil",
|
||||
"//mediapipe/objc:mediapipe_framework_ios",
|
||||
],
|
||||
"//mediapipe:macos": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
"//mediapipe/gpu:gpu_buffer",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
],
|
||||
}),
|
||||
)
|
||||
@@ -719,29 +723,28 @@ cc_library(
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
features = ["-layering_check"], # allow depending on tensors_to_detections_calculator_gpu_deps
|
||||
linkopts = select({
|
||||
"//mediapipe:apple": [
|
||||
"-framework CoreVideo",
|
||||
"-framework MetalKit",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = [
|
||||
":tensors_to_detections_calculator_cc_proto",
|
||||
"//mediapipe/framework/formats:detection_cc_proto",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
"@com_google_absl//absl/types:span",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/formats/object_detection:anchor_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:port",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/deps:file_path",
|
||||
"//mediapipe/framework/formats:detection_cc_proto",
|
||||
"//mediapipe/framework/formats:location",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/framework/formats/object_detection:anchor_cc_proto",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
"@com_google_absl//absl/types:span",
|
||||
] + selects.with_or({
|
||||
":compute_shader_unavailable": [],
|
||||
"//conditions:default": [":tensors_to_detections_calculator_gpu_deps"],
|
||||
}) + select({
|
||||
"//mediapipe:apple": [
|
||||
"//third_party/apple_frameworks:CoreVideo",
|
||||
"//third_party/apple_frameworks:MetalKit",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
alwayslink = 1,
|
||||
)
|
||||
@@ -751,8 +754,8 @@ cc_library(
|
||||
visibility = ["//visibility:private"],
|
||||
deps = select({
|
||||
"//mediapipe:ios": [
|
||||
"//mediapipe/gpu:MPPMetalUtil",
|
||||
"//mediapipe/gpu:MPPMetalHelper",
|
||||
"//mediapipe/gpu:MPPMetalUtil",
|
||||
],
|
||||
"//mediapipe:macos": [],
|
||||
"//conditions:default": [
|
||||
@@ -898,17 +901,17 @@ cc_library(
|
||||
}),
|
||||
deps = [
|
||||
":tensors_to_classification_calculator_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/formats:classification_cc_proto",
|
||||
"//mediapipe/framework/formats:location",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/util:label_map_cc_proto",
|
||||
"//mediapipe/util:resource_util",
|
||||
"@com_google_absl//absl/container:node_hash_map",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
"@com_google_absl//absl/types:span",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/formats:classification_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:location",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/util:label_map_cc_proto",
|
||||
"//mediapipe/util:resource_util",
|
||||
] + select({
|
||||
"//mediapipe:android": [
|
||||
"//mediapipe/util/android/file/base",
|
||||
@@ -968,6 +971,8 @@ cc_library(
|
||||
":image_to_tensor_converter",
|
||||
":image_to_tensor_utils",
|
||||
":loose_headers",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:port",
|
||||
"//mediapipe/framework/api2:node",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
@@ -976,8 +981,6 @@ cc_library(
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:statusor",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:port",
|
||||
"//mediapipe/gpu:gpu_origin_cc_proto",
|
||||
] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
@@ -985,6 +988,11 @@ cc_library(
|
||||
}) + select({
|
||||
"//mediapipe/framework/port:disable_opencv": [],
|
||||
"//conditions:default": [":image_to_tensor_converter_opencv"],
|
||||
}) + select({
|
||||
"//mediapipe/framework/port:enable_halide": [
|
||||
":image_to_tensor_converter_frame_buffer",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
alwayslink = 1,
|
||||
)
|
||||
@@ -997,17 +1005,20 @@ cc_library(
|
||||
":image_to_tensor_converter_gl_buffer",
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gpu_buffer",
|
||||
"//mediapipe/gpu:gpu_service",
|
||||
],
|
||||
"//mediapipe:apple": [
|
||||
":image_to_tensor_converter_metal",
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:MPPMetalHelper",
|
||||
"//mediapipe/gpu:gpu_buffer",
|
||||
"//mediapipe/gpu:gpu_service",
|
||||
],
|
||||
"//conditions:default": [
|
||||
":image_to_tensor_converter_gl_buffer",
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gpu_buffer",
|
||||
"//mediapipe/gpu:gpu_service",
|
||||
],
|
||||
}),
|
||||
)
|
||||
@@ -1065,7 +1076,10 @@ cc_test(
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
],
|
||||
] + select({
|
||||
"//mediapipe:apple": [],
|
||||
"//conditions:default": ["//mediapipe/gpu:gl_context"],
|
||||
}),
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@@ -1112,6 +1126,26 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "image_to_tensor_converter_frame_buffer",
|
||||
srcs = ["image_to_tensor_converter_frame_buffer.cc"],
|
||||
hdrs = ["image_to_tensor_converter_frame_buffer.h"],
|
||||
deps = [
|
||||
":image_to_tensor_converter",
|
||||
":image_to_tensor_utils",
|
||||
"//mediapipe/framework:calculator_context",
|
||||
"//mediapipe/framework/formats:frame_buffer",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/gpu:frame_buffer_view",
|
||||
"//mediapipe/util/frame_buffer:frame_buffer_util",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "image_to_tensor_converter_gl_buffer",
|
||||
srcs = ["image_to_tensor_converter_gl_buffer.cc"],
|
||||
@@ -1157,16 +1191,16 @@ cc_library(
|
||||
":image_to_tensor_converter",
|
||||
":image_to_tensor_converter_gl_utils",
|
||||
":image_to_tensor_utils",
|
||||
"@com_google_absl//absl/strings",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:statusor",
|
||||
"//mediapipe/gpu:gl_calculator_helper",
|
||||
"//mediapipe/gpu:gl_simple_shaders",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/gpu:shader_util",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
}),
|
||||
)
|
||||
@@ -1179,10 +1213,10 @@ cc_library(
|
||||
deps = ["//mediapipe/framework:port"] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
"//mediapipe/gpu:gl_base",
|
||||
"//mediapipe/gpu:gl_context",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:statusor",
|
||||
"//mediapipe/gpu:gl_base",
|
||||
"//mediapipe/gpu:gl_context",
|
||||
],
|
||||
}),
|
||||
)
|
||||
@@ -1210,15 +1244,15 @@ cc_library(
|
||||
"//mediapipe:apple": [
|
||||
":image_to_tensor_converter",
|
||||
":image_to_tensor_utils",
|
||||
"//mediapipe/gpu:MPPMetalHelper",
|
||||
"@com_google_absl//absl/strings",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:statusor",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/gpu:MPPMetalHelper",
|
||||
"//mediapipe/gpu:gpu_buffer_format",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:shape",
|
||||
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:types",
|
||||
],
|
||||
@@ -1239,8 +1273,6 @@ cc_library(
|
||||
}),
|
||||
deps = [
|
||||
":image_to_tensor_calculator_cc_proto",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/types:optional",
|
||||
"//mediapipe/framework/api2:packet",
|
||||
"//mediapipe/framework/api2:port",
|
||||
"//mediapipe/framework/formats:image",
|
||||
@@ -1249,6 +1281,8 @@ cc_library(
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:statusor",
|
||||
"//mediapipe/gpu:gpu_origin_cc_proto",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/types:optional",
|
||||
] + select({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": ["//mediapipe/gpu:gpu_buffer"],
|
||||
@@ -1298,20 +1332,20 @@ cc_library(
|
||||
}),
|
||||
deps = [
|
||||
":tensors_to_segmentation_calculator_cc_proto",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/types:span",
|
||||
"//mediapipe/framework:calculator_context",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:port",
|
||||
"//mediapipe/framework/formats:image",
|
||||
"//mediapipe/framework/formats:image_frame",
|
||||
"//mediapipe/framework/formats:tensor",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework:calculator_context",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:port",
|
||||
"//mediapipe/framework/port:statusor",
|
||||
"//mediapipe/gpu:gpu_origin_cc_proto",
|
||||
"//mediapipe/util:resource_util",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
"@com_google_absl//absl/types:span",
|
||||
"@org_tensorflow//tensorflow/lite:framework",
|
||||
"//mediapipe/framework/port:statusor",
|
||||
] + selects.with_or({
|
||||
"//mediapipe/gpu:disable_gpu": [],
|
||||
"//conditions:default": [
|
||||
@@ -1325,6 +1359,7 @@ cc_library(
|
||||
"//mediapipe:ios": [
|
||||
"//mediapipe/gpu:MPPMetalUtil",
|
||||
"//mediapipe/gpu:MPPMetalHelper",
|
||||
"//third_party/apple_frameworks:MetalKit",
|
||||
],
|
||||
"//conditions:default": [
|
||||
"@org_tensorflow//tensorflow/lite/delegates/gpu:gl_delegate",
|
||||
|
||||
@@ -192,7 +192,7 @@ class AudioToTensorCalculator : public Node {
|
||||
DftTensorFormat dft_tensor_format_;
|
||||
|
||||
Timestamp initial_timestamp_ = Timestamp::Unstarted();
|
||||
int64 cumulative_input_samples_ = 0;
|
||||
int64_t cumulative_input_samples_ = 0;
|
||||
Timestamp next_output_timestamp_ = Timestamp::Unstarted();
|
||||
|
||||
double source_sample_rate_ = -1;
|
||||
|
||||
@@ -163,20 +163,21 @@ class AudioToTensorCalculatorNonStreamingModeTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
void CheckTimestampsOutputPackets(
|
||||
std::vector<int64> expected_timestamp_values) {
|
||||
std::vector<int64_t> expected_timestamp_values) {
|
||||
ASSERT_EQ(num_iterations_, timestamps_packets_.size());
|
||||
for (int i = 0; i < timestamps_packets_.size(); ++i) {
|
||||
const auto& p = timestamps_packets_[i];
|
||||
MP_ASSERT_OK(p.ValidateAsType<std::vector<Timestamp>>());
|
||||
auto output_timestamps = p.Get<std::vector<Timestamp>>();
|
||||
int64 base_timestamp = i * Timestamp::kTimestampUnitsPerSecond;
|
||||
int64_t base_timestamp = i * Timestamp::kTimestampUnitsPerSecond;
|
||||
std::vector<Timestamp> expected_timestamps;
|
||||
expected_timestamps.resize(expected_timestamp_values.size());
|
||||
std::transform(
|
||||
expected_timestamp_values.begin(), expected_timestamp_values.end(),
|
||||
expected_timestamps.begin(), [base_timestamp](int64 v) -> Timestamp {
|
||||
return Timestamp(v + base_timestamp);
|
||||
});
|
||||
std::transform(expected_timestamp_values.begin(),
|
||||
expected_timestamp_values.end(),
|
||||
expected_timestamps.begin(),
|
||||
[base_timestamp](int64_t v) -> Timestamp {
|
||||
return Timestamp(v + base_timestamp);
|
||||
});
|
||||
EXPECT_EQ(expected_timestamps, output_timestamps);
|
||||
EXPECT_EQ(p.Timestamp(), expected_timestamps.back());
|
||||
}
|
||||
@@ -379,7 +380,7 @@ class AudioToTensorCalculatorStreamingModeTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
void CheckTensorsOutputPackets(int sample_offset, int num_packets,
|
||||
int64 timestamp_interval,
|
||||
int64_t timestamp_interval,
|
||||
bool output_last_at_close) {
|
||||
ASSERT_EQ(num_packets, tensors_packets_.size());
|
||||
for (int i = 0; i < num_packets; ++i) {
|
||||
@@ -550,7 +551,7 @@ class AudioToTensorCalculatorFftTest : public ::testing::Test {
|
||||
protected:
|
||||
// Creates an audio matrix containing a single sample of 1.0 at a specified
|
||||
// offset.
|
||||
std::unique_ptr<Matrix> CreateImpulseSignalData(int64 num_samples,
|
||||
std::unique_ptr<Matrix> CreateImpulseSignalData(int64_t num_samples,
|
||||
int impulse_offset_idx) {
|
||||
Matrix impulse = Matrix::Zero(1, num_samples);
|
||||
impulse(0, impulse_offset_idx) = 1.0;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user