How to use count_clock_rotate method in Airtest

Best Python code snippet using Airtest

aircv.py

Source:aircv.py Github

copy

Full Screen

...42 """43 函数使图片可顺时针或逆时针旋转90、180、270度.44 默认clockwise=True:顺时针旋转45 """46 def count_clock_rotate(img):47 # 逆时针旋转90°48 rows, cols = img.shape[:2]49 rotate_img = np.zeros((cols, rows))50 rotate_img = cv2.transpose(img)51 rotate_img = cv2.flip(rotate_img, 0)52 return rotate_img53 # 将角度旋转转化为逆时针旋转90°的次数:54 counter_rotate_time = (4 - angle / 90) % 4 if clockwise else (angle / 90) % 455 for i in range(int(counter_rotate_time)):56 img = count_clock_rotate(img)57 return img58def crop_image(img, rect):59 """60 区域截图,同时返回截取结果 和 截取偏移;61 Crop image , rect = [x_min, y_min, x_max ,y_max].62 (airtest中有用到)63 """64 if isinstance(rect, (list, tuple)) and len(rect) == 4:65 height, width = img.shape[:2]66 # 获取在图像中的实际有效区域:67 x_min, y_min, x_max, y_max = [int(i) for i in rect]68 x_min, y_min = max(0, x_min), max(0, y_min)69 x_min, y_min = min(width - 1, x_min), min(height - 1, y_min)70 x_max, y_max = max(0, x_max), max(0, y_max)...

Full Screen

Full Screen

cv.py

Source:cv.py Github

copy

Full Screen

...45 """46 函数使图片可顺时针或逆时针旋转90、180、270度.47 默认clockwise=True:顺时针旋转48 """49 def count_clock_rotate(img):50 # 逆时针旋转90°51 rows, cols = img.shape[:2]52 rotate_img = np.zeros((cols, rows))53 rotate_img = cv2.transpose(img)54 rotate_img = cv2.flip(rotate_img, 0)55 return rotate_img56 # 将角度旋转转化为逆时针旋转90°的次数:57 counter_rotate_time = (58 4 - angle / 90) % 4 if clockwise else (angle / 90) % 459 for i in range(int(counter_rotate_time)):60 img = count_clock_rotate(img)61 return img62def crop_image(img, rect):63 """64 区域截图,同时返回截取结果 和 截取偏移;65 Crop image , rect = [x_min, y_min, x_max ,y_max].66 """67 if isinstance(rect, (list, tuple)):68 height, width = img.shape[:2]69 # 获取在图像中的实际有效区域:70 x_min, y_min, x_max, y_max = [int(i) for i in rect]71 x_min, y_min = max(0, x_min), max(0, y_min)72 x_min, y_min = min(width - 1, x_min), min(height - 1, y_min)73 x_max, y_max = max(0, x_max), max(0, y_max)74 x_max, y_max = min(width - 1, x_max), min(height - 1, y_max)...

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