palletdatagenerator.modes.base_generator module

Base generator class that contains shared functionality for all generation modes. Provides common methods for scene setup, rendering, and data export.

class palletdatagenerator.modes.base_generator.BaseGenerator(config)[source]

Bases: object

Base class for all generation modes with shared functionality.

__init__(config)[source]
setup_folders()[source]

Create the output folder structure.

configure_render()[source]

Configure Blender render settings.

setup_compositor_nodes()[source]

Setup compositor nodes for depth, normals, and index passes.

setup_environment()[source]

Setup world background and floor.

setup_random_background()[source]

Setup world background exactly as in original.

create_floor_plane()[source]

Create floor plane exactly as in original.

randomize_object_material(obj)[source]

Randomize object materials if enabled.

draw_3d_bbox_edges(draw, corners_2d, color, width=2)[source]

Draw 3D bounding box wireframe.

project_points_accurate(points, cam, sc)[source]

Project 3D points to 2D screen coordinates.

create_analysis_image_multi(rgb_path, bboxes2d, bboxes3d, all_pockets_world, cam_obj, sc, output_path, frame_id, keypoints_data=None)[source]

Create analysis image with 2D/3D bounding boxes, holes, and legend. Exact copy from original one_pallet_generator.py

create_random_lights(anchor_obj, replace_existing=False)[source]

Create 1..N random lights around anchor_obj. Also ensures at least one neutral β€˜key’ light when requested. EXACT implementation from original one_pallet_generator.py

get_bbox_2d_accurate(obj, cam, sc)[source]

Get accurate 2D bounding box - EXACT from original.

bbox_3d_oriented(obj)[source]

Get 3D oriented bounding box - EXACT from original.

project_points(points, cam, sc)[source]

Project 3D points to 2D screen coordinates - EXACT from original.

hole_bboxes_3d(obj, side_margin=0.08, _gap=0.15, hole_height=(0.2, 0.85))[source]

Generate 3D hole/pocket bounding boxes for pallet - EXACT from original.

auto_expose_frame(sc, _cam_obj)[source]

Enhanced auto-exposure with minimum brightness guarantee.

detect_faces_in_scene(cam_obj, sc)[source]

Detect faces in the scene by looking for pallet objects and extracting their faces. Uses the pallet’s 3D bounding box to define 6 faces and generate keypoints for each visible face.

get_all_faces_from_bbox()[source]

Get all 6 faces from 3D bounding box corners. Returns list of face data with corner indices and names.

filter_side_faces(all_faces, corners_3d)[source]

Filter out top and bottom faces by analyzing Z coordinates. Returns only the 4 side faces.

create_3d_debug_visualization(obj, cam_obj, frame_id)[source]

Create a 3D visualization showing camera position, pallet corners, and face names. Saves the visualization to a new debug folder.

create_3d_debug_visualization_with_faces(obj, cam_obj, frame_id, selected_faces)[source]

Create a 3D visualization showing camera position, pallet corners, face names, and selected faces. Saves the visualization to the debug_3d folder.

select_faces_by_camera_proximity(visible_faces, cam_obj)[source]

Select faces based on camera proximity using nearest point distance. Returns 1-2 faces: first the nearest face, then an adjacent candidate if available.

check_faces_adjacent(face1, face2, tolerance=0.1)[source]

Check if two faces are truly adjacent (side-by-side), NEVER parallel. Uses strict geometric analysis to ensure only side-by-side faces are selected.

check_2d_middle_view(face1, face2)[source]

Check if both faces are in the middle view of the 2D bounding box. Middle view = within 50% of the box size from center.

check_geometric_adjacency_only(face1, face2, tolerance=0.1)[source]

Check if two faces are geometrically adjacent (only geometric validation, no 2D check). This is used as a fallback when the full adjacency check fails.

check_2d_surface_quality(face, image_width=1024, image_height=768, min_area=2000, min_width=30, min_height=30)[source]

Check if a face has sufficient 2D surface quality to be selected as a candidate.

Parameters:
  • face – Face data containing bbox_2d

  • image_width – Width of the rendered image

  • image_height – Height of the rendered image

  • min_area – Minimum 2D bounding box area in pixels

  • min_width – Minimum width in pixels

  • min_height – Minimum height in pixels

Returns:

True if the face has good 2D surface quality, False otherwise

check_face_behind_primary(primary_face, candidate_face)[source]

Check if the candidate face has points between the primary face’s points, which indicates the candidate is behind the camera view.

Parameters:
  • primary_face – The primary selected face

  • candidate_face – The candidate face to check

Returns:

True if candidate is behind primary (should be eliminated), False otherwise

detect_overlapping_keypoints(all_keypoints, keypoints_data, threshold=10)[source]

Detect keypoints that are overlapping (within threshold pixels). Returns groups of overlapping keypoints with face data.

draw_overlapping_keypoint_circles(draw, overlap_group, x, y)[source]

Draw overlapping keypoints with both colors (one inside the other). The face with smaller perimeter gets the inner color.

draw_single_keypoint_labels(draw, font, kp, x, y, radius, color_text)[source]

Draw labels for a single keypoint.

draw_overlapping_keypoint_labels(draw, font, overlap_group, x, y, radius)[source]

Draw stacked labels for overlapping keypoints.

calculate_face_normal(face_corners_3d)[source]

Calculate the normal vector of a face from its 4 corners.

generate_keypoints_for_frame(cam_obj, sc, frame_id=None)[source]

Generate keypoints for all faces detected in the current frame.

generate_face_2d_boxes(selected_faces, frame_id, img_width, img_height)[source]

Generate 2D bounding boxes for selected faces in YOLO format.

generate_face_3d_coordinates(selected_faces, frame_id, img_width, img_height)[source]

Generate 3D coordinates for selected faces in YOLO format.

create_interactive_3d_figure(corners_3d, camera_pos, selected_faces, frame_id, output_path)[source]

Create an interactive 3D figure using plotly that can be opened and manipulated in a browser.

generate_face_keypoints(face_data, cam_obj, sc)[source]

Generate 6 keypoints for a pallet face: 4 corners of the 3D face + 2 middle points (top and bottom center). Uses the actual face corners and calculates middle points between them.

check_keypoint_visibility(keypoint_3d, cam_obj, sc)[source]

Check if a keypoint is visible by performing ray casting from camera to keypoint. Returns True if no obstacles are blocking the line of sight.

save_keypoints_labels(keypoints_data, frame_id, img_w, img_h)[source]

Save keypoints labels in YOLO format to the keypoints_labels folder. Format: class_id x_center y_center width height kp1_x kp1_y kp1_v kp2_x kp2_y kp2_v …