-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsolve_set.py
executable file
·61 lines (51 loc) · 1.47 KB
/
solve_set.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
"""Solve SET from a game image. Prints the sets found, and optionally
writes and/or displays the game image with the sets indicated.
"""
import argparse
import sys
from SetGame import SetGame
from common import game_img_filename
def get_args():
parser = argparse.ArgumentParser(description="Solve SET from a game image.")
parser.add_argument(
"filename", metavar="filename", type=str, nargs="?", help="Game image filename"
)
parser.add_argument(
"--game",
dest="game_num",
type=int,
help="use a test image from image-data/set-games/setgame<GAME_NUM>.jpg",
)
parser.add_argument(
"--write",
dest="write",
action="store_true",
help="Write the solved image to solve-out/solved.jpg",
)
parser.add_argument(
"--display",
dest="display",
action="store_true",
help="Display the solved image with cv2.display()",
)
return parser.parse_args()
def main():
args = get_args()
if args.game_num:
filename = game_img_filename(args.game_num)
elif args.filename:
filename = args.filename
else:
print("Error: must pass either a filename or --game GAME_NUM")
sys.exit(1)
game = SetGame(filename)
game.solve()
game.print_sets()
game.draw_sets()
if args.write:
game.write_im("solved.jpg")
if args.display:
game.display()
if __name__ == "__main__":
main()