From 0dab894a5be9f7d10d85e89dea91d02c71bae84d Mon Sep 17 00:00:00 2001
From: Edmond Yoo <hj3yoo@uwaterloo.ca>
Date: Sun, 16 Sep 2018 03:24:45 +0000
Subject: [PATCH] Moving files from MTGCardDetector repo
---
generate_data.py | 42 ++++++++++++++++++++++++++++--------------
1 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/generate_data.py b/generate_data.py
index d3e7d4e..7a2ce87 100644
--- a/generate_data.py
+++ b/generate_data.py
@@ -11,7 +11,7 @@
import sys
import numpy as np
import pandas as pd
-from transform_data import ExtractedObject
+import transform_data
# Referenced from geaxgx's playing-card-detection: https://github.com/geaxgx/playing-card-detection
class Backgrounds:
@@ -66,7 +66,8 @@
def apply_bounding_box(img, card_info, display=False):
# List of detected objects to be fed into the neural net
# The first object is the entire card
- detected_object_list = [ExtractedObject('card', [(0, 0), (len(img[0]), 0), (len(img[0]), len(img)), (0, len(img))])]
+ detected_object_list = [transform_data.ExtractedObject('card', [(0, 0), (len(img[0]), 0), (len(img[0]), len(img)), (0, len(img))])]
+ '''
# Mana symbol - They are located on the top right side of the card, next to the name
# Their position is stationary, and is right-aligned.
has_mana_cost = isinstance(card_info['mana_cost'], str) # Cards with no mana cost will have nan
@@ -97,7 +98,7 @@
# Append them to the list of bounding box with the appropriate label
symbol_name = 'mana_symbol:' + mana_cost[i]
key_pts = [(x1, y1), (x2, y1), (x2, y2), (x1, y2)]
- detected_object_list.append(ExtractedObject(symbol_name, key_pts))
+ detected_object_list.append(transform_data.ExtractedObject(symbol_name, key_pts))
if display:
img_symbol = img[y1:y2, x1:x2]
@@ -162,7 +163,7 @@
# Append them to the list of bounding box with the appropriate label
symbol_name = 'set_symbol:' + card_info['set']
key_pts = [(x1, y1), (x2, y1), (x2, y2), (x1, y2)]
- detected_object_list.append(ExtractedObject(symbol_name, key_pts))
+ detected_object_list.append(transform_data.ExtractedObject(symbol_name, key_pts))
if display:
img_symbol = img[y1:y2, x1:x2]
@@ -177,26 +178,38 @@
# Image box - the large image on the top half of the card
# TODO
+ '''
return detected_object_list
def main():
+ random.seed()
#bg_images = load_dtd()
#bg = Backgrounds()
#bg.get_random(display=True)
card_pool = pd.DataFrame()
- for set_name in ['8ed', 'mrd', 'dst', '5dn', 'chk', 'bok', 'sok', '9ed', 'rav', 'gpt', 'dis', 'csp', 'tsp', 'plc',
- 'fut', '10e', 'lrw', 'mor', 'shm', 'eve', 'ala', 'con', 'arb', 'm10', 'zen', 'wwk', 'roe', 'm11',
- 'som', 'mbs', 'nph', 'm12', 'isd', 'dka', 'avr', 'm13', 'rtr', 'gtc', 'dgm', 'm14', 'ths', 'bng',
- 'jou']:
+ for set_name in fetch_data.all_set_list:
df = fetch_data.load_all_cards_text('data/csv/%s.csv' % set_name)
- for _ in range(3):
- card_info = df.iloc[random.randint(0, df.shape[0] - 1)]
- # Currently ignoring planeswalker cards due to their different card layout
- is_planeswalker = 'Planeswalker' in card_info['type_line']
- if not is_planeswalker:
- card_pool = card_pool.append(card_info)
+ #for _ in range(3):
+ # card_info = df.iloc[random.randint(0, df.shape[0] - 1)]
+ # # Currently ignoring planeswalker cards due to their different card layout
+ # is_planeswalker = 'Planeswalker' in card_info['type_line']
+ # if not is_planeswalker:
+ # card_pool = card_pool.append(card_info)
+ card_pool = card_pool.append(df)
+ '''
+ print(card_pool)
+ mana_symbol_set = set()
+ for _, card_info in card_pool.iterrows():
+ has_mana_cost = isinstance(card_info['mana_cost'], str)
+ if has_mana_cost:
+ mana_cost = re.findall('\{(.*?)\}', card_info['mana_cost'])
+ for symbol in mana_cost:
+ mana_symbol_set.add(symbol)
+
+ print(mana_symbol_set)
+ '''
for _, card_info in card_pool.iterrows():
img_name = '../usb/data/png/%s/%s_%s.png' % (card_info['set'], card_info['collector_number'],
@@ -208,6 +221,7 @@
card_img = cv2.imread(img_name)
detected_object_list = apply_bounding_box(card_img, card_info, display=True)
print(detected_object_list)
+
return
--
Gitblit v1.10.0