From abf73e60dc8efb3533e930637c3199ee0d9bdbbb Mon Sep 17 00:00:00 2001
From: "stephane.chavin" <stephanechvn@gmail.com>
Date: Fri, 20 Jan 2023 14:33:50 +0100
Subject: [PATCH] add convert json

---
 get_json_file_YOLO.py | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 get_json_file_YOLO.py

diff --git a/get_json_file_YOLO.py b/get_json_file_YOLO.py
new file mode 100644
index 0000000..aa85ee5
--- /dev/null
+++ b/get_json_file_YOLO.py
@@ -0,0 +1,40 @@
+#  /!\  TO DO before : globox convert input_YOLO/labels/val/ output_../classifier/test_convert_labels/ --format yolo --save_fmt labelme --img_folder YOLO/images/val/ #path to images
+
+import os
+import json
+import labelme
+import base64
+import pandas as pd
+
+mode = 'train' #or val
+img_dir = str('../annot/YOLO/images/'+mode+'/')
+
+filename = 'test_convert_labels_train/' #path to .json
+out_file = 'test_convert_labels_train_2/' #direction
+img_path = '/nfs/NAS7/manip_stephane/annot/YOLO/images/train/'
+
+liste_file = os.listdir(filename) 
+liste_file = pd.DataFrame(liste_file, columns =['fn'])
+
+for i in range (len(liste_file)):
+    if liste_file.fn[i][0] == '.':
+        liste_file = liste_file.drop(i)
+
+liste_file = liste_file.reset_index()
+
+for i, row in liste_file.iterrows():
+    if len(row.fn) > 30:
+        data = labelme.LabelFile.load_image_file(img_dir+row.fn[:-4]+'jpg')
+        image_data = base64.b64encode(data).decode('utf-8')
+    else:
+        continue
+    try :
+        len(data)
+    except TypeError:
+        continue
+    f = open(filename+row.fn,)
+    get_data = json.load(f)
+    get_data['imageData'] = image_data
+    get_data['imagePath'] = img_path+row.fn[:-4]+'jpg'
+    with open(out_file+row.fn, 'w') as f:
+        json.dump(get_data, f, indent=4)
-- 
GitLab