deeplabcut.generate_training_dataset.frame_extraction
Functions:
| Name | Description |
|---|---|
extract_frames |
Extracts frames from the project videos. |
select_cropping_area |
Interactively select the cropping area of all videos in the config. A user |
extract_frames
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,
config3d=None,
extracted_cam=0,
videos_list=None,
)
Extracts frames from the project videos.
Frames will be extracted from videos listed in the config.yaml file.
The frames are selected from the videos in a randomly and temporally uniformly
distributed way (uniform), by clustering based on visual appearance
(k-means), or by manual selection.
After frames have been extracted from all videos from one camera, matched frames
from other cameras can be extracted using mode = "match". This is necessary if
you plan to use epipolar lines to improve labeling across multiple camera angles.
It will overwrite previously extracted images from the second camera angle if
necessary.
Please refer to the user guide for more details on methods and parameters https://www.nature.com/articles/s41596-019-0176-0 or the preprint: https://www.biorxiv.org/content/biorxiv/early/2018/11/24/476531.full.pdf
Parameters
config : string Full path of the config.yaml file as a string.
string. Either "automatic", "manual" or "match".
String containing the mode of extraction. It must be either "automatic" or
"manual" to extract the initial set of frames. It can also be "match"
to match frames between the cameras in preparation for the use of epipolar line
during labeling; namely, extract from camera_1 first, then run this to extract
the matched frames in camera_2.
WARNING: if you use "match", and you previously extracted and labeled
frames from the second camera, this will overwrite your data. This will require
you to delete the collectdata(.h5/.csv) files before labeling. Use with
caution!
string, Either "kmeans" or "uniform", Default: "kmeans".
String specifying the algorithm to use for selecting the frames. Currently,
deeplabcut supports either kmeans or uniform based selection. This flag
is only required for automatic mode and the default is kmeans. For
"uniform", frames are picked in temporally uniform way, "kmeans"
performs clustering on downsampled frames (see user guide for details).
NOTE: Color information is discarded for "kmeans", thus e.g. for
camouflaged octopus clustering one might want to change this.
bool or str, optional
If True, video frames are cropped according to the corresponding
coordinates stored in the project configuration file. Alternatively, if
cropping coordinates are not known yet, crop="GUI" triggers a user
interface where the cropping area can be manually drawn and saved.
bool, optional
If this is set to False during "automatic" mode then frames for all
videos are extracted. The user can set this to "True", which will result in
a dialog, where the user is asked for each video if (additional/any) frames
from this video should be extracted. Use this, e.g. if you have already labeled
some folders and want to extract data for new videos.
int, default: 30
For "k-means" one can change the width to which the images are downsampled
(aspect ratio is fixed).
int, default: 1
By default each frame is used for clustering, but for long videos one could only use every nth frame (set using this parameter). This saves memory before clustering can start, however, reading the individual frames takes longer due to the skipping.
bool, default: False
If "False" then each downsampled image is treated as a grayscale vector
(discarding color information). If "True", then the color channels are
considered. This increases the computational complexity.
bool, default: True
Uses openCV for loading & extractiong (otherwise moviepy (legacy)).
string, optional
Path to the project configuration file in the 3D project. This will be used to match frames extracted from all cameras present in the field 'camera_names' to the frames extracted from the camera given by the parameter 'extracted_cam'.
int, default: 0
The index of the camera that already has extracted frames. This will match
frame numbers to extract for all other cameras. This parameter is necessary if
you wish to use epipolar lines in the labeling toolbox. Only use if
mode='match' and config3d is provided.
list[str], Default: None
A list of the string containing full paths to videos to extract frames for. If
this is left as None all videos specified in the config file will have
frames extracted. Otherwise one can select a subset by passing those paths.
Returns
None
Notes
Use the function add_new_videos at any stage of the project to add new videos
to the config file and extract their frames.
The following parameters for automatic extraction are used from the config file
numframes2pickstartandstop
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.
Examples
To extract frames automatically with 'kmeans' and then crop the frames
deeplabcut.extract_frames( config='/analysis/project/reaching-task/config.yaml', mode='automatic', algo='kmeans', crop=True, )
To extract frames automatically with 'kmeans' and then defining the cropping area using a GUI
deeplabcut.extract_frames( '/analysis/project/reaching-task/config.yaml', 'automatic', 'kmeans', 'GUI', )
To consider the color information when extracting frames automatically with 'kmeans'
deeplabcut.extract_frames( '/analysis/project/reaching-task/config.yaml', 'automatic', 'kmeans', cluster_color=True, )
To extract frames automatically with 'uniform' and then crop the frames
deeplabcut.extract_frames( '/analysis/project/reaching-task/config.yaml', 'automatic', 'uniform', crop=True, )
To extract frames manually
deeplabcut.extract_frames( '/analysis/project/reaching-task/config.yaml', 'manual' )
To extract frames manually, with a 60% wide frames slider
deeplabcut.extract_frames( '/analysis/project/reaching-task/config.yaml', 'manual', slider_width=60, )
To extract frames from a second camera that match the frames extracted from the first
deeplabcut.extract_frames( '/analysis/project/reaching-task/config.yaml', mode='match', extracted_cam=0, )
Source code in deeplabcut/generate_training_dataset/frame_extraction.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |
select_cropping_area
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.
Parameters
config : string Full path of the config.yaml file as a string.
optional (default=None)
List of videos whose cropping areas are to be defined. Note that full paths are required. By default, all videos in the config are successively loaded.
Returns
cfg : dict Updated project configuration