improve: add rotation bounds and error detection to AI prompt

- Cap normal rotation to -45 to +45 degrees (flags errors beyond)
- Add explicit warning about 60°+ being measurement error
- Clarify 'safe default' is 0 if uncertain
- Prevent Gemini from wild angle guesses (like 110°)
- Help AI self-correct measurement errors
This commit is contained in:
2026-04-22 09:44:28 +03:00
parent 1e7dd064f9
commit 70a08ae1e9

View File

@@ -90,26 +90,30 @@
- Include minimal padding (10-15 pixels) around item edges - Include minimal padding (10-15 pixels) around item edges
- Ignore background clutter, other items, hands, reflections - Ignore background clutter, other items, hands, reflections
### Rotation Analysis (CRITICAL - MEASURE TEXT ANGLE) ### Rotation Analysis (CRITICAL - PRECISE TEXT ANGLE MEASUREMENT)
**PRIORITY: Measure text orientation, not item orientation** **IMPORTANT: Return SMALL angles (typically -45 to +45). Large angles (60°+) indicate measurement error.**
1. **Locate readable text** on the item (part numbers, manufacturer names, specifications, labels) **Algorithm:**
2. **Measure the baseline angle of that text**: 1. Locate the PRIMARY text/label on the item (part number, manufacturer, specs)
- Baseline = the invisible line the text sits on 2. Imagine a perfectly horizontal line (0°)
- 0° = text baseline is HORIZONTAL (readable left-to-right) 3. Measure how many degrees the text baseline is rotated FROM horizontal:
- Positive degrees = text rotated counter-clockwise from horizontal - Count degrees counter-clockwise = POSITIVE value to return
- Negative degrees = text rotated clockwise from horizontal - Count degrees clockwise = NEGATIVE value to return
3. **Return clockwise rotation needed to make text horizontal**: - LIMIT: Most items need -45° to +45°. If you calculate ±60° or more, re-examine your measurement.
- If text tilted 22° counter-clockwise → return `+22` (rotate 22° clockwise to fix)
- If text tilted 15° clockwise → return `-15` (rotate 15° counter-clockwise to fix) 4. **Return exactly this value as `rotation_degrees`**
- If text already horizontal → return `0` - SMALL adjustments: 0° to ±30° (most common)
4. **Calibration examples** (measure the text angle precisely): - LARGE adjustments: ±31° to ±45° (rare, carefully verify)
- Text reads perfectly left-to-right → `rotation_degrees: 0` - EXTREME values (±60°+): Likely error — recalculate or return 0
- Text tilted counter-clockwise, needs ~22° clockwise to straighten → `rotation_degrees: 22`
- Text vertical, pointing left (rotated 90° counter-clockwise) → `rotation_degrees: 90` **Measurement examples** (measure the TEXT BASELINE angle only):
- Text vertical, pointing right (rotated 90° clockwise) → `rotation_degrees: -90` - Text reads horizontally → `0`
- Text tilted clockwise by ~45° → `rotation_degrees: -45` - Text tilted slightly left (counter-clockwise), ~15-25° → `+15` to `+25` (NOT higher)
- Text tilted slightly right (clockwise), ~10-20° → `-10` to `-20` (NOT lower)
- Text perfectly vertical pointing left → `90` (only if TRULY vertical)
- Text perfectly vertical pointing right → `-90` (only if TRULY vertical)
- If uncertain or mixed angles → `0` (safe default)
### Confidence Score ### Confidence Score
- Return `confidence`: 0.0-1.0 indicating reliability of crop/rotation analysis - Return `confidence`: 0.0-1.0 indicating reliability of crop/rotation analysis