Project import generated by Copybara.
GitOrigin-RevId: 73d686c40057684f8bfaca285368bf1813f9fc26
This commit is contained in:
@@ -158,6 +158,7 @@ cc_library(
|
||||
] + select({
|
||||
"//conditions:default": ["resource_util_default.cc"],
|
||||
"//mediapipe:android": ["resource_util_android.cc"],
|
||||
"//mediapipe/framework:android_no_jni": ["resource_util_loonix.cc"],
|
||||
"//mediapipe:ios": ["resource_util_apple.cc"],
|
||||
"//mediapipe:macos": ["resource_util_default.cc"],
|
||||
}),
|
||||
@@ -192,6 +193,7 @@ cc_library(
|
||||
"//mediapipe/util/android:asset_manager_util",
|
||||
"//mediapipe/util/android/file/base",
|
||||
],
|
||||
"//mediapipe/framework:android_no_jni": [],
|
||||
"//mediapipe:ios": [],
|
||||
"//mediapipe:macos": [
|
||||
"@com_google_absl//absl/flags:flag",
|
||||
|
||||
@@ -109,8 +109,7 @@ void StringReplace(absl::string_view s, absl::string_view oldsub,
|
||||
absl::string_view newsub, bool replace_all,
|
||||
std::string* res) {
|
||||
if (oldsub.empty()) {
|
||||
res->append(s.data(),
|
||||
s.length()); // If empty, append the given std::string.
|
||||
res->append(s.data(), s.length()); // If empty, append the given string.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class FdCloser {
|
||||
|
||||
} // namespace
|
||||
|
||||
// Read contents of a file to a std::string.
|
||||
// Read contents of a file to a string.
|
||||
absl::Status GetContents(int fd, std::string* output) {
|
||||
// Determine the length of the file.
|
||||
struct stat buf;
|
||||
@@ -69,7 +69,7 @@ absl::Status GetContents(int fd, std::string* output) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
// Read contents of a file to a std::string.
|
||||
// Read contents of a file to a string.
|
||||
absl::Status GetContents(absl::string_view file_name, std::string* output,
|
||||
const file::Options& /*options*/) {
|
||||
int fd = open(std::string(file_name).c_str(), O_RDONLY);
|
||||
|
||||
@@ -24,21 +24,21 @@
|
||||
namespace mediapipe {
|
||||
namespace file {
|
||||
|
||||
// Read contents of a file to a std::string.
|
||||
// Read contents of a file to a string.
|
||||
absl::Status GetContents(absl::string_view file_name, std::string* output,
|
||||
const file::Options& options);
|
||||
|
||||
// Read contents of a file to a std::string with default file options.
|
||||
// Read contents of a file to a string with default file options.
|
||||
absl::Status GetContents(absl::string_view file_name, std::string* output);
|
||||
|
||||
// Read contents of a file to a std::string from an open file descriptor.
|
||||
// Read contents of a file to a string from an open file descriptor.
|
||||
absl::Status GetContents(int fd, std::string* output);
|
||||
|
||||
// Write std::string to file.
|
||||
// Write string to file.
|
||||
absl::Status SetContents(absl::string_view file_name, absl::string_view content,
|
||||
const file::Options& options);
|
||||
|
||||
// Write std::string to file with default file options.
|
||||
// Write string to file with default file options.
|
||||
absl::Status SetContents(absl::string_view file_name,
|
||||
absl::string_view content);
|
||||
|
||||
|
||||
@@ -174,6 +174,18 @@ void AnnotationRenderer::DrawRectangle(const RenderAnnotation& annotation) {
|
||||
cv::Rect rect(left, top, right - left, bottom - top);
|
||||
cv::rectangle(mat_image_, rect, color, thickness);
|
||||
}
|
||||
if (rectangle.has_top_left_thickness()) {
|
||||
const auto& rect = RectangleToOpenCVRotatedRect(left, top, right, bottom,
|
||||
rectangle.rotation());
|
||||
const int kNumVertices = 4;
|
||||
cv::Point2f vertices[kNumVertices];
|
||||
rect.points(vertices);
|
||||
const int top_left_thickness =
|
||||
ClampThickness(round(rectangle.top_left_thickness() * scale_factor_));
|
||||
cv::ellipse(mat_image_, vertices[1],
|
||||
cv::Size(top_left_thickness, top_left_thickness), 0.0, 0, 360,
|
||||
color, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void AnnotationRenderer::DrawFilledRectangle(
|
||||
|
||||
@@ -46,6 +46,8 @@ message RenderAnnotation {
|
||||
optional double bottom = 4;
|
||||
optional bool normalized = 5 [default = false];
|
||||
optional double rotation = 6; // Rotation in radians.
|
||||
// Radius of top left corner circle.
|
||||
optional double top_left_thickness = 7;
|
||||
}
|
||||
|
||||
message FilledRectangle {
|
||||
|
||||
@@ -49,12 +49,7 @@ absl::Status DefaultGetResourceContents(const std::string& path,
|
||||
LOG(WARNING) << "Setting \"read_as_binary\" to false is a no-op on ios.";
|
||||
}
|
||||
ASSIGN_OR_RETURN(std::string full_path, PathToResourceAsFile(path));
|
||||
|
||||
std::ifstream input_file(full_path);
|
||||
std::stringstream buffer;
|
||||
buffer << input_file.rdbuf();
|
||||
buffer.str().swap(*output);
|
||||
return absl::OkStatus();
|
||||
return file::GetContents(full_path, output, read_as_binary);
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ cc_library(
|
||||
name = "media_sequence_util",
|
||||
hdrs = ["media_sequence_util.h"],
|
||||
visibility = [
|
||||
"//home/interaction:__subpackages__",
|
||||
"//mediapipe:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
// The clip label group adds labels that apply to the entire media clip. To
|
||||
// annotate that a video clip has a particular label, set the clip metadata
|
||||
// above and also set the SetClipLabelIndex and SetClipLabelString. Most
|
||||
// training pipelines will only use the label index or std::string, but we
|
||||
// recommend storing both to improve readability while maintaining ease of use.
|
||||
// training pipelines will only use the label index or string, but we recommend
|
||||
// storing both to improve readability while maintaining ease of use.
|
||||
// Example:
|
||||
// SetClipLabelString({"run", "jump"}, &sequence);
|
||||
// SetClipLabelIndex({35, 47}, &sequence);
|
||||
@@ -49,10 +49,11 @@
|
||||
// are called segments. To annotate that a video clip has time spans with labels
|
||||
// set the clip metadata above and use the functions SetSegmentStartTimestamp,
|
||||
// SetSegmentEndTimestamp, SetSegmentLabelIndex, and SetSegmentLabelString. Most
|
||||
// training pipelines will only use the label index or std::string, but we
|
||||
// recommend storing both to improve readability while maintaining ease of use.
|
||||
// By listing segments as times, the frame rate or other properties can change
|
||||
// without affecting the labels. Example:
|
||||
// training pipelines will only use the label index or string, but we recommend
|
||||
// storing both to improve readability while maintaining ease of use. By listing
|
||||
// segments as times, the frame rate or other properties can change without
|
||||
// affecting the labels.
|
||||
// Example:
|
||||
// SetSegmentStartTimestamp({500000, 1000000}, &sequence); // in microseconds
|
||||
// SetSegmentEndTimestamp({2000000, 6000000}, &sequence);
|
||||
// SetSegmentLabelIndex({35, 47}, &sequence);
|
||||
@@ -63,7 +64,7 @@
|
||||
// needed can vary by task, but to annotate a video clip for detection set the
|
||||
// clip metadata above and use repeatedly call AddBBox, AddBBoxTimestamp,
|
||||
// AddBBoxLabelIndex, and AddBBoxLabelString. Most training pipelines will only
|
||||
// use the label index or std::string, but we recommend storing both to improve
|
||||
// use the label index or string, but we recommend storing both to improve
|
||||
// readability while maintaining ease of use. Because bounding boxes are
|
||||
// assigned to timepoints in a video, changing the image frame rate can can
|
||||
// change the alignment. The ReconcileMetadata function can align bounding boxes
|
||||
@@ -100,7 +101,7 @@
|
||||
// tensorflow::SequenceExample example;
|
||||
// SetDataPath("data_path", &example);
|
||||
// if (HasDataPath(example)) {
|
||||
// std::string data_path = GetDataPath(example);
|
||||
// string data_path = GetDataPath(example);
|
||||
// ClearDataPath(&example);
|
||||
// }
|
||||
//
|
||||
@@ -146,13 +147,12 @@
|
||||
// }
|
||||
//
|
||||
// As described in media_sequence_util.h, each of these functions can take an
|
||||
// additional std::string prefix argument as their first argument. The prefix
|
||||
// can be fixed with a new NAME by calling a FIXED_PREFIX_... macro. Prefixes
|
||||
// are used to identify common storage patterns (e.g. storing an image along
|
||||
// with the height and width) under different names (e.g. storing a left and
|
||||
// right image in a stereo pair.) An example creating functions such as
|
||||
// AddLeftImageEncoded that adds a std::string under the key
|
||||
// "LEFT/image/encoded":
|
||||
// additional string prefix argument as their first argument. The prefix can
|
||||
// be fixed with a new NAME by calling a FIXED_PREFIX_... macro. Prefixes are
|
||||
// used to identify common storage patterns (e.g. storing an image along with
|
||||
// the height and width) under different names (e.g. storing a left and right
|
||||
// image in a stereo pair.) An example creating functions such as
|
||||
// AddLeftImageEncoded that adds a string under the key "LEFT/image/encoded":
|
||||
// FIXED_PREFIX_STRING_FEATURE_LIST("LEFT", LeftImageEncoded, "image/encoded");
|
||||
|
||||
#ifndef MEDIAPIPE_TENSORFLOW_SEQUENCE_MEDIA_SEQUENCE_H_
|
||||
@@ -230,7 +230,7 @@ const char kSegmentEndIndexKey[] = "segment/end/index";
|
||||
// A list with the label index for each segment.
|
||||
// Multiple labels for the same segment are encoded as repeated segments.
|
||||
const char kSegmentLabelIndexKey[] = "segment/label/index";
|
||||
// A list with the label std::string for each segment.
|
||||
// A list with the label string for each segment.
|
||||
// Multiple labels for the same segment are encoded as repeated segments.
|
||||
const char kSegmentLabelStringKey[] = "segment/label/string";
|
||||
// A list with the label confidence for each segment.
|
||||
@@ -301,7 +301,7 @@ const char kRegionTimestampKey[] = "region/timestamp";
|
||||
// An embedding for each region. The length of each list must be the product of
|
||||
// the number of regions and the product of the embedding dimensions.
|
||||
const char kRegionEmbeddingFloatKey[] = "region/embedding/float";
|
||||
// A std::string encoded embedding for each region.
|
||||
// A string encoded embedding for each region.
|
||||
const char kRegionEmbeddingEncodedKey[] = "region/embedding/encoded";
|
||||
// The confidence of the embedding.
|
||||
const char kRegionEmbeddingConfidenceKey[] = "region/embedding/confidence";
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "mediapipe/util/sequence/media_sequence.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "mediapipe/framework/formats/location.h"
|
||||
#include "mediapipe/framework/port/gmock.h"
|
||||
|
||||
@@ -29,14 +29,14 @@
|
||||
// the most basic function prototypes for the name='MyFeature' are similar to:
|
||||
//
|
||||
// {BYTES,INT64,FLOAT}_CONTEXT_FEATURE:
|
||||
// std::string GetMyFeatureKey(sequence)
|
||||
// string GetMyFeatureKey(sequence)
|
||||
// bool HasMyFeature(sequence)
|
||||
// void ClearMyFeature(*sequence)
|
||||
// void SetMyFeature(value, *sequence)
|
||||
// TYPE GetMyFeature(sequence)
|
||||
//
|
||||
// VECTOR_{BYTES,INT64,FLOAT}_CONTEXT_FEATURE:
|
||||
// std::string GetMyFeatureKey(sequence)
|
||||
// string GetMyFeatureKey(sequence)
|
||||
// bool HasMyFeature(sequence)
|
||||
// void ClearMyFeature(*sequence)
|
||||
// void SetMyFeature(repeated_value, *sequence)
|
||||
@@ -46,7 +46,7 @@
|
||||
// TYPE GetMyFeatureAt(sequence)
|
||||
//
|
||||
// {BYTES,INT64,FLOAT}_FEATURE_LIST:
|
||||
// std::string GetMyFeatureKey(sequence)
|
||||
// string GetMyFeatureKey(sequence)
|
||||
// bool HasMyFeature(sequence)
|
||||
// void ClearMyFeature(*sequence)
|
||||
// void AddMyFeature(value, *sequence)
|
||||
@@ -54,7 +54,7 @@
|
||||
// TYPE GetMyFeatureAt(sequence)
|
||||
//
|
||||
// VECTOR_{BYTES,INT64,FLOAT}_FEATURE_LIST:
|
||||
// std::string GetMyFeatureKey(sequence)
|
||||
// string GetMyFeatureKey(sequence)
|
||||
// bool HasMyFeature(sequence)
|
||||
// void ClearMyFeature(*sequence)
|
||||
// void AddMyFeature(repeated_value, *sequence)
|
||||
@@ -236,8 +236,8 @@ inline const proto_ns::RepeatedField<int64>& GetInt64sAt(
|
||||
return fl.feature().Get(index).int64_list().value();
|
||||
}
|
||||
|
||||
// Returns a refrerence to the std::string values for the feature list indicated
|
||||
// by key at the provided sequence index.
|
||||
// Returns a refrerence to the string values for the feature list indicated by
|
||||
// key at the provided sequence index.
|
||||
inline const proto_ns::RepeatedPtrField<std::string>& GetBytesAt(
|
||||
const tensorflow::SequenceExample& sequence, const std::string& key,
|
||||
const int index) {
|
||||
@@ -279,17 +279,17 @@ void AddBytesContainer(const std::string& key, const TContainer& bytes_list,
|
||||
|
||||
// The macros provided below are useful for creating getters and setters for
|
||||
// keys and values in a tf::SequenceExample. You only need to specify the C++
|
||||
// name to use in the functions and the std::string key used in the
|
||||
// SequenceExample proto maps. Macro versions exist for {strings, int64s, and
|
||||
// floats} for creating singular or repeated context features and singular or
|
||||
// repeated feature_list features.
|
||||
// name to use in the functions and the string key used in the SequenceExample
|
||||
// proto maps. Macro versions exist for {strings, int64s, and floats} for
|
||||
// creating singular or repeated context features and singular or repeated
|
||||
// feature_list features.
|
||||
|
||||
// Helpers to create functions names in the macros below.
|
||||
#define CONCAT_STR2(a, b) a##b
|
||||
#define CONCAT_STR3(a, b, c) a##b##c
|
||||
|
||||
// This macro creates functions for HasX, GetX, ClearX, and SetX where X is a
|
||||
// name and the value stored is a std::string in the context.
|
||||
// name and the value stored is a string in the context.
|
||||
#define PREFIXED_BYTES_CONTEXT_FEATURE(name, key) \
|
||||
inline const bool CONCAT_STR2(Has, name)( \
|
||||
const std::string& prefix, \
|
||||
@@ -766,7 +766,7 @@ void AddBytesContainer(const std::string& key, const TContainer& bytes_list,
|
||||
FIXED_PREFIX_VECTOR_FLOAT_CONTEXT_FEATURE(name, key, "");
|
||||
|
||||
// This macro creates functions for HasX, GetXSize, GetXAt, ClearX, and AddX
|
||||
// where X is a name and the value stored is a std::string in a feature_list.
|
||||
// where X is a name and the value stored is a string in a feature_list.
|
||||
#define PREFIXED_BYTES_FEATURE_LIST(name, key) \
|
||||
inline const bool CONCAT_STR2(Has, name)( \
|
||||
const std::string& prefix, \
|
||||
|
||||
@@ -35,7 +35,7 @@ Detection TensorToDetection(
|
||||
detection.add_score(score);
|
||||
|
||||
// According to mediapipe/framework/formats/detection.proto
|
||||
// "Either std::string or integer labels must be used but not both at the
|
||||
// "Either string or integer labels must be used but not both at the
|
||||
// same time."
|
||||
if (absl::holds_alternative<int>(class_label)) {
|
||||
detection.add_label_id(absl::get<int>(class_label));
|
||||
|
||||
@@ -98,7 +98,10 @@ cc_library(
|
||||
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:model_builder",
|
||||
"@org_tensorflow//tensorflow/lite/delegates/gpu/gl:api2",
|
||||
],
|
||||
}) + ["@org_tensorflow//tensorflow/lite/core/api"],
|
||||
}) + [
|
||||
"@com_google_absl//absl/status",
|
||||
"@org_tensorflow//tensorflow/lite/core/api",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
|
||||
@@ -252,8 +252,10 @@ absl::Status TFLiteGPURunner::InitializeOpenCL(
|
||||
MP_RETURN_IF_ERROR(cl_environment_->NewInferenceBuilder(
|
||||
cl_options, std::move(graph_cl), builder));
|
||||
|
||||
#endif // __ANDROID__
|
||||
return absl::OkStatus();
|
||||
#else
|
||||
return mediapipe::UnimplementedError("Currently only Android is supported");
|
||||
#endif // __ANDROID__
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
@@ -152,7 +152,7 @@ class TimeSeriesCalculatorTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
// Makes the CalculatorGraphConfig used to initialize CalculatorRunner
|
||||
// runner_. If no options are needed, pass the empty std::string for options.
|
||||
// runner_. If no options are needed, pass the empty string for options.
|
||||
CalculatorGraphConfig::Node MakeNodeConfig(const std::string& calculator_name,
|
||||
const int num_side_packets,
|
||||
const CalculatorOptions& options) {
|
||||
|
||||
@@ -154,7 +154,7 @@ void BoxDetectorInterface::DetectAndAddBoxFromFeatures(
|
||||
}
|
||||
|
||||
for (int idx = 0; idx < size_before_add; ++idx) {
|
||||
if ((options_.has_detect_every_n_frame() > 0 &&
|
||||
if ((options_.detect_every_n_frame() > 0 &&
|
||||
cnt_detect_called_ % options_.detect_every_n_frame() == 0) ||
|
||||
!tracked[idx] ||
|
||||
(options_.detect_out_of_fov() && has_been_out_of_fov_[idx])) {
|
||||
|
||||
@@ -93,11 +93,11 @@ float ForegroundMotion(const CameraMotion& camera_motion,
|
||||
void InitCameraMotionFromFeatureList(const RegionFlowFeatureList& feature_list,
|
||||
CameraMotion* camera_motion);
|
||||
|
||||
// Converts Camera motion flag to std::string.
|
||||
// Converts Camera motion flag to string.
|
||||
std::string CameraMotionFlagToString(const CameraMotion& motion);
|
||||
|
||||
// Converts Camera motion type to std::string. Used instead of builtin proto
|
||||
// function for mobile support.
|
||||
// Converts Camera motion type to string. Used instead of builtin proto function
|
||||
// for mobile support.
|
||||
std::string CameraMotionTypeToString(const CameraMotion& motion);
|
||||
|
||||
// Returns inlier coverage either based on mixture (if present, in this case
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace mediapipe {
|
||||
// flow_packager.FinalizeTrackingContainerFormat(&container);
|
||||
// flow_packager.FinalizeTrackingProto(&proto);
|
||||
//
|
||||
// // Convert to binary std::string to stream out.
|
||||
// // Convert to binary string to stream out.
|
||||
// std::string output;
|
||||
// flow_packager.TrackingContainerFormatToBinary(container, &output);
|
||||
// // OR:
|
||||
@@ -143,9 +143,8 @@ class FlowPackager {
|
||||
void SortRegionFlowFeatureList(float scale_x, float scale_y,
|
||||
RegionFlowFeatureList* feature_list) const;
|
||||
|
||||
// Removes binary encoded container from std::string and parses it to
|
||||
// container. Returns header std::string of the parsed container. Useful for
|
||||
// random seek.
|
||||
// Removes binary encoded container from string and parses it to container.
|
||||
// Returns header string of the parsed container. Useful for random seek.
|
||||
std::string SplitContainerFromString(absl::string_view* binary_data,
|
||||
TrackingContainer* container);
|
||||
|
||||
@@ -155,7 +154,7 @@ class FlowPackager {
|
||||
const std::vector<int>& data_sizes,
|
||||
MetaData* meta_data) const;
|
||||
|
||||
// Serializes container to binary std::string and adds it to binary_data.
|
||||
// Serializes container to binary string and adds it to binary_data.
|
||||
void AddContainerToString(const TrackingContainer& container,
|
||||
std::string* binary_data);
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace mediapipe {
|
||||
// Stores pair (tag, TypeId of type).
|
||||
typedef std::pair<std::string, size_t> TaggedType;
|
||||
|
||||
// Returns TaggedType for type T* tagged with passed std::string.
|
||||
// Returns TaggedType for type T* tagged with passed string.
|
||||
template <class T>
|
||||
TaggedType TaggedPointerType(const std::string& tag);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user