Internal change

PiperOrigin-RevId: 528799585
This commit is contained in:
MediaPipe Team 2023-05-02 09:04:56 -07:00 committed by Copybara-Service
parent 5b93477589
commit 7fdbbee5be
2 changed files with 9 additions and 0 deletions

View File

@ -791,6 +791,7 @@ cc_library(
"@com_google_absl//absl/status", "@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor", "@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@stblib//:stb_image", "@stblib//:stb_image",
"@stblib//:stb_image_write", "@stblib//:stb_image_write",
], ],

View File

@ -26,6 +26,7 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
#include "absl/strings/substitute.h" #include "absl/strings/substitute.h"
#include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator.pb.h"
@ -311,6 +312,13 @@ std::unique_ptr<ImageFrame> LoadTestPng(absl::string_view path,
// Returns the path to the output if successful. // Returns the path to the output if successful.
absl::StatusOr<std::string> SavePngTestOutput( absl::StatusOr<std::string> SavePngTestOutput(
const mediapipe::ImageFrame& image, absl::string_view prefix) { const mediapipe::ImageFrame& image, absl::string_view prefix) {
absl::flat_hash_set<ImageFormat::Format> supported_formats = {
ImageFormat::GRAY8, ImageFormat::SRGB, ImageFormat::SRGBA,
ImageFormat::LAB8, ImageFormat::SBGRA};
if (!supported_formats.contains(image.Format())) {
return absl::CancelledError(
absl::StrFormat("Format %d can not be saved to PNG.", image.Format()));
}
std::string now_string = absl::FormatTime(absl::Now()); std::string now_string = absl::FormatTime(absl::Now());
std::string output_relative_path = std::string output_relative_path =
absl::StrCat(prefix, "_", now_string, ".png"); absl::StrCat(prefix, "_", now_string, ".png");