-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprepare.php
50 lines (48 loc) · 1.7 KB
/
prepare.php
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
<?php
include __DIR__ . '/vendor/autoload.php';
include './init.php';
$max = (int) $argv[1];
$folder = $argv[2];
$count = 0;
if (($handle = fopen("roboflow/$folder/_annotations.csv", "r")) !== false) {
$coord = [];
while (($row = fgetcsv($handle, 1000, ",")) !== false) {
$count++;
if ($count <= $max + 1) {
if ($count == 1) {
continue;
}
$image = imagecreatefromjpeg("roboflow/$folder/{$row[0]}");
if (in_array($row['3'], $pieces)) {
$coord[] = $row['4'].$row['5'].$row['6'].$row['7'];
$tile = imagecrop($image, [
'x' => $row['4'] - 1,
'y' => $row['5'] - 1,
'width' => 52,
'height' => 52,
]);
if ($tile !== false) {
imagejpeg($tile, "$folder/{$row['3']}/".sprintf("%05d", $count).'.jpg');
imagedestroy($tile);
}
} elseif ($row['3'] === 'board') {
$diff = array_diff($xyImploded, $coord);
foreach ($diff as $key => $val) {
$tile = imagecrop($image, [
'x' => $xy[$key][0] - 1,
'y' => $xy[$key][1] - 1,
'width' => 52,
'height' => 52,
]);
if ($tile !== false) {
imagejpeg($tile, "$folder/1/".sprintf("%05d", $count).'.jpg');
imagedestroy($tile);
}
}
$coord = [];
}
imagedestroy($image);
}
}
fclose($handle);
}