Commit Graph

432 Commits

Author SHA1 Message Date
dba47aa656 feat: make crop box interactive in debug panel
- Add drag-to-move functionality for entire crop box
- Add resize handles at corners (drag to resize)
- Show adjusted bounds separately from AI bounds in log
- Add Reset button to revert to original crop bounds
- Allows visual verification of AI crop detection accuracy
2026-04-22 11:47:13 +03:00
11f0634721 fix: add rotation direction indicators and fix CORS for dev origins
- Add TOP/BTM labels to rotated box showing which edge is which after rotation
- Allows user to visually see rotation direction without calculating degrees
- Fix allowedDevOrigins to include common private IP ranges (192.168.*, 10.*, 172.16.*)
- Resolves CORS warning when accessing from local network IPs
2026-04-22 11:38:32 +03:00
0cff09ccd0 docs: final SESSION_STATE for v1.14.5 - Complete debug panel 2026-04-22 11:33:46 +03:00
1fca9b5ff7 feat: add orientation indicators to debug panel
- Display UP/DOWN/LEFT/RIGHT labels at canvas edges
- Shows which direction is which in the original image
- Helps verify rotation correctness visually
2026-04-22 11:33:37 +03:00
7c493c656a fix: remove dark overlay from debug panel crop visualization
- Removed black overlay that was hiding the image
- Draw crop box directly on full-brightness image with drop shadow
- Item under crop area now fully visible
- Improved visibility of both crop bounds (green) and rotation (orange)
2026-04-22 11:27:16 +03:00
7bd03864b5 docs: update SESSION_STATE with debug panel improvements 2026-04-22 11:21:57 +03:00
82948ada92 fix: improve debug panel layout and log display
- Clear logs between rotation updates (no more expanding text)
- Increase canvas size from 600x450 to 900x600 for better visibility
- Reorganize layout: left controls, right canvas + single-line log
- Make crop box much larger and easier to see
2026-04-22 11:20:43 +03:00
36e721e742 docs: update VERSION and SESSION_STATE for v1.14.5 - Original Image Storage 2026-04-22 11:15:05 +03:00
c46c8414b8 feat: store original EXIF-stripped image for debugging
- Save original image before crop/rotation with '_debug_original' variant
- Store original_photo_path in labels_data.image_processing for debug access
- Update DebugRotationPanel to display original image instead of processed
- Update ItemDetailModal to pass original image path to debug panel
- Enables accurate crop/rotation visualization with true original image
2026-04-22 11:13:09 +03:00
9f65d427a0 optimize: make debug panel more compact to fit screen
Layout changes:
- Reduced padding and margins throughout
- Changed from 3-column to 2-column layout
- Canvas + logs on right side (side-by-side)
- Smaller fonts and spacing
- Sticky header that stays in view
- Max-height with scrolling for modal
- Removed footer text to save space
- More efficient use of screen real estate

Now fits on most screen sizes even with large rotation angles.
2026-04-22 11:08:49 +03:00
f708fb7768 refactor: redesign debug panel with overlay visualization
Much better UX for identifying correct rotation:

- Shows ORIGINAL image scaled to fit the modal
- Draws GREEN bounding box showing the crop area
- Draws ORANGE rotated rectangle showing rotation effect
- Darkens everything outside the crop area (visual focus)
- Rotation slider updates the overlay in real-time
- Quick preset buttons for common angles
- Detailed debug logs showing all calculations
- Better styling: dark theme for readability

User can now visually see what will be extracted with the current
rotation angle. Report the angle that makes the label readable.
2026-04-22 11:06:01 +03:00
1a774088a1 feat: add debug rotation panel for real-time testing
New DebugRotationPanel component allows testing different rotation angles
with live preview and detailed debug logs showing:
- Current rotation angle (slider + quick presets)
- Crop bounds and calculations
- Image dimensions at each step
- Final processed image preview
- Confidence score

Integrated into ItemDetailModal via wrench icon in header (only visible
when item has a photo). Helps identify correct rotation values for images
at any angle.

Debug panel shows:
- Original image info
- Crop bounds and resulting size
- Rotation angle and final canvas size
- Step-by-step processing logs
- Live canvas preview of result
2026-04-22 10:56:27 +03:00
f6d91c92b6 clarify: rotation must optimize for PRIMARY label when multiple zones exist
Items often have multiple labels/zones at different orientations:
- Main label with part number, specs (PRIMARY)
- Vendor logos or small text (secondary)
- Barcodes at odd angles

