How to use _cal_confidence method in Airtest

Best Python code snippet using Airtest Github


Full Screen

...44 rect, matches, good = self.get_rect_from_good_matches(im_source, im_search, kp_sch, des_sch, kp_src, des_src)45 if not rect:46 return None47 # 第三步, 从匹配图片截取矩阵范围,并缩放到模板大小,进行模板匹配求出相似度48 confidence = self._cal_confidence(im_source=im_source, im_search=im_search, rect=rect, rgb=rgb)49 best_match = generate_result(rect=rect, confi=confidence)50 return best_match if confidence > threshold else None51 @print_all_result52 def find_all(self, im_source, im_search, threshold: Union[int, float] = None,53 max_count: int = 10,54 rgb: bool = None):55 threshold = threshold or self.threshold56 rgb = rgb is None and self.rgb or rgb57 im_source, im_search = self.check_detection_input(im_source, im_search)58 if not im_source or not im_search:59 return None60 result = []61 # 第一步: 获取特征点集62 kp_sch, des_sch = self.get_keypoints_and_descriptors(image=im_search.rgb_2_gray())63 kp_src, des_src = self.get_keypoints_and_descriptors(image=im_source.rgb_2_gray())64 while len(kp_src) > 2 or len(kp_sch) > 2:65 rect, matches, good = self.get_rect_from_good_matches(im_source, im_search,66 kp_sch, des_sch,67 kp_src, des_src)68 if not rect:69 break70 confidence = self._cal_confidence(im_source=im_source, im_search=im_search, rect=rect, rgb=rgb)71 if confidence > threshold and len(result) < max_count:72 result.append(generate_result(rect, confidence))73 kp_src, des_src = self.delect_good_descriptors(good, kp_src, des_src)74 kp_src, des_src = self.delect_rect_descriptors(rect, kp_src, des_src)75 return result76 def _cal_confidence(self, im_source, im_search, rect: Rect, rgb: bool):77 """ 将截图和识别结果缩放到大小一致,并计算可信度 """78 try:79 target_img = im_source.crop_image(rect)80 except OverflowError:81 raise MatchResultError("Target area({}) out of screen{}".format(rect, im_source.size))82 h, w = im_search.size83 target_img.resize(w, h)84 if rgb:85 confidence = self.template.cal_rgb_confidence(im_source=im_search, im_search=target_img)86 else:87 confidence = self.template.cal_ccoeff_confidence(im_source=im_search, im_search=target_img)88 confidence = (1 + confidence) / 289 return confidence90 @staticmethod...

Full Screen

Full Screen Github


Full Screen

...59def _dist(point, target):60 x, y = point61 m, n = target62 return np.sqrt((x - m) ** 2 + (y - n) ** 2)63def _cal_confidence(dist):64 # linear function. score decreases as the distance increases65 return -CONFIDENCE_RATE * dist + 166def is_id_card(crop_box, face_box, debug=False):67 xleft, xright, xtop, xbottom = crop_box68 yleft, yright, ytop, ybottom = face_box69 yleft += xleft70 yright += xleft71 ytop += xtop72 ybottom += xtop73 if debug:74 print('crop box: ', xleft, xright, xtop, xbottom)75 print('face box: ', yleft, yright, ytop, ybottom)76 crop_mid = _calc_mid(xleft, xright, xtop, xbottom)77 face_mid = _calc_mid(yleft, yright, ytop, ybottom)78 target = (xright + crop_mid[0]) // 2, crop_mid[1]79 return _cal_confidence(_dist(face_mid, target))80def id_card_detect(img, args):81 sess, detection_graph, category_index = args82 tensors = get_tensors(detection_graph)83 try:84 # crop85 cropped_img, crop_box, score = crop_id(img, sess, tensors, category_index)86 except:87 import traceback88 traceback.print_exc()89 return None, 090 return cropped_img if cropped_img is not None else None, score91if __name__ == "__main__":92 img = cv.imread('test_samples/1121.png')93 args = load_model()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?