def parse_patches(doc, patches_field, handle_missing="skip"):
    """Parses the patches from the given document.

    Args:
        patches_field: the name of the field defining the image patches. Must
            be of type :class:`fiftyone.core.labels.Detection`,
            :class:`fiftyone.core.labels.Detections`,
            :class:`fiftyone.core.labels.Polyline`, or
            :class:`fiftyone.core.labels.Polylines`
        handle_missing ("skip"): how to handle documents with no patches.
            Supported values are:

                -   "skip": skip the document and return ``None``
                -   "image": use the whole image as a single patch
                -   "error": raise an error

    Returns:
        a :class:`fiftyone.core.labels.Detections` instance, or ``None``
    """
    label = doc[patches_field]

    if isinstance(label, fol.Detections):
        patches = label
    elif isinstance(label, fol.Detection):
        patches = fol.Detections(detections=[label])
    elif isinstance(label, fol.Polyline):
        patches = fol.Detections(detections=[label.to_detection()])
    elif isinstance(label, fol.Polylines):
        patches = label.to_detections()
    elif label is None:
        patches = None
    else:
        raise ValueError(
            "Field '%s' with value type %s is not a valid patches field"
            % (patches_field, type(label))
        )

    if patches is None or not patches.detections:
        if handle_missing == "skip":
            patches = None
        elif handle_missing == "image":
            patches = fol.Detections(
                detections=[fol.Detection(bounding_box=[0, 0, 1, 1])]
            )
        else:
            dtype = "Frame" if isinstance(doc, fof.Frame) else "Sample"
            raise ValueError("%s '%s' has no patches" % (dtype, doc.id))

    return patches
Parses the patches from the given document.

    Args:
        patches_field: the name of the field defining the image patches. Must
            be of type :class:`fiftyone.core.labels.Detection`,
            :class:`fiftyone.core.labels.Detections`,
            :class:`fiftyone.core.labels.Polyline`, or
            :class:`fiftyone.core.labels.Polylines`
        handle_missing ("skip"): how to handle documents with no patches.
            Supported values are:

                -   "skip": skip the document and return ``None``
                -   "image": use the whole image as a single patch
                -   "error": raise an error

    Returns:
        a :class:`fiftyone.core.labels.Detections` instance, or ``None``
    
fiftyone/utils/patches.py