class_docstr: Represents one detected object in the object detector's results.
  
  Attributes:
    bounding_box: A BoundingBox object.
    categories: A list of Category objects.
    keypoints: A list of NormalizedKeypoint objects.
class_docstr_tok: ["Represents","one","detected","object","in","the","object","detector","'s","results",".","Attributes",":","bounding_box",":","A","BoundingBox","object",".","categories",":","A","list","of","Category","objects",".","keypoints",":","A","list","of","NormalizedKeypoint","objects","."]
docstr: Generates a Detection protobuf object.
docstr_tok: ["Generates","a","Detection","protobuf","object","."]
code: def to_pb2(self) -> _DetectionProto:
      """Generates a Detection protobuf object."""
      labels = []
      label_ids = []
      scores = []
      display_names = []
      relative_keypoints = []
  
      for category in self.categories:
          scores.append(category.score)
          if category.index:
              label_ids.append(category.index)
          if category.category_name:
              labels.append(category.category_name)
          if category.display_name:
              display_names.append(category.display_name)
  
      if self.keypoints:
          for keypoint in self.keypoints:
              relative_keypoint_proto = (
                  _LocationDataProto.RelativeKeypoint()
              )
              if keypoint.x:
                  relative_keypoint_proto.x = keypoint.x
              if keypoint.y:
                  relative_keypoint_proto.y = keypoint.y
              if keypoint.label:
                  relative_keypoint_proto.keypoint_label = (
                      keypoint.label
                  )
              if keypoint.score:
                  relative_keypoint_proto.score = keypoint.score
              relative_keypoints.append(relative_keypoint_proto)
  
      return _DetectionProto(
          label=labels,
          label_id=label_ids,
          score=scores,
          display_name=display_names,
          location_data=_LocationDataProto(
              format=_LocationDataProto.Format.BOUNDING_BOX,
              bounding_box=self.bounding_box.to_pb2(),
              relative_keypoints=relative_keypoints,
          ),
      )
  
file_path: mediapipe/mediapipe/tasks/python/components/containers/detections.py
imports: import dataclasses
  from typing import Any, List, Optional
  from mediapipe.framework.formats import detection_pb2
  from mediapipe.framework.formats import location_data_pb2
  from mediapipe.tasks.python.components.containers import bounding_box
  from mediapipe.tasks.python.components.containers import category
  from mediapipe.tasks.python.components.containers import keypoint
  from mediapipe.tasks.python.core.optional_dependencies import doc_controls
label_desc: Use image node_id 1 for calling the Detection obj's underlying member method code with example usage: obj.to_pb2() and returns: _DetectionProto