How to use is_pad method in Airtest

Best Python code snippet using Airtest

utils.py

Source:utils.py Github

copy

Full Screen

1import cv22import numpy as np3import matplotlib.pyplot as plt4def vis_detections(im, dets, thresh=0.5, show_text=True):5 """Draw detected bounding boxes."""6 class_name = 'face'7 inds = np.where(dets[:, -1] >= thresh)[0] if dets is not None else []8 if len(inds) == 0:9 return10 im = im[:, :, (2, 1, 0)]11 fig, ax = plt.subplots(figsize=(12, 12))12 ax.imshow(im, aspect='equal')13 for i in inds:14 bbox = dets[i, :4]15 score = dets[i, -1]16 ax.add_patch(17 plt.Rectangle((bbox[0], bbox[1]),18 bbox[2] - bbox[0],19 bbox[3] - bbox[1], fill=False,20 edgecolor='red', linewidth=2.5)21 )22 if show_text:23 ax.text(bbox[0], bbox[1] - 5,24 '{:s} {:.3f}'.format(class_name, score),25 bbox=dict(facecolor='blue', alpha=0.5),26 fontsize=10, color='white')27 ax.set_title(('{} detections with '28 'p({} | box) >= {:.1f}').format(class_name, class_name,29 thresh),30 fontsize=10)31 plt.axis('off')32 plt.tight_layout()33 plt.savefig('out.png')34 plt.show()35def bbox_vote(det):36 order = det[:, 4].ravel().argsort()[::-1]37 det = det[order, :]38 dets = None39 while det.shape[0] > 0:40 # IOU41 area = (det[:, 2] - det[:, 0] + 1) * (det[:, 3] - det[:, 1] + 1)42 xx1 = np.maximum(det[0, 0], det[:, 0])43 yy1 = np.maximum(det[0, 1], det[:, 1])44 xx2 = np.minimum(det[0, 2], det[:, 2])45 yy2 = np.minimum(det[0, 3], det[:, 3])46 w = np.maximum(0.0, xx2 - xx1 + 1)47 h = np.maximum(0.0, yy2 - yy1 + 1)48 inter = w * h49 o = inter / (area[0] + area[:] - inter)50 # get needed merge det and delete these det51 merge_index = np.where(o >= 0.3)[0]52 det_accu = det[merge_index, :]53 det = np.delete(det, merge_index, 0)54 if merge_index.shape[0] <= 1:55 continue56 det_accu[:, 0:4] = det_accu[:, 0:4] * np.tile(det_accu[:, -1:], (1, 4))57 max_score = np.max(det_accu[:, 4])58 det_accu_sum = np.zeros((1, 5))59 det_accu_sum[:, 0:4] = np.sum(det_accu[:, 0:4], axis=0) / np.sum(det_accu[:, -1:])60 det_accu_sum[:, 4] = max_score61 try:62 dets = np.row_stack((dets, det_accu_sum))63 except:64 dets = det_accu_sum65 if dets is not None:66 dets = dets[0:750, :]67 return dets68def add_borders(curr_img, target_shape=(224, 224), fill_type=0):69 curr_h, curr_w = curr_img.shape[0:2]70 shift_h = max(target_shape[0] - curr_h, 0)71 shift_w = max(target_shape[1] - curr_w, 0)72 image = cv2.copyMakeBorder(curr_img, shift_h // 2, (shift_h + 1) // 2, shift_w // 2, (shift_w + 1) // 2, fill_type)73 return image, shift_h, shift_w74def resize_image(image, target_size, resize_factor=None, is_pad=True, interpolation=3):75 curr_image_size = image.shape[0:2]76 if resize_factor is None and is_pad:77 resize_factor = min(target_size[0] / curr_image_size[0], target_size[1] / curr_image_size[1])78 elif resize_factor is None and not is_pad:79 resize_factor = np.sqrt((target_size[0] * target_size[1]) / (curr_image_size[0] * curr_image_size[1]))80 image = cv2.resize(image, None, None, fx=resize_factor, fy=resize_factor, interpolation=interpolation)81 if is_pad:82 image, shift_h, shift_w = add_borders(image, target_size)83 else:84 shift_h = shift_w = 085 scale = np.array([image.shape[1]/resize_factor, image.shape[0]/resize_factor,86 image.shape[1]/resize_factor, image.shape[0]/resize_factor])...

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