How to use _find_all_template method in Airtest

Best Python code snippet using Airtest

cv.py

Source:cv.py Github

copy

Full Screen

...98 return focus_pos99 def match_all_in(self, screen):100 image = self._imread()101 image = self._resize_image(image, screen, ST.RESIZE_METHOD)102 return self._find_all_template(image, screen)103 def _cv_match(self, screen):104 # in casePackage image file not exist in current directory:105 if isinstance(self.filepath, type('')):106 image = self._imread()107 else:108 image = self.filepath109 if isinstance(image, unicode):110 image = aircv.imread(image)111 if self.is_image_cut:112 image = self.image_cut(image)113 if isinstance(screen, type('')):114 screen = aircv.imread(screen)115 screen = self.image_cut(screen)116 image = self._resize_image(image, screen, ST.RESIZE_METHOD)117 ret = None118 for method in ST.CVSTRATEGY:119 if method == "tpl":120 ret = self._try_match(self._find_template, image, screen)121 print 'find_template**********'122 print ret123 elif method == "sift" and self.sift:124 ret = self._try_match(self._find_sift_in_predict_area, image, screen)125 print 'find_sift_in_predict_area**********'126 print ret127 if not ret:128 ret = self._try_match(self._find_sift, image, screen)129 print 'find_sift**********'130 print ret131 else:132 # G.LOGGING.warning("Undefined method in CV_STRATEGY: %s", method)133 pass134 if ret:135 break136 return ret137 @staticmethod138 def image_cut(image):139 height, width, channels = image.shape140 return image[int(height/30):height, 0:width]141 @staticmethod142 def _try_match(method, *args, **kwargs):143 # G.LOGGING.debug("try match with %s" % method.__name__)144 try:145 ret = method(*args, **kwargs)146 except aircv.BaseError as err:147 # G.LOGGING.debug(repr(err))148 return None149 else:150 return ret151 def _imread(self):152 return aircv.imread(self.filepath)153 def _find_all_template(self, image, screen):154 return aircv.find_all_template(screen, image, threshold=self.threshold, rgb=self.rgb)155 def _find_template(self, image, screen):156 return aircv.find_template(screen, image, threshold=self.threshold, rgb=self.rgb)157 def _find_sift(self, image, screen):158 return aircv.find_sift(screen, image, threshold=self.threshold, rgb=self.rgb)159 def _find_sift_in_predict_area(self, image, screen):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)...

Full Screen

Full Screen

template.py

Source:template.py Github

copy

Full Screen

...59 def match_all_in(self, screen, in_rect=None):60 image = self._imread()61 image = self._resize_image(image, screen, ST.RESIZE_METHOD)62 if in_rect is None:63 results = self._find_all_template(image, screen)64 else:65 pos_left_top = (int(in_rect[0][0] * screen.shape[1] / 2 + screen.shape[1] / 2),66 int(in_rect[0][1] * screen.shape[0] / 2 + screen.shape[0] / 2))67 pos_right_bottom = (int(in_rect[1][0] * screen.shape[1] / 2 + screen.shape[1] / 2),68 int(in_rect[1][1] * screen.shape[0] / 2 + screen.shape[0] / 2))69 img_part = screen[pos_left_top[1]: pos_right_bottom[1], pos_left_top[0]: pos_right_bottom[0]]70 results = self._find_all_template(image, img_part)71 if results is not None:72 for result in results:73 result['result'] =(result['result'][0] + pos_left_top[0], result['result'][1] + pos_left_top[1])74 rectangle = ((result["rectangle"][0][0] + pos_left_top[0], result["rectangle"][0][1] + pos_left_top[1]),75 (result["rectangle"][1][0] + pos_left_top[0], result["rectangle"][1][1] + pos_left_top[1]),76 (result["rectangle"][2][0] + pos_left_top[0], result["rectangle"][2][1] + pos_left_top[1]),77 (result["rectangle"][3][0] + pos_left_top[0], result["rectangle"][3][1] + pos_left_top[1]))78 result["rectangle"] = rectangle79 if results is None:80 return {'results': None, 'feature': self, 'screen': screen}81 else:82 return {'results': results, 'feature': self, 'screen': screen}83 def get_image(self):84 return self._imread()85 def get_caller_module(self):86 return self._caller_module87 def _find_best_template(self, image, screen):88 return TemplateMatching(image, screen, threshold=self.threshold, rgb=self.rgb).find_best_result()89 def _find_all_template(self, image, screen):90 return TemplateMatching(image, screen, threshold=self.threshold, rgb=self.rgb).find_all_results()91 def _imread(self):92 if self._img is None:93 self._img = super(Template, self)._imread()...

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:

YouTube

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?

Helpful

NotHelpful