Reputation: 10109
I have 8 points for every image in my dataset, (x1, y1, x2, y2, x3, y3, x4, y4).
My objective is to train Retina net, but the repository requires that the format be like
path/to/image.jpg,x1,y1,x2,y2,class_name
they only demand 4 points, something like this /data/imgs/img_001.jpg,837,346,981,456,cow
My 8 points for one image look like this - [[220, 129], [1028,113], [1098,684], [206,706]
Is there any way i could convert my 8 points to 4.
Thanks in advance
Upvotes: 0
Views: 84
Reputation: 14081
Assuming the four pairs are just four x,y points in the image that should be in the bounding box,
>>> vals = [[220, 129], [1028,113], [1098,684], [206,706]]
>>> bbox = [min([x[0] for x in vals]), min([x[1] for x in vals]),
... max([x[0] for x in vals]), max([x[1] for x in vals])]
>>> print(bbox)
[206, 113, 1098, 706]
>>> imgpath = 'path/to/image.jpg'
>>> print('{},{},{}'.format(imgpath, ','.join(map(str, bbox)), 'clsname'))
path/to/image.jpg,206,113,1098,706,clsname
Upvotes: 1