How to use cal_rect_pts method in Airtest

Best Python code snippet using Airtest

sift.py

Source:sift.py Github

copy

Full Screen

...159 h_s, w_s = im_source.shape[:2]160 pts = np.float32([[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0]]).reshape(-1, 1, 2)161 dst = cv2.perspectiveTransform(pts, M)162 # trans numpy arrary to python list: [(a, b), (a1, b1), ...]163 def cal_rect_pts(dst):164 return [tuple(npt[0]) for npt in dst.astype(int).tolist()]165 pypts = cal_rect_pts(dst)166 # 注意:虽然4个角点有可能越出source图边界,但是(根据精确化映射单映射矩阵M线性机制)中点不会越出边界167 lt, br = pypts[0], pypts[2]168 middle_point = int((lt[0] + br[0]) / 2), int((lt[1] + br[1]) / 2)169 # 考虑到算出的目标矩阵有可能是翻转的情况,必须进行一次处理,确保映射后的“左上角”在图片中也是左上角点:170 x_min, x_max = min(lt[0], br[0]), max(lt[0], br[0])171 y_min, y_max = min(lt[1], br[1]), max(lt[1], br[1])172 # 挑选出目标矩形区域可能会有越界情况,越界时直接将其置为边界:173 # 超出左边界取0,超出右边界取w_s-1,超出下边界取0,超出上边界取h_s-1174 # 当x_min小于0时,取0。 x_max小于0时,取0。175 x_min, x_max = int(max(x_min, 0)), int(max(x_max, 0))176 # 当x_min大于w_s时,取值w_s-1。 x_max大于w_s-1时,取w_s-1。177 x_min, x_max = int(min(x_min, w_s - 1)), int(min(x_max, w_s - 1))178 # 当y_min小于0时,取0。 y_max小于0时,取0。179 y_min, y_max = int(max(y_min, 0)), int(max(y_max, 0))180 # 当y_min大于h_s时,取值h_s-1。 y_max大于h_s-1时,取h_s-1。181 y_min, y_max = int(min(y_min, h_s - 1)), int(min(y_max, h_s - 1))182 # 目标区域的角点,按左上、左下、右下、右上点序:(x_min,y_min)(x_min,y_max)(x_max,y_max)(x_max,y_min)183 pts = np.float32([[x_min, y_min], [x_min, y_max], [184 x_max, y_max], [x_max, y_min]]).reshape(-1, 1, 2)185 pypts = cal_rect_pts(pts)186 return middle_point, pypts, [x_min, x_max, y_min, y_max, w, h]187def _two_good_points(pts_sch1, pts_sch2, pts_src1, pts_src2, im_search, im_source):188 """返回两对匹配特征点情形下的识别结果."""189 # 先算出中心点(在im_source中的坐标):190 middle_point = [int((pts_src1[0] + pts_src2[0]) / 2), int((pts_src1[1] + pts_src2[1]) / 2)]191 pypts = []192 # 如果特征点同x轴或同y轴(无论src还是sch中),均不能计算出目标矩形区域来,此时返回值同good=1情形193 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]:194 confidence = ONE_POINT_CONFI195 one_match = generate_result(middle_point, pypts, confidence)196 return one_match197 # 计算x,y轴的缩放比例:x_scale、y_scale,从middle点扩张出目标区域:(注意整数计算要转成浮点数结果!)198 h, w = im_search.shape[:2]199 h_s, w_s = im_source.shape[:2]...

Full Screen

Full Screen

sift_test.py

Source:sift_test.py Github

copy

Full Screen

