Files
supervision/supervision/notebook/utils.py
T
SkalskiP 3dad4f4a4d First batch of basic tools:
- 🎨 DEFAULT_COLOR_PALETTE, Color and ColorPalette classes
- 📐 initial implementation of Point, Vector and Rect classes
- 🎬 VideoInfo and VideoSink classes as well as get_video_frames_generator
- 📓 show_frame_in_notebook util
2023-01-18 19:27:51 +01:00

23 lines
690 B
Python

from typing import Tuple
import cv2
import matplotlib.pyplot as plt
import numpy as np
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
:param frame: np.ndarray : The frame to be displayed.
:param size: Tuple[int, int] : The size of the plot. default:(10,10)
:param cmap: str : the colormap to use for single channel images. default:gray
"""
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()