Skip to content

Commit

Permalink
requirement pins video tools
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson committed May 19, 2024
1 parent b2247f2 commit d2d0685
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 48 deletions.
49 changes: 27 additions & 22 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
pip==21.2.2;python_version=="3.6"
pip==24.0;python_version>="3.9"
setuptools==58.0.4;python_version=="3.6"
setuptools==69.5.1;python_version>="3.9"
Pillow
Pillow==8.3.2; python_version=="3.6"
Pillow==10.3.0; python_version>="3.9"
pyyaml == 5.3.1
shapely == 1.8.0; python_version=="3.6"
shapely == 2.0.2; python_version>="3.9"
dtreeviz == 0.8.1
eli5 == 0.10.1
graphviz == 0.11
imblearn == 0.0
imbalanced-learn==0.6.2; python_version=="3.6"
imbalanced-learn==0.12.2; python_version>="3.9"
imgaug == 0.4.0
imutils == 0.5.2
matplotlib == 3.3.4
numpy
matplotlib == 3.3.4; python_version=="3.6"
matplotlib == 3.5.0; python_version>="3.9"
numpy==1.19.1; python_version=="3.6"
numpy==1.26.4; python_version>="3.9"
opencv-python == 3.4.5.20; python_version=="3.6"
opencv-python == 4.8.1.78; python_version>="3.9"
pandas==0.25.3;python_version=="3.6"
pandas;python_version>="3.9"
scikit-image
scipy
pandas==2.2.2;python_version>="3.9"
scikit-image == 0.14.2; python_version=="3.6"
scikit-image == 0.23.2; python_version>="3.9"
scipy== 1.5.4; python_version=="3.6"
scipy== 1.13.0; python_version>="3.9"
seaborn == 0.11.0
scikit-learn == 0.22.2; python_version=="3.6"
scikit-learn; python_version>="3.9"
scikit-learn == 1.4.2; python_version>="3.9"
joblib == 1.1.1; python_version=="3.6"
joblib; python_version>="3.9"
joblib == 1.4.2; python_version>="3.9"
tabulate == 0.8.3; python_version=="3.6"
tabulate == 0.9.0; python_version>="3.9"
tqdm == 4.30.0
xgboost == 0.90
yellowbrick
yellowbrick==0.9.1; python_version=="3.6"
yellowbrick==1.5.0; python_version>="3.9"
kaleido == 0.2.1; python_version=="3.6"
kaleido; python_version>="3.9"
psutil == 5.9.8; python_version=="3.6"
Expand All @@ -39,19 +42,21 @@ dash_color_picker == 0.0.1
dash_core_components == 1.10.2
dash_colorscales == 0.0.4
dash_html_components == 1.0.3
h5py
h5py==2.9.0;python_version=="3.6"
h5py==3.11.0;python_version>="3.9"
numba==0.52.0;python_version=="3.6"
numba;python_version>="3.9"
numexpr
numba==0.59.1;python_version>="3.9"
numexpr==2.6.9;python_version=="3.6"
numexpr==2.10.0;python_version>="3.9"
plotly == 4.9.0
statsmodels==0.12.0;python_version=="3.6"
statsmodels;python_version>="3.9"
statsmodels==0.14.2;python_version>="3.9"
cefpython3 == 66.0
pyarrow == 6.0.1
shap == 0.35.0
tables>=3.6.1
tables==3.6.1;python_version=="3.6"
tables==3.9.2;python_version>="3.9"
xlrd==1.2.0
trafaret==2.1.1
geos
ffmpeg-python

geos==0.2.3
ffmpeg-python==0.2.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setuptools.setup(
name="Simba-UW-tf-dev",
version="1.92.4",
version="1.93.3",
author="Simon Nilsson, Jia Jie Choong, Sophia Hwang",
author_email="[email protected]",
description="Toolkit for computer classification of behaviors in experimental animals",
Expand Down
23 changes: 10 additions & 13 deletions simba/SimBA.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@
InitiateClipMultipleVideosByFrameNumbersPopUp,
InitiateClipMultipleVideosByTimestampsPopUp, InteractiveClahePopUp,
MergeFrames2VideoPopUp, MultiCropPopUp, MultiShortenPopUp,
SuperImposeFrameCountPopUp, VideoRotatorPopUp, VideoTemporalJoinPopUp)
SuperImposeFrameCountPopUp, VideoRotatorPopUp, VideoTemporalJoinPopUp,
SuperimposeTimerPopUp, SuperimposeWatermarkPopUp, SuperimposeProgressBarPopUp)
from simba.ui.pop_ups.visualize_pose_in_dir_pop_up import \
VisualizePoseInFolderPopUp
from simba.ui.tkinter_functions import DropDownMenu, Entry_Box, FileSelect
Expand Down Expand Up @@ -1777,18 +1778,14 @@ def __init__(self):
command=VideoRotatorPopUp,
)

