Skip to content

Commit bda759a

Browse files
committed
Add a grayscale flag and mandate frame_index in plot_frame()
1 parent 609f62d commit bda759a

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

pyneon/utils/variables.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@
115115
# Events columns after concatenation
116116
"message name": "string",
117117
"message type": "string",
118-
# Marker detections
118+
# Detections
119119
"frame index": "Int64",
120120
"marker family": "string",
121121
"marker id": "string",
122122
"marker name": "string",
123+
"contour name": "string",
123124
"top left x [px]": float,
124125
"top left y [px]": float,
125126
"top right x [px]": float,

pyneon/video/video.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ def __exit__(self, exc_type, exc, traceback) -> bool:
457457
@fill_doc
458458
def plot_frame(
459459
self,
460-
frame_index: int = 0,
460+
frame_index: int,
461+
grayscale: bool = False,
461462
ax: Optional[plt.Axes] = None,
462463
show: bool = True,
463464
):
@@ -468,13 +469,17 @@ def plot_frame(
468469
----------
469470
frame_index : int
470471
Index of the frame to plot.
472+
grayscale : bool, optional
473+
Whether to convert the frame to grayscale before plotting.
474+
Defaults to False.
471475
{ax_param}
476+
{show_param}
472477
473478
Returns
474479
-------
475480
{fig_ax_returns}
476481
"""
477-
return plot_frame(self, frame_index, ax, show)
482+
return plot_frame(self, frame_index, grayscale, ax, show)
478483

479484
def undistort_video(
480485
self,

pyneon/vis/video.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
@fill_doc
2121
def plot_frame(
2222
video: "Video",
23-
frame_index: int = 0,
23+
frame_index: int,
24+
grayscale: bool = False,
2425
ax: Optional[plt.Axes] = None,
2526
show: bool = True,
2627
) -> tuple[plt.Figure, plt.Axes]:
@@ -33,6 +34,9 @@ def plot_frame(
3334
Video instance to plot the frame from.
3435
frame_index : int
3536
Index of the frame to plot.
37+
grayscale : bool, optional
38+
Whether to convert the frame to grayscale before plotting.
39+
Defaults to False.
3640
{ax_param}
3741
{show_param}
3842
@@ -49,7 +53,11 @@ def plot_frame(
4953
frame = video.read_frame_at(frame_index)
5054
if frame is None:
5155
raise RuntimeError(f"Could not read frame {frame_index}")
52-
ax.imshow(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
56+
if grayscale:
57+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
58+
ax.imshow(frame, cmap="gray")
59+
else:
60+
ax.imshow(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
5361
ax.axis("off")
5462
if show:
5563
plt.show()

0 commit comments

Comments
 (0)