CULane数据集处理

数据集链接:链接: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')
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值