1212from os .path import basename
1313from pathlib import Path
1414from urllib .parse import urlparse
15+ import uuid
1516
1617import boto3
1718import cv2
@@ -553,34 +554,30 @@ def create_empty_annotation(size, image_name):
553554
554555
555556def upload_image_array_to_s3 (
556- bucket , size , orig_image , lores_image , huge_image , thumbnail_image , key ,
557- project_type
557+ bucket , img_name , img_name_hash , size , orig_image , lores_image , huge_image ,
558+ thumbnail_image , prefix
558559):
560+ key = prefix + img_name_hash
559561 bucket .put_object (Body = orig_image , Key = key )
560- #TODO: uuid__lores.jpg
561- bucket .put_object (Body = lores_image , Key = key + '___lores.jpg' )
562-
562+ bucket .put_object (Body = lores_image , Key = key + '___lores.jpg' )
563563 bucket .put_object (
564564 Body = huge_image ,
565- #TODO: uuid__huge.jpg
566565 Key = key + '___huge.jpg' ,
567566 Metadata = {
568567 'height' : str (size [1 ]),
569568 'width' : str (size [0 ])
570569 }
571570 )
572571 bucket .put_object (Body = thumbnail_image , Key = key + '___thumb.jpg' )
573- # TODO: remove suffix objects, pixel: save uuid.json
574- postfix_json = '___objects.json' if project_type == "Vector" else '___pixel.json'
575572 bucket .put_object (
576- Body = json .dumps (create_empty_annotation (size ,
577- Path (key ).name )),
578- Key = key + postfix_json
573+ Body = json .dumps (create_empty_annotation (size , img_name )),
574+ Key = key + ".json"
579575 )
576+ return key
580577
581578
582579def get_image_array_to_upload (
583- byte_io_orig , image_quality_in_editor , project_type
580+ img_name , byte_io_orig , image_quality_in_editor , project_type
584581):
585582 if image_quality_in_editor not in ["original" , "compressed" ]:
586583 raise SABaseException (0 , "NA ImageQuality in get_image_array_to_upload" )
@@ -634,7 +631,8 @@ def get_image_array_to_upload(
634631 byte_io_huge .seek (0 )
635632 byte_io_orig .seek (0 )
636633
637- return (
634+ img_name_hash = str (uuid .uuid4 ()) + Path (img_name ).suffix
635+ return img_name , img_name_hash , (
638636 width , height
639637 ), byte_io_orig , byte_io_lores , byte_io_huge , byte_io_thumbs
640638
@@ -700,23 +698,32 @@ def __upload_images_to_aws_thread(
700698 __create_image (uploaded_imgs , project , annotation_status , prefix )
701699
702700
703- def __create_image (img_paths , project , annotation_status , remote_dir ):
704- # print("Creating images ", len(img_paths))
701+ def __create_image (
702+ img_names , img_paths , project , annotation_status , remote_dir , size
703+ ):
705704 if len (img_paths ) == 0 :
706705 return
707706 team_id , project_id = project ["team_id" ], project ["id" ]
708707 data = {
709708 "project_id" : str (project_id ),
710- "team_id" : str (team_id )
711- "images" : [],
712- "annotation_status" : annotation_status
713- #TODO: {image_name: {heigh, width, annotation_path})
714- # "meta": {"a.jpg": {"height":78, "width":56, "annotation_json_path": "remote_path/a_uuid.json" }, "b.jpg": {"height":78, "width":56, "annotation_json_path": "remote_path/b_uuid.json" } }
709+ "team_id" : str (team_id ),
710+ "images" : [],
711+ "annotation_status" : annotation_status ,
712+ "team_id" : str (team_id ),
713+ "images" : [],
714+ "annotation_status" : annotation_status ,
715+ "meta" : {}
715716 }
716- for img_path in img_paths :
717- img_name = Path (img_path ).name
718- remote_path = remote_dir + f"{ img_name } "
717+ for img_name , img_path in zip ( img_names , img_paths ) :
718+ img_name_uuid = Path (img_path ).name
719+ remote_path = remote_dir + f"{ img_name_uuid } "
719720 data ["images" ].append ({"name" : img_name , "path" : remote_path })
721+ data ["meta" ][img_name ] = {
722+ "width" : size [0 ],
723+ "height" : size [1 ],
724+ "annotation_json_path" : remote_path + ".json" ,
725+ "annotation_bluemap_path" : remote_path + ".png"
726+ }
720727
721728 response = _api .send_request (
722729 req_type = 'POST' , path = '/image/ext-create' , json_req = data
@@ -727,7 +734,7 @@ def __create_image(img_paths, project, annotation_status, remote_dir):
727734 )
728735
729736
730- o_project (
737+ def upload_images_to_project (
731738 project ,
732739 img_paths ,
733740 annotation_status = "NotStarted" ,
@@ -1655,7 +1662,7 @@ def _upload_preannotations_from_folder_to_project(
16551662 annotation_classes_dict = get_annotation_classes_name_to_id (
16561663 annotation_classes
16571664 )
1658-
1665+
16591666 response = _api .send_request (
16601667 req_type = 'GET' ,
16611668 path = f'/project/{ project_id } /preannotation' ,
0 commit comments