利用ChatGPT3.5 预处理车辆计数数据集:CARPK和PUCPR+( 三 )


本文感觉这里给的不太对,就自己重写了一份:
import cv2import numpy as npimport osimport reimport argparsefrom PIL import Imageimport scipydef changeLine(lines,w,h):lines = lines.split(' ')x1 = int(lines[0])y1 = int(lines[1])x2 = int(lines[2])y2 = int(lines[3])Kx = (x1+x2)/2ky = (y1+y2)/2return str( 1 ) +' ' + str(Kx/w) +' ' + str(ky/h) + ' \n'txt_data = http://www.kingceram.com/post/r'/data/txttxt' # 保存为所需的yolo标注文件ann_data = r'/data/Annotations' # 框标注文件路径files = os.listdir(ann_data)for file in files:ann_path = os.path.join(ann_data,file)img_path = ann_path.replace('Annotations','Images').replace('.txt','.jpg')img = cv2.imread(img_path, 1)h,w = img.shape[0],img.shape[1] ann = open(ann_path, encoding='utf-8')annLines = ann.readlines()result = []for lines in annLines:resultL = changeLine(lines,w,h) #这里计算出点坐标相对图像长宽的比例信息 。result.append(resultL)print(result)#result里存储着需要另存的txt文件with open(os.path.join(txt_data, file), 'w') as f:f.writelines(result)
转换后的点标注格式如下:
至此,对CARPK数据集和PUCPR+数据集的预处理操作就此结束 。
[1] Meng-,Yen-,.Hsu.Drone-basedby,