floodfill.py
Go to the documentation of this file.
1 import os
2 from random import randint
3 
4 import cv2
5 
6 if __name__ == '__main__':
7  input_path = './../data/INPUT/gt_colored//'
8  for map in os.listdir(input_path):
9  output_path = input_path + map
10  tmp = cv2.imread(input_path + map)
11  img = tmp.copy()
12  img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
13  th, img = cv2.threshold(img, 230, 255, cv2.THRESH_BINARY)
14  img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
15  colors = []
16  for y in range(img.shape[0] - 1):
17  for x in range(img.shape[1] - 1):
18  pixel = list(img[(y, x)])
19  if pixel == [255, 255, 255]:
20  random_color = (randint(1, 254), randint(1, 254), randint(1, 254))
21  flag = False
22  while not flag:
23  if random_color in colors:
24  random_color = (randint(1, 254), randint(1, 254), randint(1, 254))
25  else:
26  flag = True
27  cv2.floodFill(img, None, (x, y), random_color, flags=8)
28  cv2.imwrite(output_path, img)


rose2
Author(s): Gabriele Somaschini, Matteo Luperto
autogenerated on Wed Jun 28 2023 02:21:53