Refactoring
This commit is contained in:
@@ -26,9 +26,7 @@ def prepare_image(image: np.array) -> np.array:
|
||||
|
||||
def get_contour(image: np.array) -> np.array:
|
||||
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
ret, edge_image = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY_INV)
|
||||
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3))
|
||||
edge_image = cv2.morphologyEx(edge_image, cv2.MORPH_CLOSE, kernel)
|
||||
ret, edge_image = cv2.threshold(gray_image, 140, 255, cv2.THRESH_BINARY_INV)
|
||||
border_image(edge_image, size=1)
|
||||
contours, hierarchy = cv2.findContours(
|
||||
edge_image, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE
|
||||
@@ -123,7 +121,7 @@ def main() -> None:
|
||||
pc = configuration.load("test_config.zip")
|
||||
laptop = configuration.load("laptop_conf.zip")
|
||||
bla = [(i, t) for i, t in pc.catalogue if t == SpecialCard.Hua]
|
||||
bla = pc.catalogue
|
||||
# bla = pc.catalogue
|
||||
for pc_image, pc_card_type in bla:
|
||||
debug_match(pc_image, pc_card_type, laptop.catalogue)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import argparse
|
||||
import copy
|
||||
import dataclasses
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
|
||||
import cv2
|
||||
@@ -48,28 +49,31 @@ def main() -> None:
|
||||
conf.field_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=8, count_y=13, adjustment=copy.deepcopy(conf.field_adjustment)
|
||||
)
|
||||
print("Field borders")
|
||||
conf.border_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=8, count_y=13, adjustment=copy.deepcopy(conf.field_adjustment)
|
||||
)
|
||||
for adj in (conf.bunker_adjustment, conf.goal_adjustment,conf.hua_adjustment):
|
||||
for adj in (
|
||||
conf.bunker_adjustment,
|
||||
conf.goal_adjustment,
|
||||
conf.hua_adjustment,
|
||||
conf.border_adjustment,
|
||||
):
|
||||
adj.w = conf.field_adjustment.w
|
||||
adj.h = conf.field_adjustment.h
|
||||
adj.dx = conf.field_adjustment.dx
|
||||
adj.dy = conf.field_adjustment.dy
|
||||
print("Field borders")
|
||||
conf.border_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=8, count_y=13, adjustment=copy.deepcopy(conf.border_adjustment)
|
||||
)
|
||||
|
||||
conf.bunker_adjustment.x = conf.field_adjustment.x
|
||||
print("Bunker cards")
|
||||
print("Bunker and goal cards")
|
||||
conf.bunker_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=3, count_y=1, adjustment=copy.deepcopy(conf.bunker_adjustment)
|
||||
image, count_x=8, count_y=1, adjustment=copy.deepcopy(conf.bunker_adjustment)
|
||||
)
|
||||
conf.goal_adjustment = copy.deepcopy(conf.bunker_adjustment)
|
||||
conf.goal_adjustment.x = math.floor(
|
||||
conf.bunker_adjustment.x + conf.bunker_adjustment.dx * 5
|
||||
)
|
||||
|
||||
conf.goal_adjustment.x = conf.field_adjustment.x + 5 * conf.field_adjustment.dx
|
||||
conf.goal_adjustment.y = conf.bunker_adjustment.y
|
||||
print("Goal cards")
|
||||
conf.goal_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=3, count_y=1, adjustment=copy.deepcopy(conf.goal_adjustment)
|
||||
)
|
||||
conf.hua_adjustment.y = conf.bunker_adjustment.y
|
||||
print("Hua card")
|
||||
conf.hua_adjustment = adjustment.adjust_squares(
|
||||
@@ -77,7 +81,10 @@ def main() -> None:
|
||||
)
|
||||
print("Special button")
|
||||
conf.special_button_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=1, count_y=3, adjustment=copy.deepcopy(conf.special_button_adjustment)
|
||||
image,
|
||||
count_x=1,
|
||||
count_y=3,
|
||||
adjustment=copy.deepcopy(conf.special_button_adjustment),
|
||||
)
|
||||
|
||||
configuration.save(conf, args.config)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import argparse
|
||||
import copy
|
||||
import math
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import copy
|
||||
from shenzhen_solitaire.card_detection import configuration, adjustment, card_finder
|
||||
|
||||
from shenzhen_solitaire.card_detection import (adjustment, card_finder,
|
||||
configuration)
|
||||
from shenzhen_solitaire.card_detection.configuration import Configuration
|
||||
|
||||
|
||||
@@ -41,7 +44,7 @@ def main() -> None:
|
||||
)
|
||||
|
||||
empty_adjust = copy.deepcopy(conf.border_adjustment)
|
||||
empty_adjust.y = empty_adjust.y + 4 * empty_adjust.dy
|
||||
empty_adjust.y = math.floor(empty_adjust.y + 4 * empty_adjust.dy)
|
||||
conf.empty_card.extend(card_finder.get_field_squares(image, empty_adjust, 1, 1))
|
||||
|
||||
conf.green_card.extend(
|
||||
|
||||
@@ -4,7 +4,7 @@ import sys
|
||||
import cv2
|
||||
|
||||
import shenzhen_solitaire.card_detection.configuration as configuration
|
||||
from shenzhen_solitaire.card_detection.board_parser import parse_to_json
|
||||
from shenzhen_solitaire.card_detection.board_parser import parse_board, parse_start_board
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@@ -13,13 +13,17 @@ def main() -> None:
|
||||
parser.add_argument(
|
||||
"--config", dest="config_path", type=str, help="Config path",
|
||||
)
|
||||
parser.add_argument("--simple", action="store_true", help="Parse a start board, use when config is not complete")
|
||||
|
||||
args = parser.parse_args()
|
||||
image = cv2.imread(args.board_path)
|
||||
|
||||
conf = configuration.load("test_config.zip")
|
||||
conf = configuration.load(args.config_path)
|
||||
|
||||
print(parse_to_json(image, conf))
|
||||
if args.simple:
|
||||
print(parse_start_board(image, conf).to_json())
|
||||
else:
|
||||
print(parse_board(image, conf).to_json())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user