diff --git a/image.py b/image.py index a1206df..edef645 100644 --- a/image.py +++ b/image.py @@ -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) @@ -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) """ 图像识别的两套方案 diff --git a/image/activity_label.png b/image/activity_label.png new file mode 100644 index 0000000..bfaf6ae Binary files /dev/null and b/image/activity_label.png differ diff --git a/main.py b/main.py index 6ddf5fa..5ed47dd 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ import wx.adv from PIL import ImageGrab from image import OpenCVImageMatcher - +import numpy as np ver = '1.0' defPwd='******' startx=0 @@ -17,7 +17,7 @@ starty=0 posy=0 isZhuaGui = True - +matcher=1 #校验密码 def CheckPwd(): @@ -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): @@ -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__': # 已经在运行的关闭窗体