Worked on additional tools
This commit is contained in:
78
tools/generate/all_borders.py
Normal file
78
tools/generate/all_borders.py
Normal file
@@ -0,0 +1,78 @@
|
||||
import argparse
|
||||
import copy
|
||||
import dataclasses
|
||||
import json
|
||||
import os
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
import shenzhen_solitaire.card_detection.adjustment as adjustment
|
||||
import shenzhen_solitaire.card_detection.card_finder as card_finder
|
||||
import shenzhen_solitaire.card_detection.configuration as configuration
|
||||
from shenzhen_solitaire.card_detection.configuration import Configuration
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Generate a configuration"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Calibrate to fit all symbols. "
|
||||
"Ideally use a screenshot with cards in the bunker, "
|
||||
"in the goal and also with a killed hua card"
|
||||
)
|
||||
parser.add_argument(
|
||||
"screenshot_path",
|
||||
metavar="screenshot_path",
|
||||
type=str,
|
||||
help="Path to the screenshot",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
metavar="config_path",
|
||||
type=str,
|
||||
default="test_config.zip",
|
||||
help="Config path, either merge or write new",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
print(args.screenshot_path)
|
||||
image = cv2.imread(args.screenshot_path)
|
||||
|
||||
if os.path.exists(args.config):
|
||||
conf = configuration.load(args.config)
|
||||
else:
|
||||
conf = Configuration()
|
||||
|
||||
print("Field cards")
|
||||
conf.field_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=8, count_y=13, adjustment=copy.deepcopy(conf.field_adjustment)
|
||||
)
|
||||
print("Field borders")
|
||||
border_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=8, count_y=13, adjustment=copy.deepcopy(conf.field_adjustment)
|
||||
)
|
||||
conf.bunker_adjustment.w = conf.field_adjustment.w
|
||||
conf.bunker_adjustment.h = conf.field_adjustment.h
|
||||
print("Bunker cards")
|
||||
bunker_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=3, count_y=1, adjustment=copy.deepcopy(conf.bunker_adjustment)
|
||||
)
|
||||
conf.goal_adjustment.w = conf.field_adjustment.w
|
||||
conf.goal_adjustment.h = conf.field_adjustment.h
|
||||
print("Goal cards")
|
||||
goal_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=3, count_y=1, adjustment=copy.deepcopy(conf.goal_adjustment)
|
||||
)
|
||||
conf.hua_adjustment.w = conf.field_adjustment.w
|
||||
conf.hua_adjustment.h = conf.field_adjustment.h
|
||||
print("Hua card")
|
||||
hua_adjustment = adjustment.adjust_squares(
|
||||
image, count_x=1, count_y=1, adjustment=copy.deepcopy(conf.hua_adjustment)
|
||||
)
|
||||
|
||||
configuration.save(conf, args.config)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -8,11 +8,19 @@ import numpy as np
|
||||
import shenzhen_solitaire.card_detection.adjustment as adjustment
|
||||
import shenzhen_solitaire.card_detection.card_finder as card_finder
|
||||
from shenzhen_solitaire.card_detection.configuration import Configuration
|
||||
import argparse
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Generate a configuration"""
|
||||
image = cv2.imread("pictures/20190809172213_1.jpg")
|
||||
|
||||
parser = argparse.ArgumentParser(description='Process some integers.')
|
||||
parser.add_argument('screenshot_path', metavar='screenshot_path', type=str,
|
||||
help='Path to the screenshot')
|
||||
|
||||
args = parser.parse_args()
|
||||
print(args.screenshot_path)
|
||||
image = cv2.imread(args.screenshot_path)
|
||||
|
||||
border_adjustment = adjustment.adjust_squares(image, count_x=8, count_y=13)
|
||||
border_square_pos = adjustment.adjust_squares(
|
||||
|
||||
54
tools/generate/catalogue.py
Normal file
54
tools/generate/catalogue.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import argparse
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from shenzhen_solitaire.card_detection import configuration, adjustment, card_finder
|
||||
from shenzhen_solitaire.card_detection.configuration import Configuration
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Generate a configuration"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate pictures for symbols. "
|
||||
"Requires screenshot of field with no moved cards, "
|
||||
"so 8 columns of 5 cards each"
|
||||
)
|
||||
parser.add_argument(
|
||||
"screenshot_path",
|
||||
metavar="screenshot_path",
|
||||
type=str,
|
||||
help="Path to the screenshot",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--conf",
|
||||
dest="config_path",
|
||||
type=str,
|
||||
default="config.zip",
|
||||
help="Path to existing config to be merged, or new config",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
print(args.screenshot_path)
|
||||
image = cv2.imread(args.screenshot_path)
|
||||
conf = configuration.load(args.config)
|
||||
squares = card_finder.get_field_squares(image, conf.field_adjustment, 5, 8)
|
||||
catalogue = card_finder.catalogue_cards(squares)
|
||||
conf.card_border.extend(
|
||||
card_finder.get_field_squares(image, conf.border_adjustment, 1, 1)
|
||||
)
|
||||
conf.green_card.extend(
|
||||
card_finder.get_field_squares(image, conf.bunker_adjustment, 1, 3)
|
||||
)
|
||||
conf.green_card.extend(
|
||||
card_finder.get_field_squares(image, conf.goal_adjustment, 1, 3)
|
||||
)
|
||||
conf.green_card.extend(
|
||||
card_finder.get_field_squares(image, conf.hua_adjustment, 1, 1)
|
||||
)
|
||||
conf.catalogue.extend(catalogue)
|
||||
configuration.save(conf, args.config_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,15 +1,42 @@
|
||||
import argparse
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
import shenzhen_solitaire.card_detection.configuration as configuration
|
||||
from shenzhen_solitaire.card_detection import configuration, adjustment, card_finder
|
||||
from shenzhen_solitaire.card_detection.configuration import Configuration
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Generate a configuration"""
|
||||
image = cv2.imread("pictures/20190809172213_1.jpg")
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate pictures for symbols, "
|
||||
"requires screenshot of field with no moved cards, "
|
||||
"so 8 columns of 5 cards each"
|
||||
)
|
||||
parser.add_argument(
|
||||
"screenshot_path",
|
||||
metavar="screenshot_path",
|
||||
type=str,
|
||||
help="Path to the screenshot",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--conf",
|
||||
dest="config_path",
|
||||
type=str,
|
||||
default="config.zip",
|
||||
help="Path to existing config to be merged, or new config",
|
||||
)
|
||||
|
||||
generated_config = configuration.generate(image)
|
||||
configuration.save(generated_config, "test_config.zip")
|
||||
args = parser.parse_args()
|
||||
print(args.screenshot_path)
|
||||
image = cv2.imread(args.screenshot_path)
|
||||
|
||||
adj = adjustment.adjust_field(image)
|
||||
squares = card_finder.get_field_squares(image, adj, 5, 8)
|
||||
catalogue = card_finder.catalogue_cards(squares)
|
||||
generated_config = Configuration(field_adjustment=adj, catalogue=catalogue, meta={})
|
||||
configuration.save(generated_config, args.config_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user