Commit c9c76b6d authored by Matt Clarkson's avatar Matt Clarkson

Merge branch '4-fix-download'

parents b7a381af 1d19326b
Pipeline #4619 failed with stages
in 35 seconds
......@@ -31,6 +31,7 @@ def run_labelbox_json_export(json_file, output_dir, output_format):
for sample in decoded_data:
dataset_name = sample['Dataset Name']
external_id = sample['External ID']
labeled_data = sample['Labeled Data']
basename = os.path.basename(external_id)
filename_no_extension = os.path.splitext(basename)[0]
objects = sample['Label']['objects']
......@@ -39,10 +40,25 @@ def run_labelbox_json_export(json_file, output_dir, output_format):
if not os.path.exists(dir_name):
os.makedirs(dir_name)
images_name = os.path.join(dir_name, 'images')
if not os.path.exists(images_name):
os.makedirs(images_name)
image_file = os.path.join(images_name,
external_id)
if not os.path.exists(image_file):
six.print_("downloading image to:" + image_file)
urllib.request.urlretrieve(labeled_data, image_file)
masks_name = os.path.join(dir_name, 'masks')
if not os.path.exists(masks_name):
os.makedirs(masks_name)
for obj in objects:
instance_uri = obj['instanceURI']
value = obj['value']
file_name = os.path.join(dir_name,
file_name = os.path.join(masks_name,
filename_no_extension
+ '_' + value + '.bmp')
......@@ -55,26 +71,28 @@ def run_labelbox_json_export(json_file, output_dir, output_format):
else:
if output_format == 'grey':
file_name = os.path.join(dir_name,
filename_no_extension
+ '_' + value + '.png')
output_file_name = os.path.join(masks_name,
filename_no_extension
+ '_' + value + '.png')
if not os.path.exists(file_name):
if os.path.exists(file_name) and \
not os.path.exists(output_file_name):
image = cv2.imread(file_name)
grey = cv2.cvtColor(image, cv2.COLOR_BGRA2GRAY)
cv2.imwrite(file_name, grey)
six.print_("writing to:" + file_name)
cv2.imwrite(output_file_name, grey)
six.print_("writing to:" + output_file_name)
elif output_format == 'rgb':
file_name = os.path.join(dir_name,
filename_no_extension
+ '_' + value + '.png')
output_file_name = os.path.join(dir_name,
filename_no_extension
+ '_' + value + '.png')
if not os.path.exists(file_name):
if os.path.exists(file_name) and \
not os.path.exists(output_file_name):
image = cv2.imread(file_name)
rgb = cv2.cvtColor(image, cv2.COLOR_BGRA2BGR)
cv2.imwrite(file_name, rgb)
six.print_("writing to:" + file_name)
cv2.imwrite(output_file_name, rgb)
six.print_("writing to:" + output_file_name)
six.print_("Done")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment