Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix video generation script #233

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions scripts/output_video.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from pathlib import Path

import cv2
import numpy as np


def create_opencv_video(
def create_opencv_video( # noqa: C901
ds,
input_video,
output_video_path,
list_individuals_idcs=None,
list_frame_idcs=None,
list_individuals=None, # IDs of individuals to plot
list_frame_idcs=None, # list of frame **indices** to plot
):
# Open the video file
cap = cv2.VideoCapture(input_video)
Expand All @@ -24,6 +25,16 @@ def create_opencv_video(
fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for mp4
out = cv2.VideoWriter(output_video_path, fourcc, fps, (width, height))

# Prepare list of indices of individuals to plot
if list_individuals:
list_individuals_idcs = [
np.argwhere(ds_pred.individuals.data == f"id_{str(ind)}").item()
for ind in list_individuals
]

else:
list_individuals_idcs = None

# bboxes format
rectangle_color = (0, 255, 0) # Green color in BGR format

Expand Down Expand Up @@ -71,10 +82,10 @@ def create_opencv_video(
3, # rectangle_thickness
)

# add ID
# add bbox ID
cv2.putText(
frame,
str(ind_idx),
str(ind_idx), # index in position array
tuple(
int(x) for x in bottom_right
), # location of text bottom left
Expand Down Expand Up @@ -169,14 +180,14 @@ def create_opencv_video(
# )

# Create prediction video
list_individuals_idcs = [22]
list_individuals = [27, 110, 129, 150, 162, 165]
output_video_path = str(
Path(__file__).parent
/ f"pred_id_{'_'.join([str(el) for el in list_individuals_idcs])}.mp4"
/ f"pred_id_{'_'.join([str(el) for el in list_individuals])}_VIA.mp4"
)
create_opencv_video(
ds=ds_pred,
input_video=input_video,
output_video_path=output_video_path,
list_individuals_idcs=list_individuals_idcs,
list_individuals=list_individuals,
)