Best Python code snippet using Airtest
action_tracking.py
Source:action_tracking.py
...54 x, y = pos55 tid = id(v)56 if self._doing_actions:57 self.action_recorder.click(tid, [1.0 * x / w, 1.0 * y / h], v.filepath)58 def post_cv_match(self, cv_ret, *args, **kwargs):59 if not cv_ret:60 return61 # å¦æå½åå½æ°æ¯ç±loop_findè°ç¨çï¼é£å°±å¯ä»¥æ¾å°ä¸ä¸ªrectï¼è¿ä¸ªrectç±airtest.core.cv._cv_matchéç»åº62 # 以ä¸å°±æ¯ä»frame stackä¸ä¸ç´æ¾å°loop_findè¿ä¸å¸§ï¼ç¶åæ¾åºloop_findç第ä¸ä¸ªargumentï¼éè¿argumentæ±åºtid63 frame = sys._getframe(0)64 while frame and frame.f_code.co_name != 'loop_find':65 frame = frame.f_back66 if frame:67 # more details about inspect parameter name in runtime,68 # see https://docs.python.org/2/library/inspect.html#inspect.getargvalues69 args, varargs, keywords, locals = inspect.getargvalues(frame)70 if len(args) > 0:71 v_name = args[0]72 elif varargs is not None and len(locals[varargs]) > 0:...
cv.py
Source:cv.py
...83 offset_w, offset_h = int(offset_w - w / 2), int(offset_h - h / 2)84 return (offset_h, offset_h + h, offset_w, offset_w + w)85 def match_in(self, screen, perdict_area=None):86 if not perdict_area:87 match_result = self._cv_match(screen)88 else:89 h1, h2, w1, w2 = perdict_area90 screen = screen[h1 : h2, w1 : w2]91 match_result = self._cv_match(screen)92 if match_result:93 match_result["result"] = (match_result["result"][0] + w1, match_result["result"][1] + h1)94 match_result['rectangle'] = (95 (match_result['rectangle'][0][0] + w1, match_result['rectangle'][0][1] + h1),96 (match_result['rectangle'][1][0] + w1, match_result['rectangle'][1][1] + h1),97 (match_result['rectangle'][2][0] + w1, match_result['rectangle'][2][1] + h1),98 (match_result['rectangle'][3][0] + w1, match_result['rectangle'][3][1] + h1),99 )100 101 G.LOGGING.debug("match result: %s", match_result)102 log_in_func({"cv": match_result})103 if not match_result:104 return None105 focus_pos = TargetPos().getXY(match_result, self.target_pos)106 return focus_pos107 108 def _cv_match(self, screen):109 try:110 match_result = super(Template, self)._cv_match(screen)111 return match_result112 except cv2.error as e:...
sift_extractor.py
Source:sift_extractor.py
...14 '''15 sift = cv2.xfeatures2d.SIFT_create()16 kp,des = sift.detectAndCompute(gray,None)17 return kp,des18 def _cv_match(self,img_1,kp_1,des_1,img_2,kp_2,des_2):19 bf = cv2.BFMatcher()20 self.count += 1 21 if des_1 is None or des_2 is None:22 return None23 matches = bf.knnMatch(des_1,des_2,k=2) 24 #print (self.count, len(matches)) 25 if len(matches) >= 2:26 good_match = []27 for each in matches:28 if len(each) == 2:29 m,n = each 30 if m.distance < self.score * n.distance:31 good_match.append([m])32 else:33 good_match = None34 break35 #good_match = [[m] for m, n in matches if m.distance < self.score * n.distance]36 else:37 good_match = None 38 39 return good_match40 def get_matched_landmark(self, img_1, img_2):41 42 gray_1 = cv2.cvtColor(img_1,cv2.COLOR_BGR2GRAY)43 gray_2 = cv2.cvtColor(img_2,cv2.COLOR_BGR2GRAY)44 45 pickle.dump(gray_1,open('img1','wb'))46 pickle.dump(gray_2,open('img2','wb'))47 kp_1,des_1 = self._get_sift(gray_1)48 kp_2,des_2 = self._get_sift(gray_2)49 good_match = self._cv_match(img_1,kp_1,des_1,img_2,kp_2,des_2)50 if good_match is None: 51 return None,None52 53 num_landmark = len(good_match)54 landmark_1 = np.zeros((num_landmark,2), dtype=np.int)55 landmark_2 = np.zeros((num_landmark,2), dtype=np.int)56 for i,each in enumerate(good_match):57 pt_1 = kp_1[each[0].queryIdx].pt58 pt_2 = kp_2[each[0].trainIdx].pt59 landmark_1[i,0] = round(pt_1[0])60 landmark_1[i,1] = round(pt_1[1])61 landmark_2[i,0] = round(pt_2[0])62 landmark_2[i,1] = round(pt_2[1])63 return landmark_1, landmark_2
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!!