Skip to content
Snippets Groups Projects
Commit b7bd4917 authored by Stephane Chavin's avatar Stephane Chavin
Browse files

correction labelme x min

parent f407f89f
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,15 @@ def arg_directory(path): ...@@ -12,6 +12,15 @@ def arg_directory(path):
else: else:
raise argparse.ArgumentTypeError(f'`{path}` is not a valid path') raise argparse.ArgumentTypeError(f'`{path}` is not a valid path')
def create_directory(directory):
try:
os.makedirs(os.path.join(directory,'labels'), exist_ok=True)
except Exception as e:
print(f'Error creating directory {directory}: {e}')
return (directory)
def convert_labelme_to_yolo(labelme_annotation_path, yolo_directory): def convert_labelme_to_yolo(labelme_annotation_path, yolo_directory):
# Load LabelMe annotation # Load LabelMe annotation
image_id = Path(labelme_annotation_path).stem image_id = Path(labelme_annotation_path).stem
...@@ -36,14 +45,18 @@ def convert_labelme_to_yolo(labelme_annotation_path, yolo_directory): ...@@ -36,14 +45,18 @@ def convert_labelme_to_yolo(labelme_annotation_path, yolo_directory):
continue continue
label = shape['label'] label = shape['label']
x1, y1 = shape['points'][0]
x2, y2 = shape['points'][1] # shape['points'] format : [[x1,y1],[x2,y2]...] #
width = x2 - x1 scale_width = 1.0 / labelme_annotation['imageWidth']
height = y2 - y1 scale_height = 1.0 / labelme_annotation['imageHeight']
x_center = (x1 + x2) / 2 width = abs(shape['points'][1][0] - shape['points'][0][0]) * scale_width
y_center = (y1 + y2) / 2 height = abs(shape['points'][1][1] - shape['points'][0][1]) * scale_height
annotation_line = f'{label} {x_center} {y_center} {width} {height}\n' x = min(shape['points'][0][0], shape['points'][1][0]) * scale_width + width / 2
y = min(shape['points'][0][1], shape['points'][1][1]) * scale_height + height / 2
if x+width/2 > 1 or y+height/2>1:
print(f'Error with bounding box values over 1 in file {yolo_image_file}')
annotation_line = f'{label} {x} {y} {width} {height}\n'
yolo_annotation_file.write(annotation_line) yolo_annotation_file.write(annotation_line)
def main(args): def main(args):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment