Commit Graph

11 Commits

Author SHA1 Message Date
bc2a6219fe 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.
2026-04-22 10:29:11 +03:00
1425856af5 fix: transform crop_bounds from EXIF-applied to raw image space
Gemini analyzes images with EXIF orientation applied (e.g., 90° CW rotation),
returning crop_bounds in that coordinate space. We need to transform them back
to raw image coordinates before cropping.

For EXIF orientation 6 (Rotate 90 CW):
- Raw: 4032×3024 (landscape)
- Displayed (after EXIF): 3024×4032 (portrait)
- Transform portrait coords back to landscape before cropping

This fixes the issue where crop was applied to wrong image region.
2026-04-22 10:25:44 +03:00
4e23899f87 fix: remove negation from rotation to match prompt semantics
New prompt defines rotation_degrees as already signed:
- positive = counter-clockwise rotation
- negative = clockwise rotation

Old code negated it: rotate(-rotation_degrees), which inverted the direction.
Now: rotate(rotation_degrees) directly uses Gemini's signed value.
2026-04-22 10:06:29 +03:00
92c8517663 debug: add explicit logging to show crop bounds and rotation values 2026-04-22 09:55:53 +03:00
197dcadfee fix: apply crop bounds before EXIF rotation to match AI analysis
Gemini analyzes raw image and returns crop_bounds for that coordinate space.
Previous code applied EXIF rotation first, changing image dimensions, then
used crop_bounds on the rotated image (coordinate mismatch).

Now: crop on raw image (matches AI) → then apply EXIF + manual rotation.
This ensures cropped region contains the actual item, not background.
2026-04-22 09:50:08 +03:00
a2847092ac debug: add detailed logging to image processing pipeline
- Log input image size, crop bounds, and rotation degrees
- Log crop rectangle coordinates and result size
- Log OpenCV smart crop success/failure details
- Track pixel count to detect zero-size crops
2026-04-22 09:23:51 +03:00
e5615826d6 Revert "fix: apply rotation before cropping for better text orientation"
This reverts commit f8e54d0f8b.
2026-04-22 09:02:22 +03:00
f8e54d0f8b fix: apply rotation before cropping for better text orientation
- Move manual rotation before cropping and text detection
- Detect text orientation on full rotated image (not just cropped region)
- This allows text angle detection to see full context and properly orient labels
- Crop happens after orientation correction for cleaner results
2026-04-22 08:58:17 +03:00
64d177e791 fix: complete image pipeline - rotation, URL, preview
- Add rotation_degrees parameter to ImageProcessor.process_photo()
- Pass rotation through _auto_save_photo_from_extraction() to processor
- Allow no-crop fallback when crop_bounds is None
- Add buildPhotoUrl() helper to resolve backend URLs correctly
- Update frontend components to use backend URL for image sources
- Replace Use/Skip Photo buttons with checkbox in AI extraction UI
- Add images/ to .gitignore to prevent accidental commits

Addresses: rotation never applied, image 404s (relative to Next.js not backend), preview blank in edit form
2026-04-22 08:50:25 +03:00
8d2750cfa3 fix(phase1): fix deprecated PIL APIs, private API, exception handling, magic numbers, transparency, DoS prevention 2026-04-20 22:21:51 +03:00
3aafacab12 feat(phase1): implement OpenCV image processing pipeline
- Create ImageProcessor service with EXIF orientation detection
- Implement smart cropping via OpenCV contour detection (10% padding)
- Add text orientation detection using Hough line transform
- Resize and compress images to 1200px with 85% JPEG quality
- Generate 200px square thumbnails with center crop
- Fallback to Pillow if OpenCV fails
- Comprehensive test suite: 28 tests all passing
- File size validation (reject >10MB)
- Graceful error handling for corrupted/invalid images
- Update requirements.txt with opencv-python, piexif, python-magic
2026-04-20 22:17:11 +03:00