Skip to content

Notebook

show_frame_in_notebook

Display a frame in Jupyter Notebook using Matplotlib

Attributes:

Name Type Description
frame ndarray

The frame to be displayed.

size Tuple[int, int]

The size of the plot. default:(10,10)

cmap str

the colormap to use for single channel images. default:gray

Examples:

>>> from supervision.notebook.utils import show_frame_in_notebook

%matplotlib inline
show_frame_in_notebook(frame, (16, 16))
Source code in supervision/notebook/utils.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def show_frame_in_notebook(
    frame: np.ndarray, size: Tuple[int, int] = (10, 10), cmap: str = "gray"
):
    """
    Display a frame in Jupyter Notebook using Matplotlib

    Attributes:
        frame (np.ndarray): The frame to be displayed.
        size (Tuple[int, int]): The size of the plot. default:(10,10)
        cmap (str): the colormap to use for single channel images. default:gray

    Examples:
        ```python
        >>> from supervision.notebook.utils import show_frame_in_notebook

        %matplotlib inline
        show_frame_in_notebook(frame, (16, 16))
        ```
    """
    if frame.ndim == 2:
        plt.figure(figsize=size)
        plt.imshow(frame, cmap=cmap)
    else:
        plt.figure(figsize=size)
        plt.imshow(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
    plt.show()