File size: 1,776 Bytes
b6130a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2
import numpy as np
from matplotlib import pyplot as plt
import os
from desktopmagic.screengrab_win32 import getScreenAsImage as getMultiScreenAsImage
from PIL import Image
import os
from pytank.Core.Classes import ScriptSettings
###############################################
lastdur = os.getcwd()

atext = "Configurator.media.Click()"#self.get_selected_text()
folderpath = "C:\Elan_Tools\ImageScripter\ProgramData\SystemFiles\Python\Lib\site-packages\pytank\User\UserData\Applications\\"
alist = atext.split('.')
theapp = alist[0]
print("App->")
print(theapp)
print('')
theimage = alist[1] + '.png'
print("Image->")
print(theimage)
print('')
theAction = alist[2]
print("Action->")
print(theAction)
print('')
imagepath = folderpath + theapp + '\\' + theapp + '_' + theimage
print("Path of Image->")
print(imagepath)
print('')

if os.path.exists(imagepath):
    os.chdir(r"C:\Elan_Tools\Data\Playground")
    def Save_Multi_Monitor_ScreenShot():
        im = getMultiScreenAsImage()
        name_Of_Image = 'templet.png'
        im.save(name_Of_Image, format='png')
    Save_Multi_Monitor_ScreenShot()
    ########################################################################
    img_rgb = cv2.imread("templet.png")
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    template = cv2.imread(imagepath, 0)
    w, h = template.shape[::-1]
    res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
    threshold = ScriptSettings.Threshold
    loc = np.where(res >= threshold)
    for pt in zip(*loc[::-1]):
        cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
    cv2.imwrite("res.png", img_rgb)
    if os.path.exists("res.png"):
        img = Image.open("res.png")
        img.show()
    else:
        print('pass image')