Worked on assistant
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
import copy
|
||||
import dataclasses
|
||||
import json
|
||||
|
||||
import cv2
|
||||
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"""
|
||||
|
||||
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(
|
||||
image, count_x=1, count_y=1, adjustment=copy.deepcopy(border_adjustment)
|
||||
)
|
||||
border_square = card_finder.get_field_squares(image, border_square_pos, 1, 1)
|
||||
empty_square_pos = adjustment.adjust_squares(
|
||||
image, count_x=1, count_y=1, adjustment=copy.deepcopy(border_adjustment)
|
||||
)
|
||||
empty_square = card_finder.get_field_squares(image, empty_square_pos, 1, 1)
|
||||
|
||||
cv2.imwrite("/tmp/border_square.png", border_square[0])
|
||||
cv2.imwrite("/tmp/empty_square.png", empty_square[0])
|
||||
print(json.dumps(dataclasses.asdict(border_adjustment)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,43 +0,0 @@
|
||||
import copy
|
||||
import dataclasses
|
||||
import json
|
||||
|
||||
import cv2
|
||||
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
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Generate a configuration"""
|
||||
image = cv2.imread("pictures/specific/BunkerCards.jpg")
|
||||
|
||||
bunker_adjustment = adjustment.adjust_squares(
|
||||
image,
|
||||
count_x=3,
|
||||
count_y=1,
|
||||
adjustment=adjustment.Adjustment(
|
||||
**{"x": 730, "y": 310, "w": 19, "h": 21, "dx": 152, "dy": 0}
|
||||
),
|
||||
)
|
||||
print(json.dumps(dataclasses.asdict(bunker_adjustment)))
|
||||
|
||||
back_image = cv2.imread("pictures/specific/BaiShiny.jpg")
|
||||
back_squares = card_finder.get_field_squares(
|
||||
back_image, count_x=1, count_y=3, adjustment=copy.deepcopy(bunker_adjustment)
|
||||
)
|
||||
|
||||
green_image = cv2.imread("pictures/20190809172213_1.jpg")
|
||||
green_squares = card_finder.get_field_squares(
|
||||
green_image, count_x=1, count_y=3, adjustment=copy.deepcopy(bunker_adjustment)
|
||||
)
|
||||
|
||||
cv2.imwrite("/tmp/bunker_green_1.png", green_squares[0])
|
||||
cv2.imwrite("/tmp/bunker_green_2.png", green_squares[1])
|
||||
cv2.imwrite("/tmp/bunker_green_3.png", green_squares[2])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -2,7 +2,7 @@ import argparse
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
import copy
|
||||
from shenzhen_solitaire.card_detection import configuration, adjustment, card_finder
|
||||
from shenzhen_solitaire.card_detection.configuration import Configuration
|
||||
|
||||
@@ -31,11 +31,19 @@ def main() -> None:
|
||||
args = parser.parse_args()
|
||||
image = cv2.imread(args.screenshot_path)
|
||||
conf = configuration.load(args.config_path)
|
||||
|
||||
squares = card_finder.get_field_squares(image, conf.field_adjustment, 5, 8)
|
||||
catalogue = card_finder.catalogue_cards(squares)
|
||||
conf.catalogue.extend(catalogue)
|
||||
|
||||
conf.card_border.extend(
|
||||
card_finder.get_field_squares(image, conf.border_adjustment, 1, 1)
|
||||
)
|
||||
|
||||
empty_adjust = copy.deepcopy(conf.border_adjustment)
|
||||
empty_adjust.y = 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(
|
||||
card_finder.get_field_squares(image, conf.bunker_adjustment, 1, 3)
|
||||
)
|
||||
@@ -45,7 +53,7 @@ def main() -> None:
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
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)
|
||||
|
||||
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__":
|
||||
main()
|
||||
@@ -1,38 +0,0 @@
|
||||
import copy
|
||||
import dataclasses
|
||||
import json
|
||||
|
||||
import cv2
|
||||
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
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Generate a configuration"""
|
||||
image = cv2.imread("pictures/specific/BaiShiny.jpg")
|
||||
|
||||
goal_adjustment = adjustment.adjust_squares(
|
||||
image,
|
||||
count_x=3,
|
||||
count_y=1,
|
||||
adjustment=adjustment.Adjustment(
|
||||
**{"x": 1490, "y": 310, "w": 19, "h": 21, "dx": 152, "dy": 0}
|
||||
),
|
||||
)
|
||||
print(json.dumps(dataclasses.asdict(goal_adjustment)))
|
||||
|
||||
green_image = cv2.imread("pictures/20190809172213_1.jpg")
|
||||
green_squares = card_finder.get_field_squares(
|
||||
green_image, count_x=1, count_y=3, adjustment=copy.deepcopy(goal_adjustment)
|
||||
)
|
||||
|
||||
cv2.imwrite("/tmp/goal_green_1.png", green_squares[0])
|
||||
cv2.imwrite("/tmp/goal_green_2.png", green_squares[1])
|
||||
cv2.imwrite("/tmp/goal_green_3.png", green_squares[2])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,34 +0,0 @@
|
||||
import copy
|
||||
import dataclasses
|
||||
import json
|
||||
|
||||
import cv2
|
||||
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
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Generate a configuration"""
|
||||
image = cv2.imread("pictures/specific/BunkerCards.jpg")
|
||||
|
||||
hua_adjustment = adjustment.adjust_squares(
|
||||
image,
|
||||
count_x=1,
|
||||
count_y=1,
|
||||
adjustment=adjustment.Adjustment(
|
||||
**{"x": 1299, "y": 314, "w": 19, "h": 21, "dx": 0, "dy": 0}
|
||||
),
|
||||
)
|
||||
print(json.dumps(dataclasses.asdict(hua_adjustment)))
|
||||
green_image = cv2.imread("pictures/specific/ZhongShiny.jpg")
|
||||
hua_green = card_finder.get_field_squares(
|
||||
green_image, hua_adjustment, count_x=1, count_y=1
|
||||
)
|
||||
cv2.imwrite("/tmp/hua_green.png", hua_green[0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user