Skip to content

vvkdhkl/DocScanner

Repository files navigation

DocScanner — Android Document Scanner App

A fully functional Android document/receipt/page scanner app built with CameraX and pure Kotlin.

Features

  • Live camera preview with real-time document edge detection overlay
  • Auto-capture — holds steady detection for ~0.4s then captures automatically
  • Perspective correction — bilinear quad-to-rect warp crops and straightens documents
  • Filters: Original, Grayscale, Black & White, Enhanced (contrast + sharpness boost)
  • Rotate captured images 90° at a time
  • Export to JPG (saved to device Pictures folder)
  • Export to PDF using Android's native PdfDocument API
  • Share via any app
  • Document gallery with grid thumbnails and long-press to delete
  • Flash toggle, manual shutter button, auto-capture toggle

How to Import in Android Studio

  1. Open Android Studio (Electric Eel or newer recommended)
  2. Click File → Open and select the DocScanner folder (this directory)
  3. Wait for Gradle sync to complete (first sync downloads dependencies, takes 1–3 min)
  4. Connect an Android device (API 24+) or start an emulator
  5. Click Run ▶

Note: Camera features require a real device for best results. Emulator camera is limited.

Project Structure

DocScanner/
├── app/src/main/
│   ├── java/com/docscanner/
│   │   ├── MainActivity.kt          # Document gallery home screen
│   │   ├── CameraActivity.kt        # Live camera + capture
│   │   ├── ReviewActivity.kt        # Post-capture review & export
│   │   ├── processor/
│   │   │   ├── DocumentDetector.kt  # Edge detection & corner finding
│   │   │   └── ImageProcessor.kt    # Perspective warp, filters, sharpen
│   │   ├── data/
│   │   │   ├── ScannedDocument.kt   # Data model
│   │   │   └── DocumentRepository.kt # File-based persistence
│   │   ├── adapter/
│   │   │   └── ScannedDocAdapter.kt # RecyclerView adapter
│   │   ├── views/
│   │   │   └── DocumentOverlayView.kt # Green corner overlay on preview
│   │   └── utils/
│   │       ├── BitmapUtils.kt
│   │       └── PdfExporter.kt
│   ├── res/                         # Layouts, drawables, strings, themes
│   └── AndroidManifest.xml
└── app/build.gradle                 # Dependencies (CameraX, Glide, Coroutines)

Dependencies Used

Library Purpose
CameraX 1.3.1 Camera preview, image capture, frame analysis
Kotlin Coroutines Async image processing off the main thread
Glide 4.16 Thumbnail loading in grid
Android PdfDocument Native PDF export (no extra library needed)
Material Components UI components

How the Scanner Works

  1. CameraX ImageAnalysis delivers frames at up to 30fps
  2. Each frame is converted YUV→Bitmap and passed to DocumentDetector
  3. The detector runs Gaussian blur → Sobel edge detection → dilation → boundary scanning to find the document quadrilateral
  4. DocumentOverlayView draws the green corner brackets over the live preview
  5. When Capture is pressed (or auto-capture triggers), ImageCapture takes a full-resolution photo
  6. ImageProcessor.perspectiveCorrect() applies a bilinear quad-to-rect warp to straighten the document
  7. Auto-enhance applies contrast adjustment and a 3×3 sharpening convolution
  8. Result is saved as JPEG to external app storage and indexed in a JSON manifest

Upgrading the Document Detector

For production-grade accuracy, replace DocumentDetector.kt with:

  • ML Kit Document Scanner API (com.google.mlkit:document-scanner) — Google's on-device model
  • OpenCV for Android — full contour/Hough-based detection

The rest of the pipeline (capture, warp, filter, export) stays the same.

Permissions Required

  • CAMERA — live preview and capture
  • READ_MEDIA_IMAGES / READ_EXTERNAL_STORAGE — saving to gallery (Android 13+)
  • WRITE_EXTERNAL_STORAGE — saving on Android ≤ 28

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors