数据集链接:链接:https://pan.baidu.com/s/1kEgJCgZBxD1pitEBx61ZIA
提取码:h1ln ;官网下载的数据标签图是黑色的,但是如果放大看,里面其实不明显的像素值,因此我们只需使用opencv的阈值过滤函数将大于0部分的像素值设置成255(白色)就可以了。
官网原图:
修改后的图
代码:
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
import os
img = cv.imread("F://study//CULane//laneseg_label_w16//laneseg_label_w16//driver_23_30frame//05151646_0421.MP4//01200.png",0)
ret1, thresh1 = cv.threshold(img,0,255,cv.THRESH_BINARY)
cv.imwrite("F://study//CULane//laneseg_label_w16//laneseg_label_w16//driver_23_30frame//05151646_0421.MP4//01200.png",thresh1)
plt.imshow(thresh1)
文件里导入:
import os
outpath = 'E:\\CULane\\161\\label'
outer_path = 'E:\\CULane\\laneseg_label_w16\\driver_161_90frame'
folderlist = os.listdir(outer_path) #列举文件夹
for folder in folderlist:
inner_path = os.path.join(outer_path, folder)
total_num_folder = len(folderlist) #文件夹的总数
filelist = os.listdir(inner_path) #列举图片
i = 0
for item in filelist:
total_num_file = len(filelist) #单个文件夹内图片的总数
if item.endswith('.png'):
src = os.path.join(os.path.abspath(inner_path), item) #原图的地址
dst = os.path.join(outpath,'161_' +str(folder)+ str(i) + '.png') #新图的地址(这里可以把str(folder) + '_' + str(i) + '.jpg'改成你想改的名称)
os.rename(src, dst)
print('converting %s to %s ...' % (src, dst))
i += 1
print ('total %d to rename & converted %d jpgs' % (total_num_file, i))
批量修改:
# -*- coding:utf8 -*-
import os
import random
import cv2 as cv
import matplotlib.pyplot as plt
path = 'E:/CULane/161/label'
filelist = []
for file in os.listdir(path):
filelist.append(file)
for i in range(len(filelist)):
p = os.path.join(path, filelist[i])
img = cv.imread(p)
ret1, thresh1 = cv.threshold(img, 0, 255, cv.THRESH_BINARY)
cv.imwrite(p, thresh1)
print('wanc')