Best Python code snippet using Airtest
multiscale_template_matching.py
Source:multiscale_template_matching.py  
...75        rectangle = (left_top_pos, left_bottom_pos,76                     right_bottom_pos, right_top_pos)77        return middle_point, rectangle78    @staticmethod79    def _resize_by_ratio(src, templ, ratio=1.0, templ_min=10, src_max=800):80        """æ ¹æ®æ¨¡æ¿ç¸å¯¹å±å¹çé¿è¾¹ ææ¯ä¾ç¼©æ¾å±å¹"""81        # æªå±æå¤§å°ºå¯¸éå¶82        sr = min(src_max/max(src.shape),1.0)83        src = cv2.resize(src, (int(src.shape[1]*sr), int(src.shape[0]*sr)))84        # æªå¾å°ºå¯¸ç¼©æ¾85        h, w = src.shape[0], src.shape[1]86        th, tw = templ.shape[0], templ.shape[1]87        if th/h >= tw/w:88            tr = (h*ratio)/th89        else:90            tr = (w*ratio)/tw91        templ = cv2.resize(templ, (max(int(tw*tr), 1), max(int(th*tr), 1)))92        return src, templ, tr, sr93    @staticmethod94    def _org_size(max_loc, w, h, tr, sr):95        """è·ååå§æ¯ä¾çæ¡"""96        max_loc = (int((max_loc[0]/sr)), int((max_loc[1]/sr)))97        w, h = int((w/sr)), int((h/sr))98        return max_loc, w, h99    def multi_scale_search(self, org_src, org_templ, templ_min=10, src_max=800, ratio_min=0.01, ratio_max=0.99, step=0.01, threshold=0.8):100        """å¤å°ºåº¦æ¨¡æ¿å¹é
"""101        mmax_val = 0102        max_info = None103        r = ratio_min104        while r <= ratio_max:105            src, templ, tr, sr = self._resize_by_ratio(106                org_src.copy(), org_templ.copy(), r, src_max=src_max)107            if min(templ.shape) > templ_min:108                src[0,0] = templ[0,0] = 0109                src[0,1] = templ[0,1] = 255110                result = cv2.matchTemplate(src, templ, cv2.TM_CCOEFF_NORMED)111                min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)112                h, w = templ.shape113                if mmax_val < max_val:114                    mmax_val = max_val115                    max_info = (r, max_val, max_loc, w, h, tr, sr)116                # print((r, max_val, max_loc, w, h, tr, sr))117                if max_val >= threshold:118                    omax_loc, ow, oh = self._org_size(max_loc, w, h, tr, sr)119                    confidence = self._get_confidence_from_matrix(omax_loc, ow, oh)...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!!
