[bfdf16]: / Docs / Applications / images / get_application_images.py

Download this file

70 lines (50 with data), 1.6 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
58
59
60
61
62
63
64
65
66
67
68
69
# Script for creating in application images and copying them into the documentation.
import os
import re
import shutil
from pathlib import Path
from PIL import Image
from anypytools import AnyPyProcess, macro_commands as mc
APP_FOLDER = Path(__file__).parent / "../../../Tests/Applications"
MOCAP_FOLDER = Path(__file__).parent / "../../../Tests/AnyMocap"
app_opts = {
"num_processes": 2,
}
RUN_ANYBODY_MODELS = True
# Small script for updating the wilke test files with the new reference values
#%%
glob_str = "test_*.any"
test_files = [
*APP_FOLDER.glob("test_*.any"),
*MOCAP_FOLDER.glob("test_*.any"),
]
defines = {"CREATE_IMAGE": "1"}
macros = []
for file in test_files:
if "CREATE_IMAGE" not in file.read_text():
continue
defines["TEST_NAME"] = f'"{file.name + "_0"}"'
macros.append(
[
mc.Load(str(file), defs=defines),
mc.OperationRun("Main.RunTest"),
]
)
if RUN_ANYBODY_MODELS:
app = AnyPyProcess(**app_opts)
results = app.start_macro(macros)
for elem in results:
if "ERROR" in elem:
print(elem["ERROR"])
image_files = [
*APP_FOLDER.joinpath("Output").iterdir(),
*MOCAP_FOLDER.joinpath("Output").iterdir(),
]
RE_IMAGE = re.compile(r'.*[tT]est_(.+?)\.any_0_InitPos.png')
for fimg in image_files:
m = RE_IMAGE.match(fimg.name)
if m:
im = Image.open(fimg).convert("RGBA")
targetfile = Path(__file__).parent / (m.group(1) +'.webp')
#print(targetfile)
im.save(targetfile, "WEBP")