Skip to content

Commit

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

#加载将要搜索的图像模板
template = cv2.imread(imgfile, 0)
Expand All @@ -28,7 +28,7 @@ def match_sub_image(self, cv_img ,imgfile):
return None

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

"""
图像识别的两套方案
Expand Down
Binary file added image/activity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/activity_baotu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/activity_baotu_start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/activity_label.png
Binary file not shown.
34 changes: 24 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ def BaoTuTh(param):
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()


# 打开活动页面
rect=matcher.match_sub_image(window_capture_all(),'./image/activity.png')
do(rect)

# 点击宝图
rect1=matcher.match_sub_image(window_capture_all(),'./image/activity_baotu.png')
print(rect1)
rect1[0]=rect1[0]+327
do(rect1)
#接受宝图
# rect=matcher.match_sub_image(window_capture_all(),'./image/activity_baotu_start.png')
# do(rect)


#抓鬼线程
Expand Down Expand Up @@ -137,9 +141,19 @@ def closeMhxy():

def window_capture(rect):
img_rgb = ImageGrab.grab(bbox=rect)
cv_img=np.array(img_rgb)
return cv_img
img_rgb.save('./test1.jpg','JPEG') #设置保存路径和图片格式
return './test1.jpg'

def window_capture_all():
return window_capture((startx,starty,startx+posx,starty+posy))

def do(rect):
if rect:
autopy.mouse.smooth_move(rect[0],rect[1])
time.sleep(1)
autopy.mouse.click()
else:
return

if __name__ == '__main__':
# 已经在运行的关闭窗体
Expand Down
Binary file added test1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e6c9526

Please sign in to comment.