video_process_menu.add_command(
label="Superimpose frame numbers on video",
compound="left",
image=self.menu_icons["trash"]["img"],
command=lambda: SuperImposeFrameCountPopUp(),
)
video_process_menu.add_command(
label="Temporal join videos",
compound="left",
image=self.menu_icons["stopwatch"]["img"],
command=VideoTemporalJoinPopUp,
)
superimpose_menu = Menu(menu)
superimpose_menu.add_command(label="Superimpose frame numbers on videos", command=SuperImposeFrameCountPopUp)
superimpose_menu.add_command(label="Superimpose watermark on videos", command=SuperimposeWatermarkPopUp)
superimpose_menu.add_command(label="Superimpose timer on videos", command=SuperimposeTimerPopUp)
superimpose_menu.add_command(label="Superimpose progress-bar on videos", command=SuperimposeProgressBarPopUp)
video_process_menu.add_cascade(label="Superimpose on videos...", compound="left", image=self.menu_icons["superimpose"]["img"], menu=superimpose_menu)

video_process_menu.add_command(label="Temporal join videos", compound="left", image=self.menu_icons["stopwatch"]["img"], command=VideoTemporalJoinPopUp)

video_process_menu.add_cascade(
label="Visualize pose-estimation in folder...",
Expand Down
13 changes: 8 additions & 5 deletions simba/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
pip==21.2.2;python_version=="3.6"
pip==24.0;python_version>="3.9"
setuptools==58.0.4;python_version=="3.6"
setuptools==69.5.1;python_version>="3.9"
Pillow
pyyaml == 5.3.1
shapely == 1.7.1;python_version=="3.6"
shapely == 1.8.0;python_version=="3.6"
shapely;python_version>="3.9"
dtreeviz == 0.8.1
eli5 == 0.10.1
graphviz == 0.11
imblearn == 0.0
imgaug == 0.4.0
imutils == 0.5.2
matplotlib >= 3.0.3
matplotlib == 3.3.4
numpy==1.18.1;python_version=="3.6"
numpy;python_version>="3.9"
numpy==1.26.4;python_version>="3.9"
opencv-python == 3.4.5.20;python_version=="3.6"
opencv-python;python_version>="3.9"
pandas==0.25.3;python_version=="3.6"
pandas;python_version>="3.9"
scikit-image
scipy
kaleido
seaborn == 0.9.0
seaborn == 0.11.0
scikit-learn
tabulate == 0.8.3;python_version=="3.6"
tabulate == 0.9.0;python_version>="3.9"
Expand Down
184 changes: 183 additions & 1 deletion simba/ui/pop_ups/video_processing_pop_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import sys
import threading
import numpy as np
from datetime import datetime
from tkinter import *
from typing import Optional, Union
Expand All @@ -31,6 +32,7 @@
from simba.utils.errors import (CountError, FrameRangeError, InvalidInputError,
MixedMosaicError, NoChoosenClassifierError,
NoFilesFoundError, NotDirectoryError)
from simba.utils.lookups import get_color_dict
from simba.utils.printing import SimbaTimer, stdout_success
from simba.utils.read_write import (
check_if_hhmmss_timestamp_is_valid_part_of_video,
Expand All @@ -57,7 +59,7 @@
extract_frames_single_video, frames_to_movie, gif_creator,
multi_split_video, remove_beginning_of_video, resize_videos_by_height,
resize_videos_by_width, superimpose_frame_count, video_concatenator,
video_to_greyscale)
video_to_greyscale, watermark_video, superimpose_video_progressbar, superimpose_elapsed_time)

sys.setrecursionlimit(10**7)

Expand Down Expand Up @@ -2567,6 +2569,186 @@ def run(self, multiple: bool):



class SuperimposeWatermarkPopUp(PopUpMixin):
def __init__(self):
PopUpMixin.__init__(self, title="WATERMARK VIDEOS")
self.LOCATIONS = {'TOP LEFT': 'top_left', 'TOP RIGHT': 'top_right', 'BOTTOM LEFT': 'bottom_left', 'BOTTOM RIGHT': 'bottom_right', 'CENTER': 'center'}
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
opacities = [round(x, 1) for x in list(np.arange(0.1, 1.1, 0.1))]
self.selected_img = FileSelect(settings_frm, "WATERMARK IMAGE PATH:", title="Select an image file", file_types=[("VIDEO", Options.ALL_IMAGE_FORMAT_OPTIONS.value)], lblwidth=25)
self.location_dropdown = DropDownMenu(settings_frm, "WATERMARK LOCATION:", list(self.LOCATIONS.keys()), labelwidth=25)
self.opacity_dropdown = DropDownMenu(settings_frm, "WATERMARK OPACITY:", opacities, labelwidth=25)
self.size_dropdown = DropDownMenu(settings_frm, "WATERMARK SCALE %:", list(range(5, 100, 5)), labelwidth=25)

