标签:结果 分辨率 open name 定位 解决问题 strong 依赖 img
import aircv as ac def matchImg(imgsrc,imgobj,confidencevalue=0.5):#imgsrc=原始图像,imgobj=待查找的图片 imsrc = ac.imread(imgsrc) imobj = ac.imread(imgobj) match_result = ac.find_template(imsrc,imobj,confidence) # {‘confidence‘: 0.5435812473297119, ‘rectangle‘: ((394, 384), (394, 416), (450, 384), (450, 416)), ‘result‘: (422.0, 400.0)} if match_result is not None: match_result[‘shape‘]=(imsrc.shape[1],imsrc.shape[0])#0为高,1为宽 return match_result
{‘confidence‘: 0.5435812473297119, ‘rectangle‘: ((394, 384), (394, 416), (450, 384), (450, 416)), ‘result‘: (422.0, 400.0)
photo_position=self.driver.get_screenshot_as_file(imgfile)#截屏手机 x = self.driver.get_window_size()[‘width‘] y = self.driver.get_window_size()[‘height‘] size_width,size_height = x,y #获得手机d的宽高尺寸 confidencevalue = 0.8 # 定义相似度 position = matchImg(imsrc,imobj,confidence)# 用第一步的方法,实际就是find_template()方法 if position != None: x, y = position[‘result‘] shape_x, shape_y = tuple(map(int,position[‘shape‘])) position_x,position_y=int(photo_position_x+(photo_width/shape_x*x)),int(photo_position_y+(photo_height/shape_y*y)) self.driver.tap([(position_x, position_y)])
driver.find_element(*element).screenshot(imgfile)
Image.open(imgfile).crop((pc_location_x,pc_location_y,pc_location_x+pc_width,pc_location_y+pc_height)).save(imgfile)
Python图片识别找坐标(appium通过识别图片点击坐标)
标签:结果 分辨率 open name 定位 解决问题 strong 依赖 img
原文地址:http://www.cnblogs.com/meitian/p/7417582.html