[HOME] Входные данные по комнатам: кропы плана (OCR 400dpi по площадям), фото по комнатам, spec.json — подготовка к генерации в Kandinsky

This commit is contained in:
root committed 2026-11-07 20:55:45 +03:00
1 parent b89c0942a0
commit 4a3519336c
38 files changed
+308

No files matched your search

+101
View File
@@ -0,0 +1,101 @@
import json
import os
import shutil
BIG = '/tmp/plans/plan400.png'
PHOTOS = '/root/buryan-infra/ops/home/plans/photos'
OUT = '/root/buryan-infra/ops/home/renders/input'
# центры комнат на чертеже 400dpi (из OCR + геометрия плана)
CENTERS = {
'bedroom': (1950, 1464), # комната 8 · 11.45 — найдено OCR
'office': (1560, 2049), # комната 6 · 11.14 — найдено OCR
'danina': (1917, 2005), # комната 7 · 14.34 — найдено OCR
'kitchen-living': (824, 1756), # 27.65 — найдено OCR
'corridor': (1209, 1654), # холл 6.83 — найдено OCR
'bathroom': (1660, 2250), # санузел 6.29 — оценка по плану
'laundry': (1580, 1310), # кладовая 1.30 — оценка по плану
'hall-way': (1216, 2341), # прихожая 3.36 — оценка по плану
}
PHOTO_PATTERNS = {
'bedroom': ['spalnya-'],
'office': ['office-'],
'bathroom': ['bath-'],
'corridor': ['corridor-'],
'danina': ['danina-'],
'laundry': ['laundry-'],
'kitchen-living': ['kitchen', 'kuhnya', 'living'],
'hall-way': [],
}
SPECS = {
'bedroom': dict(name='Спальня', area=11.45, plan_label='комната 8',
furniture=['кровать', 'тумбы', 'гардеробная 2.99', 'письменный стол', 'ТВ'],
light=['трек', 'бра слева', 'бра справа', 'гардеробная']),
'office': dict(name='Кабинет', area=11.14, plan_label='комната 6',
furniture=['стол', '2 ПК', 'кресло', 'ТВ TCL', 'PS5', 'шкаф', 'кондиционер'],
light=['трек', 'бра 1', 'бра 2', 'подсветка']),
'danina': dict(name='Данина (детская)', area=14.34, plan_label='комната 7',
furniture=['кровать', 'стол', 'диван', 'ТВ TCL', 'антресоль с лестницей', 'шкаф'],
light=['трек по балке', 'свет антресоли']),
'kitchen-living': dict(name='Кухня-гостиная', area=27.65, plan_label='кухня-гостиная',
furniture=['кухонный гарнитур', 'холодильник', 'ПММ', 'плита', 'вытяжка',
'обеденный стол', 'диван', 'ТВ 75', 'стеллаж'],
light=['2 трека по балкам', 'бра', 'подсветка рабочей зоны', 'подсветка стеллажа']),
'bathroom': dict(name='Санузел', area=6.29, plan_label='санузел',
furniture=['ванна', 'душ', 'унитаз', 'раковина', 'шкаф с зеркалом'],
light=['LED-профиль']),
'corridor': dict(name='Коридор + тамбур', area=6.83, plan_label='холл',
furniture=['шкаф', 'скамья', 'зеркало', 'тумба'],
light=['трек', 'бра', 'свет прихожей', 'свет тамбура']),
'laundry': dict(name='Прачечная / кладовая', area=1.30, plan_label='кладовая',
furniture=['стиральная машина', 'сушилка', 'полки'],
light=['общий свет']),
'hall-way': dict(name='Прихожая', area=3.36, plan_label='прихожая',
furniture=['тумба', 'зеркало'], light=['свет прихожей']),
}
def main():
from PIL import Image
im = Image.open(BIG)
W, H = im.size
print('план:', W, 'x', H)
os.makedirs(OUT, exist_ok=True)
photos = os.listdir(PHOTOS)
for key, (cx, cy) in CENTERS.items():
d = os.path.join(OUT, key)
os.makedirs(os.path.join(d, 'photos'), exist_ok=True)
# кроп плана 1400x1400 вокруг центра
r = 700
left, top = max(0, cx - r), max(0, cy - r)
right, bottom = min(W, cx + r), min(H, cy + r)
crop = im.crop((left, top, right, bottom))
crop.save(os.path.join(d, 'plan.png'))
print(' %-16s план %dx%d' % (key, crop.width, crop.height))
# фото комнаты
pats = PHOTO_PATTERNS.get(key, [])
n = 0
for ph in photos:
if any(ph.startswith(p) for p in pats):
shutil.copy(os.path.join(PHOTOS, ph), os.path.join(d, 'photos', ph))
n += 1
if n == 0:
print(' фото: НЕТ (нужно прислать)')
# спецификация
spec = SPECS.get(key, {})
spec['key'] = key
spec['photos'] = n
json.dump(spec, open(os.path.join(d, 'spec.json'), 'w'), ensure_ascii=False, indent=1)
print('\nготово:', len(CENTERS), 'комнат в', OUT)
if __name__ == '__main__':
main()
+57
View File
@@ -0,0 +1,57 @@
import json
import os
import re
import subprocess
PDF = '/root/buryan-infra/ops/home/plans/house-plans-2024-06-25.pdf'
BIG = '/tmp/plans/plan400.png'
OUT = '/root/buryan-infra/ops/home/renders/input'
os.makedirs('/tmp/plans', exist_ok=True)
subprocess.run(['pdftoppm', '-r', '400', '-png', '-singlefile', PDF, '/tmp/plans/plan400'],
check=False, capture_output=True)
print('400dpi:', os.path.exists(BIG), os.path.getsize(BIG) if os.path.exists(BIG) else 0, 'байт')
subprocess.run(['tesseract', BIG, '/tmp/plan400', '-l', 'rus', '--psm', '11', 'tsv'],
check=False, capture_output=True)
words = []
for i, line in enumerate(open('/tmp/plan400.tsv', encoding='utf-8')):
if i == 0:
continue
p = line.rstrip('\n').split('\t')
if len(p) < 12:
continue
try:
left, top, w, h = int(p[6]), int(p[7]), int(p[8]), int(p[9])
except ValueError:
continue
text = (p[11] or '').strip()
conf = float(p[10]) if p[10] not in ('', '-1') else 0
if text:
words.append((text, left, top, w, h, conf))
print('слов:', len(words))
# площади из экспликации → ищем те же числа на чертеже
AREAS = {
'bedroom': '11.45',
'office': '11.14',
'danina': '14.34',
'kitchen-living': '27.65',
'bathroom': '6.29',
'corridor': '6.83',
'laundry': '1.30',
'hall-way': '3.36',
}
hits = {}
for t, l, tp, w, h, c in words:
for key, area in AREAS.items():
if area in t.replace(',', '.'):
hits.setdefault(key, []).append((t, l, tp, w, h, round(c)))
print('\nнайдено по площадям:')
for k, v in hits.items():
print(' ', k, v[:3])
json.dump(hits, open('/tmp/plan_areas400.json', 'w'), ensure_ascii=False, indent=1)
Binary file not shown.

After

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

+17
View File
@@ -0,0 +1,17 @@
{
"name": "Санузел",
"area": 6.29,
"plan_label": "санузел",
"furniture": [
"ванна",
"душ",
"унитаз",
"раковина",
"шкаф с зеркалом"
],
"light": [
"LED-профиль"
],
"key": "bathroom",
"photos": 3
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

+20
View File
@@ -0,0 +1,20 @@
{
"name": "Спальня",
"area": 11.45,
"plan_label": "комната 8",
"furniture": [
"кровать",
"тумбы",
"гардеробная 2.99",
"письменный стол",
"ТВ"
],
"light": [
"трек",
"бра слева",
"бра справа",
"гардеробная"
],
"key": "bedroom",
"photos": 5
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

+19
View File
@@ -0,0 +1,19 @@
{
"name": "Коридор + тамбур",
"area": 6.83,
"plan_label": "холл",
"furniture": [
"шкаф",
"скамья",
"зеркало",
"тумба"
],
"light": [
"трек",
"бра",
"свет прихожей",
"свет тамбура"
],
"key": "corridor",
"photos": 4
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

+19
View File
@@ -0,0 +1,19 @@
{
"name": "Данина (детская)",
"area": 14.34,
"plan_label": "комната 7",
"furniture": [
"кровать",
"стол",
"диван",
"ТВ TCL",
"антресоль с лестницей",
"шкаф"
],
"light": [
"трек по балке",
"свет антресоли"
],
"key": "danina",
"photos": 1
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

+14
View File
@@ -0,0 +1,14 @@
{
"name": "Прихожая",
"area": 3.36,
"plan_label": "прихожая",
"furniture": [
"тумба",
"зеркало"
],
"light": [
"свет прихожей"
],
"key": "hall-way",
"photos": 0
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

@@ -0,0 +1,24 @@
{
"name": "Кухня-гостиная",
"area": 27.65,
"plan_label": "кухня-гостиная",
"furniture": [
"кухонный гарнитур",
"холодильник",
"ПММ",
"плита",
"вытяжка",
"обеденный стол",
"диван",
"ТВ 75",
"стеллаж"
],
"light": [
"2 трека по балкам",
"бра",
"подсветка рабочей зоны",
"подсветка стеллажа"
],
"key": "kitchen-living",
"photos": 0
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

+15
View File
@@ -0,0 +1,15 @@
{
"name": "Прачечная / кладовая",
"area": 1.3,
"plan_label": "кладовая",
"furniture": [
"стиральная машина",
"сушилка",
"полки"
],
"light": [
"общий свет"
],
"key": "laundry",
"photos": 1
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 490 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

+22
View File
@@ -0,0 +1,22 @@
{
"name": "Кабинет",
"area": 11.14,
"plan_label": "комната 6",
"furniture": [
"стол",
"2 ПК",
"кресло",
"ТВ TCL",
"PS5",
"шкаф",
"кондиционер"
],
"light": [
"трек",
"бра 1",
"бра 2",
"подсветка"
],
"key": "office",
"photos": 6
}