self.location_dropdown.setChoices('TOP LEFT')
self.opacity_dropdown.setChoices(50)
self.size_dropdown.setChoices(5)

settings_frm.grid(row=0, column=0, sticky=NW)
self.selected_img.grid(row=0, column=0, sticky=NW)
self.location_dropdown.grid(row=1, column=0, sticky=NW)
self.opacity_dropdown.grid(row=2, column=0, sticky=NW)
self.size_dropdown.grid(row=3, column=0, sticky=NW)

single_video_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SINGLE VIDEO - SUPERIMPOSE WATERMARK", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", lblwidth=25, file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)])
single_video_run = Button(single_video_frm, text="RUN - SINGLE VIDEO", command=lambda: self.run(multiple=False))

single_video_frm.grid(row=1, column=0, sticky="NW")
self.selected_video.grid(row=0, column=0, sticky="NW")
single_video_run.grid(row=1, column=0, sticky="NW")

multiple_videos_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="MULTIPLE VIDEOS - SUPERIMPOSE WATERMARK", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
self.selected_video_dir = FolderSelect(multiple_videos_frm, "VIDEO DIRECTORY PATH:", title="Select a video directory", lblwidth=25)
multiple_videos_run = Button(multiple_videos_frm, text="RUN - MULTIPLE VIDEOS", command=lambda: self.run(multiple=True))

multiple_videos_frm.grid(row=2, column=0, sticky="NW")
self.selected_video_dir.grid(row=0, column=0, sticky="NW")
multiple_videos_run.grid(row=1, column=0, sticky="NW")
self.main_frm.mainloop()

def run(self, multiple: bool):
img_path = self.selected_img.file_path
loc = self.location_dropdown.getChoices()
loc = self.LOCATIONS[loc]
opacity = float(self.opacity_dropdown.getChoices())
size = float(int(self.size_dropdown.getChoices()) / 100)
if size == 1.0: size = size - 0.001
check_file_exist_and_readable(file_path=img_path)
if not multiple:
data_path = self.selected_video.file_path
check_file_exist_and_readable(file_path=data_path)
else:
data_path = self.selected_video_dir.folder_path
check_if_dir_exists(in_dir=data_path)

threading.Thread(target=watermark_video(video_path=data_path,
watermark_path=img_path, position=loc,
opacity=opacity,
scale=size)).start()
#SuperimposeWatermarkPopUp()


class SuperimposeTimerPopUp(PopUpMixin):
def __init__(self):
PopUpMixin.__init__(self, title="SUPER-IMPOSE TIME ON VIDEOS")
self.LOCATIONS = {'TOP LEFT': 'top_left', 'TOP RIGHT': 'top_right', 'TOP MIDDLE': 'top_middle', 'BOTTOM LEFT': 'bottom_left', 'BOTTOM RIGHT': 'bottom_right', 'BOTTOM MIDDLE': 'bottom_middle'}
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
self.color_dict = get_color_dict()

self.location_dropdown = DropDownMenu(settings_frm, "TIMER LOCATION:", list(self.LOCATIONS.keys()), labelwidth=25)
self.font_size_dropdown = DropDownMenu(settings_frm, "FONT SIZE:", list(range(20, 100, 5)), labelwidth=25)
self.font_color_dropdown = DropDownMenu(settings_frm, "FONT COLOR:", list(self.color_dict.keys()), labelwidth=25)
self.font_border_dropdown = DropDownMenu(settings_frm, "FONT BORDER COLOR:", list(self.color_dict.keys()), labelwidth=25)
self.font_border_width_dropdown = DropDownMenu(settings_frm, "FONT BORDER WIDTH:", list(range(2, 52, 2)), labelwidth=25)

self.location_dropdown.setChoices('TOP LEFT')
self.font_size_dropdown.setChoices(20)
self.font_color_dropdown.setChoices('White')
self.font_border_dropdown.setChoices('Black')
self.font_border_width_dropdown.setChoices(2)

settings_frm.grid(row=0, column=0, sticky=NW)
self.location_dropdown.grid(row=0, column=0, sticky=NW)
self.font_size_dropdown.grid(row=1, column=0, sticky=NW)
self.font_color_dropdown.grid(row=2, column=0, sticky=NW)
self.font_border_dropdown.grid(row=3, column=0, sticky=NW)
self.font_border_width_dropdown.grid(row=4, column=0, sticky=NW)

single_video_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SINGLE VIDEO - SUPERIMPOSE TIMER", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", lblwidth=25, file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)])
single_video_run = Button(single_video_frm, text="RUN - SINGLE VIDEO", command=lambda: self.run(multiple=False))

