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.
- 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
- 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.