scripts.processing.gemini_classify

Gemini Classification + Rotation Script

Replaces the traditional pipeline steps (empty detection, identifier classification, handwritten/printed classification, rotation correction) with a single Gemini API call per specimen image.

For each specimen image: 1. Reads detection results (bounding boxes) from the detection CSV 2. Sends the full image + bounding boxes to Gemini 3. Gets per-label: category (empty/identifier/printed/handwritten/mixed) + rotation angle 4. Rotates labels locally using OpenCV 5. Saves classified images into category subdirectories and rotation metadata

Usage:

python gemini_classify.py -i <input_dir> -o <output_dir> -d <detection_csv> python gemini_classify.py -i <input_dir> -o <output_dir> # SLI mode (no detection)

Functions

load_detection_results(csv_path)

Load detection bounding boxes grouped by source filename.

main()

parse_arguments()

Parse command-line arguments.

process_sli_image(image_path, client, model)

Process a single pre-cropped label image (SLI mode).

save_rotated_label(image, bbox, angle, ...)

Crop label region from the full image, rotate it, and save to category dir.