Instruction: Always optimize rotation for the PRIMARY label (most text),
ignore secondary/vendor labels that conflict in orientation.

Examples added showing how to handle items with multiple label zones.
2026-04-22 10:45:00 +03:00
e86f3fa299 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.
2026-04-22 10:42:30 +03:00
8091cf8802 refine: clarify rotation analysis for EXIF-stripped raw images
Key changes:
- Explicitly state image has EXIF orientation stripped (raw/native state)
- Return ONLY the tilt angle, not orientation shifts
- Expect small angles (-45° to +45°), not large ones
- Add safety check: if angle > 45°, likely measurement error
- Simplify examples to show tilt-only measurement

This ensures Gemini returns consistent, sane rotation values regardless
of the item or how the photo was taken, without needing local offsets.
2026-04-22 10:39:23 +03:00
500d090dfc fix: strip EXIF from image blob in backend before processing
Backend receives the original blob which may have EXIF orientation metadata.
Strip it before processing to ensure backend analyzes the same raw image space
that Gemini analyzed (which had EXIF stripped before sending).

This ensures rotation_degrees are applied correctly to the same image state.
2026-04-22 10:32:38 +03:00
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
ee1fcfbee6 fix: remove duplicate log imports in create_item function 2026-04-22 10:17:34 +03:00
79d8a71c97 fix: import log at module level for extraction logging 2026-04-22 10:15:25 +03:00
9586aecfdc debug: log file sizes at extraction and processing stages
Add logging to compare file sizes:
- [EXTRACT] sent to Gemini
- [CREATE_ITEM] received when creating item

This will reveal if image is being processed/changed between extraction and local processing.
2026-04-22 10:14:03 +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
2546f8abbe refine: clarify rotation analysis to account for text orientation + tilt
Previous prompt only measured text baseline angle from horizontal (-45° to +45°),
missing that text can be vertical/sideways, requiring larger rotations (up to ±180°).

New guidance:
- Measure TOTAL rotation needed to make text horizontal and readable
- Account for both chassis tilt AND text orientation (horizontal vs vertical)
- Example: 22° tilt + 90° vertical text = 112° total rotation
- Allows full -180° to +180° range instead of limiting to ±45°

No changes to item identification fields, OCR rules, or crop bounds analysis.
2026-04-22 10:01:03 +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
59565c9b8a improve: comprehensive process cleanup in startup script
- Add -9 (force kill) flag to all pkill commands
- Kill Python backend processes explicitly
- Kill npm and node processes
- Use fuser to kill processes bound to ports 8000, 3001, 3002, 3003
- Add 1 second wait after cleanup
- Ensures absolutely clean state before restart
2026-04-22 09:45:50 +03:00
70a08ae1e9 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
2026-04-22 09:44:28 +03:00
1e7dd064f9 improve: clarify rotation detection in AI extraction prompt
- Emphasize MEASURING TEXT ANGLE precisely, not item orientation
- Add explicit calibration examples (22°, 90°, -45°, etc.)
- Clarify positive = counter-clockwise, negative = clockwise
- Help AI understand baseline measurement concept
- Keep all field identification rules unchanged
2026-04-22 09:40:40 +03:00
8d9e8998f8 fix: clean shutdown handling in start_server.sh
- Add signal traps for SIGINT (Ctrl-C) and SIGTERM
- Cleanup function kills all child processes gracefully
- Script now exits cleanly without hanging
- Users can press Ctrl-C to stop all services at once
2026-04-22 09:33:43 +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
ba581744ec refactor: improve checkbox styling and remove popup
- Update photo save checkbox to match app design (border-slate-600, htmlFor label)
- Remove success popup overlay - modal closes immediately after save
- Simplify confirmSingleItem to remove setTimeout logic
- Toast notification used for user feedback instead
2026-04-22 09:17:56 +03:00
99a4cae572 fix: show item save confirmation with image before closing
- Add savingIndex state to track saving operation
- Display success overlay with saved image for 1.5 seconds
- Show item name in confirmation message
- Prevents modal from closing immediately after save

