@@ -133,7 +133,10 @@ def upload_image_to_project(
133133 break
134134
135135
136- def _copy_images (source_project , destination_project , image_names = None ):
136+ def _copy_images (
137+ source_project , destination_project , image_names , include_annotations ,
138+ copy_annotation_status , copy_pin
139+ ):
137140 source_project , source_project_folder = source_project
138141 destination_project , destination_project_folder = destination_project
139142 if source_project ["id" ] != destination_project ["id" ]:
@@ -158,10 +161,48 @@ def _copy_images(source_project, destination_project, image_names=None):
158161 response .status_code , "Couldn't copy images " + response .text
159162 )
160163
164+ for image_name in image_names :
165+ if include_annotations :
166+ annotations = get_image_annotations (
167+ (source_project , source_project_folder ), image_name
168+ )
169+ if annotations ["annotation_json" ] is not None :
170+ if "annotation_mask" in annotations :
171+ upload_image_annotations (
172+ (destination_project , destination_project_folder ),
173+ image_name , annotations ["annotation_json" ],
174+ annotations ["annotation_mask" ]
175+ )
176+ else :
177+ upload_image_annotations (
178+ (destination_project , destination_project_folder ),
179+ image_name , annotations ["annotation_json" ]
180+ )
181+ if copy_annotation_status or copy_pin :
182+ img_metadata = get_image_metadata (
183+ (source_project , source_project_folder ), image_name
184+ )
185+ if copy_annotation_status :
186+ set_image_annotation_status (
187+ (destination_project , destination_project_folder ),
188+ image_name , img_metadata ["annotation_status" ]
189+ )
190+ if copy_pin :
191+ pin_image (
192+ (destination_project , destination_project_folder ),
193+ image_name , img_metadata ["is_pinned" ]
194+ )
161195 return response .json ()
162196
163197
164- def copy_images (source_project , destination_project , image_names = None ):
198+ def copy_images (
199+ source_project ,
200+ destination_project ,
201+ image_names = None ,
202+ include_annotations = True ,
203+ copy_annotation_status = True ,
204+ copy_pin = True
205+ ):
165206 source_project , source_project_folder = get_project_and_folder_metadata (
166207 source_project
167208 )
@@ -172,7 +213,8 @@ def copy_images(source_project, destination_project, image_names=None):
172213 image_names = search_images ((source_project , source_project_folder ))
173214 res = _copy_images (
174215 (source_project , source_project_folder ),
175- (destination_project , destination_project_folder ), image_names
216+ (destination_project , destination_project_folder ), image_names ,
217+ include_annotations , copy_annotation_status , copy_pin
176218 )
177219 logger .info (
178220 "Copied images %s from %s to %s. Number of skipped images %s" ,
@@ -215,7 +257,14 @@ def delete_images(project, image_names):
215257 logger .info ("Images %s deleted in project %s" , image_names , project ["name" ])
216258
217259
218- def move_images (source_project , destination_project , image_names = None ):
260+ def move_images (
261+ source_project ,
262+ destination_project ,
263+ image_names = None ,
264+ include_annotations = True ,
265+ copy_annotation_status = True ,
266+ copy_pin = True ,
267+ ):
219268 source_project , source_project_folder = get_project_and_folder_metadata (
220269 source_project
221270 )
@@ -226,7 +275,8 @@ def move_images(source_project, destination_project, image_names=None):
226275 image_names = search_images ((source_project , source_project_folder ))
227276 _copy_images (
228277 (source_project , source_project_folder ),
229- (destination_project , destination_project_folder ), image_names
278+ (destination_project , destination_project_folder ), image_names ,
279+ include_annotations , copy_annotation_status , copy_pin
230280 )
231281 delete_images ((source_project , source_project_folder ), image_names )
232282 logger .info (
@@ -308,13 +358,13 @@ def copy_image(
308358 if annotations ["annotation_json" ] is not None :
309359 if "annotation_mask" in annotations :
310360 upload_image_annotations (
311- destination_project , new_name ,
361+ ( destination_project , destination_project_folder ) , new_name ,
312362 annotations ["annotation_json" ],
313363 annotations ["annotation_mask" ]
314364 )
315365 else :
316366 upload_image_annotations (
317- destination_project , new_name ,
367+ ( destination_project , destination_project_folder ) , new_name ,
318368 annotations ["annotation_json" ]
319369 )
320370 if copy_annotation_status :
0 commit comments