def draw_rect(x, y, w, h, img, color_r, color_g, color_b):
"""Draws a rectangle to img
Args:
x, int, x location in img
y, int, y location in img
w, int, width
h, int, height
img, np.array, 3D color image matrix
color_r, int, red channel of color
color_g, int, green channel of color
color_b, int, blue channel of color
"""
y_start = int(max(0, y))
y_stop = int(min(y + h, img.shape[0] - 1))
x_start = int(max(0, x))
x_stop = int(min(x + w, img.shape[1] - 1))
for y_i in range(y_start, y_stop):
for x_i in range(x_start, x_stop):
img[y_i, x_i, 0] = color_r
img[y_i, x_i, 1] = color_g
img[y_i, x_i, 2] = color_b
评论列表
文章目录