Fixes user complaint about image disappearing too quickly without confirmation
2026-04-22 09:07:44 +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
09a66bd3d5 feat: clean up image files when item is deleted from catalog
- Delete photo_path and photo_thumbnail_path files on item deletion
- Handle file not found gracefully with logging
- Preserves audit logs while removing actual image files
2026-04-22 08:54:22 +03:00
092271790c docs: update VERSION and SESSION_STATE for v1.14.4 - Image Pipeline Complete 2026-04-22 08:51:04 +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
1c13ebd76f docs: update VERSION and SESSION_STATE for v1.14.3 - Image Confirmation UX
Documented the complete image pipeline feature:
- v1.14.1: Type system fix (photo_path fields)
- v1.14.2: Serialization fix (Blob to base64)
- v1.14.3: User control (image confirmation buttons)

Users now have full control over whether extracted photos are auto-saved
through the 'Use Photo' / 'Skip Photo' buttons in the editing form.
2026-04-21 20:01:28 +03:00
c3f63ade6a feat: add image confirmation step to AI extraction flow
Users now see the extracted photo during item editing and can choose to:
- 'Use Photo': Auto-save the image with the item
- 'Skip Photo': Create item without saving the photo

Changes:
1. frontend/components/AIOnboarding.tsx: Added image preview panel in edit form
   - Shows extracted image to user
   - Buttons to accept/reject photo
   - Visual feedback when photo is skipped

2. frontend/hooks/useAIExtraction.ts: Updated confirmSingleItem and confirmAllItems
   - Respect user's photo decision (_skipPhoto flag)
   - Only pass extractedImageBlob if user approved it
   - Prevents unwanted auto-photo-save

This gives users full control over which extracted photos are auto-saved.
2026-04-21 20:00:55 +03:00
c95e4c40b8 docs: update VERSION and SESSION_STATE for v1.14.2 - Blob serialization fix
Documented the complete image pipeline bugfix:
- Part 1 (v1.14.1): Type system mismatch for photo_path fields
- Part 2 (v1.14.2): Blob serialization issue - image not reaching backend

The extracted image blob is now converted to base64 before sending to the API,
ensuring it's JSON-safe and matches the backend's ItemCreate schema.
2026-04-21 19:54:24 +03:00
cbfd7232ca fix: convert extracted image blob to base64 before sending to API
The extracted image blob from AI extraction was not being sent to the backend
because Blob objects cannot be JSON serialized. Fixed by:

1. Converting Blob to base64 before sending to API
2. Renaming fields: extractedImageBlob → extracted_image_bytes, imageProcessing → image_processing
3. Removing Blob from local DB (keep original data structure for IndexedDB)
4. Applying same fix to both single item and batch update flows

This ensures the auto-photo-save feature receives the image data it needs.
2026-04-21 19:53:53 +03:00
f72b976c33 docs: update SESSION_STATE for Session 29 - Image Display Bugfix
Documented the image display issue, root cause (type system mismatch),
and the fix applied in v1.14.1. Images now correctly display from
the auto-photo-save feature in both ItemDetailModal and InventoryTable.
2026-04-21 19:47:52 +03:00
a62e4e0b53 build: version bump to v1.14.1 - image display fixes 2026-04-21 19:47:28 +03:00
eaa2d2d29f fix: replace toast.warning with toast.success in useItemCreate
toast.warning is not a valid method in react-hot-toast API. Changed to
toast.success since the item was successfully created even if photo upload failed.
2026-04-21 19:47:16 +03:00
b5fb2a8cdb fix: add photo_path fields to frontend Item interface to display saved photos
The backend returns photo_path, photo_thumbnail_path, and photo_upload_date
from the AI auto-save feature, but the frontend Item interface was missing
these fields, causing images not to display in ItemDetailModal and InventoryTable.

Updated:
- frontend/lib/db.ts: Added missing photo fields to Item interface
- frontend/components/ItemDetailModal.tsx: Use photo_path first, fallback to image_url
- frontend/components/InventoryTable.tsx: Use photo_path first, fallback to image_url

This ensures the UI can now display photos saved by the auto-photo-save feature.
2026-04-21 19:45:19 +03:00
2e61dfe935 chore: clean up test artifacts from photo upload tests 2026-04-21 19:38:18 +03:00
174c35bac3 docs: complete Phase 3 documentation - AI extraction + auto-photo-save implementation complete 2026-04-21 19:35:18 +03:00
baf38f227f docs: update SESSION_STATE for Phase 3 Task 8 (E2E test) completion 2026-04-21 19:33:38 +03:00
c22dadbd1a test: add E2E test for AI extraction + auto-photo-save flow 2026-04-21 19:33:18 +03:00
3ba31a7b48 docs: update SESSION_STATE for Phase 3 Task 7 completion 2026-04-21 19:31:49 +03:00