Internal change

PiperOrigin-RevId: 520263349
This commit is contained in:
MediaPipe Team 2023-03-29 01:31:00 -07:00 committed by Copybara-Service
parent dc132a5629
commit 316bd05e86
6 changed files with 68 additions and 68 deletions

View File

@ -87,7 +87,7 @@ void ImageSubmodule(pybind11::module* module) {
image image
.def( .def(
py::init([](mediapipe::ImageFormat::Format format, py::init([](mediapipe::ImageFormat::Format format,
const py::array_t<uint8, py::array::c_style>& data) { const py::array_t<uint8_t, py::array::c_style>& data) {
if (format != mediapipe::ImageFormat::GRAY8 && if (format != mediapipe::ImageFormat::GRAY8 &&
format != mediapipe::ImageFormat::SRGB && format != mediapipe::ImageFormat::SRGB &&
format != mediapipe::ImageFormat::SRGBA) { format != mediapipe::ImageFormat::SRGBA) {
@ -96,13 +96,13 @@ void ImageSubmodule(pybind11::module* module) {
"SRGB, and SRGBA MediaPipe image formats."); "SRGB, and SRGBA MediaPipe image formats.");
} }
return Image(std::shared_ptr<ImageFrame>( return Image(std::shared_ptr<ImageFrame>(
CreateImageFrame<uint8>(format, data))); CreateImageFrame<uint8_t>(format, data)));
}), }),
R"doc(For uint8 data type, valid ImageFormat are GRAY8, SGRB, and SRGBA.)doc", R"doc(For uint8 data type, valid ImageFormat are GRAY8, SGRB, and SRGBA.)doc",
py::arg("image_format"), py::arg("data").noconvert()) py::arg("image_format"), py::arg("data").noconvert())
.def( .def(
py::init([](mediapipe::ImageFormat::Format format, py::init([](mediapipe::ImageFormat::Format format,
const py::array_t<uint16, py::array::c_style>& data) { const py::array_t<uint16_t, py::array::c_style>& data) {
if (format != mediapipe::ImageFormat::GRAY16 && if (format != mediapipe::ImageFormat::GRAY16 &&
format != mediapipe::ImageFormat::SRGB48 && format != mediapipe::ImageFormat::SRGB48 &&
format != mediapipe::ImageFormat::SRGBA64) { format != mediapipe::ImageFormat::SRGBA64) {
@ -112,7 +112,7 @@ void ImageSubmodule(pybind11::module* module) {
"SRGB48, and SRGBA64 MediaPipe image formats."); "SRGB48, and SRGBA64 MediaPipe image formats.");
} }
return Image(std::shared_ptr<ImageFrame>( return Image(std::shared_ptr<ImageFrame>(
CreateImageFrame<uint16>(format, data))); CreateImageFrame<uint16_t>(format, data)));
}), }),
R"doc(For uint16 data type, valid ImageFormat are GRAY16, SRGB48, and SRGBA64.)doc", R"doc(For uint16 data type, valid ImageFormat are GRAY16, SRGB48, and SRGBA64.)doc",
py::arg("image_format"), py::arg("data").noconvert()) py::arg("image_format"), py::arg("data").noconvert())
@ -182,10 +182,10 @@ void ImageSubmodule(pybind11::module* module) {
py::cast(self, py::return_value_policy::reference); py::cast(self, py::return_value_policy::reference);
switch (self.GetImageFrameSharedPtr()->ByteDepth()) { switch (self.GetImageFrameSharedPtr()->ByteDepth()) {
case 1: case 1:
return GetValue<uint8>(*self.GetImageFrameSharedPtr(), pos, return GetValue<uint8_t>(*self.GetImageFrameSharedPtr(), pos,
py_object); py_object);
case 2: case 2:
return GetValue<uint16>(*self.GetImageFrameSharedPtr(), pos, return GetValue<uint16_t>(*self.GetImageFrameSharedPtr(), pos,
py_object); py_object);
case 4: case 4:
return GetValue<float>(*self.GetImageFrameSharedPtr(), pos, return GetValue<float>(*self.GetImageFrameSharedPtr(), pos,
@ -223,7 +223,7 @@ void ImageSubmodule(pybind11::module* module) {
R"doc(Return True if the pixel data is unallocated.)doc") R"doc(Return True if the pixel data is unallocated.)doc")
.def( .def(
"is_aligned", "is_aligned",
[](Image& self, uint32 alignment_boundary) { [](Image& self, uint32_t alignment_boundary) {
return self.GetImageFrameSharedPtr()->IsAligned(alignment_boundary); return self.GetImageFrameSharedPtr()->IsAligned(alignment_boundary);
}, },
R"doc(Return True if each row of the data is aligned to alignment boundary, which must be 1 or a power of 2. R"doc(Return True if each row of the data is aligned to alignment boundary, which must be 1 or a power of 2.

View File

@ -114,7 +114,7 @@ void ImageFrameSubmodule(pybind11::module* module) {
image_frame image_frame
.def( .def(
py::init([](mediapipe::ImageFormat::Format format, py::init([](mediapipe::ImageFormat::Format format,
const py::array_t<uint8, py::array::c_style>& data) { const py::array_t<uint8_t, py::array::c_style>& data) {
if (format != mediapipe::ImageFormat::GRAY8 && if (format != mediapipe::ImageFormat::GRAY8 &&
format != mediapipe::ImageFormat::SRGB && format != mediapipe::ImageFormat::SRGB &&
format != mediapipe::ImageFormat::SRGBA) { format != mediapipe::ImageFormat::SRGBA) {
@ -122,13 +122,13 @@ void ImageFrameSubmodule(pybind11::module* module) {
"uint8 image data should be one of the GRAY8, " "uint8 image data should be one of the GRAY8, "
"SRGB, and SRGBA MediaPipe image formats."); "SRGB, and SRGBA MediaPipe image formats.");
} }
return CreateImageFrame<uint8>(format, data); return CreateImageFrame<uint8_t>(format, data);
}), }),
R"doc(For uint8 data type, valid ImageFormat are GRAY8, SGRB, and SRGBA.)doc", R"doc(For uint8 data type, valid ImageFormat are GRAY8, SGRB, and SRGBA.)doc",
py::arg("image_format"), py::arg("data").noconvert()) py::arg("image_format"), py::arg("data").noconvert())
.def( .def(
py::init([](mediapipe::ImageFormat::Format format, py::init([](mediapipe::ImageFormat::Format format,
const py::array_t<uint16, py::array::c_style>& data) { const py::array_t<uint16_t, py::array::c_style>& data) {
if (format != mediapipe::ImageFormat::GRAY16 && if (format != mediapipe::ImageFormat::GRAY16 &&
format != mediapipe::ImageFormat::SRGB48 && format != mediapipe::ImageFormat::SRGB48 &&
format != mediapipe::ImageFormat::SRGBA64) { format != mediapipe::ImageFormat::SRGBA64) {
@ -137,7 +137,7 @@ void ImageFrameSubmodule(pybind11::module* module) {
"uint16 image data should be one of the GRAY16, " "uint16 image data should be one of the GRAY16, "
"SRGB48, and SRGBA64 MediaPipe image formats."); "SRGB48, and SRGBA64 MediaPipe image formats.");
} }
return CreateImageFrame<uint16>(format, data); return CreateImageFrame<uint16_t>(format, data);
}), }),
R"doc(For uint16 data type, valid ImageFormat are GRAY16, SRGB48, and SRGBA64.)doc", R"doc(For uint16 data type, valid ImageFormat are GRAY16, SRGB48, and SRGBA64.)doc",
py::arg("image_format"), py::arg("data").noconvert()) py::arg("image_format"), py::arg("data").noconvert())
@ -203,9 +203,9 @@ void ImageFrameSubmodule(pybind11::module* module) {
py::cast(self, py::return_value_policy::reference); py::cast(self, py::return_value_policy::reference);
switch (self.ByteDepth()) { switch (self.ByteDepth()) {
case 1: case 1:
return GetValue<uint8>(self, pos, py_object); return GetValue<uint8_t>(self, pos, py_object);
case 2: case 2:
return GetValue<uint16>(self, pos, py_object); return GetValue<uint16_t>(self, pos, py_object);
case 4: case 4:
return GetValue<float>(self, pos, py_object); return GetValue<float>(self, pos, py_object);
default: default:

View File

@ -53,11 +53,11 @@ void PacketSubmodule(pybind11::module* module) {
packet.def(py::init<Packet const&>()) packet.def(py::init<Packet const&>())
.def("at", [](Packet* self, .def("at", [](Packet* self,
int64 ts_value) { return self->At(Timestamp(ts_value)); }) int64_t ts_value) { return self->At(Timestamp(ts_value)); })
.def("at", [](Packet* self, Timestamp ts) { return self->At(ts); }) .def("at", [](Packet* self, Timestamp ts) { return self->At(ts); })
.def_property( .def_property(
"timestamp", &Packet::Timestamp, "timestamp", &Packet::Timestamp,
[](Packet* p, int64 ts_value) { *p = p->At(Timestamp(ts_value)); }) [](Packet* p, int64_t ts_value) { *p = p->At(Timestamp(ts_value)); })
.def("__repr__", [](const Packet& self) { .def("__repr__", [](const Packet& self) {
return absl::StrCat( return absl::StrCat(
"<mediapipe.Packet with timestamp: ", "<mediapipe.Packet with timestamp: ",

View File

@ -36,11 +36,11 @@ Packet CreateImageFramePacket(mediapipe::ImageFormat::Format format,
if (format == mediapipe::ImageFormat::SRGB || if (format == mediapipe::ImageFormat::SRGB ||
format == mediapipe::ImageFormat::SRGBA || format == mediapipe::ImageFormat::SRGBA ||
format == mediapipe::ImageFormat::GRAY8) { format == mediapipe::ImageFormat::GRAY8) {
return Adopt(CreateImageFrame<uint8>(format, data, copy).release()); return Adopt(CreateImageFrame<uint8_t>(format, data, copy).release());
} else if (format == mediapipe::ImageFormat::GRAY16 || } else if (format == mediapipe::ImageFormat::GRAY16 ||
format == mediapipe::ImageFormat::SRGB48 || format == mediapipe::ImageFormat::SRGB48 ||
format == mediapipe::ImageFormat::SRGBA64) { format == mediapipe::ImageFormat::SRGBA64) {
return Adopt(CreateImageFrame<uint16>(format, data, copy).release()); return Adopt(CreateImageFrame<uint16_t>(format, data, copy).release());
} else if (format == mediapipe::ImageFormat::VEC32F1 || } else if (format == mediapipe::ImageFormat::VEC32F1 ||
format == mediapipe::ImageFormat::VEC32F2) { format == mediapipe::ImageFormat::VEC32F2) {
return Adopt(CreateImageFrame<float>(format, data, copy).release()); return Adopt(CreateImageFrame<float>(format, data, copy).release());
@ -56,12 +56,12 @@ Packet CreateImagePacket(mediapipe::ImageFormat::Format format,
format == mediapipe::ImageFormat::SRGBA || format == mediapipe::ImageFormat::SRGBA ||
format == mediapipe::ImageFormat::GRAY8) { format == mediapipe::ImageFormat::GRAY8) {
return MakePacket<Image>(std::shared_ptr<ImageFrame>( return MakePacket<Image>(std::shared_ptr<ImageFrame>(
CreateImageFrame<uint8>(format, data, copy))); CreateImageFrame<uint8_t>(format, data, copy)));
} else if (format == mediapipe::ImageFormat::GRAY16 || } else if (format == mediapipe::ImageFormat::GRAY16 ||
format == mediapipe::ImageFormat::SRGB48 || format == mediapipe::ImageFormat::SRGB48 ||
format == mediapipe::ImageFormat::SRGBA64) { format == mediapipe::ImageFormat::SRGBA64) {
return MakePacket<Image>(std::shared_ptr<ImageFrame>( return MakePacket<Image>(std::shared_ptr<ImageFrame>(
CreateImageFrame<uint16>(format, data, copy))); CreateImageFrame<uint16_t>(format, data, copy)));
} else if (format == mediapipe::ImageFormat::VEC32F1 || } else if (format == mediapipe::ImageFormat::VEC32F1 ||
format == mediapipe::ImageFormat::VEC32F2) { format == mediapipe::ImageFormat::VEC32F2) {
return MakePacket<Image>(std::shared_ptr<ImageFrame>( return MakePacket<Image>(std::shared_ptr<ImageFrame>(
@ -139,7 +139,7 @@ void PublicPacketCreators(pybind11::module* m) {
m->def( m->def(
"create_int", "create_int",
[](int64 data) { [](int64_t data) {
RaisePyErrorIfOverflow(data, INT_MIN, INT_MAX); RaisePyErrorIfOverflow(data, INT_MIN, INT_MAX);
return MakePacket<int>(data); return MakePacket<int>(data);
}, },
@ -163,9 +163,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def( m->def(
"create_int8", "create_int8",
[](int64 data) { [](int64_t data) {
RaisePyErrorIfOverflow(data, INT8_MIN, INT8_MAX); RaisePyErrorIfOverflow(data, INT8_MIN, INT8_MAX);
return MakePacket<int8>(data); return MakePacket<int8_t>(data);
}, },
R"doc(Create a MediaPipe int8 Packet from an integer. R"doc(Create a MediaPipe int8 Packet from an integer.
@ -187,9 +187,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def( m->def(
"create_int16", "create_int16",
[](int64 data) { [](int64_t data) {
RaisePyErrorIfOverflow(data, INT16_MIN, INT16_MAX); RaisePyErrorIfOverflow(data, INT16_MIN, INT16_MAX);
return MakePacket<int16>(data); return MakePacket<int16_t>(data);
}, },
R"doc(Create a MediaPipe int16 Packet from an integer. R"doc(Create a MediaPipe int16 Packet from an integer.
@ -211,9 +211,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def( m->def(
"create_int32", "create_int32",
[](int64 data) { [](int64_t data) {
RaisePyErrorIfOverflow(data, INT32_MIN, INT32_MAX); RaisePyErrorIfOverflow(data, INT32_MIN, INT32_MAX);
return MakePacket<int32>(data); return MakePacket<int32_t>(data);
}, },
R"doc(Create a MediaPipe int32 Packet from an integer. R"doc(Create a MediaPipe int32 Packet from an integer.
@ -234,7 +234,7 @@ void PublicPacketCreators(pybind11::module* m) {
py::arg().noconvert(), py::return_value_policy::move); py::arg().noconvert(), py::return_value_policy::move);
m->def( m->def(
"create_int64", [](int64 data) { return MakePacket<int64>(data); }, "create_int64", [](int64_t data) { return MakePacket<int64_t>(data); },
R"doc(Create a MediaPipe int64 Packet from an integer. R"doc(Create a MediaPipe int64 Packet from an integer.
Args: Args:
@ -254,9 +254,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def( m->def(
"create_uint8", "create_uint8",
[](int64 data) { [](int64_t data) {
RaisePyErrorIfOverflow(data, 0, UINT8_MAX); RaisePyErrorIfOverflow(data, 0, UINT8_MAX);
return MakePacket<uint8>(data); return MakePacket<uint8_t>(data);
}, },
R"doc(Create a MediaPipe uint8 Packet from an integer. R"doc(Create a MediaPipe uint8 Packet from an integer.
@ -278,9 +278,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def( m->def(
"create_uint16", "create_uint16",
[](int64 data) { [](int64_t data) {
RaisePyErrorIfOverflow(data, 0, UINT16_MAX); RaisePyErrorIfOverflow(data, 0, UINT16_MAX);
return MakePacket<uint16>(data); return MakePacket<uint16_t>(data);
}, },
R"doc(Create a MediaPipe uint16 Packet from an integer. R"doc(Create a MediaPipe uint16 Packet from an integer.
@ -302,9 +302,9 @@ void PublicPacketCreators(pybind11::module* m) {
m->def( m->def(
"create_uint32", "create_uint32",
[](int64 data) { [](int64_t data) {
RaisePyErrorIfOverflow(data, 0, UINT32_MAX); RaisePyErrorIfOverflow(data, 0, UINT32_MAX);
return MakePacket<uint32>(data); return MakePacket<uint32_t>(data);
}, },
R"doc(Create a MediaPipe uint32 Packet from an integer. R"doc(Create a MediaPipe uint32 Packet from an integer.
@ -325,7 +325,7 @@ void PublicPacketCreators(pybind11::module* m) {
py::arg().noconvert(), py::return_value_policy::move); py::arg().noconvert(), py::return_value_policy::move);
m->def( m->def(
"create_uint64", [](uint64 data) { return MakePacket<uint64>(data); }, "create_uint64", [](uint64_t data) { return MakePacket<uint64_t>(data); },
R"doc(Create a MediaPipe uint64 Packet from an integer. R"doc(Create a MediaPipe uint64 Packet from an integer.
Args: Args:

View File

@ -100,15 +100,15 @@ void PublicPacketGetters(pybind11::module* m) {
"get_int", "get_int",
[](const Packet& packet) { [](const Packet& packet) {
if (packet.ValidateAsType<int>().ok()) { if (packet.ValidateAsType<int>().ok()) {
return static_cast<int64>(packet.Get<int>()); return static_cast<int64_t>(packet.Get<int>());
} else if (packet.ValidateAsType<int8>().ok()) { } else if (packet.ValidateAsType<int8_t>().ok()) {
return static_cast<int64>(packet.Get<int8>()); return static_cast<int64_t>(packet.Get<int8_t>());
} else if (packet.ValidateAsType<int16>().ok()) { } else if (packet.ValidateAsType<int16_t>().ok()) {
return static_cast<int64>(packet.Get<int16>()); return static_cast<int64_t>(packet.Get<int16_t>());
} else if (packet.ValidateAsType<int32>().ok()) { } else if (packet.ValidateAsType<int32_t>().ok()) {
return static_cast<int64>(packet.Get<int32>()); return static_cast<int64_t>(packet.Get<int32_t>());
} else if (packet.ValidateAsType<int64>().ok()) { } else if (packet.ValidateAsType<int64_t>().ok()) {
return static_cast<int64>(packet.Get<int64>()); return static_cast<int64_t>(packet.Get<int64_t>());
} }
throw RaisePyError( throw RaisePyError(
PyExc_ValueError, PyExc_ValueError,
@ -133,14 +133,14 @@ void PublicPacketGetters(pybind11::module* m) {
m->def( m->def(
"get_uint", "get_uint",
[](const Packet& packet) { [](const Packet& packet) {
if (packet.ValidateAsType<uint8>().ok()) { if (packet.ValidateAsType<uint8_t>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint8>()); return static_cast<std::uint64_t>(packet.Get<uint8_t>());
} else if (packet.ValidateAsType<uint16>().ok()) { } else if (packet.ValidateAsType<uint16_t>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint16>()); return static_cast<std::uint64_t>(packet.Get<uint16_t>());
} else if (packet.ValidateAsType<uint32>().ok()) { } else if (packet.ValidateAsType<uint32_t>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint32>()); return static_cast<std::uint64_t>(packet.Get<uint32_t>());
} else if (packet.ValidateAsType<uint64>().ok()) { } else if (packet.ValidateAsType<uint64_t>().ok()) {
return static_cast<std::uint64_t>(packet.Get<uint64>()); return static_cast<std::uint64_t>(packet.Get<uint64_t>());
} }
throw RaisePyError( throw RaisePyError(
PyExc_ValueError, PyExc_ValueError,
@ -194,19 +194,19 @@ void PublicPacketGetters(pybind11::module* m) {
[](const Packet& packet) { [](const Packet& packet) {
if (packet.ValidateAsType<std::vector<int>>().ok()) { if (packet.ValidateAsType<std::vector<int>>().ok()) {
auto int_list = packet.Get<std::vector<int>>(); auto int_list = packet.Get<std::vector<int>>();
return std::vector<int64>(int_list.begin(), int_list.end()); return std::vector<int64_t>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int8>>().ok()) { } else if (packet.ValidateAsType<std::vector<int8_t>>().ok()) {
auto int_list = packet.Get<std::vector<int8>>(); auto int_list = packet.Get<std::vector<int8_t>>();
return std::vector<int64>(int_list.begin(), int_list.end()); return std::vector<int64_t>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int16>>().ok()) { } else if (packet.ValidateAsType<std::vector<int16_t>>().ok()) {
auto int_list = packet.Get<std::vector<int16>>(); auto int_list = packet.Get<std::vector<int16_t>>();
return std::vector<int64>(int_list.begin(), int_list.end()); return std::vector<int64_t>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int32>>().ok()) { } else if (packet.ValidateAsType<std::vector<int32_t>>().ok()) {
auto int_list = packet.Get<std::vector<int32>>(); auto int_list = packet.Get<std::vector<int32_t>>();
return std::vector<int64>(int_list.begin(), int_list.end()); return std::vector<int64_t>(int_list.begin(), int_list.end());
} else if (packet.ValidateAsType<std::vector<int64>>().ok()) { } else if (packet.ValidateAsType<std::vector<int64_t>>().ok()) {
auto int_list = packet.Get<std::vector<int64>>(); auto int_list = packet.Get<std::vector<int64_t>>();
return std::vector<int64>(int_list.begin(), int_list.end()); return std::vector<int64_t>(int_list.begin(), int_list.end());
} }
throw RaisePyError(PyExc_ValueError, throw RaisePyError(PyExc_ValueError,
"Packet doesn't contain int, int8, int16, int32, or " "Packet doesn't contain int, int8, int16, int32, or "

View File

@ -56,7 +56,7 @@ void TimestampSubmodule(pybind11::module* module) {
)doc"); )doc");
timestamp.def(py::init<const Timestamp&>()) timestamp.def(py::init<const Timestamp&>())
.def(py::init<int64>()) .def(py::init<int64_t>())
.def_property_readonly("value", &Timestamp::Value) .def_property_readonly("value", &Timestamp::Value)
.def_property_readonly_static( .def_property_readonly_static(
"UNSET", [](py::object) { return Timestamp::Unset(); }) "UNSET", [](py::object) { return Timestamp::Unset(); })
@ -137,7 +137,7 @@ void TimestampSubmodule(pybind11::module* module) {
timestamp_now = mp.Timestamp.from_seconds(time.time()) timestamp_now = mp.Timestamp.from_seconds(time.time())
)doc"); )doc");
py::implicitly_convertible<int64, Timestamp>(); py::implicitly_convertible<int64_t, Timestamp>();
} }
} // namespace python } // namespace python