无人机视角的行人小目标检测
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3KB

  1. import os
  2. import pandas as pd
  3. from PIL import Image
  4. YOLO_LABELS_PATH = "../datasets/VisDrone/VisDrone2019-DET-val/labels"
  5. VISANN_PATH = "../datasets/VisDrone/VisDrone2019-DET-val/annotations/"
  6. VISIMG_PATH = "../datasets//VisDrone/VisDrone2019-DET-val/images/"
  7. def convert(bbox, img_size):
  8. #将标注visDrone数据集标注转为yolov5
  9. #bbox top_left_x top_left_y width height
  10. dw = 1/(img_size[0])
  11. dh = 1/(img_size[1])
  12. x = bbox[0] + bbox[2]/2
  13. y = bbox[1] + bbox[3]/2
  14. x = x * dw
  15. y = y * dh
  16. w = bbox[2] * dw
  17. h = bbox[3] * dh
  18. return (x,y,w,h)
  19. def ChangeToYolo5():
  20. if not os.path.exists(YOLO_LABELS_PATH):
  21. os.makedirs(YOLO_LABELS_PATH)
  22. print(len(os.listdir(VISANN_PATH)))
  23. for file in os.listdir(VISANN_PATH):
  24. image_path = VISIMG_PATH + '/' + file.replace('txt', 'jpg')
  25. ann_file = VISANN_PATH + '/' + file
  26. out_file = open(YOLO_LABELS_PATH + '/' + file, 'w')
  27. bbox = pd.read_csv(ann_file,header=None).values
  28. img = Image.open(image_path)
  29. img_size = img.size
  30. for row in bbox:
  31. if(row[4]==1 and 0<row[5]<11):
  32. label = convert(row[:4], img_size)
  33. out_file.write(str(row[5]-1) + " " + " ".join(str(f'{x:.6f}') for x in label) + '\n')
  34. out_file.close()
  35. if __name__ == '__main__':
  36. ChangeToYolo5()