Drei Änderungen, die den Spitzenverbrauch eines Stapelscans senken: - Zuschnitte werden nicht mehr auf 1400 px hochgerechnet. Auf einem Stapelfoto ist eine Karte nur ein paar hundert Pixel breit; sie aufzublasen erzeugt vier Mal so viele Pixel ohne mehr Information und kostet zusätzlich Bildtokens beim Modellaufruf. OUT_WIDTH ist jetzt eine Obergrenze. - Die um 180 Grad gedrehte Fassung entsteht erst, wenn ein Ergebnis leer bleibt, statt für jede Karte auf Vorrat. Das halbiert die JPEG-Kodierungen im Normalfall. - Zuschnitte werden einzeln kodiert und sofort freigegeben, statt gesammelt im Speicher zu liegen. Dazu mem_limit und cpus für den App-Container: ein Ausreißer soll den Container treffen, nicht den Host, auf dem auch Jitsi und MySQL laufen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
import numpy as np
|
|
|
|
from app import segment
|
|
from tests.helpers import photo_with_cards
|
|
|
|
|
|
def test_findet_alle_karten_im_stapel():
|
|
photo = photo_with_cards(count=6)
|
|
crops, fallback = segment.segment(photo)
|
|
|
|
assert fallback is False
|
|
assert len(crops) == 6
|
|
|
|
|
|
def test_zuschnitte_haben_kartenformat():
|
|
crops, _ = segment.segment(photo_with_cards(count=4))
|
|
|
|
for crop in crops:
|
|
height, width = crop.shape[:2]
|
|
assert abs(width / height - segment.CARD_RATIO) < 0.01
|
|
assert segment.MIN_WIDTH <= width <= segment.OUT_WIDTH
|
|
|
|
|
|
def test_zuschnitt_wird_nicht_hochskaliert():
|
|
# Auf einem Stapelfoto ist eine Karte schmaler als OUT_WIDTH - der
|
|
# Zuschnitt darf die Vorlage nicht kuenstlich aufblasen.
|
|
crops, _ = segment.segment(photo_with_cards(count=12))
|
|
|
|
assert all(crop.shape[1] < segment.OUT_WIDTH for crop in crops)
|
|
|
|
|
|
def test_zuschnitt_enthaelt_die_karte_und_nicht_den_tisch():
|
|
crops, _ = segment.segment(photo_with_cards(count=4))
|
|
|
|
for crop in crops:
|
|
# Die Karte ist weiss, der Untergrund dunkel. Ein Zuschnitt, der
|
|
# danebenliegt, waere im Mittel dunkel.
|
|
assert crop.mean() > 170
|
|
|
|
|
|
def test_grosser_stapel():
|
|
crops, fallback = segment.segment(photo_with_cards(count=12))
|
|
|
|
assert fallback is False
|
|
assert len(crops) == 12
|
|
|
|
|
|
def test_einzelne_formatfuellende_karte_faellt_auf_gesamtbild_zurueck():
|
|
# Randlose Karte: es gibt keine Kante zum Untergrund, also keinen Fund.
|
|
card = np.full((1080, 1712, 3), 245, dtype=np.uint8)
|
|
crops, fallback = segment.segment(card)
|
|
|
|
assert fallback is True
|
|
assert len(crops) == 1
|