refactor: rotation analysis to handle any photo angle
Real-world photos come at ANY angle - upside down, sideways, at weird tilts. Stop assuming small angles. Instead: - Measure CURRENT text orientation (horizontal/vertical/upside-down/tilted) - Calculate rotation needed to make it READABLE in standard English - Allow full -180° to +180° range - No artificial limits or assumptions about how operator took the photo Examples: vertical text → ±90°, upside-down → ±180°, tilted → measure tilt This gives Gemini freedom to analyze real-world messy photos correctly.
This commit is contained in:
@@ -90,30 +90,32 @@
|
||||
- Include minimal padding (10-15 pixels) around item edges
|
||||
- Ignore background clutter, other items, hands, reflections
|
||||
|
||||
### Rotation Analysis (CRITICAL - SMALL TILT ANGLE MEASUREMENT)
|
||||
### Rotation Analysis (CRITICAL - MAKE TEXT READABLE IN STANDARD ENGLISH)
|
||||
|
||||
**IMPORTANT: The image has EXIF orientation metadata stripped. Analyze it in its RAW/NATIVE state.**
|
||||
**IMPORTANT: Photos may be at ANY angle. Your job: return the rotation angle to make the TEXT readable in standard English (horizontal, left-to-right, top-to-bottom).**
|
||||
|
||||
**Return the SMALL tilt angle needed to make the text perfectly horizontal and readable.**
|
||||
**The image has EXIF orientation metadata stripped. Analyze it in its RAW/NATIVE state. Measure how much to rotate the image so that the PRIMARY label text reads normally.**
|
||||
|
||||
**Algorithm:**
|
||||
1. Locate the PRIMARY text/label on the item (part number, manufacturer, specs)
|
||||
2. **Measure ONLY the tilt angle**: How many degrees is the text rotated from horizontal?
|
||||
- Text reads horizontally left-to-right → `0°`
|
||||
- Text tilted slightly clockwise (right side up) → **negative angle** (e.g., `-15°`)
|
||||
- Text tilted slightly counter-clockwise (left side up) → **positive angle** (e.g., `+20°`)
|
||||
3. **IGNORE text orientation** (vertical/sideways): The image is in raw/native state, so text orientation is simply directional tilt, not a 90° shift
|
||||
4. **Return this tilt angle as `rotation_degrees`** (expected range: **-45° to +45°**)
|
||||
- Clockwise tilt = NEGATIVE value (e.g., `-22°` to level a clockwise tilt)
|
||||
- Counter-clockwise tilt = POSITIVE value (e.g., `+18°` to level a counter-clockwise tilt)
|
||||
2. Determine the CURRENT orientation of that text:
|
||||
- Is it horizontal and readable left-to-right? → rotation needed: `0°`
|
||||
- Is it rotated 90° (vertical, pointing up)? → rotation to horizontal: `-90°` or `+90°` (depending on which way)
|
||||
- Is it rotated 180° (upside down)? → rotation to horizontal: `±180°`
|
||||
- Is it tilted at an angle? → measure exact tilt needed to make it horizontal
|
||||
3. **Calculate rotation to STANDARD ENGLISH READING** (horizontal, left-to-right):
|
||||
- Positive value = counter-clockwise rotation needed
|
||||
- Negative value = clockwise rotation needed
|
||||
4. **Return any value in range -180° to +180°** (full circle allowed)
|
||||
|
||||
**Measurement examples** (RAW image, EXIF-stripped, measuring ONLY tilt):
|
||||
- Text reads perfectly horizontal → `0`
|
||||
- Item tilted 22° clockwise (text tilts down-right) → `-22`
|
||||
- Item tilted 15° counter-clockwise (text tilts up-left) → `+15`
|
||||
- Item slightly rotated 5° → `-5` or `+5` depending on direction
|
||||
- **SAFETY CHECK**: If your calculated angle is > ±45°, re-examine. Most hardware is only slightly tilted in photos (±30° max)
|
||||
- If uncertain → `0` (safe default; OpenCV fallback will handle it)
|
||||
**Measurement examples** (make text readable left-to-right, top-to-bottom):
|
||||
- Text already reads normally horizontally → `0°`
|
||||
- Text is vertical, pointing up (90° rotated) → `-90°` (rotate clockwise to make horizontal)
|
||||
- Text is vertical, pointing down (270° rotated) → `+90°` (rotate counter-clockwise)
|
||||
- Text is upside-down (180° rotated) → `+180°` or `-180°` (rotate half-circle)
|
||||
- Text at 22° angle (tilted right) → `-22°` (rotate clockwise to level)
|
||||
- Text at -35° angle (tilted left) → `+35°` (rotate counter-clockwise to level)
|
||||
- **No angle limit**: Photos may be taken at any angle. Return whatever rotation makes the label text readable in standard English orientation.
|
||||
|
||||
### Confidence Score
|
||||
- Return `confidence`: 0.0-1.0 indicating reliability of crop/rotation analysis
|
||||
|
||||
Reference in New Issue
Block a user