single_video_frm.grid(row=1, column=0, sticky="NW")
self.selected_video.grid(row=0, column=0, sticky="NW")
single_video_run.grid(row=1, column=0, sticky="NW")

multiple_videos_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="MULTIPLE VIDEOS - SUPERIMPOSE TIMER", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
self.selected_video_dir = FolderSelect(multiple_videos_frm, "VIDEO DIRECTORY PATH:", title="Select a video directory", lblwidth=25)
multiple_videos_run = Button(multiple_videos_frm, text="RUN - MULTIPLE VIDEOS", command=lambda: self.run(multiple=True))

multiple_videos_frm.grid(row=2, column=0, sticky="NW")
self.selected_video_dir.grid(row=0, column=0, sticky="NW")
multiple_videos_run.grid(row=1, column=0, sticky="NW")
self.main_frm.mainloop()

def run(self, multiple: bool):
loc = self.location_dropdown.getChoices()
loc = self.LOCATIONS[loc]
font_size = int(self.font_size_dropdown.getChoices())
font_clr = self.font_color_dropdown.getChoices()
font_border_clr = self.font_border_dropdown.getChoices()
font_border_width = int(self.font_border_width_dropdown.getChoices())
if not multiple:
data_path = self.selected_video.file_path
check_file_exist_and_readable(file_path=data_path)
else:
data_path = self.selected_video_dir.folder_path
check_if_dir_exists(in_dir=data_path)

threading.Thread(target=superimpose_elapsed_time(video_path=data_path,
font_size=font_size,
font_color=font_clr,
font_border_color=font_border_clr,
font_border_width=font_border_width,
position=loc)).start()


class SuperimposeProgressBarPopUp(PopUpMixin):
def __init__(self):
PopUpMixin.__init__(self, title="SUPER-IMPOSE PROGRESS BAR ON VIDEOS")
self.LOCATIONS = {'TOP': 'top', 'BOTTOM': 'bottom'}
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
self.color_dict = get_color_dict()
size_lst = list(range(0, 110, 5))
size_lst[0] = 1
self.bar_loc_dropdown = DropDownMenu(settings_frm, "PROGRESS BAR LOCATION:", list(self.LOCATIONS.keys()), labelwidth=25)
self.bar_color_dropdown = DropDownMenu(settings_frm, "PROGRESS BAR COLOR:", list(self.color_dict.keys()), labelwidth=25)
self.bar_size_dropdown = DropDownMenu(settings_frm, "PROGRESS BAR HEIGHT (%):", size_lst, labelwidth=25)
self.bar_color_dropdown.setChoices('Red')
self.bar_size_dropdown.setChoices(10)
self.bar_loc_dropdown.setChoices('BOTTOM')

settings_frm.grid(row=0, column=0, sticky=NW)
self.bar_loc_dropdown.grid(row=0, column=0, sticky=NW)
self.bar_color_dropdown.grid(row=1, column=0, sticky=NW)
self.bar_size_dropdown.grid(row=2, column=0, sticky=NW)

single_video_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SINGLE VIDEO - SUPERIMPOSE PROGRESS BAR", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", lblwidth=25, file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)])
single_video_run = Button(single_video_frm, text="RUN - SINGLE VIDEO", command=lambda: self.run(multiple=False))

single_video_frm.grid(row=1, column=0, sticky="NW")
self.selected_video.grid(row=0, column=0, sticky="NW")
single_video_run.grid(row=1, column=0, sticky="NW")

multiple_videos_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="MULTIPLE VIDEOS - SUPERIMPOSE PROGRESS BAR", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
self.selected_video_dir = FolderSelect(multiple_videos_frm, "VIDEO DIRECTORY PATH:", title="Select a video directory", lblwidth=25)
multiple_videos_run = Button(multiple_videos_frm, text="RUN - MULTIPLE VIDEOS", command=lambda: self.run(multiple=True))

multiple_videos_frm.grid(row=2, column=0, sticky="NW")
self.selected_video_dir.grid(row=0, column=0, sticky="NW")
multiple_videos_run.grid(row=1, column=0, sticky="NW")
self.main_frm.mainloop()

def run(self, multiple: bool):
loc = self.bar_loc_dropdown.getChoices()
loc = self.LOCATIONS[loc]
bar_clr = self.bar_color_dropdown.getChoices()
bar_size = int(self.bar_size_dropdown.getChoices())
if not multiple:
data_path = self.selected_video.file_path
check_file_exist_and_readable(file_path=data_path)
else:
data_path = self.selected_video_dir.folder_path
check_if_dir_exists(in_dir=data_path)

threading.Thread(target=superimpose_video_progressbar(video_path=data_path,
bar_height=bar_size,
color=bar_clr,
position=loc)).start()




# ClipMultipleVideosByFrameNumbers
Expand Down
Loading

0 comments on commit d2d0685

Please sign in to comment.