def addDirt(img):
rows, cols = img.shape
Dirt = np.ones(img.shape, np.uint8) * 255
change = 0
for i in range(random.randint(0,3)):
change = 1
y = random.randint(0,rows-1)
x = random.randint(0,cols-1)
dy = random.randint(rows//30,rows//5)
dx = random.randint(cols//30,cols//5)
Dirt[y:min(y+dy,rows-1), x:min(x+dx,cols-1)] = random.randint(215,230)
k_size = random.randint(max(rows,cols)//18,max(rows,cols)//14) * 2 + 1
Dirt = cv2.GaussianBlur(Dirt, (k_size, k_size), 0)
if change:
img = np.where(img < 230, img, Dirt)
return img
评论列表
文章目录