Worked on saving configuration
This commit is contained in:
@@ -11,6 +11,7 @@ import cv2 # type: ignore
|
|||||||
from .context import shenzhen_solitaire
|
from .context import shenzhen_solitaire
|
||||||
from shenzhen_solitaire.cv import adjustment
|
from shenzhen_solitaire.cv import adjustment
|
||||||
from shenzhen_solitaire.cv import card_finder
|
from shenzhen_solitaire.cv import card_finder
|
||||||
|
from shenzhen_solitaire import board
|
||||||
|
|
||||||
|
|
||||||
def pixelcount(image: np.ndarray) -> List[Tuple[Tuple[int, int, int], int]]:
|
def pixelcount(image: np.ndarray) -> List[Tuple[Tuple[int, int, int], int]]:
|
||||||
@@ -37,21 +38,25 @@ def simplify(image: np.ndarray) -> None:
|
|||||||
def calibrate(image: np.ndarray) -> None:
|
def calibrate(image: np.ndarray) -> None:
|
||||||
adj = adjustment.adjust_field(image)
|
adj = adjustment.adjust_field(image)
|
||||||
squares = card_finder.get_field_squares(image, adj)
|
squares = card_finder.get_field_squares(image, adj)
|
||||||
catalogue = card_finder.catalague_cards(squares)
|
catalogue = card_finder.catalague_cards(squares[:2])
|
||||||
simplified_catalogue = []
|
|
||||||
for square, card in catalogue:
|
|
||||||
simplified_catalogue.append((card_finder.simplify(square), card))
|
|
||||||
|
|
||||||
zip_stream = io.BytesIO()
|
zip_stream = io.BytesIO()
|
||||||
with zipfile.ZipFile(zip_stream, "w") as zip_file:
|
with zipfile.ZipFile(zip_stream, "w") as zip_file:
|
||||||
zip_file.writestr('adjustment.json', json.dumps(dataclasses.asdict(adj)))
|
zip_file.writestr('adjustment.json', json.dumps(dataclasses.asdict(adj)))
|
||||||
|
counter = 0
|
||||||
|
for square, card in catalogue:
|
||||||
|
counter += 1
|
||||||
file_stream = io.BytesIO()
|
file_stream = io.BytesIO()
|
||||||
np.save(file_stream, squares[0], allow_pickle=False)
|
np.save(file_stream, square, allow_pickle=False)
|
||||||
print(file_stream.getvalue())
|
file_name = ""
|
||||||
zip_file.writestr('0.dat', file_stream.getvalue())
|
if isinstance(card, board.SpecialCard):
|
||||||
print()
|
file_name = f's{card.value}-{card.name}-{counter}.npy'
|
||||||
print(zip_stream.getvalue())
|
elif isinstance(card, board.NumberCard):
|
||||||
|
file_name = f'n{card.suit.value}{card.number}-{card.suit.name}-{card.number}-{counter}.npy'
|
||||||
|
else:
|
||||||
|
raise AssertionError()
|
||||||
|
zip_file.writestr(f"templates/{file_name}", file_stream.getvalue())
|
||||||
|
|
||||||
with open('myzip.zip', 'wb') as fd:
|
with open('myzip.zip', 'wb') as fd:
|
||||||
fd.write(zip_stream.getvalue())
|
fd.write(zip_stream.getvalue())
|
||||||
|
|
||||||
@@ -62,7 +67,7 @@ def main() -> None:
|
|||||||
nparr = np.frombuffer(img_str, np.uint8)
|
nparr = np.frombuffer(img_str, np.uint8)
|
||||||
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
||||||
|
|
||||||
#print(squares[0])
|
calibrate(image)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -77,4 +82,3 @@ def main2() -> None:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
main2()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user