diff --git a/mediapipe/calculators/image/color_convert_calculator.cc b/mediapipe/calculators/image/color_convert_calculator.cc index f31586d9d..7891463c0 100644 --- a/mediapipe/calculators/image/color_convert_calculator.cc +++ b/mediapipe/calculators/image/color_convert_calculator.cc @@ -57,6 +57,8 @@ constexpr char kGrayOutTag[] = "GRAY_OUT"; // RGB -> RGBA // RGBA -> BGRA // BGRA -> RGBA +// RGBA -> GRAY + // // This calculator only supports a single input stream and output stream at a // time. If more than one input stream or output stream is present, the @@ -196,6 +198,12 @@ REGISTER_CALCULATOR(ColorConvertCalculator); cv::COLOR_RGBA2BGRA, cc); } + // RGBA -> GRAY + if (cc->Inputs().HasTag(kRgbaInTag) && cc->Outputs().HasTag(kGrayOutTag)) { + return ConvertAndOutput(kRgbaInTag, kGrayOutTag, ImageFormat::GRAY8, + cv::COLOR_RGBA2GRAY, cc); + } + return ::mediapipe::InvalidArgumentErrorBuilder(MEDIAPIPE_LOC) << "Unsupported image format conversion."; } diff --git a/mediapipe/calculators/util/detection_unique_id_calculator.cc b/mediapipe/calculators/util/detection_unique_id_calculator.cc index 2069f1677..fd58e5126 100644 --- a/mediapipe/calculators/util/detection_unique_id_calculator.cc +++ b/mediapipe/calculators/util/detection_unique_id_calculator.cc @@ -33,8 +33,8 @@ inline int GetNextDetectionId() { return ++detection_id; } } // namespace // Assign a unique id to detections. -// Note that the calculator will consume the input vector of Detection or -// DetectionList. So the input stream can not be connected to other calculators. +// Note that the calculator will consume or copy the input vector of Detection or +// DetectionList. // // Example config: // node { @@ -76,7 +76,7 @@ REGISTER_CALCULATOR(DetectionUniqueIdCalculator); if (cc->Inputs().HasTag(kDetectionListTag) && !cc->Inputs().Tag(kDetectionListTag).IsEmpty()) { auto result = - cc->Inputs().Tag(kDetectionListTag).Value().Consume(); + cc->Inputs().Tag(kDetectionListTag).Value().ConsumeOrCopy(); if (result.ok()) { auto detection_list = std::move(result).ValueOrDie(); for (Detection& detection : *detection_list->mutable_detection()) { @@ -93,7 +93,7 @@ REGISTER_CALCULATOR(DetectionUniqueIdCalculator); auto result = cc->Inputs() .Tag(kDetectionsTag) .Value() - .Consume>(); + .ConsumeOrCopy>(); if (result.ok()) { auto detections = std::move(result).ValueOrDie(); for (Detection& detection : *detections) {