Project import generated by Copybara.
GitOrigin-RevId: 19a829ffd755edb43e54d20c0e7b9348512d5108
This commit is contained in:
committed by
schmidt-sebastian
parent
c6c80c3745
commit
7fb37c80e8
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "mediapipe/framework/formats/image.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "mediapipe/python/pybind/image_frame_util.h"
|
||||
#include "mediapipe/python/pybind/util.h"
|
||||
#include "pybind11/stl.h"
|
||||
@@ -84,8 +86,8 @@ void ImageSubmodule(pybind11::module* module) {
|
||||
"uint8 image data should be one of the GRAY8, "
|
||||
"SRGB, and SRGBA MediaPipe image formats.");
|
||||
}
|
||||
return Image(std::make_shared<ImageFrame>(
|
||||
std::move(*CreateImageFrame<uint8>(format, data).release())));
|
||||
return Image(std::shared_ptr<ImageFrame>(
|
||||
CreateImageFrame<uint8>(format, data)));
|
||||
}),
|
||||
R"doc(For uint8 data type, valid ImageFormat are GRAY8, SGRB, and SRGBA.)doc",
|
||||
py::arg("image_format"), py::arg("data").noconvert())
|
||||
@@ -100,8 +102,8 @@ void ImageSubmodule(pybind11::module* module) {
|
||||
"uint16 image data should be one of the GRAY16, "
|
||||
"SRGB48, and SRGBA64 MediaPipe image formats.");
|
||||
}
|
||||
return Image(std::make_shared<ImageFrame>(
|
||||
std::move(*CreateImageFrame<uint16>(format, data).release())));
|
||||
return Image(std::shared_ptr<ImageFrame>(
|
||||
CreateImageFrame<uint16>(format, data)));
|
||||
}),
|
||||
R"doc(For uint16 data type, valid ImageFormat are GRAY16, SRGB48, and SRGBA64.)doc",
|
||||
py::arg("image_format"), py::arg("data").noconvert())
|
||||
@@ -115,8 +117,8 @@ void ImageSubmodule(pybind11::module* module) {
|
||||
"float image data should be either VEC32F1 or VEC32F2 "
|
||||
"MediaPipe image formats.");
|
||||
}
|
||||
return Image(std::make_shared<ImageFrame>(
|
||||
std::move(*CreateImageFrame<float>(format, data).release())));
|
||||
return Image(std::shared_ptr<ImageFrame>(
|
||||
CreateImageFrame<float>(format, data)));
|
||||
}),
|
||||
R"doc(For float data type, valid ImageFormat are VEC32F1 and VEC32F2.)doc",
|
||||
py::arg("image_format"), py::arg("data").noconvert());
|
||||
|
||||
@@ -55,17 +55,17 @@ Packet CreateImagePacket(mediapipe::ImageFormat::Format format,
|
||||
if (format == mediapipe::ImageFormat::SRGB ||
|
||||
format == mediapipe::ImageFormat::SRGBA ||
|
||||
format == mediapipe::ImageFormat::GRAY8) {
|
||||
return MakePacket<Image>(std::make_shared<ImageFrame>(
|
||||
std::move(*CreateImageFrame<uint8>(format, data, copy).release())));
|
||||
return MakePacket<Image>(std::shared_ptr<ImageFrame>(
|
||||
CreateImageFrame<uint8>(format, data, copy)));
|
||||
} else if (format == mediapipe::ImageFormat::GRAY16 ||
|
||||
format == mediapipe::ImageFormat::SRGB48 ||
|
||||
format == mediapipe::ImageFormat::SRGBA64) {
|
||||
return MakePacket<Image>(std::make_shared<ImageFrame>(
|
||||
std::move(*CreateImageFrame<uint16>(format, data, copy).release())));
|
||||
return MakePacket<Image>(std::shared_ptr<ImageFrame>(
|
||||
CreateImageFrame<uint16>(format, data, copy)));
|
||||
} else if (format == mediapipe::ImageFormat::VEC32F1 ||
|
||||
format == mediapipe::ImageFormat::VEC32F2) {
|
||||
return MakePacket<Image>(std::make_shared<ImageFrame>(
|
||||
std::move(*CreateImageFrame<float>(format, data, copy).release())));
|
||||
return MakePacket<Image>(std::shared_ptr<ImageFrame>(
|
||||
CreateImageFrame<float>(format, data, copy)));
|
||||
}
|
||||
throw RaisePyError(PyExc_RuntimeError,
|
||||
absl::StrCat("Unsupported ImageFormat: ", format).c_str());
|
||||
@@ -633,8 +633,9 @@ void InternalPacketCreators(pybind11::module* m) {
|
||||
// both GPU and CPU can process it.
|
||||
image_frame_copy->CopyFrom(*image.GetImageFrameSharedPtr(),
|
||||
ImageFrame::kGlDefaultAlignmentBoundary);
|
||||
return MakePacket<Image>(std::make_shared<ImageFrame>(
|
||||
std::move(*image_frame_copy.release())));
|
||||
std::shared_ptr<ImageFrame> shared_image_frame =
|
||||
std::move(image_frame_copy);
|
||||
return MakePacket<Image>(shared_image_frame);
|
||||
},
|
||||
py::arg("image").noconvert(), py::return_value_policy::move);
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ class PacketDataType(enum.Enum):
|
||||
BOOL = 'bool'
|
||||
BOOL_LIST = 'bool_list'
|
||||
INT = 'int'
|
||||
INT_LIST = 'int_list'
|
||||
FLOAT = 'float'
|
||||
FLOAT_LIST = 'float_list'
|
||||
AUDIO = 'matrix'
|
||||
@@ -123,6 +124,12 @@ NAME_TO_TYPE: Mapping[str, 'PacketDataType'] = {
|
||||
PacketDataType.BOOL_LIST,
|
||||
'int':
|
||||
PacketDataType.INT,
|
||||
'::std::vector<int>':
|
||||
PacketDataType.INT_LIST,
|
||||
'int64':
|
||||
PacketDataType.INT,
|
||||
'::std::vector<int64>':
|
||||
PacketDataType.INT_LIST,
|
||||
'float':
|
||||
PacketDataType.FLOAT,
|
||||
'::std::vector<float>':
|
||||
|
||||
@@ -158,10 +158,10 @@ class Holistic(SolutionBase):
|
||||
"""
|
||||
|
||||
results = super().process(input_data={'image': image})
|
||||
if results.pose_landmarks:
|
||||
for landmark in results.pose_landmarks.landmark:
|
||||
if results.pose_landmarks: # pytype: disable=attribute-error
|
||||
for landmark in results.pose_landmarks.landmark: # pytype: disable=attribute-error
|
||||
landmark.ClearField('presence')
|
||||
if results.pose_world_landmarks:
|
||||
for landmark in results.pose_world_landmarks.landmark:
|
||||
if results.pose_world_landmarks: # pytype: disable=attribute-error
|
||||
for landmark in results.pose_world_landmarks.landmark: # pytype: disable=attribute-error
|
||||
landmark.ClearField('presence')
|
||||
return results
|
||||
|
||||
@@ -258,10 +258,10 @@ class Objectron(SolutionBase):
|
||||
"""
|
||||
|
||||
results = super().process(input_data={'image': image})
|
||||
if results.detected_objects:
|
||||
results.detected_objects = self._convert_format(results.detected_objects)
|
||||
if results.detected_objects: # pytype: disable=attribute-error
|
||||
results.detected_objects = self._convert_format(results.detected_objects) # type: ignore
|
||||
else:
|
||||
results.detected_objects = None
|
||||
results.detected_objects = None # pytype: disable=not-writable
|
||||
return results
|
||||
|
||||
def _convert_format(
|
||||
|
||||
@@ -183,10 +183,10 @@ class Pose(SolutionBase):
|
||||
"""
|
||||
|
||||
results = super().process(input_data={'image': image})
|
||||
if results.pose_landmarks:
|
||||
for landmark in results.pose_landmarks.landmark:
|
||||
if results.pose_landmarks: # pytype: disable=attribute-error
|
||||
for landmark in results.pose_landmarks.landmark: # pytype: disable=attribute-error
|
||||
landmark.ClearField('presence')
|
||||
if results.pose_world_landmarks:
|
||||
for landmark in results.pose_world_landmarks.landmark:
|
||||
if results.pose_world_landmarks: # pytype: disable=attribute-error
|
||||
for landmark in results.pose_world_landmarks.landmark: # pytype: disable=attribute-error
|
||||
landmark.ClearField('presence')
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user