summaryrefslogtreecommitdiff
path: root/build_dataset.pl
blob: 9d7776677b82f61967bbd96ebccdc018f3f53099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl

use strict;
use Cwd qw(cwd);
my $base_dir = cwd;

our $tag = shift @ARGV;

our $images_dir = $base_dir . "/sequences/$tag/";
our $thumbs_dir = $base_dir . "/datasets/$tag/";

mkdir($base_dir . "/datasets/");
mkdir($thumbs_dir);
mkdir($thumbs_dir . "train_A/");
mkdir($thumbs_dir . "test_A/");
mkdir($thumbs_dir . "train_B/");
mkdir($thumbs_dir . "test_B/");

our $test_split = 10; # 1/N videos will be for the test split

our @files = ();

opendir DIR, $images_dir;
while (readdir DIR) {
  next if /^\./;
  push(@files, $_);
}
closedir DIR;

our @images = sort @files;

my $count = scalar(@images) - 1;

print "Processing " . $count . " frames\n";

my $i;
my $j;
my $dir;
my $src;
my $dst;
for ($i = 0; $i < $count; $i++) {
  if (($i % $test_split) == ($test_split-1)) {
    $dir = $thumbs_dir . "test_";

    $src = $images_dir . $images[$i];
    $dst = $dir . sprintf("A/frame_%05d.png", $i);
    system("ln", "-s", $src, $dst);

    $src = $images_dir . $images[$i+1];
    $dst = $dir . sprintf("B/frame_%05d.png", $i);
    system("ln", "-s", $src, $dst);
  }

  $dir = $thumbs_dir . "train_";
  $src = $images_dir . $images[$i];
  $dst = $dir . sprintf("A/frame_%05d.png", $i);
  system("ln", "-s", $src, $dst);

  $src = $images_dir . $images[$i+1];
  $dst = $dir . sprintf("B/frame_%05d.png", $i);
  system("ln", "-s", $src, $dst);

  if (($i % 100) == 0) {
    print $i . "...\n";
  }
}
print "Done\n";