小图
OpenCV 大图(当前页面)找小图(需要点击的地方),主要方法(cv.matchTemplate)
import aircv as ac from PIL import ImageGrab import win32api import win32con from ctypes import * import cv2 as cv def draw_circle(pos, circle_radius, color, line_width, src_path): imsrc = ac.imread(src_path) cv.circle(imsrc, pos, circle_radius, color, line_width) cv.imshow('objDetect', imsrc) cv.waitKey(0) cv.destroyAllwindows() def find_image_cv(obj_path, src_path): # basefolder = os.path.abspath('.') + "\\source\\" #ImageGrab.grab().save(src_path) source = cv.imread(src_path) template = cv.imread(obj_path) result = cv.matchTemplate(source, template, cv.TM_CCOEFF_NORMED) print(result) pos_start = cv.minMaxLoc(result)[3] test = cv.minMaxLoc(result) print(test) print(pos_start) x = int(pos_start[0]) + int(template.shape[1] / 2) y = int(pos_start[1]) + int(template.shape[0] / 2) similarity = cv.minMaxLoc(result)[1] if similarity < 0.85: return (-1, -1) else: print("pass") return [(x, y),(x, y)] def double_click(obj_path, src_path): p, q = find_image_cv(obj_path, src_path) x, y = p windll.user32.SetCursorPos(x, y) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) def main1(): #调试 circle_radius = 50 color = (0, 255, 0) line_width = 10 src_path = './pic/destop.png' obj_path = './pic/action.png' p, circle_center_pos = find_image_cv(obj_path, src_path) print(circle_center_pos) draw_circle(circle_center_pos, circle_radius, color, line_width, src_path) #画圈 def main2(): #找到并双击 src_path = './pic/destop.png'(当前页面) obj_path = './pic/action.png' (需要点击的地方) print (find_image_cv(obj_path, src_path)) double_click(obj_path, src_path) if __name__ == "__main__": #main1() main2()
不积跬步,何以至千里
文章最后发布于: 2018-11-16 10:10:55
相关阅读
google消失了快一个月,对于一个做IT的人来说无非是一件坏事,因为google可以检索出来很多有价值的东西,最近发现一个插件使用它可以打
php include_once加载其他文件后无法找到里面的方法
php中引入其他文件需要使用include及相关函数include_once($_SERVER['DOCUMENT_ROOT'].'/xxxx/UrlTools.php'); 但要使用里面的
很多新手买家们在开店的时候会选择一件代发,而且再上传宝贝的时候完全随着自己的性子,随便上传几款宝贝,宝贝的标题、类目等等都没有
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=de