-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·57 lines (48 loc) · 1.36 KB
/
cli.js
File metadata and controls
executable file
·57 lines (48 loc) · 1.36 KB
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
const yargs = require("yargs")
const fs = require("fs")
const mkdirp = require("mkdirp")
const cliProgress = require("cli-progress")
const { sampleToPNG } = require("./index.js")
const { argv } = yargs
.usage("Usage: $0 path/to/dataset.udt.json -o output-masks-dir")
.option("use-sample-number", {
describe:
"Use the number of the sample as the mask filename (sample0001.mask.png, etc.) ",
})
.option("crisp", {
describe: "Remove anti-aliasing around shapes (uses headless chromium)",
})
.option("output-dir", {
alias: "o",
describe: "Output directory for masks",
})
.demandOption(["o"])
const {
_: [pathToFile],
outputDir,
crisp,
useSampleNumber,
} = argv
async function main() {
const ds = JSON.parse(fs.readFileSync(pathToFile))
await mkdirp(outputDir)
const bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic)
for (const [sampleIndex, sample] of ds.samples.entries()) {
if (sampleIndex >= 1) {
if (sampleIndex === 1) bar1.start(ds.samples.length, 0)
bar1.update(sampleIndex)
}
const { pngBuffer, fileName } = await sampleToPNG(sample, { crisp })
fs.writeFileSync(
`${outputDir}/${
useSampleNumber
? `sample${sampleIndex.toString().padStart(6, "0")}.mask.png`
: fileName
}`,
pngBuffer
)
}
bar1.stop()
process.exit(0)
}
main()