Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import urllib.request
- from PIL import Image
- import numpy as np
- # Provide a project ID and feature ID.
- PROJECT_ID = "clon7uqxl01st073p72a1a8q2"
- feature_id = "clonq7vmq01122a6e9tawqe9s"
- # Create a directory to store the mask images
- output_directory = "masks"
- os.makedirs(output_directory, exist_ok=True)
- # Number of frames (405 in your case)
- num_frames = 405
- # Iterate through each frame and fetch the mask image
- for frame_number in range(1, num_frames + 1):
- mask_url = f"https://api.labelbox.com/api/v1/projects/{PROJECT_ID}/annotations/{feature_id}/index/{frame_number}/mask"
- # Make the API request
- req = urllib.request.Request(mask_url, headers=client.headers)
- # Open the URL and retrieve the image
- image = Image.open(urllib.request.urlopen(req))
- # Check if the mask image is empty (all black)
- mask_data = np.array(image)
- if np.max(mask_data) == 0:
- print(f"Frame {frame_number} has no mask.")
- else:
- # Save the image with the frame number as the filename
- filename = os.path.join(output_directory, f"{frame_number}.png")
- image.save(filename, "PNG")
- print("Mask images saved in the 'masks' directory.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement