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