Created
August 7, 2018 12:08
-
-
Save elranu/40bc952fadf62175c218724f98a7428e to your computer and use it in GitHub Desktop.
to yolo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
with open("labels_imagenes.csv", "r") as inp: | |
content = inp.read() | |
out = open('algo.csv', 'a') | |
out_dict = dict() | |
for line in content.split('\n')[1:-1]: | |
file, x, y, w, h, class_id = tuple(*re.findall(r'"(.+?),.+?x""""\:(\d+?)\b.+?y""""\:(\d+?)\b.+width"""":(\d+?)\b.+height"""":(\d+?)\b.+?idf"""":""""(.+?)"', line)) | |
xmax = int(x) + int(w) | |
ymax = int(y) + int(h) | |
object = f'{x},{y},{xmax},{ymax},{class_id}' | |
if file in out_dict: | |
out_dict[file].append(object) | |
else: | |
out_dict[file] = [object] | |
for k, v in out_dict.items(): | |
out.write(f'{k} {" ".join(v)}\n') | |
out.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment