This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmatching_mon.py
74 lines (49 loc) · 2.39 KB
/
matching_mon.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
62
63
64
65
66
67
68
69
70
71
72
73
74
import cv2
import os
import numpy as np
import imutils
import logging
import time
from PIL import Image
from walkerArgs import parseArgs
log = logging.getLogger(__name__)
args = parseArgs()
def mon_image_matching(url_img_name, fort_img_name, raidNo, hash):
url_img = cv2.imread(url_img_name,3)
if (url_img is None):
log.error('[Crop: ' + str(raidNo) + ' (' + str(hash) +') ] ' + 'fort_image_matching: %s appears to be corrupted' % str(url_img_name))
return 0.0
fort_img = cv2.imread(fort_img_name,3)
if (fort_img is None):
log.error('[Crop: ' + str(raidNo) + ' (' + str(hash) +') ] ' + 'fort_image_matching: %s appears to be corrupted' % str(fort_img_name))
return 0.0
height, width,_ = url_img.shape
height_f, width_f,_ = fort_img.shape
fort_img = imutils.resize(fort_img, width = int(fort_img.shape[1] * 1))
resized = imutils.resize(url_img, width = int(url_img.shape[1] * 1))
crop = cv2.Canny(resized, 100, 200)
if crop.mean() == 255 or crop.mean() == 0:
return 0.0
(tH, tW) = crop.shape[:2]
fort_img = cv2.blur(fort_img,(3,3))
fort_img = cv2.Canny(fort_img, 50, 100)
found = None
for scale in np.linspace(args.npmFrom,args.npmValue, 10)[::-1]:
resized = imutils.resize(fort_img, width = int(fort_img.shape[1] * scale))
r = fort_img.shape[1] / float(resized.shape[1])
if resized.shape[0] < tH or resized.shape[1] < tW:
break
result = cv2.matchTemplate(resized, crop, cv2.TM_CCOEFF_NORMED)
(_, maxVal, _, maxLoc) = cv2.minMaxLoc(result)
(endX, endY) = (int((maxLoc[0] + tW) * r), int((maxLoc[1] + tH) * r))
if endY < height_f/2 or endX < width_f/2 or endY > height_f/2+height_f/2*0.4 or endY < height_f/2+height_f/2*0.3:
maxVal = 0.0
log.debug('[Crop: ' + str(raidNo) + ' (' + str(hash) +') ] ' + 'Filename: ' + str(url_img_name) + ' Matchvalue: ' + str(maxVal) + ' Scale: ' + str(scale))
if found is None or maxVal > found[0]:
found = (maxVal, maxLoc, r)
return found[0]
if __name__ == '__main__':
fort_id = 'raid1'
fort_img_path = os.getcwd() + '/' + str(fort_id) + '.jpg'
url_img_path = os.getcwd() + '/mon_img/ic_raid_egg_rare.png'
print(mon_image_matching('_mon_191_1.png','2_gym_51.9018472368_-0.521566117825_1535541942.24_False.jpg',False, 0.1, 1, 123))