import os
from random import randint
import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import (
Card,
Container,
Timeline,
Text,
InputNumber,
VideoThumbnail,
)
Write a function for dividing the total number of frames by ranges
def divide_to_ranges(total, n):
step = total // n
ranges = []
for i in range(n):
start = i * step
end = start + step - 1 if i < n - 1 else total - 1
ranges.append([start, end])
return ranges, len(ranges)
Write function generating random hex colors for each range
def generate_hex_colors(n):
colors = []
for _ in range(n):
color = "#{:06x}".format(randint(0, 0xFFFFFF))
colors.append(color)
return colors
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
Initialize Video ID we will use
video_id = 350000 # set your video id here
Get video info from server and prepare VideoThumbnail widget
video = api.video.get_info_by_id(video_id)
video_thumbnail = VideoThumbnail(video)
Get video intervals and colors from video frame count