MCPcopy
hub / github.com/TencentQQGYLab/AppAgent / draw_grid

Function draw_grid

scripts/utils.py:63–95  ·  view source on GitHub ↗
(img_path, output_path)

Source from the content-addressed store, hash-verified

61
62
63def draw_grid(img_path, output_path):
64 def get_unit_len(n):
65 for i in range(1, n + 1):
66 if n % i == 0 and 120 <= i <= 180:
67 return i
68 return -1
69
70 image = cv2.imread(img_path)
71 height, width, _ = image.shape
72 color = (255, 116, 113)
73 unit_height = get_unit_len(height)
74 if unit_height < 0:
75 unit_height = 120
76 unit_width = get_unit_len(width)
77 if unit_width < 0:
78 unit_width = 120
79 thick = int(unit_width // 50)
80 rows = height // unit_height
81 cols = width // unit_width
82 for i in range(rows):
83 for j in range(cols):
84 label = i * cols + j + 1
85 left = int(j * unit_width)
86 top = int(i * unit_height)
87 right = int((j + 1) * unit_width)
88 bottom = int((i + 1) * unit_height)
89 cv2.rectangle(image, (left, top), (right, bottom), color, thick // 2)
90 cv2.putText(image, str(label), (left + int(unit_width * 0.05) + 3, top + int(unit_height * 0.3) + 3), 0,
91 int(0.01 * unit_width), (0, 0, 0), thick)
92 cv2.putText(image, str(label), (left + int(unit_width * 0.05), top + int(unit_height * 0.3)), 0,
93 int(0.01 * unit_width), color, thick)
94 cv2.imwrite(output_path, image)
95 return rows, cols
96
97
98def encode_image(image_path):

Callers 1

task_executor.pyFile · 0.90

Calls 1

get_unit_lenFunction · 0.85

Tested by

no test coverage detected