refactor: strip EXIF orientation before Gemini analysis for coordinate accuracy
Instead of transforming coordinates after Gemini returns crop_bounds, strip EXIF orientation from image before sending to Gemini. This ensures: - Gemini analyzes the same raw image as our backend - crop_bounds are in raw image coordinate space - No coordinate transformation needed - Works for all images (with or without EXIF) Added strip_exif_orientation() utility that removes orientation tag and re-encodes image. Used in extract_label endpoint before sending to Gemini.
This commit is contained in:
@@ -10,7 +10,7 @@ from slowapi.util import get_remote_address
|
||||
from pathlib import Path
|
||||
from .. import models, schemas, auth
|
||||
from ..database import get_db
|
||||
from ..services.image_processing import ImageProcessor
|
||||
from ..services.image_processing import ImageProcessor, strip_exif_orientation
|
||||
from ..services.image_storage import save_image, get_unique_filename
|
||||
from ..logger import log
|
||||
|
||||
@@ -104,8 +104,12 @@ async def extract_label(
|
||||
detail="File exceeds 10MB limit."
|
||||
)
|
||||
|
||||
log.info(f"[EXTRACT] Sending {len(contents)} bytes to Gemini for analysis")
|
||||
result = extract_label_info(contents, mode=mode)
|
||||
# Strip EXIF orientation so Gemini analyzes raw image (not rotated)
|
||||
# Backend will process the same raw image
|
||||
contents_no_exif = strip_exif_orientation(contents)
|
||||
log.info(f"[EXTRACT] Sending {len(contents_no_exif)} bytes to Gemini (EXIF orientation stripped)")
|
||||
|
||||
result = extract_label_info(contents_no_exif, mode=mode)
|
||||
log.info(f"[EXTRACT] Gemini returned: {type(result).__name__}")
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user