Skip to content

Image Processing

The processing pipeline uses OpenCV for deterministic on-device image enhancement.

processDocumentImage(...) performs:

  1. Image decode from base64.
  2. EXIF/device orientation normalization.
  3. Optional center crop to camera preview aspect ratio.
  4. Quad point mapping from normalized coordinates.
  5. Perspective warp to flattened document output.
  6. Optional enhancement filter.
  7. JPEG encoding and file write.

processImageFilterPreview(...) performs fast filtered previews without perspective warp.

Use it to keep edit UX responsive while the user toggles filters.

Supported FilterMode values:

  • original
  • grayscale
  • bw

detectDocument(...) evaluates multiple masks (edge + paper region), scores quad candidates by geometry/position, and returns the best contour when available.