semlog_vis API¶
semlog_vis.image¶
-
image.cut_object(rgb_image_path, mask_image_path, object_color, saving_path=None, flag_remove_background=False, new_background_color=(255, 255, 255))¶ This function is used to cut a specific object from the pair RGB/mask image.
- Parameters
rgb_image_path – Path to a RGB image.
mask_image_path – Path to a mask image.
object_color – Mask color for the target object
saving_path – Path to save the cropped image.
flag_remove_background – A boolean whether to remvoe the background of the cropped image.
new_background_color – If remove the background, use this color to fill the background.
- Returns
Coordinates of the object in the image.
-
image.load_img_and_mask(img, mask)¶ Load a pair of image and its mask, convert BGR to RGB of the mask image.
-
image.pad_image(img_path, width, height, pad_type, value=(0, 0, 0))¶ Pad the give image with different size and padding type.
- Parameters
img_path – Path of the source image.
width – The target width.
height – The target height.
pad_type – The padding type in cv2.copyMakeBorder.
value – If pad_type=”cv2.Border_CONSTANT”, this value is used as the padding constant color.
- Returns
The processed image.
-
image.remove_image_background(img, mask, mask_color, background_color=(255, 255, 255))¶ Replace the image background with a single color. :param img: The source image. :param mask: The source mask. :param mask_color: Mask color of the object. :param background_color: New background color to be replaced.
- Returns
The new image as ndarray.s
-
image.replace_single_color(img, color, new_color)¶ Replace one color in an image to another color.
- Parameters
img – The source image.
color – The color in the image that you want to replace.
new_color – New color to replace.
- Returns
New image as ndarray.
-
image.resize_all_images(image_dir, width, height, resize_type)¶ Multiprocessing function for resize images.
- Parameters
image_dir – A dict of images to be resized.
width – Target width.
height – Target height.
resize_type – Stretch or sclae depending on the input.
-
image.resize_image(img_path, width='', height='', type='cut')¶ Resize one image.
- Parameters
img_path – Path of the image
width – Target width.
height – Target height.
type – ‘cut’ -> Stretch the image absolutely, otherwise scale the image by width or height.
-
image.scale_image(img_path, ratio)¶ Scale an image with a given ratio.
- Parameters
img_path – Path to the image.
ratio – ratio to scale the image.
semlog_vis.point_cloud¶
-
class
point_cloud.PointCloudGenerator(rgb_file, depth_file, focal_length, scalingfactor)¶ Class for generate point cloud from RGB and depth image pair.
-
calculate(flag_depth_conversion=False)¶ Calculate the 3D position according to the depth data.
-
depthConversion(PointDepth)¶ Adjust the relative depth in UE4.
-
save_npy(path, alpha=False)¶ Save the .npy file of the point cloud.
-
show_point_cloud()¶ Show the point cloud directly with open3d.
-
write_ply(path)¶ Save the point cloud as a .ply file.
-
-
class
point_cloud.PointCloudGenerator(rgb_file, depth_file, focal_length, scalingfactor) Class for generate point cloud from RGB and depth image pair.
-
calculate(flag_depth_conversion=False) Calculate the 3D position according to the depth data.
-
depthConversion(PointDepth) Adjust the relative depth in UE4.
-
save_npy(path, alpha=False) Save the .npy file of the point cloud.
-
show_point_cloud() Show the point cloud directly with open3d.
-
write_ply(path) Save the point cloud as a .ply file.
-
semlog_vis.create_annotation¶
-
create_annotation.clean_df_for_annotation(df)¶ Remove unused columns and create number mapping to classes.
- Parameters
df – Result df from calculate bounding box.
- Returns
Cleaned df. class_mapping_dict: Map class name to number.
- Return type
df
-
create_annotation.convert_df_to_annotation(df, bb_path, mapping_path)¶ Convert a result df to annotation and store data as txt file
- Parameters
df – Result df from calcualte bounding box.
bb_path – path to save bounding box data.
mapping_path – path to save class mapping dict.
-
create_annotation.write_bb_to_txt(result, txt_path)¶ Wrtie bounding boxes to txt file
- Parameters
result – A result df contains bb information.
txt_path – Path to save the data.
-
create_annotation.write_mapping_to_txt(class_mapping_dict, mapping_path)¶ Write mapping dict to txt.
- Parameters
class_mapping_dict – A dict maps class to number.
mapping_path – Path to save the txt file.
Returns:
semlog_vis.bounding_box¶
-
bounding_box.calculate_bounding_box(df, object_rgb_dict, root_folder_path, root_folder_name)¶ Main function for calculate bounding boxes.
- Parameters
df – Information Data Frame.
object_rgb_dict – A dict maps object id to mask colors.
root_folder_path – Root path for images.
root_folder_name – Root folder name.
-
bounding_box.crop_with_all_bounding_box(object_rgb_dict, image_dir)¶ Crop full images with max boundary of all objects.
- Parameters
object_rgb_dict – A dict contains objects and their mask colors.
image_dir – A dict contains all target images
-
bounding_box.download_bounding_box(df, object_rgb_dict, root_folder_path, root_folder_name)¶ Main function for download bounding boxes.
- Parameters
df – Information Data Frame.
object_rgb_dict – A dict maps object id to mask colors.
root_folder_path – Root path for images.
root_folder_name – Root folder name.