How to use get_and_plot_keypoints method in Airtest

Best Python code snippet using Airtest

profile_recorder.py

Source:profile_recorder.py Github

copy

Full Screen

...49 import traceback50 traceback.print_exc()51 return [], [], [], None52 return method_object.kp_sch, method_object.kp_src, method_object.good, result53 def get_and_plot_keypoints(self, method_name, plot=False):54 """获取并且绘制出特征点匹配结果."""55 if method_name not in self.method_object_dict.keys():56 print("'%s' is not in MATCHING_METHODS" % method_name)57 return None58 kp_sch, kp_src, good, result = self._get_result(method_name)59 if not plot or result is None:60 return kp_sch, kp_src, good, result61 else:62 im_search, im_source = deepcopy(self.im_search), deepcopy(self.im_source)63 # 绘制特征点识别情况、基于特征的图像匹配结果:64 h_sch, w_sch = im_search.shape[:2]65 h_src, w_src = im_source.shape[:2]66 # init the plot image:67 plot_img = np.zeros([max(h_sch, h_src), w_sch + w_src, 3], np.uint8)68 plot_img[:h_sch, :w_sch, :] = im_search69 plot_img[:h_src, w_sch:, :] = im_source70 # plot good matche points:71 for m in good:72 color = tuple([int(random() * 255) for _ in range(3)]) # 随机颜色画线73 cv2.line(plot_img, (int(kp_sch[m.queryIdx].pt[0]), int(kp_sch[m.queryIdx].pt[1])), (int(kp_src[m.trainIdx].pt[0] + w_sch), int(kp_src[m.trainIdx].pt[1])), color)74 # plot search_image75 for kp in kp_sch:76 color = tuple([int(random() * 255) for _ in range(3)]) # 随机颜色画点77 pos = (int(kp.pt[0]), int(kp.pt[1]))78 mark_point(im_search, pos, circle=False, color=color, radius=5)79 # plot source_image80 for kp in kp_src:81 color = tuple([int(random() * 255) for _ in range(3)]) # 随机颜色画点82 pos = (int(kp.pt[0]), int(kp.pt[1]))83 mark_point(im_source, pos, circle=False, color=color, radius=10)84 from airtest.aircv import show85 show(plot_img)86 show(im_search)87 show(im_source)88class RecordThread(threading.Thread):89 """记录CPU和内存数据的thread."""90 def __init__(self, interval=0.1):91 super(RecordThread, self).__init__()92 self.pid = os.getpid()93 self.interval = interval94 self.cpu_num = psutil.cpu_count()95 self.process = psutil.Process(self.pid)96 self.profile_data = []97 self.stop_flag = False98 def set_interval(self, interval):99 """设置数据采集间隔."""100 self.interval = interval101 def run(self):102 """开始线程."""103 while not self.stop_flag:104 timestamp = time.time()105 cpu_percent = self.process.cpu_percent() / self.cpu_num106 # mem_percent = mem = self.process.memory_percent()107 mem_info = dict(self.process.memory_info()._asdict())108 mem_gb_num = mem_info.get('rss', 0) / 1024 / 1024109 # 记录类变量110 self.profile_data.append({"mem_gb_num": mem_gb_num, "cpu_percent": cpu_percent, "timestamp": timestamp})111 # 记录cpu和mem_gb_num112 time.sleep(self.interval)113 # print("--> mem_gb_num:", mem_gb_num)114class ProfileRecorder(object):115 """帮助用户记录性能数据."""116 def __init__(self, profile_interval=0.1):117 super(ProfileRecorder, self).__init__()118 self.record_thread = RecordThread()119 self.record_thread.set_interval(profile_interval)120 def load_images(self, search_file, source_file):121 """加载待匹配图片."""122 self.search_file, self.source_file = search_file, source_file123 self.im_search, self.im_source = imread(self.search_file), imread(self.source_file)124 # 初始化对象125 self.check_macthing_object = CheckKeypointResult(self.im_search, self.im_source)126 def profile_methods(self, method_list):127 """帮助函数执行时记录数据."""128 self.method_exec_info = []129 # 开始数据记录进程130 self.record_thread.stop_flag = False131 self.record_thread.start()132 for name in method_list:133 if name not in self.check_macthing_object.MATCHING_METHODS.keys():134 continue135 time.sleep(3) # 留出绘图空白区136 start_time = time.time() # 记录开始时间137 print("--->>> start '%s' matching:\n" % name)138 kp_sch, kp_src, good, result = self.check_macthing_object.get_and_plot_keypoints(name) # 根据方法名绘制对应的识别结果139 print("\n\n\n")140 end_time = time.time() # 记录结束时间141 time.sleep(3) # 留出绘图空白区142 # 记录本次匹配的相关数据143 ret_info = {144 "name": name,145 "start_time": start_time,146 "end_time": end_time,147 "result": result,148 "kp_sch": len(kp_sch),149 "kp_src": len(kp_src),150 "good": len(good)}151 self.method_exec_info.append(ret_info)152 self.record_thread.stop_flag = True...

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