kitti和cityscape的gt的分割不太一样,下边缘不再是从黑色开始的,而是直接是类别
red,green,blue = img_gt[i,j]
1.道路的颜色(紫色):128 64 128
2.汽车的颜色(蓝色):142 0 0
3.人行道的颜色(朱红色):232 35 244
4.树和绿色植物的颜色(绿色):35 142 107
5.灰色:70 70 70
6.绿地(浅绿色):152 251 152
7.石子路(肉色、浅粉红色):160 170 250
8.另一种石子路(土褐色):81 0 81(图83_10.png)
75_10.png这张图中黄色柱状物下面的图黄色那部分如何处理其实是一个很大的问题,处理掉,但是确实这个东西有高度,不处理掉,那上面的柱状物体就检测不出来
要处理的有3,6,7,8
处理代码和之前在cityscape的略微有点不同:
import cv2 import numpy as np with open('/media/hdc/xing/data_semantics/training/semantic_rgb/a.txt','r') as file: # num = 0 for line in file: # if num == 1: # break # num += 1 gt_image = '/media/hdc/xing/data_semantics/training/semantic_rgb/' + line.strip().split('./')[1] # print gt_image save_dir = '/media/hdc/xing/data_semantics/training/label012/' + line.strip().split('./')[1] img_gt = cv2.imread(gt_image) # print type(img_gt) height = img_gt.shape[0] width = img_gt.shape[1] # print width,height result = np.zeros((height,width)) for i in range(width): index = height-1 red,green,blue = img_gt[index,i] # print i,red,green,blue while index >= 1 and (red != 128 or green != 64 or blue != 128): index -= 1 red,green,blue = img_gt[index,i] while index >= 1 and red == 128 and green == 64 and blue == 128: index -= 1 result[index][i] = 1 # result[index][i] = 255 red,green,blue = img_gt[index,i] while (index >= 1 and red == 232 and green == 35 and blue == 244) or (index >= 1 and red == 152 and green == 251 and blue == 152) or (index >= 1 and red == 160 and green == 170 and blue == 250) or (index >= 1 and red == 81 and green == 0 and blue == 81): index -= 1 red,green,blue = img_gt[index,i] while index >= 1 and red == 128 and green == 64 and blue == 128: index -= 1 result[index][i] = 1 # result[index][i] = 255 red,green,blue = img_gt[index,i] blue1 = blue green1 = green red1 = red # print blue1,green1,red1 while index >= 1 and blue == blue1 and green == green1 and red == red1: result[index][i] = 2 # result[index][i] = 150 index -= 1 red,green,blue = img_gt[index,i] while index >= 1 and red == 128 and green == 64 and blue == 128: index -= 1 result[index][i] = 1 # result[index][i] = 255 red,green,blue = img_gt[index,i] while index >= 1 and blue == blue1 and green == green1 and red == red1: result[index][i] = 2 # result[index][i] = 150 index -= 1 red,green,blue = img_gt[index,i] # while index >= 1 and (red != 128 or green != 64 or blue != 128): # index -= 1 # red,green,blue = img_gt[index,i] # while index >= 1 and red == 128 and green == 64 and blue == 128: # index -= 1 # # result[index][i] = 1 # result[index][i] = 255 # red,green,blue = img_gt[index,i] # while index >= 1 and red == 250 and green == 170 and blue == 160: # index -= 1 # red,green,blue = img_gt[index,i] # while index >= 1 and red == 244 and green == 35 and blue == 232: # index -= 1 # red,green,blue = img_gt[index,i] # while index >= 1 and red == 152 and green == 251 and blue == 152: # index -= 1 # red,green,blue = img_gt[index,i] # blue2 = blue # green2 = green # red2 = red # while index >= 1 and blue == blue2 and green == green2 and red == red2: # index -= 1 # # result[index][i] = 2 # result[index][i] = 150 # red,green,blue = img_gt[index,i] # print index for i in range(width): for j in range(height): red,green,blue = img_gt[j,i] if blue == 0 and green == 0 and red == 0: result[j][i] = 0 cv2.imwrite(save_dir,result) print save_dir