csv文件的格式主要是filename,x1,y1,x2,y2,x3,y3,x4,y4,type,如下图:
import pandas as pd
from sklearn.model_selection import train_test_split
import os
import cv2
import json
def train_val(files_path, images_path):
"""
file_path: annotation file path
image_path: image file path
"""
file = pd.read_csv(files_path)
filename_list = []
x1_list = []
y1_list = []
x2_list = []
y2_list = []
category_list = []
for filename, x1, y1, x2, y2, category in zip(file.filename, file.X1, file.Y1, file.X3, file.Y3, file.type):
if x1 < x2 and y1 < y2:
image_path = os.path.join(images_path, filename)
filename_list.append(image_path)
x1_list.append(x1)
x2_list.append(x2)
y1_