summaryrefslogtreecommitdiff
path: root/build_dataset.pl
blob: 6b0524d2ef976d236258abc5777f13f4bf270cca (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
#!/usr/bin/perl

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

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);

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

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

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

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

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