3 files modified
17 files added
| | |
| | | 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: |
| | |
| | | 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. |
| | |
| | | # 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] |
| | |
| | | # 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] |
| | |
| | | import os |
| | | from glob import glob |
| | | import random |
| | | from transform_data import data_dir, darknet_dir |
| | | import transform_data |
| | | |
| | | |
| | | def main(): |
| | | random.seed() |
| | | data_list = [] |
| | | for subdir in glob('%s/train/*' % data_dir): |
| | | for subdir in glob('%s/train/*' % transform_data.data_dir): |
| | | for data in glob(subdir + "/*.jpg"): |
| | | data_list.append(os.path.abspath(data)) |
| | | random.shuffle(data_list) |
| | |
| | | test_ratio = 0.1 |
| | | test_list = data_list[:int(test_ratio * len(data_list))] |
| | | train_list = data_list[int(test_ratio * len(data_list)):] |
| | | with open('%s/train.txt' % darknet_dir, 'w') as train_txt: |
| | | with open('%s/train.txt' % transform_data.darknet_dir, 'w') as train_txt: |
| | | for data in train_list: |
| | | train_txt.write(data + '\n') |
| | | with open('%s/test.txt' % darknet_dir, 'w') as test_txt: |
| | | with open('%s/test.txt' % transform_data.darknet_dir, 'w') as test_txt: |
| | | for data in test_list: |
| | | test_txt.write(data + '\n') |
| | | return |
| | |
| | | from imgaug import parameters as iap |
| | | |
| | | card_mask = cv2.imread('data/mask.png') |
| | | data_dir = os.path.abspath('/media/edmond/My Passport/data') |
| | | data_dir = os.path.abspath('/media/win10/data') |
| | | darknet_dir = os.path.abspath('darknet') |
| | | |
| | | |
| | |
| | | ]) |
| | | if i % 3 == 0: |
| | | generator.generate_non_obstructive() |
| | | generator.export_training_data(visibility=0.0, out_name='%s/train/non_obstructive/%s_%d' |
| | | generator.export_training_data(visibility=0.0, out_name='%s/train/non_obstructive_skew/%s_%d' |
| | | % (data_dir, out_name, j), aug=seq) |
| | | elif i % 3 == 1: |
| | | generator.generate_horizontal_span(theta=random.uniform(-math.pi, math.pi)) |
| | | generator.export_training_data(visibility=0.0, out_name='%s/train/horizontal_span/%s_%d' |
| | | generator.export_training_data(visibility=0.0, out_name='%s/train/horizontal_span_skew/%s_%d' |
| | | % (data_dir, out_name, j), aug=seq) |
| | | else: |
| | | generator.generate_vertical_span(theta=random.uniform(-math.pi, math.pi)) |
| | | generator.export_training_data(visibility=0.0, out_name='%s/train/vertical_span/%s_%d' |
| | | generator.export_training_data(visibility=0.0, out_name='%s/train/vertical_span_skew/%s_%d' |
| | | % (data_dir, out_name, j), aug=seq) |
| | | #generator.generate_horizontal_span(theta=random.uniform(-math.pi, math.pi)) |
| | | #generator.render(display=True, aug=seq, debug=True) |