python 图中找目标并截图

import numpy as np
def
sjjt(xha,sjh,beitu,jl,xx,yy): #检查目标,并将目标指定范围内截图 pull_screenshot(xha,sjh,xx) #pull_screenshot(xh,sjh) # 截图 au='./tmall'+str(xx)+'.png' temp = cv2.imread(au) amn='./tmall'+str(yy)+'.png' target = cv2.imread(beitu) pos = find_button(target,temp) if pos: print(pos[0],pos[1]) y=pos[1]-49 y1=pos[1]+71 x=pos[0]-50 x1=pos[0]+60 img_crop = temp[(y):(y1),(x):(x1)]#截图(先Y 后X) cv2.imwrite(amn, img_crop)#截图保存 time.sleep(2) im=np.array(Image.open(amn).convert('RGB')) sought = [255,80,0]#红色颜色的特征 result = np.count_nonzero(np.all(im==sought,axis=2))#统计图形中红色的比例 print(result) return True else: return False

 

posted @ 2020-12-20 16:33  myrj  阅读(370)  评论(0编辑  收藏  举报