Skip to content

feat(ai): Auto-Rotate & Face Alignment Correction (#2083) - #2084

Open
Dev1822 wants to merge 1 commit into
souma9830:masterfrom
Dev1822:feature/issue-2083-auto-rotate-face-align
Open

feat(ai): Auto-Rotate & Face Alignment Correction (#2083)#2084
Dev1822 wants to merge 1 commit into
souma9830:masterfrom
Dev1822:feature/issue-2083-auto-rotate-face-align

Conversation

@Dev1822

@Dev1822 Dev1822 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Description

Implements pre-processing step that detects face tilt via eye landmarks and auto-rotates the image so the face is perfectly level before cropping. Closes #2083.

Changes

New: python-ai-service/app/services/face_align.py

  • Detects face using OpenCV Haar cascade
  • Detects eyes within the upper 60% of the face ROI
  • Calculates roll angle via arctan2 between eye centers
  • Falls back to PCA-based roll estimation on Canny edges when eyes aren't found
  • Rotates the image by the negative of the detected angle (white border fill)
  • Clamps correction to +/-25 degrees to avoid incorrect rotations on non-frontal photos

Modified: python-ai-service/app/routes/process_routes.py

  • POST /remove-bg: Auto-rotation now runs as a pre-processing step before background removal (silent - if no face is detected, processing continues without rotation)
  • New POST /auto-rotate: Standalone endpoint that accepts a multipart image and returns the corrected PNG with X-Roll-Degrees and X-Eyes-Detected response headers

Modified: python-ai-service/app/routes/compliance_routes.py

  • POST /auto-correct: Added auto-rotate as a new issue type alongside the existing tilt type
  • The existing tilt type now also uses the new face_align module (replacing the previous inline implementation)

New: python-ai-service/app/services/test_face_align.py

  • 11 unit tests covering face detection, eye roll detection, auto-rotate edge cases, and data structures

Testing

All 11 tests pass.

API Usage

Standalone auto-rotate

curl -X POST http://localhost:8000/auto-rotate -F "image=@selfie.jpg"

Returns corrected PNG with metadata headers.

Part of processing pipeline

Auto-rotation is now applied automatically in POST /remove-bg before background removal - no additional parameters needed.

Via compliance auto-correct

POST /api/compliance/auto-correct
{ "file_path": "uploads/photo.jpg", "issue": "auto-rotate" }

Add pre-processing step that detects face tilt via eye landmarks
and auto-rotates the image so the face is level before cropping.

- New face_align.py service using OpenCV Haar cascades for eye
  detection and PCA-based roll angle estimation as fallback
- Integrated as auto pre-processing step in the /remove-bg pipeline
- New standalone POST /auto-rotate endpoint for direct use
- Added 'auto-rotate' as a new auto-correct issue type in the
  compliance endpoint (alongside the existing 'tilt' type which now
  also uses the new face_align module)
- Roll angles beyond ±25° are clamped (not corrected) to avoid
  incorrect rotations on non-frontal photos
- 11 unit tests covering detection, rotation, edge cases, and data
  structures
@vercel

vercel Bot commented Aug 17, 2026

Copy link
Copy Markdown

@Dev1822 is attempting to deploy a commit to the souma9830's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ai): Auto-Rotate & Face Alignment Correction

1 participant