MCPcopy Create free account
hub / github.com/DeepLabCut/DeepLabCut / select_cropping_area

Function select_cropping_area

deeplabcut/gui/tabs/extract_frames.py:29–79  ·  view source on GitHub ↗

Interactively select the cropping area of all videos in the config. A user interface pops up with a frame to select the cropping parameters. Use the left click to draw a box and hit the button 'set cropping parameters' to store the cropping parameters for a video in the config.yaml file.

(config, videos=None)

Source from the content-addressed store, hash-verified

27
28
29def select_cropping_area(config, videos=None):
30 """Interactively select the cropping area of all videos in the config. A user
31 interface pops up with a frame to select the cropping parameters. Use the left click
32 to draw a box and hit the button 'set cropping parameters' to store the cropping
33 parameters for a video in the config.yaml file.
34
35 Parameters
36 ----------
37 config : string
38 Full path of the config.yaml file as a string.
39
40 videos : optional (default=None)
41 List of videos whose cropping areas are to be defined. Note that full paths are required.
42 By default, all videos in the config are successively loaded.
43
44 Returns
45 -------
46 cfg : dict
47 Updated project configuration
48 """
49 from deeplabcut.gui.widgets import FrameCropper
50 from deeplabcut.utils import auxiliaryfunctions
51
52 cfg = auxiliaryfunctions.read_config(config)
53 if videos is None:
54 videos = list(cfg.get("video_sets_original") or cfg["video_sets"])
55
56 for video in videos:
57 fc = FrameCropper(video)
58 coords = fc.draw_bbox()
59 if coords:
60 temp = {
61 "crop": ", ".join(
62 map(
63 str,
64 [
65 int(coords[0]),
66 int(coords[2]),
67 int(coords[1]),
68 int(coords[3]),
69 ],
70 )
71 )
72 }
73 try:
74 cfg["video_sets"][video] = temp
75 except KeyError:
76 cfg["video_sets_original"][video] = temp
77
78 auxiliaryfunctions.write_config(config, cfg)
79 return cfg
80
81
82class ExtractFrames(DefaultTab):

Callers 1

extract_framesMethod · 0.70

Calls 5

draw_bboxMethod · 0.95
FrameCropperClass · 0.90
read_configMethod · 0.45
getMethod · 0.45
write_configMethod · 0.45

Tested by

no test coverage detected