Skip to content

Commit

Permalink
Feat(baotu):add baotu function
Browse files Browse the repository at this point in the history
  • Loading branch information
linrong committed Mar 3, 2019
1 parent 8b18acb commit 12cc962
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
18 changes: 11 additions & 7 deletions image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import cv2
class OpenCVImageMatcher(object):
# 全图进行配对
def match_sub_image(self, img_rgb ,imgfile):
def match_sub_image(self, cv_img ,imgfile):
#加载原始RGB图像
cv_img = np.array(img_rgb)
img = cv2.cvtColor(cv_img, cv2.cv.CV_BGR2RGB)
img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)
#创建一个原始图像的灰度版本,所有操作在灰度版本中处理,然后在RGB图像中使用相同坐标还原
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Expand All @@ -21,10 +20,15 @@ def match_sub_image(self, img_rgb ,imgfile):
#res大于70%
loc = np.where( res >= threshold)
locs = zip(*loc[::-1])# 列表
if locs:
return (locs[0],locs[1],locs[0]+w,locs[1]+h)
else:
return None

for pt in locs:
if pt:
return getpoint(( pt[0], pt[1], pt[0]+w, pt[1]+h))
break
return None

def getpoint(rect):
return (rect[0]+(rect[2]-rect[0])/2,rect[1]+(rect[3]-rect[1])/2)

"""
图像识别的两套方案
Expand Down
Binary file added image/activity_label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 22 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import wx.adv
from PIL import ImageGrab
from image import OpenCVImageMatcher

import numpy as np
ver = '1.0'
defPwd='******'
startx=0
posx=0
starty=0
posy=0
isZhuaGui = True

matcher=1

#校验密码
def CheckPwd():
Expand Down Expand Up @@ -49,10 +49,24 @@ def BaoTuTh(param):
if frame.autoDaTu.LabelText =='自动宝图':
frame.autoDaTu.LabelText='停止自动宝图'
# 检查口令
if(CheckPwd() != True):
return False
# if(CheckPwd() != True):
# return False
t = threading.Thread(target=baotu)
t.setDaemon(True)
t.start()
else:
frame.autoDaTu.LabelText='自动宝图'

def baotu():
rect=matcher.match_sub_image(window_capture((startx,starty,startx+posx,starty+posy)),'./image/activity_label.png')
if rect:
print(rect)
autopy.mouse.smooth_move(rect)
time.sleep(1)
autopy.mouse.click()




#抓鬼线程
def zhuaGuiTh(param):
Expand Down Expand Up @@ -122,8 +136,10 @@ def closeMhxy():
win32api.PostMessage(mhwin, win32con.WM_QUIT, 0, 0)

def window_capture(rect):
img = ImageGrab.grab(bbox=rect)
return img
img_rgb = ImageGrab.grab(bbox=rect)
cv_img=np.array(img_rgb)
return cv_img


if __name__ == '__main__':
# 已经在运行的关闭窗体
Expand Down

0 comments on commit 12cc962

Please sign in to comment.