|View source on GitHub|
Create a MediaPipe Image packet.
mp.packet_creator.create_image( data: Union[
mp.Image, np.ndarray], *, image_format:
mp.ImageFormat= None, copy: bool = None ) ->
A MediaPipe Image packet can be created from an existing MediaPipe Image object and the data will be realigned and copied into a new Image object inside of the packet.
A MediaPipe Image 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 Image 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.
||A MediaPipe Image object or the raw pixel data that is represnted as a numpy ndarray.|
||One of the mp.ImageFormat enum types.|
||Indicate if the packet should copy the data from the numpy nparray.|
|A MediaPipe Image Packet.|
np_array = np.random.randint(255, size=(321, 123, 3), dtype=np.uint8)
Copy mode by default if the data array is writable.
image_packet = mp.packet_creator.create_image( image_format=mp.ImageFormat.SRGB, data=np_array)
Make the array unwriteable to trigger the reference mode.
np_array.flags.writeable = False image_packet = mp.packet_creator.create_image( image_format=mp.ImageFormat.SRGB, data=np_array)
image = mp.Image(image_format=mp.ImageFormat.SRGB, data=np_array) image_packet = mp.packet_creator.create_image(image)