...77 h_s, w_s = im_source.shape[:2]78 pts = np.float32([[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0]]).reshape(-1, 1, 2)79 dst = cv2.perspectiveTransform(pts, M)80 # trans numpy arrary to python list: [(a, b), (a1, b1), ...]81 def cal_rect_pts(dst):82 return [tuple(npt[0]) for npt in dst.astype(int).tolist()]83 pypts = cal_rect_pts(dst)84 # 注意:虽然4个角点有可能越出source图边界,但是(根据精确化映射单映射矩阵M线性机制)中点不会越出边界85 lt, br = pypts[0], pypts[2]86 middle_point = int((lt[0] + br[0]) / 2), int((lt[1] + br[1]) / 2)87 # 考虑到算出的目标矩阵有可能是翻转的情况,必须进行一次处理,确保映射后的“左上角”在图片中也是左上角点:88 x_min, x_max = min(lt[0], br[0]), max(lt[0], br[0])89 y_min, y_max = min(lt[1], br[1]), max(lt[1], br[1])90 # 挑选出目标矩形区域可能会有越界情况,越界时直接将其置为边界:91 # 超出左边界取0,超出右边界取w_s-1,超出下边界取0,超出上边界取h_s-192 # 当x_min小于0时,取0。 x_max小于0时,取0。93 x_min, x_max = int(max(x_min, 0)), int(max(x_max, 0))94 # 当x_min大于w_s时,取值w_s-1。 x_max大于w_s-1时,取w_s-1。95 x_min, x_max = int(min(x_min, w_s - 1)), int(min(x_max, w_s - 1))96 # 当y_min小于0时,取0。 y_max小于0时,取0。97 y_min, y_max = int(max(y_min, 0)), int(max(y_max, 0))98 # 当y_min大于h_s时,取值h_s-1。 y_max大于h_s-1时,取h_s-1。99 y_min, y_max = int(min(y_min, h_s - 1)), int(min(y_max, h_s - 1))100 # 目标区域的角点,按左上、左下、右下、右上点序:(x_min,y_min)(x_min,y_max)(x_max,y_max)(x_max,y_min)101 pts = np.float32([[x_min, y_min], [x_min, y_max], [102 x_max, y_max], [x_max, y_min]]).reshape(-1, 1, 2)103 pypts = cal_rect_pts(pts)104 return middle_point, pypts, [x_min, x_max, y_min, y_max, w, h]105# 匹配点对 >= 4个,使用单矩阵映射求出目标区域,据此算出可信度:106middle_point, pypts, w_h_range = _many_good_pts(im_source, im_search, kp_sch, kp_src, good)107print(middle_point)108print(pypts)109print(w_h_range)110# best_match = generate_result(middle_point, pypts, confidence)111#112# print("[sift] result=%s" % (best_match))113# matchesMask = [[0, 0] for i in range(len(matches))]114# coff = 0.2115# for i,(m,n) in enumerate(matches):116# if m.distance < coff * n.distance:117# matchesMask[i]=[1,0]...

Full Screen

Full Screen

keypoint.py

Source:keypoint.py Github

copy

Full Screen

...54 -1, 1, 255 )56 dst = cv2.perspectiveTransform(pts, M)57 # trans numpy arrary to python list: [(a, b), (a1, b1), ...]58 def cal_rect_pts(dst):59 return [tuple(npt[0]) for npt in dst.astype(int).tolist()]60 pypts = cal_rect_pts(dst)61 # 注意:虽然4个角点有可能越出source图边界,但是(根据精确化映射单映射矩阵M线性机制)中点不会越出边界62 lt, br = pypts[0], pypts[2]63 middlePoint = int((lt[0] + br[0]) / 2), int((lt[1] + br[1]) / 2)64 # 考虑到算出的目标矩阵有可能是翻转的情况,必须进行一次处理,确保映射后的“左上角”在图片中也是左上角点:65 xMin, xMax = min(lt[0], br[0]), max(lt[0], br[0])66 yMin, yMax = min(lt[1], br[1]), max(lt[1], br[1])67 # 挑选出目标矩形区域可能会有越界情况,越界时直接将其置为边界:68 # 超出左边界取0,超出右边界取w_s-1,超出下边界取0,超出上边界取h_s-169 # 当x_min小于0时,取0。 x_max小于0时,取0。70 xMin, xMax = int(max(xMin, 0)), int(max(xMax, 0))71 # 当x_min大于w_s时,取值w_s-1。 x_max大于w_s-1时,取w_s-1。72 xMin, xMax = int(min(xMin, w_s - 1)), int(min(xMax, w_s - 1))73 # 当y_min小于0时,取0。 y_max小于0时,取0。74 yMin, yMax = int(max(yMin, 0)), int(max(yMax, 0))75 # 当y_min大于h_s时,取值h_s-1。 y_max大于h_s-1时,取h_s-1。76 yMin, yMax = int(min(yMin, h_s - 1)), int(min(yMax, h_s - 1))77 # 目标区域的角点,按左上、左下、右下、右上点序:(x_min,y_min)(x_min,y_max)(x_max,y_max)(x_max,y_min)78 pts = np.float32(79 [[xMin, yMin], [xMin, yMax], [xMax, yMax], [xMax, yMin]]80 ).reshape(-1, 1, 2)81 pypts = cal_rect_pts(pts)82 return middlePoint, pypts, [xMin, xMax, yMin, yMax, w, h]83def KAZEMatching(filename, device, threshold=0.9, targetPos=5):84 # 1.读取图片85 imSearch = cv2.imread("img/{name}".format(name=filename))86 imSource = device.screenshot(format="opencv")87 # 2.获取特征点集并匹配出特征点对88 kpSch, kpSrc, good = getKeyPoints(imSearch, imSource)89 # 3.根据匹配点对(good),提取出来识别区域:90 originResult = handleGoodPoints(kpSch, kpSrc, good, imSearch, imSource)91 # 某些特殊情况下直接返回None作为匹配结果:92 if originResult is None:93 return None94 else:95 middlePoint, pypts, posRange = originResult...

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