
    Wpf,              	          d Z ddlmZmZ ddlZddlZddlmZ ddl	m
Z
 ddl	mZ ddl	mZ ddl	mZ e
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j        Ze
j         Z e
j!        Z!e
j"        Z"e
j#        Z#e
j$        Z$ddd	d
eej%        ej&        f         dej'        de(dej)        fdZ*ddd	d
eej+        ej&        f         dej'        de(dej)        fdZ,dej-        dej)        fdZ.deej-                 dej)        fdZ/dS )z&The public facing packet creator APIs.    )ListUnionN)message)_packet_creator)image)image_frame)packet)image_formatcopydatar
   r   returnc                   t          | t          j                  rC|| j        |k    rt	          d          ||st	          d          t          j        |           S |t	          d          || j        j        rdnd}|sB| j        j	        st	          d          | j        j        rt          j        dt          d	           t          j        || |          S )
a#	  Create a MediaPipe ImageFrame packet.

  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.

  Examples:
    np_array = np.random.randint(255, size=(321, 123, 3), dtype=np.uint8)
    # 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)

  NBThe provided image_format doesn't match the one from the data arg.zcCreating ImageFrame packet by taking a reference of another ImageFrame object is not supported yet.*Please provide 'image_format' with 'data'.TF<Reference mode is unavailable if 'data' is not c_contiguous.zc'data' is still writeable. Taking a reference of the data to create ImageFrame packet is dangerous.   )
isinstancer   
ImageFramer
   
ValueErrorr   $_create_image_frame_from_image_frameflags	writeablec_contiguouswarningswarnRuntimeWarning#_create_image_frame_from_pixel_datar   r
   r   s      _/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/mediapipe/python/packet_creator.pycreate_image_framer    6   s"   z k,-- !"D$5$E$E
OQ Q Q 
o   ?EEE GHHH |Z)4TTud 	 Z$ NLN N 	N		 sA	 	 	 >dD" " "    c                   t          | t          j                  rC|| j        |k    rt	          d          ||st	          d          t          j        |           S |t	          d          || j        j        rdnd}|sB| j        j	        st	          d          | j        j        rt          j        dt          d	           t          j        || |          S )
a  Create a MediaPipe Image packet.

  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.

  Args:
    data: A MediaPipe Image object or the raw pixel data that is represnted as a
      numpy ndarray.
    image_format: One of the mp.ImageFormat enum types.
    copy: Indicate if the packet should copy the data from the numpy nparray.

  Returns:
    A MediaPipe Image 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 Image object, the "image_format" arg doesn't
        match the image format of the "data" Image object or "copy" is
        explicitly set to False.
    TypeError: If "image format" doesn't match "data" array's data type.

  Examples:
    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)

  Nr   zYCreating Image packet by taking a reference of another Image object is not supported yet.r   TFr   z^'data' is still writeable. Taking a reference of the data to create Image packet is dangerous.r   )r   r   Imager
   r   r   _create_image_from_imager   r   r   r   r   r   _create_image_from_pixel_datar   s      r   create_imager&      s!   z ek"" !"D$5$E$E
OQ Q Q 
e   3D999 GHHH |Z)4TTud 	 Z$ NLN N 	N		 nA	 	 	 8dD" " "r!   proto_messagec                 d    t          j        | j        j        |                                           S )a  Create a MediaPipe protobuf message packet.

  Args:
    proto_message: A Python protobuf message.

  Returns:
    A MediaPipe protobuf message Packet.

  Raises:
    RuntimeError: If the protobuf message type is not registered in MediaPipe.

  Examples:
    detection = detection_pb2.Detection()
    text_format.Parse('score: 0.5', detection)
    packet = mp.packet_creator.create_proto(detection)
    output_detection = mp.packet_getter.get_proto(packet)
  )r   _create_proto
DESCRIPTOR	full_nameSerializeToString)r'   s    r   create_protor-      s3    & 
	&}'?'I'4'F'F'H'H
J 
J Jr!   message_listc                      t          d          )Nz'create_proto_vector is not implemented.)NotImplementedError)r.   s    r   create_proto_vectorr1     s    EFFFr!   )0__doc__typingr   r   r   numpynpgoogle.protobufr   $mediapipe.python._framework_bindingsr   r   r   r	   create_stringcreate_bool
create_intcreate_int8create_int16create_int32create_int64create_uint8create_uint16create_uint32create_uint64create_floatcreate_doublecreate_int_arraycreate_float_arraycreate_int_vectorcreate_bool_vectorcreate_float_vectorcreate_string_vectorcreate_image_vectorcreate_packet_vectorcreate_string_to_packet_mapcreate_matrixr   ndarrayImageFormatboolPacketr    r#   r&   Messager-   r1    r!   r   <module>rU      s   - ,              # # # # # # @ @ @ @ @ @ 6 6 6 6 6 6 < < < < < < 7 7 7 7 7 7  -)'
)++++---+-"3 $7 #5 $7 %9 &; %9 &; -I -
 @D$(^" ^" ^"U;#92:#EF ^"%0%<^" "^" .4]^" ^" ^" ^"H :>"^" ^" ^"uU["*45 ^"*6^" ^" (.}^" ^" ^" ^"DJ JFM J J J J0Gd7?&; G G G G G G Gr!   