Best Python code snippet using Airtest
keypoint_base.py
Source: keypoint_base.py
...139 pts_sch1 = int(kp_sch[good[0].queryIdx].pt[0]), int(kp_sch[good[0].queryIdx].pt[1])140 pts_sch2 = int(kp_sch[good[1].queryIdx].pt[0]), int(kp_sch[good[1].queryIdx].pt[1])141 pts_src1 = int(kp_src[good[0].trainIdx].pt[0]), int(kp_src[good[0].trainIdx].pt[1])142 pts_src2 = int(kp_src[good[1].trainIdx].pt[0]), int(kp_src[good[1].trainIdx].pt[1])143 return self._get_origin_result_with_two_points(pts_sch1, pts_sch2, pts_src1, pts_src2)144 def _handle_three_good_points(self, kp_sch, kp_src, good):145 """å¤çä¸å¯¹ç¹å¾ç¹çæ
åµ."""146 # æ¿åºschåsrcç两个ç¹(ç¹1)å(ç¹2ç¹3çä¸ç¹)ï¼147 # ç¶åæ ¹æ®ä¸¤ä¸ªç¹ååè¿è¡åå¤ç(注æke_schåkp_src以åqueryIdxåtrainIdx):148 pts_sch1 = int(kp_sch[good[0].queryIdx].pt[0]), int(kp_sch[good[0].queryIdx].pt[1])149 pts_sch2 = int((kp_sch[good[1].queryIdx].pt[0] + kp_sch[good[2].queryIdx].pt[0]) / 2), int(150 (kp_sch[good[1].queryIdx].pt[1] + kp_sch[good[2].queryIdx].pt[1]) / 2)151 pts_src1 = int(kp_src[good[0].trainIdx].pt[0]), int(kp_src[good[0].trainIdx].pt[1])152 pts_src2 = int((kp_src[good[1].trainIdx].pt[0] + kp_src[good[2].trainIdx].pt[0]) / 2), int(153 (kp_src[good[1].trainIdx].pt[1] + kp_src[good[2].trainIdx].pt[1]) / 2)154 return self._get_origin_result_with_two_points(pts_sch1, pts_sch2, pts_src1, pts_src2)155 def _many_good_pts(self, kp_sch, kp_src, good):156 """ç¹å¾ç¹å¹é
ç¹å¯¹æ°ç®>=4个ï¼å¯ä½¿ç¨åç©éµæ å°,æ±åºè¯å«çç®æ åºå."""157 sch_pts, img_pts = np.float32([kp_sch[m.queryIdx].pt for m in good]).reshape(158 -1, 1, 2), np.float32([kp_src[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)159 # Mæ¯è½¬åç©éµ160 M, mask = self._find_homography(sch_pts, img_pts)161 matches_mask = mask.ravel().tolist()162 # ä»goodä¸é´çéåºæ´ç²¾ç¡®çç¹(å设goodä¸å¤§é¨åç¹ä¸ºæ£ç¡®çï¼ç±ratio=0.7ä¿é)163 selected = [v for k, v in enumerate(good) if matches_mask[k]]164 # é对ææçselectedç¹å次计ç®åºæ´ç²¾ç¡®ç转åç©éµMæ¥165 sch_pts, img_pts = np.float32([kp_sch[m.queryIdx].pt for m in selected]).reshape(166 -1, 1, 2), np.float32([kp_src[m.trainIdx].pt for m in selected]).reshape(-1, 1, 2)167 M, mask = self._find_homography(sch_pts, img_pts)168 # 计ç®å个è§ç©éµåæ¢åçåæ ï¼ä¹å°±æ¯å¨å¤§å¾ä¸çç®æ åºåç顶ç¹åæ :169 h, w = self.im_search.shape[:2]170 h_s, w_s = self.im_source.shape[:2]171 pts = np.float32([[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0]]).reshape(-1, 1, 2)172 dst = cv2.perspectiveTransform(pts, M)173 # trans numpy arrary to python list: [(a, b), (a1, b1), ...]174 def cal_rect_pts(dst):175 return [tuple(npt[0]) for npt in dst.astype(int).tolist()]176 pypts = cal_rect_pts(dst)177 # 注æï¼è½ç¶4个è§ç¹æå¯è½è¶åºsourceå¾è¾¹çï¼ä½æ¯(æ ¹æ®ç²¾ç¡®åæ å°åæ å°ç©éµM线æ§æºå¶)ä¸ç¹ä¸ä¼è¶åºè¾¹ç178 lt, br = pypts[0], pypts[2]179 middle_point = int((lt[0] + br[0]) / 2), int((lt[1] + br[1]) / 2)180 # èèå°ç®åºçç®æ ç©éµæå¯è½æ¯ç¿»è½¬çæ
åµï¼å¿
é¡»è¿è¡ä¸æ¬¡å¤çï¼ç¡®ä¿æ å°åçâå·¦ä¸è§âå¨å¾çä¸ä¹æ¯å·¦ä¸è§ç¹ï¼181 x_min, x_max = min(lt[0], br[0]), max(lt[0], br[0])182 y_min, y_max = min(lt[1], br[1]), max(lt[1], br[1])183 # æéåºç®æ ç©å½¢åºåå¯è½ä¼æè¶çæ
åµï¼è¶çæ¶ç´æ¥å°å
¶ç½®ä¸ºè¾¹çï¼184 # è¶
åºå·¦è¾¹çå0ï¼è¶
åºå³è¾¹çåw_s-1ï¼è¶
åºä¸è¾¹çå0ï¼è¶
åºä¸è¾¹çåh_s-1185 # å½x_minå°äº0æ¶ï¼å0ã x_maxå°äº0æ¶ï¼å0ã186 x_min, x_max = int(max(x_min, 0)), int(max(x_max, 0))187 # å½x_min大äºw_sæ¶ï¼åå¼w_s-1ã x_max大äºw_s-1æ¶ï¼åw_s-1ã188 x_min, x_max = int(min(x_min, w_s - 1)), int(min(x_max, w_s - 1))189 # å½y_minå°äº0æ¶ï¼å0ã y_maxå°äº0æ¶ï¼å0ã190 y_min, y_max = int(max(y_min, 0)), int(max(y_max, 0))191 # å½y_min大äºh_sæ¶ï¼åå¼h_s-1ã y_max大äºh_s-1æ¶ï¼åh_s-1ã192 y_min, y_max = int(min(y_min, h_s - 1)), int(min(y_max, h_s - 1))193 # ç®æ åºåçè§ç¹ï¼æå·¦ä¸ãå·¦ä¸ãå³ä¸ãå³ä¸ç¹åºï¼(x_min,y_min)(x_min,y_max)(x_max,y_max)(x_max,y_min)194 pts = np.float32([[x_min, y_min], [x_min, y_max], [195 x_max, y_max], [x_max, y_min]]).reshape(-1, 1, 2)196 pypts = cal_rect_pts(pts)197 return middle_point, pypts, [x_min, x_max, y_min, y_max, w, h]198 def _get_origin_result_with_two_points(self, pts_sch1, pts_sch2, pts_src1, pts_src2):199 """è¿å两对ææå¹é
ç¹å¾ç¹æ
å½¢ä¸çè¯å«ç»æ."""200 # å
ç®åºä¸å¿ç¹(å¨self.im_sourceä¸çåæ )ï¼201 middle_point = [int((pts_src1[0] + pts_src2[0]) / 2), int((pts_src1[1] + pts_src2[1]) / 2)]202 pypts = []203 # å¦æç¹å¾ç¹åxè½´æåyè½´(æ 论srcè¿æ¯schä¸)ï¼åä¸è½è®¡ç®åºç®æ ç©å½¢åºåæ¥ï¼æ¤æ¶è¿åå¼ågood=1æ
å½¢204 if pts_sch1[0] == pts_sch2[0] or pts_sch1[1] == pts_sch2[1] or pts_src1[0] == pts_src2[0] or pts_src1[1] == pts_src2[1]:205 return None206 # 计ç®x,yè½´ç缩æ¾æ¯ä¾ï¼x_scaleãy_scaleï¼ä»middleç¹æ©å¼ åºç®æ åºå:(注ææ´æ°è®¡ç®è¦è½¬ææµ®ç¹æ°ç»æ!)207 h, w = self.im_search.shape[:2]208 h_s, w_s = self.im_source.shape[:2]209 x_scale = abs(1.0 * (pts_src2[0] - pts_src1[0]) / (pts_sch2[0] - pts_sch1[0]))210 y_scale = abs(1.0 * (pts_src2[1] - pts_src1[1]) / (pts_sch2[1] - pts_sch1[1]))211 # å¾å°scaleåéè¦å¯¹middle_pointè¿è¡æ ¡æ£ï¼å¹¶éç¹å¾ç¹ä¸ç¹ï¼èæ¯æ å°ç©éµçä¸ç¹ã212 sch_middle_point = int((pts_sch1[0] + pts_sch2[0]) / 2), int((pts_sch1[1] + pts_sch2[1]) / 2)...
Check out the latest blogs from LambdaTest on this topic:
Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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!!