Merge a0e1f2e6bf
into a92cff7a60
This commit is contained in:
commit
696a80cecf
|
@ -465,6 +465,21 @@ cc_test(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "pulsar_calculator",
|
||||||
|
srcs = ["pulsar_calculator.cc"],
|
||||||
|
hdrs = ["pulsar_calculator.h"],
|
||||||
|
visibility = [
|
||||||
|
"//visibility:public",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
"//mediapipe/framework:calculator_framework",
|
||||||
|
"//mediapipe/framework/formats:rect_cc_proto",
|
||||||
|
"//mediapipe/framework/port:ret_check",
|
||||||
|
],
|
||||||
|
alwayslink = 1,
|
||||||
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "packet_cloner_calculator",
|
name = "packet_cloner_calculator",
|
||||||
srcs = ["packet_cloner_calculator.cc"],
|
srcs = ["packet_cloner_calculator.cc"],
|
||||||
|
|
46
mediapipe/calculators/core/pulsar_calculator.cc
Normal file
46
mediapipe/calculators/core/pulsar_calculator.cc
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
#include "mediapipe/calculators/core/pulsar_calculator.h"
|
||||||
|
|
||||||
|
#include "mediapipe/framework/calculator_framework.h"
|
||||||
|
#include "mediapipe/framework/formats/rect.pb.h"
|
||||||
|
#include "mediapipe/framework/port/ret_check.h"
|
||||||
|
|
||||||
|
namespace mediapipe {
|
||||||
|
|
||||||
|
// Example use-case:
|
||||||
|
// Suppose we are debugging a pipeline where a vector of NormalizedRect has to
|
||||||
|
// be passed to a ImageCroppingCalculator somehow, which only takes non-vectors.
|
||||||
|
//
|
||||||
|
// Example config:
|
||||||
|
// node {
|
||||||
|
// calculator: "NormalizedRectsPulsarCalculator"
|
||||||
|
// input_stream: "head_rects"
|
||||||
|
// output_stream: "head_rect"
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// node {
|
||||||
|
// calculator: "ImageCroppingCalculator"
|
||||||
|
// input_stream: "IMAGE:throttled_input_video"
|
||||||
|
// input_stream: "NORM_RECT:head_rect"
|
||||||
|
// output_stream: "IMAGE:cropped_head"
|
||||||
|
// }
|
||||||
|
typedef PulsarCalculator<NormalizedRect> NormalizedRectsPulsarCalculator;
|
||||||
|
REGISTER_CALCULATOR(NormalizedRectsPulsarCalculator);
|
||||||
|
|
||||||
|
typedef PulsarCalculator<Rect> RectsPulsarCalculator;
|
||||||
|
REGISTER_CALCULATOR(RectsPulsarCalculator);
|
||||||
|
|
||||||
|
} // namespace mediapipe
|
58
mediapipe/calculators/core/pulsar_calculator.h
Normal file
58
mediapipe/calculators/core/pulsar_calculator.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
#ifndef MEDIAPIPE_CALCULATORS_CORE_PULSAR_CALCULATOR_H_
|
||||||
|
#define MEDIAPIPE_CALCULATORS_CORE_PULSAR_CALCULATOR_H_
|
||||||
|
|
||||||
|
#include "mediapipe/framework/calculator_framework.h"
|
||||||
|
#include "mediapipe/framework/port/ret_check.h"
|
||||||
|
|
||||||
|
namespace mediapipe {
|
||||||
|
|
||||||
|
// This turns a packet of vector<NormalizedRect> into as many NormalizedRect
|
||||||
|
// items there are in said vector.
|
||||||
|
template <typename T>
|
||||||
|
class PulsarCalculator : public CalculatorBase {
|
||||||
|
public:
|
||||||
|
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
|
||||||
|
RET_CHECK_EQ(cc->Inputs().NumEntries(), 1);
|
||||||
|
RET_CHECK_EQ(cc->Outputs().NumEntries(), 1);
|
||||||
|
cc->Inputs().Index(0).Set<std::vector<T>>();
|
||||||
|
cc->Outputs().Index(0).Set<T>();
|
||||||
|
return ::mediapipe::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
::mediapipe::Status Open(CalculatorContext* cc) final {
|
||||||
|
cc->SetOffset(TimestampDiff(0));
|
||||||
|
return ::mediapipe::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
::mediapipe::Status Process(CalculatorContext* cc) final {
|
||||||
|
const auto& items = cc->Inputs().Index(0).Get<std::vector<T>>();
|
||||||
|
auto ts = std::max(cc->InputTimestamp(), ts_);
|
||||||
|
for (const auto& item : items) {
|
||||||
|
auto just_one = absl::make_unique<T>(item);
|
||||||
|
cc->Outputs().Index(0).Add(just_one.release(), ts++);
|
||||||
|
}
|
||||||
|
ts_ = ts;
|
||||||
|
return ::mediapipe::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Timestamp ts_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mediapipe
|
||||||
|
|
||||||
|
#endif // MEDIAPIPE_CALCULATORS_CORE_PULSAR_CALCULATOR_H_
|
Loading…
Reference in New Issue
Block a user