Add build, deploy and test sources
This commit is contained in:
1 parent
b962581812
commit
3d1a08f230
259 files changed
+15273
No files matched your search
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
python3 - <<'EOF'
|
||||
import numpy as np, glob, os
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
bmp = Image.open('/mnt/f/efi/Paravis/Boot/xor/Main1.bmp').convert('L')
|
||||
crop = bmp.crop((44, 620, 240, 650))
|
||||
A = np.array(crop) < 128
|
||||
ys, xs = np.where(A)
|
||||
T = A[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
TH, TW = T.shape
|
||||
print('target', TW, TH)
|
||||
|
||||
texts = [('Перезагрузка (R)', (44, 620, 240, 650), T)]
|
||||
|
||||
def render(path, text, size, stroke=0):
|
||||
try:
|
||||
f = ImageFont.truetype(path, size)
|
||||
img = Image.new('L', (900, 120), 255)
|
||||
ImageDraw.Draw(img).text((20, 20), text, font=f, fill=0, stroke_width=stroke, stroke_fill=0)
|
||||
except Exception:
|
||||
return None
|
||||
m = np.array(img) < 128
|
||||
if not m.any(): return None
|
||||
ys, xs = np.where(m)
|
||||
return m[ys.min():ys.max()+1, xs.min():xs.max()+1]
|
||||
|
||||
def iou(A, B):
|
||||
ha, wa = A.shape; hb, wb = B.shape; best = 0
|
||||
for dy in range(-4, 5):
|
||||
for dx in range(-5, 6):
|
||||
y0 = max(0, dy); x0 = max(0, dx)
|
||||
y1 = min(ha, hb+dy); x1 = min(wa, wb+dx)
|
||||
if y1 <= y0 or x1 <= x0: continue
|
||||
s1 = A[y0:y1, x0:x1]; s2 = B[y0-dy:y1-dy, x0-dx:x1-dx]
|
||||
u = np.logical_or(s1, s2).sum()
|
||||
if u: best = max(best, np.logical_and(s1, s2).sum()/u)
|
||||
return best
|
||||
|
||||
fonts = glob.glob('/mnt/c/Windows/Fonts/*.ttf') + glob.glob('/mnt/c/Windows/Fonts/*.otf')
|
||||
fonts += glob.glob('/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/*/test/subset/data/fonts/*.ttf')
|
||||
fonts += glob.glob('/mnt/d/GIT/aspia_no2fa-3.0/vcpkg4aspia/buildtrees/harfbuzz/src/*/test/subset/data/fonts/*.otf')
|
||||
|
||||
res = []
|
||||
for fp in fonts:
|
||||
for size10 in range(200, 245, 5):
|
||||
size = size10/10.0
|
||||
B = render(fp, 'Перезагрузка (R)', size)
|
||||
if B is None or abs(B.shape[1]-TW) > 6: continue
|
||||
s = iou(T, B)
|
||||
res.append((s, os.path.basename(fp), size, B.shape[1]))
|
||||
res.sort(reverse=True)
|
||||
seen = set(); out = []
|
||||
for s, n, size, w in res:
|
||||
if n in seen: continue
|
||||
seen.add(n); out.append((s, n, size, w))
|
||||
if len(out) >= 20: break
|
||||
for s, n, size, w in out:
|
||||
print(f' {s:.3f} {n:34s} size={size:<5} w={w}')
|
||||
EOF
|
||||
Reference in new issue
Block a user