Skip to content

Register now for

# Reference for `ultralytics/solutions/vision_eye.py`

Note

This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/vision_eye.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!

## `` ultralytics.solutions.vision_eye.VisionEye

    VisionEye(**kwargs: Any)

Bases: `BaseSolution`

A class to manage object detection and vision mapping in images or video streams.

This class extends the BaseSolution class and provides functionality for detecting objects, mapping vision points, and annotating results with bounding boxes and labels.

Attributes:

Name | Type | Description
--- | --- | ---
`vision_point` | `tuple[int, int]` | Coordinates (x, y) where vision will view objects and draw tracks.

Methods:

Name | Description
--- | ---
`process` | Process the input image to detect objects, annotate them, and apply vision mapping.

Examples:

    >>> vision_eye = VisionEye()
    >>> frame = cv2.imread("frame.jpg")
    >>> results = vision_eye.process(frame)
    >>> print(f"Total detected instances: {results.total_tracks}")

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`**kwargs` | `Any` | Keyword arguments passed to the parent class and for configuring vision_point. | `{}`

Source code in `ultralytics/solutions/vision_eye.py`

    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    def __init__(self, **kwargs: Any) -> None:
        """
        Initialize the VisionEye class for detecting objects and applying vision mapping.

        Args:
            **kwargs (Any): Keyword arguments passed to the parent class and for configuring vision_point.
        """
        super().__init__(**kwargs)
        # Set the vision point where the system will view objects and draw tracks
        self.vision_point = self.CFG["vision_point"]

### `` process

    process(im0) -> SolutionResults

Perform object detection, vision mapping, and annotation on the input image.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`im0` | `ndarray` | The input image for detection and annotation. | required

Returns:

Type | Description
--- | ---
`SolutionResults` | Object containing the annotated image and tracking statistics. - plot_im: Annotated output image with bounding boxes and vision mapping - total_tracks: Number of tracked objects in the frame

Examples:

    >>> vision_eye = VisionEye()
    >>> frame = cv2.imread("image.jpg")
    >>> results = vision_eye.process(frame)
    >>> print(f"Detected {results.total_tracks} objects")

Source code in `ultralytics/solutions/vision_eye.py`

    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    def process(self, im0) -> SolutionResults:
        """
        Perform object detection, vision mapping, and annotation on the input image.

        Args:
            im0 (np.ndarray): The input image for detection and annotation.

        Returns:
            (SolutionResults): Object containing the annotated image and tracking statistics.
                - plot_im: Annotated output image with bounding boxes and vision mapping
                - total_tracks: Number of tracked objects in the frame

        Examples:
            >>> vision_eye = VisionEye()
            >>> frame = cv2.imread("image.jpg")
            >>> results = vision_eye.process(frame)
            >>> print(f"Detected {results.total_tracks} objects")
        """
        self.extract_tracks(im0)  # Extract tracks (bounding boxes, classes, and masks)
        annotator = SolutionAnnotator(im0, self.line_width)

        for cls, t_id, box, conf in zip(self.clss, self.track_ids, self.boxes, self.confs):
            # Annotate the image with bounding boxes, labels, and vision mapping
            annotator.box_label(box, label=self.adjust_box_label(cls, conf, t_id), color=colors(int(t_id), True))
            annotator.visioneye(box, self.vision_point)

        plot_im = annotator.result()
        self.display_output(plot_im)  # Display the annotated output using the base class function

        # Return a SolutionResults object with the annotated image and tracking statistics
        return SolutionResults(plot_im=plot_im, total_tracks=len(self.track_ids))

📅 Created 6 months ago ✏️ Updated 6 months ago