A MediaPipe ImageFrame packet can be created from an existing MediaPipe
ImageFrame object and the data will be realigned and copied into a new
ImageFrame object inside of the packet.
A MediaPipe ImageFrame packet can also be created from the raw pixel data
represented as a numpy array with one of the uint8, uint16, and float data
types. There are three data ownership modes depending on how the 'copy' arg
is set.
i) Default mode
If copy is not set, mutable data is always copied while the immutable data
is by reference.
ii) Copy mode (safe)
If copy is set to True, the data will be realigned and copied into an
ImageFrame object inside of the packet regardless the immutablity of the
original data.
iii) Reference mode (dangerous)
If copy is set to False, the data will be forced to be shared. If the data is
mutable (data.flags.writeable is True), a warning will be raised.
Args
data
A MediaPipe ImageFrame object or the raw pixel data that is
represnted as a numpy ndarray.
image_format
One of the image_frame.ImageFormat enum types.
copy
Indicate if the packet should copy the data from the numpy nparray.
Returns
A MediaPipe ImageFrame Packet.
Raises
ValueError
i) When "data" is a numpy ndarray, "image_format" is not provided or
the "data" array is not c_contiguous in the reference mode.
ii) When "data" is an ImageFrame object, the "image_format" arg doesn't
match the image format of the "data" ImageFrame object or "copy" is
explicitly set to False.
TypeError
If "image format" doesn't match "data" array's data type.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-01 UTC."],[],[],null,["# mp.packet_creator.create_image_frame\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/google/mediapipe/blob/master/mediapipe/python/packet_creator.py#L54-L149) |\n\nCreate a MediaPipe ImageFrame packet.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`mp.tasks.vision.holistic_landmarker.packet_creator.create_image_frame`](https://ai.google.dev/edge/api/mediapipe/python/edge/api/mediapipe/python/mp/packet_creator/create_image_frame)\n\n\u003cbr /\u003e\n\n mp.packet_creator.create_image_frame(\n data: Union[../../mp/ImageFrame, np.ndarray],\n *,\n image_format: ../../mp/ImageFormat = None,\n copy: bool = None\n ) -\u003e ../../mp/Packet\n\nA MediaPipe ImageFrame packet can be created from an existing MediaPipe\nImageFrame object and the data will be realigned and copied into a new\nImageFrame object inside of the packet.\n\nA MediaPipe ImageFrame packet can also be created from the raw pixel data\nrepresented as a numpy array with one of the uint8, uint16, and float data\ntypes. There are three data ownership modes depending on how the 'copy' arg\nis set.\n\ni) Default mode\nIf copy is not set, mutable data is always copied while the immutable data\nis by reference.\n\nii) Copy mode (safe)\nIf copy is set to True, the data will be realigned and copied into an\nImageFrame object inside of the packet regardless the immutablity of the\noriginal data.\n\niii) Reference mode (dangerous)\nIf copy is set to False, the data will be forced to be shared. If the data is\nmutable (data.flags.writeable is True), a warning will be raised.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|--------------------------------------------------------------------------------------------|\n| `data` | A MediaPipe ImageFrame object or the raw pixel data that is represnted as a numpy ndarray. |\n| `image_format` | One of the image_frame.ImageFormat enum types. |\n| `copy` | Indicate if the packet should copy the data from the numpy nparray. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A MediaPipe ImageFrame Packet. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | i) When \"data\" is a numpy ndarray, \"image_format\" is not provided or the \"data\" array is not c_contiguous in the reference mode. ii) When \"data\" is an ImageFrame object, the \"image_format\" arg doesn't match the image format of the \"data\" ImageFrame object or \"copy\" is explicitly set to False. |\n| `TypeError` | If \"image format\" doesn't match \"data\" array's data type. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Examples -------- ||\n|---|---|\n| np_array = np.random.randint(255, size=(321, 123, 3), dtype=np.uint8) \u003cbr /\u003e Copy mode by default if the data array is writable. =================================================== image_frame_packet = mp.packet_creator.create_image_frame( image_format=mp.ImageFormat.SRGB, data=np_array) Make the array unwriteable to trigger the reference mode. ========================================================= np_array.flags.writeable = False image_frame_packet = mp.packet_creator.create_image_frame( image_format=mp.ImageFormat.SRGB, data=np_array) image_frame = mp.ImageFrame(image_format=mp.ImageFormat.SRGB, data=np_array) image_frame_packet = mp.packet_creator.create_image_frame(image_frame) ||\n\n\u003cbr /\u003e"]]