Skip to content

Commit

Permalink
Change slider_width to extract_frames function parameter #315
Browse files Browse the repository at this point in the history
  • Loading branch information
alchemyconsulting committed Jun 11, 2019
1 parent 07beb43 commit 6568c2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 7 additions & 2 deletions deeplabcut/generate_training_dataset/frame_extraction.py
Expand Up @@ -7,7 +7,7 @@
"""


def extract_frames(config,mode='automatic',algo='kmeans',crop=False,userfeedback=True,cluster_step=1,cluster_resizewidth=30,cluster_color=False,opencv=True):
def extract_frames(config,mode='automatic',algo='kmeans',crop=False,userfeedback=True,cluster_step=1,cluster_resizewidth=30,cluster_color=False,opencv=True,slider_width=25):
"""
Extracts frames from the videos in the config.yaml file. Only the videos in the config.yaml will be used to select the frames.\n
Use the function ``add_new_video`` at any stage of the project to add new videos to the config file and extract their frames.
Expand Down Expand Up @@ -55,6 +55,8 @@ def extract_frames(config,mode='automatic',algo='kmeans',crop=False,userfeedback
opencv: bool, default: True
Uses openCV for loading & extractiong (otherwise moviepy (legacy))
slider_width: number, default: 25
Width of the video frames slider, in percent of window
Examples
--------
Expand All @@ -69,6 +71,9 @@ def extract_frames(config,mode='automatic',algo='kmeans',crop=False,userfeedback
--------
for selecting frames manually,
>>> deeplabcut.extract_frames('/analysis/project/reaching-task/config.yaml','manual')
--------
for selecting frames manually, with a 60% wide frames slider
>>> deeplabcut.extract_frames('/analysis/project/reaching-task/config.yaml','manual', slider_width=60)
While selecting the frames manually, you do not need to specify the ``crop`` parameter in the command. Rather, you will get a prompt in the graphic user interface to choose
if you need to crop or not.
Expand All @@ -93,7 +98,7 @@ def extract_frames(config,mode='automatic',algo='kmeans',crop=False,userfeedback
wd = Path(config).resolve().parents[0]
os.chdir(str(wd))
from deeplabcut.generate_training_dataset import frame_extraction_toolbox
frame_extraction_toolbox.show(config)
frame_extraction_toolbox.show(config, slider_width)

elif mode == "automatic":
config_file = Path(config).resolve()
Expand Down
15 changes: 4 additions & 11 deletions deeplabcut/generate_training_dataset/frame_extraction_toolbox.py
Expand Up @@ -68,10 +68,7 @@ def __init__(self, parent):
class MainFrame(wx.Frame):
"""Contains the main GUI and button boxes"""

def __init__(self, parent,config):
# Read in config
self.cfg = auxiliaryfunctions.read_config(config)

def __init__(self, parent,config,slider_width=25):
# Settting the GUI size and panels design
displays = (wx.Display(i) for i in range(wx.Display.GetCount())) # Gets the number of displays
screenSizes = [display.GetGeometry().GetSize() for display in displays] # Gets the size of each display
Expand Down Expand Up @@ -120,11 +117,6 @@ def __init__(self, parent,config):
self.grab.Enable(False)

widgetsizer.AddStretchSpacer(5)

try:
slider_width = self.cfg['slider_width']
except:
slider_width = 25
size_x = round(self.gui_size[0] * (slider_width/100), 0)
self.slider = wx.Slider(self.widget_panel, id=wx.ID_ANY, value = 0, minValue=0, maxValue=1,size=(size_x, -1), style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS )
widgetsizer.Add(self.slider,1, wx.ALL,5)
Expand Down Expand Up @@ -180,6 +172,7 @@ def __init__(self, parent,config):
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.drs = []
self.cfg = auxiliaryfunctions.read_config(config)
self.Task = self.cfg['Task']
self.start = self.cfg['start']
self.stop = self.cfg['stop']
Expand Down Expand Up @@ -443,11 +436,11 @@ def __init__(self, parent,config):
self.figure = Figure()
self.axes = self.figure.add_subplot(111)

def show(config):
def show(config, slider_width=25):
import imageio
imageio.plugins.ffmpeg.download()
app = wx.App()
frame = MainFrame(None,config).Show()
frame = MainFrame(None,config,slider_width).Show()
app.MainLoop()


Expand Down

0 comments on commit 6568c2b

Please sign in to comment.