From c227f3b327ee9f6cfd7e3dc5eb2b96418aee8a47 Mon Sep 17 00:00:00 2001
From: SpeedProg <speedprog@googlemail.com>
Date: Fri, 23 Aug 2019 17:13:03 +0000
Subject: [PATCH] added some new sets
---
opencv_dnn.py | 32 +++++++++++++++++++++++++++-----
1 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/opencv_dnn.py b/opencv_dnn.py
index a2c9d3b..37ecaae 100644
--- a/opencv_dnn.py
+++ b/opencv_dnn.py
@@ -49,21 +49,41 @@
for card_name in card_names:
# Fetch the image - name can be found based on the card's information
card_info['name'] = card_name
+ cname = card_name
+ if cname == 'con':
+ cname == 'con__'
img_name = '%s/card_img/png/%s/%s_%s.png' % (Config.data_dir, card_info['set'],
card_info['collector_number'],
- fetch_data.get_valid_filename(card_info['name']))
+ fetch_data.get_valid_filename(cname))
card_img = cv2.imread(img_name)
# If the image doesn't exist, download it from the URL
if card_img is None:
+ set_name = card_info['set']
+ if set_name == 'con':
+ set_name = 'con__'
fetch_data.fetch_card_image(card_info,
- out_dir='%s/card_img/png/%s' % (Config.data_dir, card_info['set']))
+ out_dir='%s/card_img/png/%s' % (Config.data_dir, set_name))
card_img = cv2.imread(img_name)
if card_img is None:
print('WARNING: card %s is not found!' % img_name)
continue
-
- set_img = card_img[575:638, 567:700]
+ """
+ img_cc = cv2.cvtColor(card_img, cv2.COLOR_BGR2GRAY)
+ img_thresh = cv2.adaptiveThreshold(img_cc, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 11, 5)
+ # Dilute the image, then erode them to remove minor noises
+ kernel = np.ones((3, 3), np.uint8)
+ img_dilate = cv2.dilate(img_thresh, kernel, iterations=1)
+ img_erode = cv2.erode(img_dilate, kernel, iterations=1)
+ cnts, hier = cv2.findContours(img_erode, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
+ cnts2 = sorted(cnts, key=cv2.contourArea, reverse=True)
+ cnts2 = cnts2[:10]
+ if True:
+ cv2.drawContours(img_cc, cnts2, -1, (0, 255, 0), 3)
+ #cv2.imshow('Contours', card_img)
+ #cv2.waitKey(10000)
+ """
+ set_img = card_img[595:635, 600:690]
#cv2.imshow(card_info['name'], set_img)
# Compute value of the card's perceptual hash, then store it to the database
#img_art = Image.fromarray(card_img[121:580, 63:685]) # For 745*1040 size card image
@@ -374,7 +394,7 @@
return img_graph
-def detect_frame(img, card_pool, hash_size=32, size_thresh=100000,
+def detect_frame(img, card_pool, hash_size=32, size_thresh=10000,
out_path=None, display=True, debug=False):
"""
Identify all cards in the input frame, display or save the frame if needed
@@ -624,6 +644,8 @@
# Merge database for all cards, then calculate pHash values of each, store them
df_list = []
for set_name in Config.all_set_list:
+ if set_name == 'con':
+ set_name = 'con__'
csv_name = '%s/csv/%s.csv' % (Config.data_dir, set_name)
df = fetch_data.load_all_cards_text(csv_name)
df_list.append(df)
--
Gitblit v1.10.0