Project import generated by Copybara.

GitOrigin-RevId: d8caa66de45839696f5bd0786ad3bfbcb9cff632
This commit is contained in:
MediaPipe Team
2020-12-09 22:43:33 -05:00
committed by chuoling
parent f15da632de
commit 2b58cceec9
750 changed files with 22901 additions and 9478 deletions
@@ -32,5 +32,6 @@
<meta-data android:name="inputVideoStreamName" android:value="${inputVideoStreamName}"/>
<meta-data android:name="outputVideoStreamName" android:value="${outputVideoStreamName}"/>
<meta-data android:name="flipFramesVertically" android:value="${flipFramesVertically}"/>
<meta-data android:name="converterNumBuffers" android:value="${converterNumBuffers}"/>
</application>
</manifest>
@@ -74,6 +74,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -46,6 +46,14 @@ public class MainActivity extends AppCompatActivity {
// NOTE: use "flipFramesVertically" in manifest metadata to override this behavior.
private static final boolean FLIP_FRAMES_VERTICALLY = true;
// Number of output frames allocated in ExternalTextureConverter.
// NOTE: use "converterNumBuffers" in manifest metadata to override number of buffers. For
// example, when there is a FlowLimiterCalculator in the graph, number of buffers should be at
// least `max_in_flight + max_in_queue + 1` (where max_in_flight and max_in_queue are used in
// FlowLimiterCalculator options). That's because we need buffers for all the frames that are in
// flight/queue plus one for the next frame from the camera.
private static final int NUM_BUFFERS = 2;
static {
// Load all native libraries needed by the app.
System.loadLibrary("mediapipe_jni");
@@ -103,7 +111,6 @@ public class MainActivity extends AppCompatActivity {
applicationInfo.metaData.getString("binaryGraphName"),
applicationInfo.metaData.getString("inputVideoStreamName"),
applicationInfo.metaData.getString("outputVideoStreamName"));
processor
.getVideoSurfaceOutput()
.setFlipY(
@@ -121,7 +128,10 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onResume() {
super.onResume();
converter = new ExternalTextureConverter(eglManager.getContext());
converter =
new ExternalTextureConverter(
eglManager.getContext(),
applicationInfo.metaData.getInt("converterNumBuffers", NUM_BUFFERS));
converter.setFlipY(
applicationInfo.metaData.getBoolean("flipFramesVertically", FLIP_FRAMES_VERTICALLY));
converter.setConsumer(processor);
@@ -168,7 +178,7 @@ public class MainActivity extends AppCompatActivity {
? CameraHelper.CameraFacing.FRONT
: CameraHelper.CameraFacing.BACK;
cameraHelper.startCamera(
this, cameraFacing, /*surfaceTexture=*/ null, cameraTargetResolution());
this, cameraFacing, /*unusedSurfaceTexture=*/ null, cameraTargetResolution());
}
protected Size computeViewSize(int width, int height) {
@@ -50,6 +50,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -50,6 +50,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -55,6 +55,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -51,6 +51,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -50,6 +50,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -50,6 +50,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -52,6 +52,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -0,0 +1,69 @@
# Copyright 2019 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"])
package(default_visibility = ["//visibility:private"])
cc_binary(
name = "libmediapipe_jni.so",
linkshared = 1,
linkstatic = 1,
deps = [
"//mediapipe/graphs/holistic_tracking:holistic_tracking_gpu_deps",
"//mediapipe/java/com/google/mediapipe/framework/jni:mediapipe_framework_jni",
],
)
cc_library(
name = "mediapipe_jni_lib",
srcs = [":libmediapipe_jni.so"],
alwayslink = 1,
)
android_binary(
name = "holistictrackinggpu",
srcs = glob(["*.java"]),
assets = [
"//mediapipe/graphs/holistic_tracking:holistic_tracking_gpu.binarypb",
"//mediapipe/modules/face_detection:face_detection_front.tflite",
"//mediapipe/modules/face_landmark:face_landmark.tflite",
"//mediapipe/modules/hand_landmark:hand_landmark.tflite",
"//mediapipe/modules/hand_landmark:handedness.txt",
"//mediapipe/modules/holistic_landmark:hand_recrop.tflite",
"//mediapipe/modules/pose_detection:pose_detection.tflite",
"//mediapipe/modules/pose_landmark:pose_landmark_upper_body.tflite",
"//mediapipe/modules/pose_landmark:pose_landmark_full_body.tflite",
],
assets_dir = "",
manifest = "//mediapipe/examples/android/src/java/com/google/mediapipe/apps/basic:AndroidManifest.xml",
manifest_values = {
"applicationId": "com.google.mediapipe.apps.holistictrackinggpu",
"appName": "Holistic Tracking",
"mainActivity": "com.google.mediapipe.apps.basic.MainActivity",
"cameraFacingFront": "False",
"binaryGraphName": "holistic_tracking_gpu.binarypb",
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "3",
},
multidex = "native",
deps = [
":mediapipe_jni_lib",
"//mediapipe/examples/android/src/java/com/google/mediapipe/apps/basic:basic_lib",
"//mediapipe/framework/formats:landmark_java_proto_lite",
"//mediapipe/java/com/google/mediapipe/framework:android_framework",
],
)
@@ -89,6 +89,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -52,6 +52,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -10,5 +10,6 @@ def generate_manifest_values(application_id, app_name):
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
}
return manifest_values
@@ -51,6 +51,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -51,6 +51,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -51,6 +51,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -0,0 +1,63 @@
# Copyright 2020 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"])
package(default_visibility = ["//visibility:private"])
cc_binary(
name = "libmediapipe_jni.so",
linkshared = 1,
linkstatic = 1,
deps = [
"//mediapipe/graphs/pose_tracking:pose_tracking_gpu_deps",
"//mediapipe/java/com/google/mediapipe/framework/jni:mediapipe_framework_jni",
],
)
cc_library(
name = "mediapipe_jni_lib",
srcs = [":libmediapipe_jni.so"],
alwayslink = 1,
)
android_binary(
name = "posetrackinggpu",
srcs = glob(["*.java"]),
assets = [
"//mediapipe/graphs/pose_tracking:pose_tracking_gpu.binarypb",
"//mediapipe/modules/pose_landmark:pose_landmark_full_body.tflite",
"//mediapipe/modules/pose_detection:pose_detection.tflite",
],
assets_dir = "",
manifest = "//mediapipe/examples/android/src/java/com/google/mediapipe/apps/basic:AndroidManifest.xml",
manifest_values = {
"applicationId": "com.google.mediapipe.apps.posetrackinggpu",
"appName": "Pose Tracking",
"mainActivity": ".MainActivity",
"cameraFacingFront": "False",
"binaryGraphName": "pose_tracking_gpu.binarypb",
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
":mediapipe_jni_lib",
"//mediapipe/examples/android/src/java/com/google/mediapipe/apps/basic:basic_lib",
"//mediapipe/framework/formats:landmark_java_proto_lite",
"//mediapipe/java/com/google/mediapipe/framework:android_framework",
],
)
@@ -0,0 +1,75 @@
// Copyright 2020 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.mediapipe.apps.posetrackinggpu;
import android.os.Bundle;
import android.util.Log;
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmark;
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList;
import com.google.mediapipe.framework.PacketGetter;
import com.google.protobuf.InvalidProtocolBufferException;
/** Main activity of MediaPipe pose tracking app. */
public class MainActivity extends com.google.mediapipe.apps.basic.MainActivity {
private static final String TAG = "MainActivity";
private static final String OUTPUT_LANDMARKS_STREAM_NAME = "pose_landmarks";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// To show verbose logging, run:
// adb shell setprop log.tag.MainActivity VERBOSE
if (Log.isLoggable(TAG, Log.VERBOSE)) {
processor.addPacketCallback(
OUTPUT_LANDMARKS_STREAM_NAME,
(packet) -> {
Log.v(TAG, "Received pose landmarks packet.");
try {
NormalizedLandmarkList poseLandmarks =
PacketGetter.getProto(packet, NormalizedLandmarkList.class);
Log.v(
TAG,
"[TS:"
+ packet.getTimestamp()
+ "] "
+ getPoseLandmarksDebugString(poseLandmarks));
} catch (InvalidProtocolBufferException exception) {
Log.e(TAG, "Failed to get proto.", exception);
}
});
}
}
private static String getPoseLandmarksDebugString(NormalizedLandmarkList poseLandmarks) {
String poseLandmarkStr = "Pose landmarks: " + poseLandmarks.getLandmarkCount() + "\n";
int landmarkIndex = 0;
for (NormalizedLandmark landmark : poseLandmarks.getLandmarkList()) {
poseLandmarkStr +=
"\tLandmark ["
+ landmarkIndex
+ "]: ("
+ landmark.getX()
+ ", "
+ landmark.getY()
+ ", "
+ landmark.getZ()
+ ")\n";
++landmarkIndex;
}
return poseLandmarkStr;
}
}
@@ -52,6 +52,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -51,6 +51,7 @@ android_binary(
"inputVideoStreamName": "input_video",
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
},
multidex = "native",
deps = [
@@ -40,7 +40,7 @@ DEFINE_string(output_video_path, "",
"Full path of where to save result (.mp4 only). "
"If not provided, show result in a window.");
::mediapipe::Status RunMPPGraph() {
mediapipe::Status RunMPPGraph() {
std::string calculator_graph_config_contents;
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
FLAGS_calculator_graph_config_file, &calculator_graph_config_contents));
@@ -143,7 +143,7 @@ DEFINE_string(output_video_path, "",
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
::mediapipe::Status run_status = RunMPPGraph();
mediapipe::Status run_status = RunMPPGraph();
if (!run_status.ok()) {
LOG(ERROR) << "Failed to run the graph: " << run_status.message();
return EXIT_FAILURE;
@@ -97,12 +97,12 @@ class BorderDetectionCalculator : public CalculatorBase {
};
REGISTER_CALCULATOR(BorderDetectionCalculator);
::mediapipe::Status BorderDetectionCalculator::Open(
mediapipe::Status BorderDetectionCalculator::Open(
mediapipe::CalculatorContext* cc) {
options_ = cc->Options<BorderDetectionCalculatorOptions>();
RET_CHECK_LT(options_.vertical_search_distance(), 0.5)
<< "Search distance must be less than half the full image.";
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
mediapipe::Status BorderDetectionCalculator::SetAndCheckInputs(
@@ -118,14 +118,14 @@ mediapipe::Status BorderDetectionCalculator::SetAndCheckInputs(
RET_CHECK_EQ(frame.rows, frame_height_)
<< "Input frame dimensions must remain constant throughout the video.";
RET_CHECK_EQ(frame.channels(), 3) << "Input video type must be 3-channel";
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
mediapipe::Status BorderDetectionCalculator::Process(
mediapipe::CalculatorContext* cc) {
if (!cc->Inputs().HasTag(kVideoInputTag) ||
cc->Inputs().Tag(kVideoInputTag).Value().IsEmpty()) {
return ::mediapipe::InvalidArgumentErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::InvalidArgumentErrorBuilder(MEDIAPIPE_LOC)
<< "Input tag VIDEO not set or empty at timestamp: "
<< cc->InputTimestamp().Value();
}
@@ -173,7 +173,7 @@ mediapipe::Status BorderDetectionCalculator::Process(
.Tag(kDetectedBorders)
.AddPacket(Adopt(features.release()).At(cc->InputTimestamp()));
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// Find the dominant color within an image.
@@ -291,11 +291,11 @@ void BorderDetectionCalculator::DetectBorder(
}
}
::mediapipe::Status BorderDetectionCalculator::GetContract(
mediapipe::Status BorderDetectionCalculator::GetContract(
mediapipe::CalculatorContract* cc) {
cc->Inputs().Tag(kVideoInputTag).Set<ImageFrame>();
cc->Outputs().Tag(kDetectedBorders).Set<StaticFeatures>();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -55,15 +55,15 @@ class ContentZoomingCalculator : public CalculatorBase {
ContentZoomingCalculator(const ContentZoomingCalculator&) = delete;
ContentZoomingCalculator& operator=(const ContentZoomingCalculator&) = delete;
static ::mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
::mediapipe::Status Open(mediapipe::CalculatorContext* cc) override;
::mediapipe::Status Process(mediapipe::CalculatorContext* cc) override;
static mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
mediapipe::Status Open(mediapipe::CalculatorContext* cc) override;
mediapipe::Status Process(mediapipe::CalculatorContext* cc) override;
private:
// Converts bounds to tilt offset, pan offset and height.
::mediapipe::Status ConvertToPanTiltZoom(float xmin, float xmax, float ymin,
float ymax, int* tilt_offset,
int* pan_offset, int* height);
mediapipe::Status ConvertToPanTiltZoom(float xmin, float xmax, float ymin,
float ymax, int* tilt_offset,
int* pan_offset, int* height);
ContentZoomingCalculatorOptions options_;
// Detection frame width/height.
int frame_height_;
@@ -89,7 +89,7 @@ class ContentZoomingCalculator : public CalculatorBase {
};
REGISTER_CALCULATOR(ContentZoomingCalculator);
::mediapipe::Status ContentZoomingCalculator::GetContract(
mediapipe::Status ContentZoomingCalculator::GetContract(
mediapipe::CalculatorContract* cc) {
RET_CHECK(
!(cc->Inputs().HasTag(kVideoFrame) && cc->Inputs().HasTag(kVideoSize)))
@@ -99,7 +99,7 @@ REGISTER_CALCULATOR(ContentZoomingCalculator);
} else if (cc->Inputs().HasTag(kVideoSize)) {
cc->Inputs().Tag(kVideoSize).Set<std::pair<int, int>>();
} else {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "Input VIDEO or VIDEO_SIZE must be provided.";
}
if (cc->Inputs().HasTag(kSalientRegions)) {
@@ -114,27 +114,27 @@ REGISTER_CALCULATOR(ContentZoomingCalculator);
if (cc->Outputs().HasTag(kCropRect)) {
cc->Outputs().Tag(kCropRect).Set<mediapipe::Rect>();
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status ContentZoomingCalculator::Open(
mediapipe::Status ContentZoomingCalculator::Open(
mediapipe::CalculatorContext* cc) {
options_ = cc->Options<ContentZoomingCalculatorOptions>();
if (options_.has_kinematic_options()) {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "Deprecated kinematic_options was set, please set "
"kinematic_options_zoom and kinematic_options_tilt.";
}
if (options_.has_min_motion_to_reframe()) {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "Deprecated min_motion_to_reframe was set, please set "
"in kinematic_options_zoom and kinematic_options_tilt "
"directly.";
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status ContentZoomingCalculator::ConvertToPanTiltZoom(
mediapipe::Status ContentZoomingCalculator::ConvertToPanTiltZoom(
float xmin, float xmax, float ymin, float ymax, int* tilt_offset,
int* pan_offset, int* height) {
// Find center of the y-axis offset (for tilt control).
@@ -161,7 +161,7 @@ REGISTER_CALCULATOR(ContentZoomingCalculator);
*tilt_offset = frame_height_ * y_center;
*pan_offset = frame_width_ * x_center;
*height = frame_height_ * fit_size;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
namespace {
@@ -185,12 +185,12 @@ mediapipe::autoflip::RectF ShiftDetection(
relative_bounding_box.width() * x_offset_percent);
return shifted_bb;
}
::mediapipe::Status UpdateRanges(const SalientRegion& region,
const float shift_vertical,
const float shift_horizontal, float* xmin,
float* xmax, float* ymin, float* ymax) {
mediapipe::Status UpdateRanges(const SalientRegion& region,
const float shift_vertical,
const float shift_horizontal, float* xmin,
float* xmax, float* ymin, float* ymax) {
if (!region.has_location_normalized()) {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "SalientRegion did not have location normalized set.";
}
auto location = ShiftDetection(region.location_normalized(), shift_vertical,
@@ -200,12 +200,12 @@ mediapipe::autoflip::RectF ShiftDetection(
*ymin = fmin(*ymin, location.y());
*ymax = fmax(*ymax, location.y() + location.height());
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status UpdateRanges(const mediapipe::Detection& detection,
const float shift_vertical,
const float shift_horizontal, float* xmin,
float* xmax, float* ymin, float* ymax) {
mediapipe::Status UpdateRanges(const mediapipe::Detection& detection,
const float shift_vertical,
const float shift_horizontal, float* xmin,
float* xmax, float* ymin, float* ymax) {
RET_CHECK(detection.location_data().format() ==
mediapipe::LocationData::RELATIVE_BOUNDING_BOX)
<< "Face detection input is lacking required relative_bounding_box()";
@@ -217,7 +217,7 @@ mediapipe::autoflip::RectF ShiftDetection(
*ymin = fmin(*ymin, location.ymin());
*ymax = fmax(*ymax, location.ymin() + location.height());
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
void MakeStaticFeatures(const int top_border, const int bottom_border,
const int frame_width, const int frame_height,
@@ -238,21 +238,21 @@ void MakeStaticFeatures(const int top_border, const int bottom_border,
}
} // namespace
::mediapipe::Status ContentZoomingCalculator::Process(
mediapipe::Status ContentZoomingCalculator::Process(
mediapipe::CalculatorContext* cc) {
if (cc->Inputs().HasTag(kVideoFrame)) {
frame_width_ = cc->Inputs().Tag(kVideoFrame).Get<ImageFrame>().Width();
frame_height_ = cc->Inputs().Tag(kVideoFrame).Get<ImageFrame>().Height();
} else if (cc->Inputs().HasTag(kVideoSize)) {
if (cc->Inputs().Tag(kVideoSize).IsEmpty()) {
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
frame_width_ =
cc->Inputs().Tag(kVideoSize).Get<std::pair<int, int>>().first;
frame_height_ =
cc->Inputs().Tag(kVideoSize).Get<std::pair<int, int>>().second;
} else {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "Input VIDEO or VIDEO_SIZE must be provided.";
}
@@ -311,7 +311,7 @@ void MakeStaticFeatures(const int top_border, const int bottom_border,
default_rect->set_height(frame_height_);
cc->Outputs().Tag(kCropRect).Add(default_rect.release(),
Timestamp(cc->InputTimestamp()));
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
auto raw_detections =
cc->Inputs().Tag(kDetections).Get<std::vector<mediapipe::Detection>>();
@@ -358,10 +358,13 @@ void MakeStaticFeatures(const int top_border, const int bottom_border,
int path_width = path_height * target_aspect_;
// Update pixel-per-degree value for pan/tilt.
int target_height;
MP_RETURN_IF_ERROR(path_solver_height_->GetTargetPosition(&target_height));
int target_width = target_height * target_aspect_;
MP_RETURN_IF_ERROR(path_solver_width_->UpdatePixelsPerDegree(
static_cast<float>(path_width) / kFieldOfView));
static_cast<float>(target_width) / kFieldOfView));
MP_RETURN_IF_ERROR(path_solver_offset_->UpdatePixelsPerDegree(
static_cast<float>(path_height) / kFieldOfView));
static_cast<float>(target_height) / kFieldOfView));
// Compute smoothed pan/tilt paths.
MP_RETURN_IF_ERROR(path_solver_width_->AddObservation(
@@ -412,7 +415,7 @@ void MakeStaticFeatures(const int top_border, const int bottom_border,
Timestamp(cc->InputTimestamp()));
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -55,9 +55,9 @@ class FaceToRegionCalculator : public CalculatorBase {
FaceToRegionCalculator(const FaceToRegionCalculator&) = delete;
FaceToRegionCalculator& operator=(const FaceToRegionCalculator&) = delete;
static ::mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
::mediapipe::Status Open(mediapipe::CalculatorContext* cc) override;
::mediapipe::Status Process(mediapipe::CalculatorContext* cc) override;
static mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
mediapipe::Status Open(mediapipe::CalculatorContext* cc) override;
mediapipe::Status Process(mediapipe::CalculatorContext* cc) override;
private:
double NormalizeX(const int pixel);
@@ -78,17 +78,17 @@ REGISTER_CALCULATOR(FaceToRegionCalculator);
FaceToRegionCalculator::FaceToRegionCalculator() {}
::mediapipe::Status FaceToRegionCalculator::GetContract(
mediapipe::Status FaceToRegionCalculator::GetContract(
mediapipe::CalculatorContract* cc) {
if (cc->Inputs().HasTag("VIDEO")) {
cc->Inputs().Tag("VIDEO").Set<ImageFrame>();
}
cc->Inputs().Tag("FACES").Set<std::vector<mediapipe::Detection>>();
cc->Outputs().Tag("REGIONS").Set<DetectionSet>();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status FaceToRegionCalculator::Open(
mediapipe::Status FaceToRegionCalculator::Open(
mediapipe::CalculatorContext* cc) {
options_ = cc->Options<FaceToRegionCalculatorOptions>();
if (!cc->Inputs().HasTag("VIDEO")) {
@@ -105,7 +105,7 @@ FaceToRegionCalculator::FaceToRegionCalculator() {}
scorer_ = absl::make_unique<VisualScorer>(options_.scorer_options());
frame_width_ = -1;
frame_height_ = -1;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
inline double FaceToRegionCalculator::NormalizeX(const int pixel) {
@@ -146,11 +146,11 @@ void FaceToRegionCalculator::ExtendSalientRegionWithPoint(
}
}
::mediapipe::Status FaceToRegionCalculator::Process(
mediapipe::Status FaceToRegionCalculator::Process(
mediapipe::CalculatorContext* cc) {
if (cc->Inputs().HasTag("VIDEO") &&
cc->Inputs().Tag("VIDEO").Value().IsEmpty()) {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "No VIDEO input at time " << cc->InputTimestamp().Seconds();
}
@@ -280,7 +280,7 @@ void FaceToRegionCalculator::ExtendSalientRegionWithPoint(
}
cc->Outputs().Tag("REGIONS").Add(region_set.release(), cc->InputTimestamp());
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -38,9 +38,9 @@ class LocalizationToRegionCalculator : public mediapipe::CalculatorBase {
LocalizationToRegionCalculator& operator=(
const LocalizationToRegionCalculator&) = delete;
static ::mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
::mediapipe::Status Open(mediapipe::CalculatorContext* cc) override;
::mediapipe::Status Process(mediapipe::CalculatorContext* cc) override;
static mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
mediapipe::Status Open(mediapipe::CalculatorContext* cc) override;
mediapipe::Status Process(mediapipe::CalculatorContext* cc) override;
private:
// Calculator options.
@@ -84,21 +84,21 @@ void FillSalientRegion(const mediapipe::Detection& detection,
} // namespace
::mediapipe::Status LocalizationToRegionCalculator::GetContract(
mediapipe::Status LocalizationToRegionCalculator::GetContract(
mediapipe::CalculatorContract* cc) {
cc->Inputs().Tag("DETECTIONS").Set<std::vector<mediapipe::Detection>>();
cc->Outputs().Tag("REGIONS").Set<DetectionSet>();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status LocalizationToRegionCalculator::Open(
mediapipe::Status LocalizationToRegionCalculator::Open(
mediapipe::CalculatorContext* cc) {
options_ = cc->Options<LocalizationToRegionCalculatorOptions>();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status LocalizationToRegionCalculator::Process(
mediapipe::Status LocalizationToRegionCalculator::Process(
mediapipe::CalculatorContext* cc) {
const auto& annotations =
cc->Inputs().Tag("DETECTIONS").Get<std::vector<mediapipe::Detection>>();
@@ -119,7 +119,7 @@ void FillSalientRegion(const mediapipe::Detection& detection,
}
cc->Outputs().Tag("REGIONS").Add(regions.release(), cc->InputTimestamp());
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -68,8 +68,8 @@ constexpr char kOutputSummary[] = "CROPPING_SUMMARY";
constexpr char kExternalRenderingPerFrame[] = "EXTERNAL_RENDERING_PER_FRAME";
constexpr char kExternalRenderingFullVid[] = "EXTERNAL_RENDERING_FULL_VID";
::mediapipe::Status SceneCroppingCalculator::GetContract(
::mediapipe::CalculatorContract* cc) {
mediapipe::Status SceneCroppingCalculator::GetContract(
mediapipe::CalculatorContract* cc) {
if (cc->InputSidePackets().HasTag(kInputExternalSettings)) {
cc->InputSidePackets().Tag(kInputExternalSettings).Set<std::string>();
}
@@ -136,10 +136,10 @@ constexpr char kExternalRenderingFullVid[] = "EXTERNAL_RENDERING_FULL_VID";
cc->Outputs().HasTag(kExternalRenderingFullVid) ||
cc->Outputs().HasTag(kOutputCroppedFrames))
<< "At leaset one output stream must be specified";
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SceneCroppingCalculator::Open(CalculatorContext* cc) {
mediapipe::Status SceneCroppingCalculator::Open(CalculatorContext* cc) {
options_ = cc->Options<SceneCroppingCalculatorOptions>();
RET_CHECK_GT(options_.max_scene_size(), 0)
<< "Maximum scene size is non-positive.";
@@ -175,12 +175,12 @@ constexpr char kExternalRenderingFullVid[] = "EXTERNAL_RENDERING_FULL_VID";
should_perform_frame_cropping_ = cc->Outputs().HasTag(kOutputCroppedFrames);
scene_camera_motion_analyzer_ = absl::make_unique<SceneCameraMotionAnalyzer>(
options_.scene_camera_motion_analyzer_options());
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
namespace {
::mediapipe::Status ParseAspectRatioString(
const std::string& aspect_ratio_string, double* aspect_ratio) {
mediapipe::Status ParseAspectRatioString(const std::string& aspect_ratio_string,
double* aspect_ratio) {
std::string error_msg =
"Aspect ratio std::string must be in the format of 'width:height', e.g. "
"'1:1' or '5:4', your input was " +
@@ -196,7 +196,7 @@ namespace {
&height_ratio))
<< error_msg;
*aspect_ratio = width_ratio / height_ratio;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
void ConstructExternalRenderMessage(
const cv::Rect& crop_from_location, const cv::Rect& render_to_location,
@@ -235,8 +235,8 @@ int RoundToEven(float value) {
} // namespace
::mediapipe::Status SceneCroppingCalculator::InitializeSceneCroppingCalculator(
::mediapipe::CalculatorContext* cc) {
mediapipe::Status SceneCroppingCalculator::InitializeSceneCroppingCalculator(
mediapipe::CalculatorContext* cc) {
if (cc->Inputs().HasTag(kInputVideoFrames)) {
const auto& frame = cc->Inputs().Tag(kInputVideoFrames).Get<ImageFrame>();
frame_width_ = frame.Width();
@@ -248,7 +248,7 @@ int RoundToEven(float value) {
frame_height_ =
cc->Inputs().Tag(kInputVideoSize).Get<std::pair<int, int>>().second;
} else {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "Input VIDEO or VIDEO_SIZE must be provided.";
}
RET_CHECK_GT(frame_height_, 0) << "Input frame height is non-positive.";
@@ -337,18 +337,18 @@ int RoundToEven(float value) {
scene_cropper_ = absl::make_unique<SceneCropper>(
options_.camera_motion_options(), frame_width_, frame_height_);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
bool HasFrameSignal(::mediapipe::CalculatorContext* cc) {
bool HasFrameSignal(mediapipe::CalculatorContext* cc) {
if (cc->Inputs().HasTag(kInputVideoFrames)) {
return !cc->Inputs().Tag(kInputVideoFrames).Value().IsEmpty();
}
return !cc->Inputs().Tag(kInputVideoSize).Value().IsEmpty();
}
::mediapipe::Status SceneCroppingCalculator::Process(
::mediapipe::CalculatorContext* cc) {
mediapipe::Status SceneCroppingCalculator::Process(
mediapipe::CalculatorContext* cc) {
// Sets frame dimension and initializes scenecroppingcalculator on first video
// frame.
if (frame_width_ < 0) {
@@ -417,11 +417,11 @@ bool HasFrameSignal(::mediapipe::CalculatorContext* cc) {
continue_last_scene_ = true;
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SceneCroppingCalculator::Close(
::mediapipe::CalculatorContext* cc) {
mediapipe::Status SceneCroppingCalculator::Close(
mediapipe::CalculatorContext* cc) {
if (!scene_frame_timestamps_.empty()) {
MP_RETURN_IF_ERROR(ProcessScene(/* is_end_of_scene = */ true, cc));
}
@@ -435,12 +435,12 @@ bool HasFrameSignal(::mediapipe::CalculatorContext* cc) {
.Tag(kExternalRenderingFullVid)
.Add(external_render_list_.release(), Timestamp::PostStream());
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// TODO: split this function into two, one for calculating the border
// sizes, the other for the actual removal of borders from the frames.
::mediapipe::Status SceneCroppingCalculator::RemoveStaticBorders(
mediapipe::Status SceneCroppingCalculator::RemoveStaticBorders(
CalculatorContext* cc, int* top_border_size, int* bottom_border_size) {
*top_border_size = 0;
*bottom_border_size = 0;
@@ -492,11 +492,10 @@ bool HasFrameSignal(::mediapipe::CalculatorContext* cc) {
*key_frame_infos_[i].mutable_detections() = adjusted_detections;
}
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status
SceneCroppingCalculator::InitializeFrameCropRegionComputer() {
mediapipe::Status SceneCroppingCalculator::InitializeFrameCropRegionComputer() {
key_frame_crop_options_ = options_.key_frame_crop_options();
MP_RETURN_IF_ERROR(
SetKeyFrameCropTarget(frame_width_, effective_frame_height_,
@@ -505,7 +504,7 @@ SceneCroppingCalculator::InitializeFrameCropRegionComputer() {
VLOG(1) << "Target height " << key_frame_crop_options_.target_height();
frame_crop_region_computer_ =
absl::make_unique<FrameCropRegionComputer>(key_frame_crop_options_);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
void SceneCroppingCalculator::FilterKeyFrameInfo() {
@@ -531,7 +530,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
}
}
::mediapipe::Status SceneCroppingCalculator::ProcessScene(
mediapipe::Status SceneCroppingCalculator::ProcessScene(
const bool is_end_of_scene, CalculatorContext* cc) {
// Removes detections under special circumstances.
FilterKeyFrameInfo();
@@ -654,10 +653,10 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
is_key_frames_.clear();
static_features_.clear();
static_features_timestamps_.clear();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SceneCroppingCalculator::FormatAndOutputCroppedFrames(
mediapipe::Status SceneCroppingCalculator::FormatAndOutputCroppedFrames(
const int crop_width, const int crop_height, const int num_frames,
std::vector<cv::Rect>* render_to_locations, bool* apply_padding,
std::vector<cv::Scalar>* padding_colors, float* vertical_fill_percent,
@@ -730,7 +729,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
padding_colors->push_back(padding_color_to_add);
}
if (!cropped_frames_ptr) {
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// Resizes cropped frames, pads frames, and output frames.
@@ -773,7 +772,7 @@ void SceneCroppingCalculator::FilterKeyFrameInfo() {
.Add(scaled_frame.release(), timestamp);
}
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
mediapipe::Status SceneCroppingCalculator::OutputVizFrames(
@@ -816,7 +815,7 @@ mediapipe::Status SceneCroppingCalculator::OutputVizFrames(
.Add(viz_frames[i].release(), Timestamp(scene_frame_timestamps_[i]));
}
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
REGISTER_CALCULATOR(SceneCroppingCalculator);
@@ -125,35 +125,35 @@ namespace autoflip {
// fields are optional with default settings.
class SceneCroppingCalculator : public CalculatorBase {
public:
static ::mediapipe::Status GetContract(CalculatorContract* cc);
static mediapipe::Status GetContract(CalculatorContract* cc);
// Validates calculator options and initializes SceneCameraMotionAnalyzer and
// SceneCropper.
::mediapipe::Status Open(CalculatorContext* cc) override;
mediapipe::Status Open(CalculatorContext* cc) override;
// Buffers each scene frame and its timestamp. Packs and stores KeyFrameInfo
// for key frames (a.k.a. frames with detection features). When a shot
// boundary is encountered or when the buffer is full, calls ProcessScene()
// to process the scene at once, and clears buffers.
::mediapipe::Status Process(CalculatorContext* cc) override;
mediapipe::Status Process(CalculatorContext* cc) override;
// Calls ProcessScene() on remaining buffered frames. Optionally outputs a
// VideoCroppingSummary if the output stream CROPPING_SUMMARY is present.
::mediapipe::Status Close(::mediapipe::CalculatorContext* cc) override;
mediapipe::Status Close(mediapipe::CalculatorContext* cc) override;
private:
// Removes any static borders from the scene frames before cropping. The
// arguments |top_border_size| and |bottom_border_size| report the size of the
// removed borders.
::mediapipe::Status RemoveStaticBorders(CalculatorContext* cc,
int* top_border_size,
int* bottom_border_size);
mediapipe::Status RemoveStaticBorders(CalculatorContext* cc,
int* top_border_size,
int* bottom_border_size);
// Sets up autoflip after first frame is received and input size is known.
::mediapipe::Status InitializeSceneCroppingCalculator(
::mediapipe::CalculatorContext* cc);
mediapipe::Status InitializeSceneCroppingCalculator(
mediapipe::CalculatorContext* cc);
// Initializes a FrameCropRegionComputer given input and target frame sizes.
::mediapipe::Status InitializeFrameCropRegionComputer();
mediapipe::Status InitializeFrameCropRegionComputer();
// Processes a scene using buffered scene frames and KeyFrameInfos:
// 1. Computes key frame crop regions using a FrameCropRegionComputer.
@@ -165,8 +165,8 @@ class SceneCroppingCalculator : public CalculatorBase {
// to force flush).
// 6. Optionally outputs visualization frames.
// 7. Optionally updates cropping summary.
::mediapipe::Status ProcessScene(const bool is_end_of_scene,
CalculatorContext* cc);
mediapipe::Status ProcessScene(const bool is_end_of_scene,
CalculatorContext* cc);
// Formats and outputs the cropped frames passed in through
// |cropped_frames_ptr|. Scales them to be at least as big as the target
@@ -177,14 +177,14 @@ class SceneCroppingCalculator : public CalculatorBase {
// cropped frames. This is useful when the calculator is only used for
// computing the cropping metadata rather than doing the actual cropping
// operation.
::mediapipe::Status FormatAndOutputCroppedFrames(
mediapipe::Status FormatAndOutputCroppedFrames(
const int crop_width, const int crop_height, const int num_frames,
std::vector<cv::Rect>* render_to_locations, bool* apply_padding,
std::vector<cv::Scalar>* padding_colors, float* vertical_fill_percent,
const std::vector<cv::Mat>* cropped_frames_ptr, CalculatorContext* cc);
// Draws and outputs visualization frames if those streams are present.
::mediapipe::Status OutputVizFrames(
mediapipe::Status OutputVizFrames(
const std::vector<KeyFrameCropResult>& key_frame_crop_results,
const std::vector<FocusPointFrame>& focus_point_frames,
const std::vector<cv::Rect>& crop_from_locations,
@@ -60,7 +60,7 @@ class ShotBoundaryCalculator : public mediapipe::CalculatorBase {
ShotBoundaryCalculator(const ShotBoundaryCalculator&) = delete;
ShotBoundaryCalculator& operator=(const ShotBoundaryCalculator&) = delete;
static ::mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
static mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
mediapipe::Status Open(mediapipe::CalculatorContext* cc) override;
mediapipe::Status Process(mediapipe::CalculatorContext* cc) override;
@@ -103,7 +103,7 @@ mediapipe::Status ShotBoundaryCalculator::Open(
options_ = cc->Options<ShotBoundaryCalculatorOptions>();
last_shot_timestamp_ = Timestamp(0);
init_ = false;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
void ShotBoundaryCalculator::Transmit(mediapipe::CalculatorContext* cc,
@@ -127,7 +127,7 @@ void ShotBoundaryCalculator::Transmit(mediapipe::CalculatorContext* cc,
}
}
::mediapipe::Status ShotBoundaryCalculator::Process(
mediapipe::Status ShotBoundaryCalculator::Process(
mediapipe::CalculatorContext* cc) {
// Connect to input frame and make a mutable copy.
cv::Mat frame_org = mediapipe::formats::MatView(
@@ -142,7 +142,7 @@ void ShotBoundaryCalculator::Transmit(mediapipe::CalculatorContext* cc,
last_histogram_ = current_histogram;
init_ = true;
Transmit(cc, false);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
double current_motion_estimate =
@@ -152,7 +152,7 @@ void ShotBoundaryCalculator::Transmit(mediapipe::CalculatorContext* cc,
if (motion_history_.size() != options_.window_size()) {
Transmit(cc, false);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// Shot detection algorithm is a mixture of adaptive (controlled with
@@ -176,14 +176,14 @@ void ShotBoundaryCalculator::Transmit(mediapipe::CalculatorContext* cc,
// Store histogram for next frame.
last_histogram_ = current_histogram;
motion_history_.pop_back();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status ShotBoundaryCalculator::GetContract(
mediapipe::Status ShotBoundaryCalculator::GetContract(
mediapipe::CalculatorContract* cc) {
cc->Inputs().Tag(kVideoInputTag).Set<ImageFrame>();
cc->Outputs().Tag(kShotChangeTag).Set<bool>();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -105,7 +105,7 @@ class SignalFusingCalculator : public mediapipe::CalculatorBase {
SignalFusingCalculator(const SignalFusingCalculator&) = delete;
SignalFusingCalculator& operator=(const SignalFusingCalculator&) = delete;
static ::mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
static mediapipe::Status GetContract(mediapipe::CalculatorContract* cc);
mediapipe::Status Open(mediapipe::CalculatorContext* cc) override;
mediapipe::Status Process(mediapipe::CalculatorContext* cc) override;
mediapipe::Status Close(mediapipe::CalculatorContext* cc) override;
@@ -166,7 +166,7 @@ mediapipe::Status SignalFusingCalculator::Open(
process_by_scene_ = false;
}
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
mediapipe::Status SignalFusingCalculator::Close(
@@ -175,7 +175,7 @@ mediapipe::Status SignalFusingCalculator::Close(
MP_RETURN_IF_ERROR(ProcessScene(cc));
scene_frames_.clear();
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
mediapipe::Status SignalFusingCalculator::ProcessScene(
@@ -240,7 +240,7 @@ mediapipe::Status SignalFusingCalculator::ProcessScene(
}
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
std::vector<Packet> SignalFusingCalculator::GetSignalPackets(
@@ -302,17 +302,17 @@ mediapipe::Status SignalFusingCalculator::Process(
scene_frames_.clear();
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SignalFusingCalculator::GetContract(
mediapipe::Status SignalFusingCalculator::GetContract(
mediapipe::CalculatorContract* cc) {
if (cc->Inputs().NumEntries(kSignalInputsTag) > 0) {
SetupTagInput(cc);
} else {
SetupOrderedInput(cc);
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -57,20 +57,20 @@ class VideoFilteringCalculator : public CalculatorBase {
VideoFilteringCalculator() = default;
~VideoFilteringCalculator() override = default;
static ::mediapipe::Status GetContract(CalculatorContract* cc);
static mediapipe::Status GetContract(CalculatorContract* cc);
::mediapipe::Status Process(CalculatorContext* cc) override;
mediapipe::Status Process(CalculatorContext* cc) override;
};
REGISTER_CALCULATOR(VideoFilteringCalculator);
::mediapipe::Status VideoFilteringCalculator::GetContract(
mediapipe::Status VideoFilteringCalculator::GetContract(
CalculatorContract* cc) {
cc->Inputs().Tag(kInputFrameTag).Set<ImageFrame>();
cc->Outputs().Tag(kOutputFrameTag).Set<ImageFrame>();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status VideoFilteringCalculator::Process(CalculatorContext* cc) {
mediapipe::Status VideoFilteringCalculator::Process(CalculatorContext* cc) {
const auto& options = cc->Options<VideoFilteringCalculatorOptions>();
const Packet& input_packet = cc->Inputs().Tag(kInputFrameTag).Value();
@@ -84,7 +84,7 @@ REGISTER_CALCULATOR(VideoFilteringCalculator);
if (filter_type ==
VideoFilteringCalculatorOptions::AspectRatioFilter::NO_FILTERING) {
cc->Outputs().Tag(kOutputFrameTag).AddPacket(input_packet);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
const int target_width = options.aspect_ratio_filter().target_width();
const int target_height = options.aspect_ratio_filter().target_height();
@@ -92,7 +92,7 @@ REGISTER_CALCULATOR(VideoFilteringCalculator);
RET_CHECK_GT(target_height, 0);
bool should_pass = false;
cv::Mat frame_mat = ::mediapipe::formats::MatView(&frame);
cv::Mat frame_mat = mediapipe::formats::MatView(&frame);
const double ratio = static_cast<double>(frame_mat.cols) / frame_mat.rows;
const double target_ratio = static_cast<double>(target_width) / target_height;
if (filter_type == VideoFilteringCalculatorOptions::AspectRatioFilter::
@@ -106,16 +106,16 @@ REGISTER_CALCULATOR(VideoFilteringCalculator);
}
if (should_pass) {
cc->Outputs().Tag(kOutputFrameTag).AddPacket(input_packet);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
if (options.fail_if_any()) {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC) << absl::Substitute(
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC) << absl::Substitute(
"Failing due to aspect ratio. Target aspect ratio: $0. Frame "
"width: $1, height: $2.",
target_ratio, frame.Width(), frame.Height());
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
} // namespace mediapipe
@@ -166,8 +166,8 @@ TEST(VerticalFrameRemovalCalculatorTest, OutputError) {
runner->MutableInputs()
->Tag("INPUT_FRAMES")
.packets.push_back(Adopt(input_frame.release()).At(Timestamp(1000)));
::mediapipe::Status status = runner->Run();
EXPECT_EQ(status.code(), ::mediapipe::StatusCode::kUnknown);
mediapipe::Status status = runner->Run();
EXPECT_EQ(status.code(), mediapipe::StatusCode::kUnknown);
EXPECT_THAT(status.ToString(),
::testing::HasSubstr("Failing due to aspect ratio"));
}
@@ -22,7 +22,7 @@
namespace mediapipe {
namespace autoflip {
::mediapipe::Status FrameCropRegionComputer::ExpandSegmentUnderConstraint(
mediapipe::Status FrameCropRegionComputer::ExpandSegmentUnderConstraint(
const Segment& segment_to_add, const Segment& base_segment,
const int max_length, Segment* combined_segment,
CoverType* cover_type) const {
@@ -75,10 +75,10 @@ namespace autoflip {
*combined_segment =
std::make_pair(combined_segment_left, combined_segment_right);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status FrameCropRegionComputer::ExpandRectUnderConstraints(
mediapipe::Status FrameCropRegionComputer::ExpandRectUnderConstraints(
const Rect& rect_to_add, const int max_width, const int max_height,
Rect* base_rect, CoverType* cover_type) const {
RET_CHECK(base_rect != nullptr) << "Base rect is null.";
@@ -129,7 +129,7 @@ namespace autoflip {
}
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
void FrameCropRegionComputer::UpdateCropRegionScore(
@@ -167,7 +167,7 @@ void FrameCropRegionComputer::UpdateCropRegionScore(
}
}
::mediapipe::Status FrameCropRegionComputer::ComputeFrameCropRegion(
mediapipe::Status FrameCropRegionComputer::ComputeFrameCropRegion(
const KeyFrameInfo& frame_info, KeyFrameCropResult* crop_result) const {
RET_CHECK(crop_result != nullptr) << "KeyFrameCropResult is null.";
@@ -254,7 +254,7 @@ void FrameCropRegionComputer::UpdateCropRegionScore(
crop_result->set_region_is_empty(crop_region_is_empty);
crop_result->set_region_score(crop_region_score);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -43,7 +43,7 @@ class FrameCropRegionComputer {
// consider static features, and simply tries to fit the detected features
// within the target frame size. The score of the crop region is aggregated
// from individual feature scores given the score aggregation type.
::mediapipe::Status ComputeFrameCropRegion(
mediapipe::Status ComputeFrameCropRegion(
const KeyFrameInfo& frame_info, KeyFrameCropResult* crop_result) const;
protected:
@@ -75,10 +75,11 @@ class FrameCropRegionComputer {
// fraction of the new segment exceeds the maximum length.
// In this case the combined segment is the base segment, and cover
// type is NOT_COVERED.
::mediapipe::Status ExpandSegmentUnderConstraint(
const Segment& segment_to_add, const Segment& base_segment,
const int max_length, Segment* combined_segment,
CoverType* cover_type) const;
mediapipe::Status ExpandSegmentUnderConstraint(const Segment& segment_to_add,
const Segment& base_segment,
const int max_length,
Segment* combined_segment,
CoverType* cover_type) const;
// Expands a base rectangle to cover a new rectangle to be added under width
// and height constraints. The operation is best-effort. It considers
@@ -87,11 +88,11 @@ class FrameCropRegionComputer {
// FULLY_COVERED if the new rectangle is fully covered in both directions,
// PARTIALLY_COVERED if it is at least partially covered in both directions,
// and NOT_COVERED if it is not covered in either direction.
::mediapipe::Status ExpandRectUnderConstraints(const Rect& rect_to_add,
const int max_width,
const int max_height,
Rect* base_rect,
CoverType* cover_type) const;
mediapipe::Status ExpandRectUnderConstraints(const Rect& rect_to_add,
const int max_width,
const int max_height,
Rect* base_rect,
CoverType* cover_type) const;
// Updates crop region score given current feature score, whether the feature
// is required, and the score aggregation type. Ignores negative scores.
@@ -14,10 +14,13 @@ int Median(const std::deque<std::pair<uint64, int>>& positions_raw) {
return positions[n];
}
} // namespace
::mediapipe::Status KinematicPathSolver::AddObservation(int position,
const uint64 time_us) {
mediapipe::Status KinematicPathSolver::AddObservation(int position,
const uint64 time_us) {
if (!initialized_) {
current_position_px_ = position;
target_position_px_ = position;
motion_state_ = false;
mean_delta_t_ = -1;
raw_positions_at_time_.push_front(
std::pair<uint64, int>(time_us, position));
current_time_ = time_us;
@@ -31,7 +34,9 @@ int Median(const std::deque<std::pair<uint64, int>>& positions_raw) {
<< "Reframe window cannot exceed min_motion_to_reframe.";
RET_CHECK_GE(options_.filtering_time_window_us(), 0)
<< "update_rate_seconds must be greater than 0.";
return ::mediapipe::OkStatus();
RET_CHECK_GE(options_.mean_period_update_rate(), 0)
<< "mean_period_update_rate must be greater than 0.";
return mediapipe::OkStatus();
}
RET_CHECK(current_time_ < time_us)
@@ -50,18 +55,30 @@ int Median(const std::deque<std::pair<uint64, int>>& positions_raw) {
double delta_degs = (Median(raw_positions_at_time_) - current_position_px_) /
pixels_per_degree_;
// If the motion is smaller than the min, don't use the update.
if (abs(delta_degs) < options_.min_motion_to_reframe()) {
position = current_position_px_;
// If the motion is smaller than the min_motion_to_reframe and camera is
// stationary, don't use the update.
if (abs(delta_degs) < options_.min_motion_to_reframe() && !motion_state_) {
delta_degs = 0;
motion_state_ = false;
} else if (abs(delta_degs) < options_.reframe_window() && motion_state_) {
// If the motion is smaller than the reframe_window and camera is moving,
// don't use the update.
delta_degs = 0;
motion_state_ = false;
} else if (delta_degs > 0) {
// Apply new position, less the reframe window size.
position = position - pixels_per_degree_ * options_.reframe_window();
delta_degs = (position - current_position_px_) / pixels_per_degree_;
target_position_px_ =
position - pixels_per_degree_ * options_.reframe_window();
delta_degs =
(target_position_px_ - current_position_px_) / pixels_per_degree_;
motion_state_ = true;
} else {
// Apply new position, plus the reframe window size.
position = position + pixels_per_degree_ * options_.reframe_window();
delta_degs = (position - current_position_px_) / pixels_per_degree_;
target_position_px_ =
position + pixels_per_degree_ * options_.reframe_window();
delta_degs =
(target_position_px_ - current_position_px_) / pixels_per_degree_;
motion_state_ = true;
}
// Time and position updates.
@@ -82,17 +99,25 @@ int Median(const std::deque<std::pair<uint64, int>>& positions_raw) {
return UpdatePrediction(time_us);
}
::mediapipe::Status KinematicPathSolver::UpdatePrediction(const int64 time_us) {
mediapipe::Status KinematicPathSolver::UpdatePrediction(const int64 time_us) {
RET_CHECK(current_time_ < time_us)
<< "Prediction time added before a prior observation or prediction.";
// Time since last state/prediction update.
// Time since last state/prediction update, smoothed by
// mean_period_update_rate.
double delta_t = (time_us - current_time_) / 1000000.0;
if (mean_delta_t_ < 0) {
mean_delta_t_ = delta_t;
} else {
mean_delta_t_ = mean_delta_t_ * (1 - options_.mean_period_update_rate()) +
delta_t * options_.mean_period_update_rate();
}
// Position update limited by min/max.
const double update_position_px =
double update_position_px =
current_position_px_ +
current_velocity_deg_per_s_ * delta_t * pixels_per_degree_;
current_velocity_deg_per_s_ * mean_delta_t_ * pixels_per_degree_;
if (update_position_px < min_location_) {
current_position_px_ = min_location_;
current_velocity_deg_per_s_ = 0;
@@ -104,21 +129,28 @@ int Median(const std::deque<std::pair<uint64, int>>& positions_raw) {
}
current_time_ = time_us;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status KinematicPathSolver::GetState(int* position) {
mediapipe::Status KinematicPathSolver::GetState(int* position) {
RET_CHECK(initialized_) << "GetState called before first observation added.";
*position = round(current_position_px_);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status KinematicPathSolver::UpdatePixelsPerDegree(
mediapipe::Status KinematicPathSolver::GetTargetPosition(int* target_position) {
RET_CHECK(initialized_)
<< "GetTargetPosition called before first observation added.";
*target_position = round(target_position_px_);
return mediapipe::OkStatus();
}
mediapipe::Status KinematicPathSolver::UpdatePixelsPerDegree(
const float pixels_per_degree) {
RET_CHECK_GT(pixels_per_degree_, 0)
<< "pixels_per_degree must be larger than 0.";
pixels_per_degree_ = pixels_per_degree;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -43,13 +43,15 @@ class KinematicPathSolver {
initialized_(false),
pixels_per_degree_(pixels_per_degree) {}
// Add an observation (detection) at a position and time.
::mediapipe::Status AddObservation(int position, const uint64 time_us);
mediapipe::Status AddObservation(int position, const uint64 time_us);
// Get the predicted position at a time.
::mediapipe::Status UpdatePrediction(const int64 time_us);
mediapipe::Status UpdatePrediction(const int64 time_us);
// Get the state at a time.
::mediapipe::Status GetState(int* position);
mediapipe::Status GetState(int* position);
// Update PixelPerDegree value.
::mediapipe::Status UpdatePixelsPerDegree(const float pixels_per_degree);
mediapipe::Status UpdatePixelsPerDegree(const float pixels_per_degree);
// Provide the current target position of the reframe action.
mediapipe::Status GetTargetPosition(int* target_position);
private:
// Tuning options.
@@ -65,6 +67,13 @@ class KinematicPathSolver {
uint64 current_time_;
// History of observations (second) and their time (first).
std::deque<std::pair<uint64, int>> raw_positions_at_time_;
// Current target position.
double target_position_px_;
// Defines if the camera is moving to a target (true) or reached a target
// within a tolerance (false).
bool motion_state_;
// Average period of incoming frames.
double mean_delta_t_;
};
} // namespace autoflip
@@ -22,4 +22,6 @@ message KinematicOptions {
optional double max_update_rate = 6 [default = 0.8];
// History time window of observations to be median filtered.
optional int64 filtering_time_window_us = 7 [default = 0];
// Weighted update of average period, used for motion updates.
optional float mean_period_update_rate = 8 [default = 0.25];
}
@@ -118,7 +118,7 @@ TEST(KinematicPathSolverTest, PassEnoughMotionNotFiltered) {
MP_ASSERT_OK(solver.AddObservation(500, kMicroSecInSec * 3));
MP_ASSERT_OK(solver.GetState(&state));
// Expect cam to not move.
EXPECT_EQ(state, 519);
EXPECT_EQ(state, 506);
}
TEST(KinematicPathSolverTest, PassEnoughMotionLargeImg) {
@@ -187,7 +187,7 @@ TEST(KinematicPathSolverTest, PassReframeWindow) {
MP_ASSERT_OK(solver.AddObservation(520, kMicroSecInSec * 1));
MP_ASSERT_OK(solver.GetState(&state));
// Expect cam to move 1.2-.75 deg, * 16.6 = 7.47px + 500 =
EXPECT_EQ(state, 507);
EXPECT_EQ(state, 508);
}
TEST(KinematicPathSolverTest, PassUpdateRate30FPS) {
@@ -227,9 +227,13 @@ TEST(KinematicPathSolverTest, PassUpdateRate) {
options.set_max_update_rate(1.0);
options.set_max_velocity(18);
KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
int state;
int state, target_position;
MP_ASSERT_OK(solver.AddObservation(500, kMicroSecInSec * 0));
MP_ASSERT_OK(solver.GetTargetPosition(&target_position));
EXPECT_EQ(target_position, 500);
MP_ASSERT_OK(solver.AddObservation(520, kMicroSecInSec * 1));
MP_ASSERT_OK(solver.GetTargetPosition(&target_position));
EXPECT_EQ(target_position, 520);
MP_ASSERT_OK(solver.GetState(&state));
EXPECT_EQ(state, 505);
}
@@ -45,7 +45,7 @@ PaddingEffectGenerator::PaddingEffectGenerator(const int input_width,
}
}
::mediapipe::Status PaddingEffectGenerator::Process(
mediapipe::Status PaddingEffectGenerator::Process(
const ImageFrame& input_frame, const float background_contrast,
const int blur_cv_size, const float overlay_opacity,
ImageFrame* output_frame, const cv::Scalar* background_color_in_rgb) {
@@ -170,7 +170,7 @@ PaddingEffectGenerator::PaddingEffectGenerator(const int input_width,
output_frame->CopyPixelData(input_frame.Format(), canvas.cols, canvas.rows,
canvas.data,
ImageFrame::kDefaultAlignmentBoundary);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
cv::Rect PaddingEffectGenerator::ComputeOutputLocation() {
@@ -49,7 +49,7 @@ class PaddingEffectGenerator {
// the opacity of the black layer.
// - background_color_in_rgb: If not null, uses this solid color as background
// instead of blurring the image, and does not adjust contrast or opacity.
::mediapipe::Status Process(
mediapipe::Status Process(
const ImageFrame& input_frame, const float background_contrast,
const int blur_cv_size, const float overlay_opacity,
ImageFrame* output_frame,
@@ -72,11 +72,11 @@ void TestWithAspectRatio(const double aspect_ratio,
cv::cvtColor(decoded_mat, output_mat, cv::COLOR_BGR2RGB);
break;
case 4:
MP_ASSERT_OK(::mediapipe::UnimplementedErrorBuilder(MEDIAPIPE_LOC)
MP_ASSERT_OK(mediapipe::UnimplementedErrorBuilder(MEDIAPIPE_LOC)
<< "4-channel image isn't supported yet");
break;
default:
MP_ASSERT_OK(::mediapipe::FailedPreconditionErrorBuilder(MEDIAPIPE_LOC)
MP_ASSERT_OK(mediapipe::FailedPreconditionErrorBuilder(MEDIAPIPE_LOC)
<< "Unsupported number of channels: "
<< decoded_mat.channels());
}
@@ -101,11 +101,11 @@ void TestWithAspectRatio(const double aspect_ratio,
cv::cvtColor(original_mat, input_mat, cv::COLOR_RGB2BGR);
break;
case 4:
MP_ASSERT_OK(::mediapipe::UnimplementedErrorBuilder(MEDIAPIPE_LOC)
MP_ASSERT_OK(mediapipe::UnimplementedErrorBuilder(MEDIAPIPE_LOC)
<< "4-channel image isn't supported yet");
break;
default:
MP_ASSERT_OK(::mediapipe::FailedPreconditionErrorBuilder(MEDIAPIPE_LOC)
MP_ASSERT_OK(mediapipe::FailedPreconditionErrorBuilder(MEDIAPIPE_LOC)
<< "Unsupported number of channels: "
<< original_mat.channels());
}
@@ -120,7 +120,7 @@ void TestWithAspectRatio(const double aspect_ratio,
// Check its JpegEncoder::write() in "imgcodecs/src/grfmt_jpeg.cpp" for more
// info.
if (!cv::imencode(".jpg", input_mat, encode_buffer, parameters)) {
MP_ASSERT_OK(::mediapipe::InternalErrorBuilder(MEDIAPIPE_LOC)
MP_ASSERT_OK(mediapipe::InternalErrorBuilder(MEDIAPIPE_LOC)
<< "Fail to encode the image to be jpeg format.");
}
@@ -91,7 +91,7 @@ void PolynomialRegressionPathSolver::AddCostFunctionToProblem(
problem->AddResidualBlock(cost_function, new CauchyLoss(0.5), a, b, c, d, k);
}
::mediapipe::Status PolynomialRegressionPathSolver::ComputeCameraPath(
mediapipe::Status PolynomialRegressionPathSolver::ComputeCameraPath(
const std::vector<FocusPointFrame>& focus_point_frames,
const std::vector<FocusPointFrame>& prior_focus_point_frames,
const int original_width, const int original_height, const int output_width,
@@ -42,7 +42,7 @@ class PolynomialRegressionPathSolver {
// y-axis, such that focus points can be preserved as much as possible. The
// returned |all_transforms| hold the camera location at each timestamp
// corresponding to each input frame.
::mediapipe::Status ComputeCameraPath(
mediapipe::Status ComputeCameraPath(
const std::vector<FocusPointFrame>& focus_point_frames,
const std::vector<FocusPointFrame>& prior_focus_point_frames,
const int original_width, const int original_height,
@@ -30,7 +30,7 @@
namespace mediapipe {
namespace autoflip {
::mediapipe::Status
mediapipe::Status
SceneCameraMotionAnalyzer::AnalyzeSceneAndPopulateFocusPointFrames(
const KeyFrameCropOptions& key_frame_crop_options,
const std::vector<KeyFrameCropResult>& key_frame_crop_results,
@@ -67,7 +67,7 @@ SceneCameraMotionAnalyzer::AnalyzeSceneAndPopulateFocusPointFrames(
scene_frame_timestamps, focus_point_frames);
}
::mediapipe::Status SceneCameraMotionAnalyzer::ToUseSteadyMotion(
mediapipe::Status SceneCameraMotionAnalyzer::ToUseSteadyMotion(
const float look_at_center_x, const float look_at_center_y,
const int crop_window_width, const int crop_window_height,
SceneKeyFrameCropSummary* scene_summary,
@@ -77,10 +77,10 @@ SceneCameraMotionAnalyzer::AnalyzeSceneAndPopulateFocusPointFrames(
auto* steady_motion = scene_camera_motion->mutable_steady_motion();
steady_motion->set_steady_look_at_center_x(look_at_center_x);
steady_motion->set_steady_look_at_center_y(look_at_center_y);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SceneCameraMotionAnalyzer::ToUseSweepingMotion(
mediapipe::Status SceneCameraMotionAnalyzer::ToUseSweepingMotion(
const float start_x, const float start_y, const float end_x,
const float end_y, const int crop_window_width,
const int crop_window_height, const double time_duration_in_sec,
@@ -99,10 +99,10 @@ SceneCameraMotionAnalyzer::AnalyzeSceneAndPopulateFocusPointFrames(
scene_summary->frame_success_rate(), start_x, start_y, end_x, end_y,
time_duration_in_sec);
VLOG(1) << sweeping_log;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SceneCameraMotionAnalyzer::DecideCameraMotionType(
mediapipe::Status SceneCameraMotionAnalyzer::DecideCameraMotionType(
const KeyFrameCropOptions& key_frame_crop_options,
const double scene_span_sec, const int64 end_time_us,
SceneKeyFrameCropSummary* scene_summary,
@@ -131,7 +131,7 @@ SceneCameraMotionAnalyzer::AnalyzeSceneAndPopulateFocusPointFrames(
no_salient_position_x, no_salient_position_y,
scene_summary->crop_window_width(), scene_summary->crop_window_height(),
scene_summary, scene_camera_motion));
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// Sweep across the scene when 1) success rate is too low, AND 2) the current
@@ -164,7 +164,7 @@ SceneCameraMotionAnalyzer::AnalyzeSceneAndPopulateFocusPointFrames(
start_x, start_y, end_x, end_y, key_frame_crop_options.target_width(),
key_frame_crop_options.target_height(), scene_span_sec, scene_summary,
scene_camera_motion));
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// If scene motion is small, then look at a steady point in the scene.
@@ -179,14 +179,14 @@ SceneCameraMotionAnalyzer::AnalyzeSceneAndPopulateFocusPointFrames(
// Otherwise, tracks the focus regions.
scene_camera_motion->mutable_tracking_motion();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// If there is no required focus region, looks at the middle of the center
// range, and snaps to the scene center if close. Otherwise, look at the center
// of the union of the required focus regions, and ensures the crop region
// covers this union.
::mediapipe::Status SceneCameraMotionAnalyzer::DecideSteadyLookAtRegion(
mediapipe::Status SceneCameraMotionAnalyzer::DecideSteadyLookAtRegion(
const KeyFrameCropOptions& key_frame_crop_options,
SceneKeyFrameCropSummary* scene_summary,
SceneCameraMotion* scene_camera_motion) const {
@@ -252,10 +252,10 @@ SceneCameraMotionAnalyzer::AnalyzeSceneAndPopulateFocusPointFrames(
MP_RETURN_IF_ERROR(ToUseSteadyMotion(center_x, center_y, crop_width,
crop_height, scene_summary,
scene_camera_motion));
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status
mediapipe::Status
SceneCameraMotionAnalyzer::AddFocusPointsFromCenterTypeAndWeight(
const float center_x, const float center_y, const int frame_width,
const int frame_height, const FocusPointFrameType type, const float weight,
@@ -294,10 +294,10 @@ SceneCameraMotionAnalyzer::AddFocusPointsFromCenterTypeAndWeight(
} else {
RET_CHECK_FAIL() << absl::StrCat("Invalid FocusPointFrameType ", type);
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SceneCameraMotionAnalyzer::PopulateFocusPointFrames(
mediapipe::Status SceneCameraMotionAnalyzer::PopulateFocusPointFrames(
const SceneKeyFrameCropSummary& scene_summary,
const SceneCameraMotion& scene_camera_motion,
const std::vector<int64>& scene_frame_timestamps,
@@ -340,7 +340,7 @@ SceneCameraMotionAnalyzer::AddFocusPointsFromCenterTypeAndWeight(
options_.salient_point_bound(), &focus_point_frame));
focus_point_frames->push_back(focus_point_frame);
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
} else if (scene_camera_motion.has_sweeping_motion()) {
// Camera sweeps across the frame.
const auto& sweeping_motion = scene_camera_motion.sweeping_motion();
@@ -361,7 +361,7 @@ SceneCameraMotionAnalyzer::AddFocusPointsFromCenterTypeAndWeight(
options_.salient_point_bound(), &focus_point_frame));
focus_point_frames->push_back(focus_point_frame);
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
} else if (scene_camera_motion.has_tracking_motion()) {
// Camera tracks crop regions.
RET_CHECK_GT(scene_summary.num_key_frames(), 0) << "No key frames.";
@@ -369,8 +369,8 @@ SceneCameraMotionAnalyzer::AddFocusPointsFromCenterTypeAndWeight(
scene_summary, focus_point_frame_type, scene_frame_timestamps,
focus_point_frames);
} else {
return ::mediapipe::Status(StatusCode::kInvalidArgument,
"Unknown motion type.");
return mediapipe::Status(StatusCode::kInvalidArgument,
"Unknown motion type.");
}
}
@@ -380,7 +380,7 @@ SceneCameraMotionAnalyzer::AddFocusPointsFromCenterTypeAndWeight(
// The weight for the focus point is proportional to the interpolated score
// and scaled so that the maximum weight is equal to
// maximum_focus_point_weight in the SceneCameraMotionAnalyzerOptions.
::mediapipe::Status
mediapipe::Status
SceneCameraMotionAnalyzer::PopulateFocusPointFramesForTracking(
const SceneKeyFrameCropSummary& scene_summary,
const FocusPointFrameType focus_point_frame_type,
@@ -440,7 +440,7 @@ SceneCameraMotionAnalyzer::PopulateFocusPointFramesForTracking(
focus_point->set_weight(scale * focus_point->weight());
}
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -62,7 +62,7 @@ class SceneCameraMotionAnalyzer {
// Aggregates information from KeyFrameInfos and KeyFrameCropResults into
// SceneKeyFrameCropSummary, and populates FocusPointFrames given scene
// frame timestamps. Optionally returns SceneCameraMotion.
::mediapipe::Status AnalyzeSceneAndPopulateFocusPointFrames(
mediapipe::Status AnalyzeSceneAndPopulateFocusPointFrames(
const KeyFrameCropOptions& key_frame_crop_options,
const std::vector<KeyFrameCropResult>& key_frame_crop_results,
const int scene_frame_width, const int scene_frame_height,
@@ -75,7 +75,7 @@ class SceneCameraMotionAnalyzer {
protected:
// Decides SceneCameraMotion based on SceneKeyFrameCropSummary. Updates the
// crop window in SceneKeyFrameCropSummary in the case of steady motion.
::mediapipe::Status DecideCameraMotionType(
mediapipe::Status DecideCameraMotionType(
const KeyFrameCropOptions& key_frame_crop_options,
const double scene_span_sec, const int64 end_time_us,
SceneKeyFrameCropSummary* scene_summary,
@@ -83,7 +83,7 @@ class SceneCameraMotionAnalyzer {
// Populates the FocusPointFrames for each scene frame based on
// SceneKeyFrameCropSummary, SceneCameraMotion, and scene frame timestamps.
::mediapipe::Status PopulateFocusPointFrames(
mediapipe::Status PopulateFocusPointFrames(
const SceneKeyFrameCropSummary& scene_summary,
const SceneCameraMotion& scene_camera_motion,
const std::vector<int64>& scene_frame_timestamps,
@@ -91,7 +91,7 @@ class SceneCameraMotionAnalyzer {
private:
// Decides the look-at region when camera is steady.
::mediapipe::Status DecideSteadyLookAtRegion(
mediapipe::Status DecideSteadyLookAtRegion(
const KeyFrameCropOptions& key_frame_crop_options,
SceneKeyFrameCropSummary* scene_summary,
SceneCameraMotion* scene_camera_motion) const;
@@ -105,7 +105,7 @@ class SceneCameraMotionAnalyzer {
// Adds FocusPoint(s) to given FocusPointFrame given center location,
// frame size, FocusPointFrameType, weight, and bound.
::mediapipe::Status AddFocusPointsFromCenterTypeAndWeight(
mediapipe::Status AddFocusPointsFromCenterTypeAndWeight(
const float center_x, const float center_y, const int frame_width,
const int frame_height, const FocusPointFrameType type,
const float weight, const float bound,
@@ -114,21 +114,21 @@ class SceneCameraMotionAnalyzer {
// Populates the FocusPointFrames for each scene frame based on
// SceneKeyFrameCropSummary and scene frame timestamps in the case where
// camera is tracking the crop regions.
::mediapipe::Status PopulateFocusPointFramesForTracking(
mediapipe::Status PopulateFocusPointFramesForTracking(
const SceneKeyFrameCropSummary& scene_summary,
const FocusPointFrameType focus_point_frame_type,
const std::vector<int64>& scene_frame_timestamps,
std::vector<FocusPointFrame>* focus_point_frames) const;
// Decide to use steady motion.
::mediapipe::Status ToUseSteadyMotion(
mediapipe::Status ToUseSteadyMotion(
const float look_at_center_x, const float look_at_center_y,
const int crop_window_width, const int crop_window_height,
SceneKeyFrameCropSummary* scene_summary,
SceneCameraMotion* scene_camera_motion) const;
// Decide to use sweeping motion.
::mediapipe::Status ToUseSweepingMotion(
mediapipe::Status ToUseSweepingMotion(
const float start_x, const float start_y, const float end_x,
const float end_y, const int crop_window_width,
const int crop_window_height, const double time_duration_in_sec,
@@ -29,7 +29,7 @@ constexpr float kWidthFieldOfView = 60;
namespace mediapipe {
namespace autoflip {
::mediapipe::Status SceneCropper::ProcessKinematicPathSolver(
mediapipe::Status SceneCropper::ProcessKinematicPathSolver(
const SceneKeyFrameCropSummary& scene_summary,
const std::vector<int64>& scene_timestamps,
const std::vector<bool>& is_key_frames,
@@ -77,10 +77,10 @@ namespace autoflip {
-(x_path - scene_summary.crop_window_width() / 2);
all_xforms->push_back(transform);
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SceneCropper::CropFrames(
mediapipe::Status SceneCropper::CropFrames(
const SceneKeyFrameCropSummary& scene_summary,
const std::vector<int64>& scene_timestamps,
const std::vector<bool>& is_key_frames,
@@ -151,7 +151,7 @@ namespace autoflip {
// If no cropped_frames is passed in, return directly.
if (!cropped_frames) {
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
RET_CHECK(!scene_frames_or_empty.empty())
<< "If |cropped_frames| != nullptr, scene_frames_or_empty must not be "
@@ -60,7 +60,7 @@ class SceneCropper {
// on the transform matrix if |cropped_frames| is not nullptr and
// |scene_frames_or_empty| isn't empty.
// TODO: split this function into two separate functions.
::mediapipe::Status CropFrames(
mediapipe::Status CropFrames(
const SceneKeyFrameCropSummary& scene_summary,
const std::vector<int64>& scene_timestamps,
const std::vector<bool>& is_key_frames,
@@ -71,7 +71,7 @@ class SceneCropper {
const bool continue_last_scene, std::vector<cv::Rect>* crop_from_location,
std::vector<cv::Mat>* cropped_frames);
::mediapipe::Status ProcessKinematicPathSolver(
mediapipe::Status ProcessKinematicPathSolver(
const SceneKeyFrameCropSummary& scene_summary,
const std::vector<int64>& scene_timestamps,
const std::vector<bool>& is_key_frames,
@@ -46,7 +46,7 @@ const cv::Scalar kOrange =
cv::Scalar(255.0, 165.0, 0.0); // ica object detector
const cv::Scalar kWhite = cv::Scalar(255.0, 255.0, 255.0); // others
::mediapipe::Status DrawDetectionsAndCropRegions(
mediapipe::Status DrawDetectionsAndCropRegions(
const std::vector<cv::Mat>& scene_frames,
const std::vector<bool>& is_key_frames,
const std::vector<KeyFrameInfo>& key_frame_infos,
@@ -130,7 +130,7 @@ const cv::Scalar kWhite = cv::Scalar(255.0, 255.0, 255.0); // others
}
viz_frames->push_back(std::move(viz_frame));
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
namespace {
@@ -147,7 +147,7 @@ cv::Rect LimitBounds(const cv::Rect& rect, const int max_width,
}
} // namespace
::mediapipe::Status DrawDetectionAndFramingWindow(
mediapipe::Status DrawDetectionAndFramingWindow(
const std::vector<cv::Mat>& org_scene_frames,
const std::vector<cv::Rect>& crop_from_locations,
const ImageFormat::Format image_format, const float overlay_opacity,
@@ -166,10 +166,10 @@ cv::Rect LimitBounds(const cv::Rect& rect, const int max_width,
scene_frame(crop_from_bounded).copyTo(darkened(crop_from_bounded));
viz_frames->push_back(std::move(viz_frame));
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status DrawFocusPointAndCropWindow(
mediapipe::Status DrawFocusPointAndCropWindow(
const std::vector<cv::Mat>& scene_frames,
const std::vector<FocusPointFrame>& focus_point_frames,
const float overlay_opacity, const int crop_window_width,
@@ -215,7 +215,7 @@ cv::Rect LimitBounds(const cv::Rect& rect, const int max_width,
}
viz_frames->push_back(std::move(viz_frame));
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -36,7 +36,7 @@ namespace autoflip {
// magenta, logos are red, ocrs are yellow (foreground) and light yellow
// (background), brain objects are cyan, ica objects are orange, and the rest
// are white.
::mediapipe::Status DrawDetectionsAndCropRegions(
mediapipe::Status DrawDetectionsAndCropRegions(
const std::vector<cv::Mat>& scene_frames,
const std::vector<bool>& is_key_frames,
const std::vector<KeyFrameInfo>& key_frame_infos,
@@ -47,7 +47,7 @@ namespace autoflip {
// Draws the focus point from the given FocusPointFrame and the crop window
// centered around it on the scene frame in red. This helps visualize the input
// to the retargeter.
::mediapipe::Status DrawFocusPointAndCropWindow(
mediapipe::Status DrawFocusPointAndCropWindow(
const std::vector<cv::Mat>& scene_frames,
const std::vector<FocusPointFrame>& focus_point_frames,
const float overlay_opacity, const int crop_window_width,
@@ -57,7 +57,7 @@ namespace autoflip {
// Draws the final smoothed path of the camera retargeter by darkening the
// removed areas.
::mediapipe::Status DrawDetectionAndFramingWindow(
mediapipe::Status DrawDetectionAndFramingWindow(
const std::vector<cv::Mat>& org_scene_frames,
const std::vector<cv::Rect>& crop_from_locations,
const ImageFormat::Format image_format, const float overlay_opacity,
@@ -53,13 +53,12 @@ void NormalizedRectToRect(const RectF& normalized_location, const int width,
ScaleRect(normalized_location, width, height, location);
}
::mediapipe::Status ClampRect(const int width, const int height,
Rect* location) {
mediapipe::Status ClampRect(const int width, const int height, Rect* location) {
return ClampRect(0, 0, width, height, location);
}
::mediapipe::Status ClampRect(const int x0, const int y0, const int x1,
const int y1, Rect* location) {
mediapipe::Status ClampRect(const int x0, const int y0, const int x1,
const int y1, Rect* location) {
RET_CHECK(!(location->x() >= x1 || location->x() + location->width() <= x0 ||
location->y() >= y1 || location->y() + location->height() <= y0));
@@ -74,7 +73,7 @@ void NormalizedRectToRect(const RectF& normalized_location, const int width,
location->set_y(clamped_top);
location->set_width(std::max(0, clamped_right - clamped_left));
location->set_height(std::max(0, clamped_bottom - clamped_top));
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
void RectUnion(const Rect& rect_to_add, Rect* rect) {
@@ -90,13 +89,13 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
rect->set_height(y2 - y1);
}
::mediapipe::Status PackKeyFrameInfo(const int64 frame_timestamp_ms,
const DetectionSet& detections,
const int original_frame_width,
const int original_frame_height,
const int feature_frame_width,
const int feature_frame_height,
KeyFrameInfo* key_frame_info) {
mediapipe::Status PackKeyFrameInfo(const int64 frame_timestamp_ms,
const DetectionSet& detections,
const int original_frame_width,
const int original_frame_height,
const int feature_frame_width,
const int feature_frame_height,
KeyFrameInfo* key_frame_info) {
RET_CHECK(key_frame_info != nullptr) << "KeyFrameInfo is null";
RET_CHECK(original_frame_width > 0 && original_frame_height > 0 &&
feature_frame_width > 0 && feature_frame_height > 0)
@@ -136,10 +135,10 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
}
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SortDetections(
mediapipe::Status SortDetections(
const DetectionSet& detections,
std::vector<SalientRegion>* required_regions,
std::vector<SalientRegion>* non_required_regions) {
@@ -175,13 +174,13 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
non_required_regions->push_back(detections.detections(original_idx));
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status SetKeyFrameCropTarget(const int frame_width,
const int frame_height,
const double target_aspect_ratio,
KeyFrameCropOptions* crop_options) {
mediapipe::Status SetKeyFrameCropTarget(const int frame_width,
const int frame_height,
const double target_aspect_ratio,
KeyFrameCropOptions* crop_options) {
RET_CHECK_NE(crop_options, nullptr) << "KeyFrameCropOptions is null.";
RET_CHECK_GT(frame_width, 0) << "Frame width is non-positive.";
RET_CHECK_GT(frame_height, 0) << "Frame height is non-positive.";
@@ -199,10 +198,10 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
: std::round(frame_width / target_aspect_ratio);
crop_options->set_target_width(crop_target_width);
crop_options->set_target_height(crop_target_height);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status AggregateKeyFrameResults(
mediapipe::Status AggregateKeyFrameResults(
const KeyFrameCropOptions& key_frame_crop_options,
const std::vector<KeyFrameCropResult>& key_frame_crop_results,
const int scene_frame_width, const int scene_frame_height,
@@ -232,7 +231,7 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
// Handles the corner case of no key frames.
if (num_key_frames == 0) {
scene_summary->set_has_salient_region(false);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
scene_summary->set_num_key_frames(num_key_frames);
@@ -328,10 +327,10 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
scene_summary->key_frame_center_min_y()) /
scene_frame_height;
scene_summary->set_vertical_motion_amount(motion_y);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status ComputeSceneStaticBordersSize(
mediapipe::Status ComputeSceneStaticBordersSize(
const std::vector<StaticFeatures>& static_features, int* top_border_size,
int* bottom_border_size) {
RET_CHECK(top_border_size) << "Output top border size is null.";
@@ -375,10 +374,10 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
*top_border_size = std::max(0, *top_border_size);
*bottom_border_size = std::max(0, *bottom_border_size);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status FindSolidBackgroundColor(
mediapipe::Status FindSolidBackgroundColor(
const std::vector<StaticFeatures>& static_features,
const std::vector<int64>& static_features_timestamps,
const double min_fraction_solid_background_color,
@@ -423,13 +422,13 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
min_fraction_solid_background_color) {
*has_solid_background = true;
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status AffineRetarget(
const cv::Size& output_size, const std::vector<cv::Mat>& frames,
const std::vector<cv::Mat>& affine_projection,
std::vector<cv::Mat>* cropped_frames) {
mediapipe::Status AffineRetarget(const cv::Size& output_size,
const std::vector<cv::Mat>& frames,
const std::vector<cv::Mat>& affine_projection,
std::vector<cv::Mat>* cropped_frames) {
RET_CHECK(frames.size() == affine_projection.size())
<< "number of frames and retarget offsets must be the same.";
RET_CHECK(cropped_frames->size() == frames.size())
@@ -443,7 +442,7 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
RET_CHECK(affine.rows == 2) << "Affine matrix must be 2x3";
cv::warpAffine(frames[i], (*cropped_frames)[i], affine, output_size);
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
} // namespace mediapipe
@@ -29,16 +29,16 @@ namespace autoflip {
// Packs detected features and timestamp (ms) into a KeyFrameInfo object. Scales
// features back to the original frame size if features have been detected on a
// different frame size.
::mediapipe::Status PackKeyFrameInfo(const int64 frame_timestamp_ms,
const DetectionSet& detections,
const int original_frame_width,
const int original_frame_height,
const int feature_frame_width,
const int feature_frame_height,
KeyFrameInfo* key_frame_info);
mediapipe::Status PackKeyFrameInfo(const int64 frame_timestamp_ms,
const DetectionSet& detections,
const int original_frame_width,
const int original_frame_height,
const int feature_frame_width,
const int feature_frame_height,
KeyFrameInfo* key_frame_info);
// Sorts required and non-required salient regions given a detection set.
::mediapipe::Status SortDetections(
mediapipe::Status SortDetections(
const DetectionSet& detections,
std::vector<SalientRegion>* required_regions,
std::vector<SalientRegion>* non_required_regions);
@@ -46,14 +46,14 @@ namespace autoflip {
// Sets the target crop size in KeyFrameCropOptions based on frame size and
// target aspect ratio so that the target crop size covers the biggest area
// possible in the frame.
::mediapipe::Status SetKeyFrameCropTarget(const int frame_width,
const int frame_height,
const double target_aspect_ratio,
KeyFrameCropOptions* crop_options);
mediapipe::Status SetKeyFrameCropTarget(const int frame_width,
const int frame_height,
const double target_aspect_ratio,
KeyFrameCropOptions* crop_options);
// Aggregates information from KeyFrameInfos and KeyFrameCropResults into
// SceneKeyFrameCropSummary.
::mediapipe::Status AggregateKeyFrameResults(
mediapipe::Status AggregateKeyFrameResults(
const KeyFrameCropOptions& key_frame_crop_options,
const std::vector<KeyFrameCropResult>& key_frame_crop_results,
const int scene_frame_width, const int scene_frame_height,
@@ -61,7 +61,7 @@ namespace autoflip {
// Computes the static top and border size across a scene given a vector of
// StaticFeatures over frames.
::mediapipe::Status ComputeSceneStaticBordersSize(
mediapipe::Status ComputeSceneStaticBordersSize(
const std::vector<StaticFeatures>& static_features, int* top_border_size,
int* bottom_border_size);
@@ -70,7 +70,7 @@ namespace autoflip {
// background color exceeds given threshold, i.e.,
// min_fraction_solid_background_color. Builds the background color
// interpolation functions in Lab space using input timestamps.
::mediapipe::Status FindSolidBackgroundColor(
mediapipe::Status FindSolidBackgroundColor(
const std::vector<StaticFeatures>& static_features,
const std::vector<int64>& static_features_timestamps,
const double min_fraction_solid_background_color,
@@ -93,13 +93,12 @@ void NormalizedRectToRect(const RectF& normalized_location, const int width,
// Clamps a rectangle to lie within [x0, y0] and [x1, y1]. Returns true if the
// rectangle has any overlapping with the target window.
::mediapipe::Status ClampRect(const int x0, const int y0, const int x1,
const int y1, Rect* location);
mediapipe::Status ClampRect(const int x0, const int y0, const int x1,
const int y1, Rect* location);
// Convenience function to clamp a rectangle to lie within [0, 0] and
// [width, height].
::mediapipe::Status ClampRect(const int width, const int height,
Rect* location);
mediapipe::Status ClampRect(const int width, const int height, Rect* location);
// Enlarges a given rectangle to cover a new rectangle to be added.
void RectUnion(const Rect& rect_to_add, Rect* rect);
@@ -107,10 +106,10 @@ void RectUnion(const Rect& rect_to_add, Rect* rect);
// Performs an affine retarget on a list of input images. Output vector
// cropped_frames must be filled with Mats of the same size as output_size and
// type.
::mediapipe::Status AffineRetarget(
const cv::Size& output_size, const std::vector<cv::Mat>& frames,
const std::vector<cv::Mat>& affine_projection,
std::vector<cv::Mat>* cropped_frames);
mediapipe::Status AffineRetarget(const cv::Size& output_size,
const std::vector<cv::Mat>& frames,
const std::vector<cv::Mat>& affine_projection,
std::vector<cv::Mat>* cropped_frames);
} // namespace autoflip
} // namespace mediapipe
@@ -67,14 +67,14 @@ mediapipe::Status VisualScorer::CalculateScore(const cv::Mat& image,
region.location_normalized().width() * image.cols,
region.location_normalized().height() * image.rows);
} else {
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "Unset region location.";
}
CropRectToMat(image, &region_rect);
if (region_rect.area() == 0) {
*score = 0;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// Compute a score based on area covered by this region.
@@ -89,7 +89,7 @@ mediapipe::Status VisualScorer::CalculateScore(const cv::Mat& image,
float sharpness_score_result = 0.0;
if (options_.sharpness_weight() > kEpsilon) {
// TODO: implement a sharpness score or remove this code block.
return ::mediapipe::InvalidArgumentErrorBuilder(MEDIAPIPE_LOC)
return mediapipe::InvalidArgumentErrorBuilder(MEDIAPIPE_LOC)
<< "sharpness scorer is not yet implemented, please set weight to "
"0.0";
}
@@ -108,7 +108,7 @@ mediapipe::Status VisualScorer::CalculateScore(const cv::Mat& image,
if (*score > 1.0f || *score < 0.0f) {
LOG(WARNING) << "Score of region outside expected range: " << *score;
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
mediapipe::Status VisualScorer::CalculateColorfulness(
@@ -134,7 +134,7 @@ mediapipe::Status VisualScorer::CalculateColorfulness(
// If the mask is empty, return.
if (empty_mask) {
*colorfulness = 0;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// Generate a 2D histogram (hue/saturation).
@@ -162,7 +162,7 @@ mediapipe::Status VisualScorer::CalculateColorfulness(
}
if (hue_sum == 0.0f) {
*colorfulness = 0;
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
// Compute the histogram entropy.
@@ -175,7 +175,7 @@ mediapipe::Status VisualScorer::CalculateColorfulness(
}
*colorfulness /= std::log(2.0f);
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
} // namespace autoflip
@@ -40,7 +40,7 @@ DEFINE_string(output_video_path, "",
"Full path of where to save result (.mp4 only). "
"If not provided, show result in a window.");
::mediapipe::Status RunMPPGraph() {
mediapipe::Status RunMPPGraph() {
std::string calculator_graph_config_contents;
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
FLAGS_calculator_graph_config_file, &calculator_graph_config_contents));
@@ -86,7 +86,14 @@ DEFINE_string(output_video_path, "",
// Capture opencv camera or video frame.
cv::Mat camera_frame_raw;
capture >> camera_frame_raw;
if (camera_frame_raw.empty()) break; // End of video.
if (camera_frame_raw.empty()) {
if (!load_video) {
LOG(INFO) << "Ignore empty frames from camera.";
continue;
}
LOG(INFO) << "Empty frame, end of video reached.";
break;
}
cv::Mat camera_frame;
cv::cvtColor(camera_frame_raw, camera_frame, cv::COLOR_BGR2RGB);
if (!load_video) {
@@ -141,7 +148,7 @@ DEFINE_string(output_video_path, "",
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
::mediapipe::Status run_status = RunMPPGraph();
mediapipe::Status run_status = RunMPPGraph();
if (!run_status.ok()) {
LOG(ERROR) << "Failed to run the graph: " << run_status.message();
return EXIT_FAILURE;
@@ -44,7 +44,7 @@ DEFINE_string(output_video_path, "",
"Full path of where to save result (.mp4 only). "
"If not provided, show result in a window.");
::mediapipe::Status RunMPPGraph() {
mediapipe::Status RunMPPGraph() {
std::string calculator_graph_config_contents;
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
FLAGS_calculator_graph_config_file, &calculator_graph_config_contents));
@@ -96,16 +96,23 @@ DEFINE_string(output_video_path, "",
// Capture opencv camera or video frame.
cv::Mat camera_frame_raw;
capture >> camera_frame_raw;
if (camera_frame_raw.empty()) break; // End of video.
if (camera_frame_raw.empty()) {
if (!load_video) {
LOG(INFO) << "Ignore empty frames from camera.";
continue;
}
LOG(INFO) << "Empty frame, end of video reached.";
break;
}
cv::Mat camera_frame;
cv::cvtColor(camera_frame_raw, camera_frame, cv::COLOR_BGR2RGB);
cv::cvtColor(camera_frame_raw, camera_frame, cv::COLOR_BGR2RGBA);
if (!load_video) {
cv::flip(camera_frame, camera_frame, /*flipcode=HORIZONTAL*/ 1);
}
// Wrap Mat into an ImageFrame.
auto input_frame = absl::make_unique<mediapipe::ImageFrame>(
mediapipe::ImageFormat::SRGB, camera_frame.cols, camera_frame.rows,
mediapipe::ImageFormat::SRGBA, camera_frame.cols, camera_frame.rows,
mediapipe::ImageFrame::kGlDefaultAlignmentBoundary);
cv::Mat input_frame_mat = mediapipe::formats::MatView(input_frame.get());
camera_frame.copyTo(input_frame_mat);
@@ -125,7 +132,7 @@ DEFINE_string(output_video_path, "",
MP_RETURN_IF_ERROR(graph.AddPacketToInputStream(
kInputStream, mediapipe::Adopt(gpu_frame.release())
.At(mediapipe::Timestamp(frame_timestamp_us))));
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}));
// Get the graph result packet, or stop if that fails.
@@ -149,12 +156,15 @@ DEFINE_string(output_video_path, "",
info.gl_type, output_frame->MutablePixelData());
glFlush();
texture.Release();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}));
// Convert back to opencv for display or saving.
cv::Mat output_frame_mat = mediapipe::formats::MatView(output_frame.get());
cv::cvtColor(output_frame_mat, output_frame_mat, cv::COLOR_RGB2BGR);
if (output_frame_mat.channels() == 4)
cv::cvtColor(output_frame_mat, output_frame_mat, cv::COLOR_RGBA2BGR);
else
cv::cvtColor(output_frame_mat, output_frame_mat, cv::COLOR_RGB2BGR);
if (save_video) {
if (!writer.isOpened()) {
LOG(INFO) << "Prepare video writer.";
@@ -181,7 +191,7 @@ DEFINE_string(output_video_path, "",
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
::mediapipe::Status run_status = RunMPPGraph();
mediapipe::Status run_status = RunMPPGraph();
if (!run_status.ok()) {
LOG(ERROR) << "Failed to run the graph: " << run_status.message();
return EXIT_FAILURE;
@@ -21,7 +21,7 @@
namespace mediapipe {
::mediapipe::Status PrintHelloWorld() {
mediapipe::Status PrintHelloWorld() {
// Configures a simple graph, which concatenates 2 PassThroughCalculators.
CalculatorGraphConfig config = ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
input_stream: "in"
@@ -0,0 +1,34 @@
# Copyright 2020 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
cc_binary(
name = "holistic_tracking_cpu",
deps = [
"//mediapipe/examples/desktop:demo_run_graph_main",
"//mediapipe/graphs/holistic_tracking:holistic_tracking_cpu_graph_deps",
],
)
# Linux only
cc_binary(
name = "holistic_tracking_gpu",
deps = [
"//mediapipe/examples/desktop:demo_run_graph_main_gpu",
"//mediapipe/graphs/holistic_tracking:holistic_tracking_gpu_deps",
],
)
@@ -47,25 +47,25 @@ DEFINE_string(output_image_path, "",
namespace {
::mediapipe::StatusOr<std::string> ReadFileToString(
mediapipe::StatusOr<std::string> ReadFileToString(
const std::string& file_path) {
std::string contents;
MP_RETURN_IF_ERROR(::mediapipe::file::GetContents(file_path, &contents));
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(file_path, &contents));
return contents;
}
::mediapipe::Status ProcessImage(
std::unique_ptr<::mediapipe::CalculatorGraph> graph) {
mediapipe::Status ProcessImage(
std::unique_ptr<mediapipe::CalculatorGraph> graph) {
LOG(INFO) << "Load the image.";
ASSIGN_OR_RETURN(const std::string raw_image,
ReadFileToString(FLAGS_input_image_path));
LOG(INFO) << "Start running the calculator graph.";
ASSIGN_OR_RETURN(::mediapipe::OutputStreamPoller output_image_poller,
ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller output_image_poller,
graph->AddOutputStreamPoller(kOutputImageStream));
ASSIGN_OR_RETURN(::mediapipe::OutputStreamPoller left_iris_depth_poller,
ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller left_iris_depth_poller,
graph->AddOutputStreamPoller(kLeftIrisDepthMmStream));
ASSIGN_OR_RETURN(::mediapipe::OutputStreamPoller right_iris_depth_poller,
ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller right_iris_depth_poller,
graph->AddOutputStreamPoller(kRightIrisDepthMmStream));
MP_RETURN_IF_ERROR(graph->StartRun({}));
@@ -74,22 +74,22 @@ namespace {
(double)cv::getTickFrequency() *
kMicrosPerSecond;
MP_RETURN_IF_ERROR(graph->AddPacketToInputStream(
kInputStream, ::mediapipe::MakePacket<std::string>(raw_image).At(
::mediapipe::Timestamp(fake_timestamp_us))));
kInputStream, mediapipe::MakePacket<std::string>(raw_image).At(
mediapipe::Timestamp(fake_timestamp_us))));
// Get the graph result packets, or stop if that fails.
::mediapipe::Packet left_iris_depth_packet;
mediapipe::Packet left_iris_depth_packet;
if (!left_iris_depth_poller.Next(&left_iris_depth_packet)) {
return ::mediapipe::UnknownError(
return mediapipe::UnknownError(
"Failed to get packet from output stream 'left_iris_depth_mm'.");
}
const auto& left_iris_depth_mm = left_iris_depth_packet.Get<float>();
const int left_iris_depth_cm = std::round(left_iris_depth_mm / 10);
std::cout << "Left Iris Depth: " << left_iris_depth_cm << " cm." << std::endl;
::mediapipe::Packet right_iris_depth_packet;
mediapipe::Packet right_iris_depth_packet;
if (!right_iris_depth_poller.Next(&right_iris_depth_packet)) {
return ::mediapipe::UnknownError(
return mediapipe::UnknownError(
"Failed to get packet from output stream 'right_iris_depth_mm'.");
}
const auto& right_iris_depth_mm = right_iris_depth_packet.Get<float>();
@@ -97,15 +97,15 @@ namespace {
std::cout << "Right Iris Depth: " << right_iris_depth_cm << " cm."
<< std::endl;
::mediapipe::Packet output_image_packet;
mediapipe::Packet output_image_packet;
if (!output_image_poller.Next(&output_image_packet)) {
return ::mediapipe::UnknownError(
return mediapipe::UnknownError(
"Failed to get packet from output stream 'output_image'.");
}
auto& output_frame = output_image_packet.Get<::mediapipe::ImageFrame>();
auto& output_frame = output_image_packet.Get<mediapipe::ImageFrame>();
// Convert back to opencv for display or saving.
cv::Mat output_frame_mat = ::mediapipe::formats::MatView(&output_frame);
cv::Mat output_frame_mat = mediapipe::formats::MatView(&output_frame);
cv::cvtColor(output_frame_mat, output_frame_mat, cv::COLOR_RGB2BGR);
const bool save_image = !FLAGS_output_image_path.empty();
if (save_image) {
@@ -123,26 +123,26 @@ namespace {
return graph->WaitUntilDone();
}
::mediapipe::Status RunMPPGraph() {
mediapipe::Status RunMPPGraph() {
std::string calculator_graph_config_contents;
MP_RETURN_IF_ERROR(::mediapipe::file::GetContents(
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
kCalculatorGraphConfigFile, &calculator_graph_config_contents));
LOG(INFO) << "Get calculator graph config contents: "
<< calculator_graph_config_contents;
::mediapipe::CalculatorGraphConfig config =
::mediapipe::ParseTextProtoOrDie<::mediapipe::CalculatorGraphConfig>(
mediapipe::CalculatorGraphConfig config =
mediapipe::ParseTextProtoOrDie<mediapipe::CalculatorGraphConfig>(
calculator_graph_config_contents);
LOG(INFO) << "Initialize the calculator graph.";
std::unique_ptr<::mediapipe::CalculatorGraph> graph =
absl::make_unique<::mediapipe::CalculatorGraph>();
std::unique_ptr<mediapipe::CalculatorGraph> graph =
absl::make_unique<mediapipe::CalculatorGraph>();
MP_RETURN_IF_ERROR(graph->Initialize(config));
const bool load_image = !FLAGS_input_image_path.empty();
if (load_image) {
return ProcessImage(std::move(graph));
} else {
return ::mediapipe::InvalidArgumentError("Missing image file.");
return mediapipe::InvalidArgumentError("Missing image file.");
}
}
@@ -151,7 +151,7 @@ namespace {
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
::mediapipe::Status run_status = RunMPPGraph();
mediapipe::Status run_status = RunMPPGraph();
if (!run_status.ok()) {
LOG(ERROR) << "Failed to run the graph: " << run_status.message();
return EXIT_FAILURE;
@@ -38,7 +38,7 @@ DEFINE_string(output_side_packets, "",
"side packets and paths to write to disk for the "
"CalculatorGraph.");
::mediapipe::Status RunMPPGraph() {
mediapipe::Status RunMPPGraph() {
std::string calculator_graph_config_contents;
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
FLAGS_calculator_graph_config_file, &calculator_graph_config_contents));
@@ -47,18 +47,18 @@ DEFINE_string(output_side_packets, "",
mediapipe::CalculatorGraphConfig config =
mediapipe::ParseTextProtoOrDie<mediapipe::CalculatorGraphConfig>(
calculator_graph_config_contents);
std::map<std::string, ::mediapipe::Packet> input_side_packets;
std::map<std::string, mediapipe::Packet> input_side_packets;
std::vector<std::string> kv_pairs =
absl::StrSplit(FLAGS_input_side_packets, ',');
for (const std::string& kv_pair : kv_pairs) {
std::vector<std::string> name_and_value = absl::StrSplit(kv_pair, '=');
RET_CHECK(name_and_value.size() == 2);
RET_CHECK(!::mediapipe::ContainsKey(input_side_packets, name_and_value[0]));
RET_CHECK(!mediapipe::ContainsKey(input_side_packets, name_and_value[0]));
std::string input_side_packet_contents;
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
name_and_value[1], &input_side_packet_contents));
input_side_packets[name_and_value[0]] =
::mediapipe::MakePacket<std::string>(input_side_packet_contents);
mediapipe::MakePacket<std::string>(input_side_packet_contents);
}
LOG(INFO) << "Initialize the calculator graph.";
mediapipe::CalculatorGraph graph;
@@ -70,7 +70,7 @@ DEFINE_string(output_side_packets, "",
for (const std::string& kv_pair : kv_pairs) {
std::vector<std::string> name_and_value = absl::StrSplit(kv_pair, '=');
RET_CHECK(name_and_value.size() == 2);
::mediapipe::StatusOr<::mediapipe::Packet> output_packet =
mediapipe::StatusOr<mediapipe::Packet> output_packet =
graph.GetOutputSidePacket(name_and_value[0]);
RET_CHECK(output_packet.ok())
<< "Packet " << name_and_value[0] << " was not available.";
@@ -79,13 +79,13 @@ DEFINE_string(output_side_packets, "",
MP_RETURN_IF_ERROR(
mediapipe::file::SetContents(name_and_value[1], serialized_string));
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
::mediapipe::Status run_status = RunMPPGraph();
mediapipe::Status run_status = RunMPPGraph();
if (!run_status.ok()) {
LOG(ERROR) << "Failed to run the graph: " << run_status.message();
return EXIT_FAILURE;
@@ -0,0 +1,34 @@
# Copyright 2020 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
# bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/object_detection_3d:objectron_cpu
# To run 3D object detection for shoes,
# bazel-bin/mediapipe/examples/desktop/object_detection_3d/objectron_cpu \
# --calculator_graph_config_file=mediapipe/graphs/object_detection_3d/objectron_desktop_cpu.pbtxt \
# --input_side_packets="input_video_path=<input_video_path>,box_landmark_model_path=mediapipe/models/object_detection_3d_sneakers.tflite,output_video_path=<output_video_path>,allowed_labels=Footwear"
# To detect objects from other categories, change box_landmark_model_path and allowed_labels accordingly.
# Chair: box_landmark_model_path=mediapipe/models/object_detection_3d_chair.tflite,allowed_labels=Chair
# Camera: box_landmark_model_path=mediapipe/models/object_detection_3d_camera.tflite,allowed_labels=Camera
# Cup: box_landmark_model_path=mediapipe/models/object_detection_3d_cup.tflite,allowed_labels=Mug
cc_binary(
name = "objectron_cpu",
deps = [
"//mediapipe/examples/desktop:simple_run_graph_main",
"//mediapipe/graphs/object_detection_3d:desktop_cpu_calculators",
],
)
@@ -0,0 +1,34 @@
# Copyright 2020 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"])
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
cc_binary(
name = "pose_tracking_cpu",
deps = [
"//mediapipe/examples/desktop:demo_run_graph_main",
"//mediapipe/graphs/pose_tracking:pose_tracking_cpu_deps",
],
)
# Linux only
cc_binary(
name = "pose_tracking_gpu",
deps = [
"//mediapipe/examples/desktop:demo_run_graph_main_gpu",
"//mediapipe/graphs/pose_tracking:pose_tracking_gpu_deps",
],
)
@@ -58,11 +58,11 @@ DEFINE_string(output_side_packets_file, "",
"The name of the local file to output all side packets specified "
"with --output_side_packets. ");
::mediapipe::Status OutputStreamToLocalFile(
::mediapipe::OutputStreamPoller& poller) {
mediapipe::Status OutputStreamToLocalFile(
mediapipe::OutputStreamPoller& poller) {
std::ofstream file;
file.open(FLAGS_output_stream_file);
::mediapipe::Packet packet;
mediapipe::Packet packet;
while (poller.Next(&packet)) {
std::string output_data;
if (!FLAGS_strip_timestamps) {
@@ -72,11 +72,11 @@ DEFINE_string(output_side_packets_file, "",
file << output_data;
}
file.close();
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status OutputSidePacketsToLocalFile(
::mediapipe::CalculatorGraph& graph) {
mediapipe::Status OutputSidePacketsToLocalFile(
mediapipe::CalculatorGraph& graph) {
if (!FLAGS_output_side_packets.empty() &&
!FLAGS_output_side_packets_file.empty()) {
std::ofstream file;
@@ -96,33 +96,32 @@ DEFINE_string(output_side_packets_file, "",
<< "--output_side_packets and --output_side_packets_file should be "
"specified in pair.";
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
::mediapipe::Status RunMPPGraph() {
mediapipe::Status RunMPPGraph() {
std::string calculator_graph_config_contents;
MP_RETURN_IF_ERROR(::mediapipe::file::GetContents(
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
FLAGS_calculator_graph_config_file, &calculator_graph_config_contents));
LOG(INFO) << "Get calculator graph config contents: "
<< calculator_graph_config_contents;
::mediapipe::CalculatorGraphConfig config =
::mediapipe::ParseTextProtoOrDie<::mediapipe::CalculatorGraphConfig>(
mediapipe::CalculatorGraphConfig config =
mediapipe::ParseTextProtoOrDie<mediapipe::CalculatorGraphConfig>(
calculator_graph_config_contents);
std::map<std::string, ::mediapipe::Packet> input_side_packets;
std::map<std::string, mediapipe::Packet> input_side_packets;
if (!FLAGS_input_side_packets.empty()) {
std::vector<std::string> kv_pairs =
absl::StrSplit(FLAGS_input_side_packets, ',');
for (const std::string& kv_pair : kv_pairs) {
std::vector<std::string> name_and_value = absl::StrSplit(kv_pair, '=');
RET_CHECK(name_and_value.size() == 2);
RET_CHECK(
!::mediapipe::ContainsKey(input_side_packets, name_and_value[0]));
RET_CHECK(!mediapipe::ContainsKey(input_side_packets, name_and_value[0]));
input_side_packets[name_and_value[0]] =
::mediapipe::MakePacket<std::string>(name_and_value[1]);
mediapipe::MakePacket<std::string>(name_and_value[1]);
}
}
LOG(INFO) << "Initialize the calculator graph.";
::mediapipe::CalculatorGraph graph;
mediapipe::CalculatorGraph graph;
MP_RETURN_IF_ERROR(graph.Initialize(config, input_side_packets));
if (!FLAGS_output_stream.empty() && !FLAGS_output_stream_file.empty()) {
ASSIGN_OR_RETURN(auto poller,
@@ -144,7 +143,7 @@ DEFINE_string(output_side_packets_file, "",
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
::mediapipe::Status run_status = RunMPPGraph();
mediapipe::Status run_status = RunMPPGraph();
if (!run_status.ok()) {
LOG(ERROR) << "Failed to run the graph: " << run_status.message();
return EXIT_FAILURE;
@@ -1,7 +1,7 @@
### Steps to run the YouTube-8M feature extraction graph
1. Checkout the repository and follow
[the installation instructions](https://github.com/google/mediapipe/blob/master/mediapipe/docs/install.md)
[the installation instructions](https://github.com/google/mediapipe/blob/master/docs/getting_started/install.md)
to set up MediaPipe.
```bash
@@ -39,7 +39,7 @@ DEFINE_string(output_side_packets, "",
"side packets and paths to write to disk for the "
"CalculatorGraph.");
::mediapipe::Status RunMPPGraph() {
mediapipe::Status RunMPPGraph() {
std::string calculator_graph_config_contents;
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
FLAGS_calculator_graph_config_file, &calculator_graph_config_contents));
@@ -48,18 +48,18 @@ DEFINE_string(output_side_packets, "",
mediapipe::CalculatorGraphConfig config =
mediapipe::ParseTextProtoOrDie<mediapipe::CalculatorGraphConfig>(
calculator_graph_config_contents);
std::map<std::string, ::mediapipe::Packet> input_side_packets;
std::map<std::string, mediapipe::Packet> input_side_packets;
std::vector<std::string> kv_pairs =
absl::StrSplit(FLAGS_input_side_packets, ',');
for (const std::string& kv_pair : kv_pairs) {
std::vector<std::string> name_and_value = absl::StrSplit(kv_pair, '=');
RET_CHECK(name_and_value.size() == 2);
RET_CHECK(!::mediapipe::ContainsKey(input_side_packets, name_and_value[0]));
RET_CHECK(!mediapipe::ContainsKey(input_side_packets, name_and_value[0]));
std::string input_side_packet_contents;
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
name_and_value[1], &input_side_packet_contents));
input_side_packets[name_and_value[0]] =
::mediapipe::MakePacket<std::string>(input_side_packet_contents);
mediapipe::MakePacket<std::string>(input_side_packet_contents);
}
mediapipe::MatrixData inc3_pca_mean_matrix_data,
@@ -75,7 +75,7 @@ DEFINE_string(output_side_packets, "",
mediapipe::MatrixFromMatrixDataProto(inc3_pca_mean_matrix_data,
&inc3_pca_mean_matrix);
input_side_packets["inception3_pca_mean_matrix"] =
::mediapipe::MakePacket<mediapipe::Matrix>(inc3_pca_mean_matrix);
mediapipe::MakePacket<mediapipe::Matrix>(inc3_pca_mean_matrix);
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
"/tmp/mediapipe/inception3_projection_matrix_data.pb", &content));
@@ -83,7 +83,7 @@ DEFINE_string(output_side_packets, "",
mediapipe::MatrixFromMatrixDataProto(inc3_pca_projection_matrix_data,
&inc3_pca_projection_matrix);
input_side_packets["inception3_pca_projection_matrix"] =
::mediapipe::MakePacket<mediapipe::Matrix>(inc3_pca_projection_matrix);
mediapipe::MakePacket<mediapipe::Matrix>(inc3_pca_projection_matrix);
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
"/tmp/mediapipe/vggish_mean_matrix_data.pb", &content));
@@ -91,7 +91,7 @@ DEFINE_string(output_side_packets, "",
mediapipe::MatrixFromMatrixDataProto(vggish_pca_mean_matrix_data,
&vggish_pca_mean_matrix);
input_side_packets["vggish_pca_mean_matrix"] =
::mediapipe::MakePacket<mediapipe::Matrix>(vggish_pca_mean_matrix);
mediapipe::MakePacket<mediapipe::Matrix>(vggish_pca_mean_matrix);
MP_RETURN_IF_ERROR(mediapipe::file::GetContents(
"/tmp/mediapipe/vggish_projection_matrix_data.pb", &content));
@@ -99,7 +99,7 @@ DEFINE_string(output_side_packets, "",
mediapipe::MatrixFromMatrixDataProto(vggish_pca_projection_matrix_data,
&vggish_pca_projection_matrix);
input_side_packets["vggish_pca_projection_matrix"] =
::mediapipe::MakePacket<mediapipe::Matrix>(vggish_pca_projection_matrix);
mediapipe::MakePacket<mediapipe::Matrix>(vggish_pca_projection_matrix);
LOG(INFO) << "Initialize the calculator graph.";
mediapipe::CalculatorGraph graph;
@@ -111,7 +111,7 @@ DEFINE_string(output_side_packets, "",
for (const std::string& kv_pair : kv_pairs) {
std::vector<std::string> name_and_value = absl::StrSplit(kv_pair, '=');
RET_CHECK(name_and_value.size() == 2);
::mediapipe::StatusOr<::mediapipe::Packet> output_packet =
mediapipe::StatusOr<mediapipe::Packet> output_packet =
graph.GetOutputSidePacket(name_and_value[0]);
RET_CHECK(output_packet.ok())
<< "Packet " << name_and_value[0] << " was not available.";
@@ -120,13 +120,13 @@ DEFINE_string(output_side_packets, "",
MP_RETURN_IF_ERROR(
mediapipe::file::SetContents(name_and_value[1], serialized_string));
}
return ::mediapipe::OkStatus();
return mediapipe::OkStatus();
}
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
::mediapipe::Status run_status = RunMPPGraph();
mediapipe::Status run_status = RunMPPGraph();
if (!run_status.ok()) {
LOG(ERROR) << "Failed to run the graph: " << run_status.message();
return EXIT_FAILURE;
@@ -18,6 +18,7 @@
#import "mediapipe/objc/MPPGraph.h"
#import "mediapipe/objc/MPPLayerRenderer.h"
#import "mediapipe/objc/MPPPlayerInputSource.h"
#import "mediapipe/objc/MPPTimestampConverter.h"
typedef NS_ENUM(NSInteger, MediaPipeDemoSourceMode) {
MediaPipeDemoSourceCamera,
@@ -36,6 +37,9 @@ typedef NS_ENUM(NSInteger, MediaPipeDemoSourceMode) {
// Provides data from a video.
@property(nonatomic) MPPPlayerInputSource* videoSource;
// Helps to convert timestamp.
@property(nonatomic) MPPTimestampConverter* timestampConverter;
// The data source for the demo.
@property(nonatomic) MediaPipeDemoSourceMode sourceMode;
@@ -77,6 +77,8 @@ static const char* kVideoQueueLabel = "com.google.mediapipe.example.videoQueue";
[self.liveView.layer addSublayer:self.renderer.layer];
self.renderer.frameScaleMode = MPPFrameScaleModeFillAndCrop;
self.timestampConverter = [[MPPTimestampConverter alloc] init];
dispatch_queue_attr_t qosAttribute = dispatch_queue_attr_make_with_qos_class(
DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, /*relative_priority=*/0);
self.videoQueue = dispatch_queue_create(kVideoQueueLabel, qosAttribute);
@@ -173,7 +175,8 @@ static const char* kVideoQueueLabel = "com.google.mediapipe.example.videoQueue";
[self.mediapipeGraph sendPixelBuffer:imageBuffer
intoStream:self.graphInputStream
packetType:MPPPacketTypePixelBuffer];
packetType:MPPPacketTypePixelBuffer
timestamp:[self.timestampConverter timestampForMediaTime:timestamp]];
}
#pragma mark - MPPGraphDelegate methods
+27 -15
View File
@@ -49,27 +49,14 @@ ios_application(
)
objc_library(
name = "FaceEffectAppLibrary",
name = "FaceEffectViewController",
srcs = [
"AppDelegate.m",
"FaceEffectViewController.mm",
"main.m",
],
hdrs = [
"AppDelegate.h",
"FaceEffectViewController.h",
],
data = [
"Base.lproj/LaunchScreen.storyboard",
"Base.lproj/Main.storyboard",
"//mediapipe/graphs/face_effect:face_effect_gpu.binarypb",
"//mediapipe/graphs/face_effect/data:facepaint.pngblob",
"//mediapipe/graphs/face_effect/data:glasses.binarypb",
"//mediapipe/graphs/face_effect/data:glasses.pngblob",
"//mediapipe/modules/face_detection:face_detection_front.tflite",
"//mediapipe/modules/face_geometry/data:geometry_pipeline_metadata.binarypb",
"//mediapipe/modules/face_landmark:face_landmark.tflite",
],
copts = ["-std=c++17"],
sdk_frameworks = [
"AVFoundation",
"CoreGraphics",
@@ -90,3 +77,28 @@ objc_library(
],
}),
)
objc_library(
name = "FaceEffectAppLibrary",
srcs = [
"AppDelegate.m",
"main.m",
],
hdrs = [
"AppDelegate.h",
],
data = [
"Base.lproj/LaunchScreen.storyboard",
"Base.lproj/Main.storyboard",
"//mediapipe/graphs/face_effect:face_effect_gpu.binarypb",
"//mediapipe/graphs/face_effect/data:facepaint.pngblob",
"//mediapipe/graphs/face_effect/data:glasses.binarypb",
"//mediapipe/graphs/face_effect/data:glasses.pngblob",
"//mediapipe/modules/face_detection:face_detection_front.tflite",
"//mediapipe/modules/face_geometry/data:geometry_pipeline_metadata.binarypb",
"//mediapipe/modules/face_landmark:face_landmark.tflite",
],
deps = [
":FaceEffectViewController",
],
)
+1
View File
@@ -59,6 +59,7 @@ objc_library(
hdrs = [
"FaceMeshGpuViewController.h",
],
copts = ["-std=c++17"],
data = [
"//mediapipe/graphs/face_mesh:face_mesh_mobile_gpu.binarypb",
"//mediapipe/modules/face_detection:face_detection_front.tflite",
@@ -59,6 +59,7 @@ objc_library(
hdrs = [
"HandTrackingViewController.h",
],
copts = ["-std=c++17"],
data = [
"//mediapipe/graphs/hand_tracking:hand_tracking_mobile_gpu.binarypb",
"//mediapipe/modules/hand_landmark:hand_landmark.tflite",
@@ -0,0 +1,76 @@
# Copyright 2020 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load(
"@build_bazel_rules_apple//apple:ios.bzl",
"ios_application",
)
load(
"//mediapipe/examples/ios:bundle_id.bzl",
"BUNDLE_ID_PREFIX",
"example_provisioning",
)
licenses(["notice"])
MIN_IOS_VERSION = "10.0"
alias(
name = "holistictrackinggpu",
actual = "HolisticTrackingGpuApp",
)
ios_application(
name = "HolisticTrackingGpuApp",
app_icons = ["//mediapipe/examples/ios/common:AppIcon"],
bundle_id = BUNDLE_ID_PREFIX + ".HolisticTrackingGpu",
families = [
"iphone",
"ipad",
],
infoplists = [
"//mediapipe/examples/ios/common:Info.plist",
"Info.plist",
],
minimum_os_version = MIN_IOS_VERSION,
provisioning_profile = example_provisioning(),
deps = [
":HolisticTrackingGpuAppLibrary",
"@ios_opencv//:OpencvFramework",
],
)
objc_library(
name = "HolisticTrackingGpuAppLibrary",
data = [
"//mediapipe/graphs/holistic_tracking:holistic_tracking_gpu.binarypb",
"//mediapipe/modules/face_detection:face_detection_front.tflite",
"//mediapipe/modules/face_landmark:face_landmark.tflite",
"//mediapipe/modules/hand_landmark:hand_landmark.tflite",
"//mediapipe/modules/hand_landmark:handedness.txt",
"//mediapipe/modules/holistic_landmark:hand_recrop.tflite",
"//mediapipe/modules/pose_detection:pose_detection.tflite",
"//mediapipe/modules/pose_landmark:pose_landmark_full_body.tflite",
"//mediapipe/modules/pose_landmark:pose_landmark_upper_body.tflite",
],
deps = [
"//mediapipe/examples/ios/common:CommonMediaPipeAppLibrary",
] + select({
"//mediapipe:ios_i386": [],
"//mediapipe:ios_x86_64": [],
"//conditions:default": [
"//mediapipe/graphs/holistic_tracking:holistic_tracking_gpu_deps",
],
}),
)
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CameraPosition</key>
<string>back</string>
<key>GraphOutputStream</key>
<string>output_video</string>
<key>GraphInputStream</key>
<string>input_video</string>
<key>GraphName</key>
<string>holistic_tracking_gpu</string>
</dict>
</plist>
@@ -59,6 +59,7 @@ objc_library(
hdrs = [
"IrisTrackingViewController.h",
],
copts = ["-std=c++17"],
data = [
"//mediapipe/graphs/iris_tracking:iris_tracking_gpu.binarypb",
"//mediapipe/modules/face_detection:face_detection_front.tflite",
@@ -0,0 +1,78 @@
# Copyright 2020 The MediaPipe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load(
"@build_bazel_rules_apple//apple:ios.bzl",
"ios_application",
)
load(
"//mediapipe/examples/ios:bundle_id.bzl",
"BUNDLE_ID_PREFIX",
"example_provisioning",
)
licenses(["notice"])
MIN_IOS_VERSION = "10.0"
alias(
name = "posetrackinggpu",
actual = "PoseTrackingGpuApp",
)
ios_application(
name = "PoseTrackingGpuApp",
app_icons = ["//mediapipe/examples/ios/common:AppIcon"],
bundle_id = BUNDLE_ID_PREFIX + ".PoseTrackingGpu",
families = [
"iphone",
"ipad",
],
infoplists = [
"//mediapipe/examples/ios/common:Info.plist",
"Info.plist",
],
minimum_os_version = MIN_IOS_VERSION,
provisioning_profile = example_provisioning(),
deps = [
":PoseTrackingGpuAppLibrary",
"@ios_opencv//:OpencvFramework",
],
)
objc_library(
name = "PoseTrackingGpuAppLibrary",
srcs = [
"PoseTrackingViewController.mm",
],
hdrs = [
"PoseTrackingViewController.h",
],
copts = ["-std=c++17"],
data = [
"//mediapipe/graphs/pose_tracking:pose_tracking_gpu.binarypb",
"//mediapipe/modules/pose_detection:pose_detection.tflite",
"//mediapipe/modules/pose_landmark:pose_landmark_full_body.tflite",
],
deps = [
"//mediapipe/examples/ios/common:CommonMediaPipeAppLibrary",
] + select({
"//mediapipe:ios_i386": [],
"//mediapipe:ios_x86_64": [],
"//conditions:default": [
"//mediapipe/graphs/pose_tracking:pose_tracking_gpu_deps",
"//mediapipe/framework/formats:landmark_cc_proto",
],
}),
)
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CameraPosition</key>
<string>back</string>
<key>MainViewController</key>
<string>PoseTrackingViewController</string>
<key>GraphOutputStream</key>
<string>output_video</string>
<key>GraphInputStream</key>
<string>input_video</string>
<key>GraphName</key>
<string>pose_tracking_gpu</string>
</dict>
</plist>
@@ -0,0 +1,21 @@
// Copyright 2020 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <UIKit/UIKit.h>
#import "mediapipe/examples/ios/common/CommonViewController.h"
@interface PoseTrackingViewController : CommonViewController
@end
@@ -0,0 +1,53 @@
// Copyright 2020 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "PoseTrackingViewController.h"
#include "mediapipe/framework/formats/landmark.pb.h"
static const char* kLandmarksOutputStream = "pose_landmarks";
@implementation PoseTrackingViewController
#pragma mark - UIViewController methods
- (void)viewDidLoad {
[super viewDidLoad];
[self.mediapipeGraph addFrameOutputStream:kLandmarksOutputStream
outputPacketType:MPPPacketTypeRaw];
}
#pragma mark - MPPGraphDelegate methods
// Receives a raw packet from the MediaPipe graph. Invoked on a MediaPipe worker thread.
- (void)mediapipeGraph:(MPPGraph*)graph
didOutputPacket:(const ::mediapipe::Packet&)packet
fromStream:(const std::string&)streamName {
if (streamName == kLandmarksOutputStream) {
if (packet.IsEmpty()) {
NSLog(@"[TS:%lld] No pose landmarks", packet.Timestamp().Value());
return;
}
const auto& landmarks = packet.Get<::mediapipe::NormalizedLandmarkList>();
NSLog(@"[TS:%lld] Number of pose landmarks: %d", packet.Timestamp().Value(),
landmarks.landmark_size());
for (int i = 0; i < landmarks.landmark_size(); ++i) {
NSLog(@"\tLandmark[%d]: (%f, %f, %f)", i, landmarks.landmark(i).x(),
landmarks.landmark(i).y(), landmarks.landmark(i).z());
}
}
}
@end
@@ -59,6 +59,7 @@ objc_library(
hdrs = [
"UpperBodyPoseTrackingViewController.h",
],
copts = ["-std=c++17"],
data = [
"//mediapipe/graphs/pose_tracking:upper_body_pose_tracking_gpu.binarypb",
"//mediapipe/modules/pose_detection:pose_detection.tflite",