Internal change

PiperOrigin-RevId: 548886447
This commit is contained in:
Jiuqiang Tang 2023-07-17 21:55:24 -07:00 committed by Copybara-Service
parent ef12ce8575
commit 0c01187cf5
2 changed files with 12 additions and 2 deletions

View File

@ -104,6 +104,7 @@ class GlScalerCalculator : public CalculatorBase {
bool vertical_flip_output_; bool vertical_flip_output_;
bool horizontal_flip_output_; bool horizontal_flip_output_;
FrameScaleMode scale_mode_ = FrameScaleMode::kStretch; FrameScaleMode scale_mode_ = FrameScaleMode::kStretch;
bool use_nearest_neighbor_interpolation_ = false;
}; };
REGISTER_CALCULATOR(GlScalerCalculator); REGISTER_CALCULATOR(GlScalerCalculator);
@ -186,7 +187,8 @@ absl::Status GlScalerCalculator::Open(CalculatorContext* cc) {
scale_mode_ = scale_mode_ =
FrameScaleModeFromProto(options.scale_mode(), FrameScaleMode::kStretch); FrameScaleModeFromProto(options.scale_mode(), FrameScaleMode::kStretch);
} }
use_nearest_neighbor_interpolation_ =
options.use_nearest_neighbor_interpolation();
if (HasTagOrIndex(cc->InputSidePackets(), "OUTPUT_DIMENSIONS", 1)) { if (HasTagOrIndex(cc->InputSidePackets(), "OUTPUT_DIMENSIONS", 1)) {
const auto& dimensions = const auto& dimensions =
TagOrIndex(cc->InputSidePackets(), "OUTPUT_DIMENSIONS", 1) TagOrIndex(cc->InputSidePackets(), "OUTPUT_DIMENSIONS", 1)
@ -297,6 +299,11 @@ absl::Status GlScalerCalculator::Process(CalculatorContext* cc) {
glBindTexture(src2.target(), src2.name()); glBindTexture(src2.target(), src2.name());
} }
if (use_nearest_neighbor_interpolation_) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
MP_RETURN_IF_ERROR(renderer->GlRender( MP_RETURN_IF_ERROR(renderer->GlRender(
src1.width(), src1.height(), dst.width(), dst.height(), scale_mode_, src1.width(), src1.height(), dst.width(), dst.height(), scale_mode_,
rotation_, horizontal_flip_output_, vertical_flip_output_, rotation_, horizontal_flip_output_, vertical_flip_output_,

View File

@ -19,7 +19,7 @@ package mediapipe;
import "mediapipe/framework/calculator.proto"; import "mediapipe/framework/calculator.proto";
import "mediapipe/gpu/scale_mode.proto"; import "mediapipe/gpu/scale_mode.proto";
// Next id: 8. // Next id: 9.
message GlScalerCalculatorOptions { message GlScalerCalculatorOptions {
extend CalculatorOptions { extend CalculatorOptions {
optional GlScalerCalculatorOptions ext = 166373014; optional GlScalerCalculatorOptions ext = 166373014;
@ -39,4 +39,7 @@ message GlScalerCalculatorOptions {
// Flip the output texture horizontally. This is applied after rotation. // Flip the output texture horizontally. This is applied after rotation.
optional bool flip_horizontal = 5; optional bool flip_horizontal = 5;
optional ScaleMode.Mode scale_mode = 6; optional ScaleMode.Mode scale_mode = 6;
// Whether to use nearest neighbor interpolation. Default to use linear
// interpolation.
optional bool use_nearest_neighbor_interpolation = 8 [default = false];
} }