Made calibration more ergonomic. Crashes because loading empty 'empty_card' directory
This commit is contained in:
@@ -3,7 +3,7 @@ import enum
|
||||
import itertools
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Optional, Set, Tuple, Union
|
||||
|
||||
import json
|
||||
|
||||
class SpecialCard(enum.Enum):
|
||||
"""Different types of special cards"""
|
||||
@@ -50,6 +50,27 @@ class Position(enum.Enum):
|
||||
Bunker = enum.auto()
|
||||
Goal = enum.auto()
|
||||
|
||||
def _field_card_to_str(card: Card):
|
||||
if card == SpecialCard.Hua:
|
||||
return "Hua"
|
||||
if isinstance(card, SpecialCard):
|
||||
return {"Special": card.name}
|
||||
elif isinstance(card, NumberCard):
|
||||
return {"Number": {"value": card.number, "suit": card.suit.name}}
|
||||
|
||||
|
||||
def _bunker_card_to_str(card: Union[Tuple[SpecialCard, int], Optional[Card]]):
|
||||
if card is None:
|
||||
return "Empty"
|
||||
if isinstance(card, tuple):
|
||||
return {"Blocked": card[0].name}
|
||||
return {"Stashed": _field_card_to_str(card)}
|
||||
|
||||
|
||||
def _goal_card_to_str(card: Optional[NumberCard]):
|
||||
if card is None:
|
||||
return None
|
||||
return {"value": card.number, "suit": card.suit.name}
|
||||
|
||||
class Board:
|
||||
"""Solitaire board"""
|
||||
@@ -187,3 +208,12 @@ class Board:
|
||||
if count != 4:
|
||||
return False
|
||||
return True
|
||||
|
||||
def to_json(self) -> str:
|
||||
mystruct = {
|
||||
"field": [[_field_card_to_str(card) for card in row] for row in self.field],
|
||||
"hua_set": self.flower_gone,
|
||||
"bunker": [_bunker_card_to_str(card) for card in self.bunker],
|
||||
"goal": [_goal_card_to_str(card) for card in self.goal],
|
||||
}
|
||||
return json.dumps(mystruct)
|
||||
|
||||
@@ -36,7 +36,6 @@ def get_field_square_iterator(
|
||||
"""Return iterator for both the square, as well as the matching card border"""
|
||||
my_adj = fake_adjustment(conf.field_adjustment)
|
||||
my_border_adj = fake_adjustment(conf.border_adjustment)
|
||||
|
||||
squares = card_finder.get_field_squares(
|
||||
image, my_adj, count_x=row_count, count_y=column_count
|
||||
)
|
||||
@@ -50,7 +49,6 @@ def get_field_square_iterator(
|
||||
|
||||
def match_template(template: np.ndarray, search_image: np.ndarray) -> float:
|
||||
"""Return matchiness for the template on the search image"""
|
||||
|
||||
res = cv2.matchTemplate(search_image, template, cv2.TM_CCOEFF_NORMED)
|
||||
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
|
||||
assert isinstance(max_val, (int, float))
|
||||
@@ -64,7 +62,6 @@ def parse_field_square(
|
||||
(match_template(template, square), name) for template, name in conf.catalogue
|
||||
]
|
||||
best_val, best_name = max(square_fits, key=lambda x: x[0])
|
||||
|
||||
best_border = max(
|
||||
match_template(template=template, search_image=border)
|
||||
for template in conf.card_border
|
||||
@@ -232,6 +229,14 @@ def parse_board(image: np.ndarray, conf: Configuration) -> Board:
|
||||
result.goal = parse_goal(image, conf)
|
||||
return result
|
||||
|
||||
def parse_start_board(image: np.ndarray, conf: Configuration) -> Board:
|
||||
result = Board()
|
||||
result.field = parse_field(image, conf)
|
||||
result.flower_gone = parse_hua(image, conf)
|
||||
result.bunker = [None] * 3
|
||||
result.goal = parse_goal(image, conf)
|
||||
return result
|
||||
|
||||
|
||||
def field_card_to_str(card: Card):
|
||||
if card == SpecialCard.Hua:
|
||||
|
||||
Reference in New Issue
Block a user