Best Python code snippet using Airtest
cv.py
Source:cv.py
...160 if not self.record_pos:161 return None162 # calc predict area in screen163 screen_resolution = aircv.get_resolution(screen)164 xmin, ymin, xmax, ymax = Predictor.get_predict_area(self.record_pos, screen_resolution)165 # crop predict image from screen166 predict_area = aircv.crop_image(screen, (xmin, ymin, xmax, ymax))167 # aircv.show(predict_area)168 # find sift in that image169 ret_in_area = aircv.find_sift(predict_area, image, threshold=self.threshold, rgb=self.rgb)170 # calc cv ret if found171 if not ret_in_area:172 return None173 ret = deepcopy(ret_in_area)174 ret["result"] = (ret_in_area["result"][0] + xmin, ret_in_area["result"][1] + ymin)175 return ret176 def _resize_image(self, image, screen, resize_method):177 """模æ¿å¹é
ä¸ï¼å°è¾å
¥çæªå¾éé
æ çå¾
模æ¿å¹é
çæªå¾."""178 # æªè®°å½å½å¶å辨çï¼è·³è¿179 if not self.resolution:180 # return image181 self.resolution = aircv.get_resolution(image)182 screen_resolution = aircv.get_resolution(screen)183 # å¦æå辨çä¸è´ï¼åä¸éè¦è¿è¡im_searchçéé
:184 if tuple(self.resolution) == tuple(screen_resolution) or resize_method is None:185 return image186 if isinstance(resize_method, types.MethodType):187 resize_method = resize_method.__func__188 # å辨çä¸ä¸è´åè¿è¡éé
ï¼é»è®¤ä½¿ç¨cocos_min_strategy:189 h, w = image.shape[:2]190 w_re, h_re = resize_method(w, h, self.resolution, screen_resolution)191 # ç¡®ä¿w_reåh_re > 0, è³å°æ1个åç´ :192 w_re, h_re = max(1, w_re), max(1, h_re)193 # è°è¯ä»£ç : è¾åºè°è¯ä¿¡æ¯.194 # G.LOGGING.debug("resize: (%s, %s)->(%s, %s), resolution: %s=>%s" % (195 # w, h, w_re, h_re, self.resolution, screen_resolution))196 # è¿è¡å¾ç缩æ¾:197 image = cv2.resize(image, (w_re, h_re))198 return image199class Predictor(object):200 """201 this class predicts the press_point and the area to search im_search.202 """203 RADIUS_X = 250204 RADIUS_Y = 250205 @staticmethod206 def count_record_pos(pos, resolution):207 """计ç®åæ 对åºçä¸ç¹å移å¼ç¸å¯¹äºå辨ççç¾åæ¯"""208 _w, _h = resolution209 # é½æ宽度缩æ¾ï¼é对G18çå®éªç»è®º210 delta_x = (pos[0] - _w * 0.5) / _w211 delta_y = (pos[1] - _h * 0.5) / _w212 delta_x = round(delta_x, 3)213 delta_y = round(delta_y, 3)214 return delta_x, delta_y215 @classmethod216 def get_predict_point(cls, record_pos, screen_resolution):217 """é¢æµç¼©æ¾åçç¹å»ä½ç½®ç¹"""218 delta_x, delta_y = record_pos219 _w, _h = screen_resolution220 target_x = delta_x * _w + _w * 0.5221 target_y = delta_y * _w + _h * 0.5222 return target_x, target_y223 @classmethod224 def get_predict_area(cls, record_pos, screen_resolution):225 x, y = cls.get_predict_point(record_pos, screen_resolution)226 area = (x - cls.RADIUS_X, y - cls.RADIUS_Y, x + cls.RADIUS_X, y + cls.RADIUS_Y)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!