A web-based document scanner that turns photos of documents into PDFs. Built with FastAPI, OpenCV, and Docker. Handles edge detection, perspective correction, and adaptive thresholding.
- Document edge detection via Canny edge detection and contour analysis
- Perspective correction (flattens angled photos using homography)
- Four processing modes:
- Scan - black & white, adaptive thresholding, shadows removed
- Color - original colors preserved
- Gray - standard grayscale
- Enhanced - high contrast via CLAHE
- Multi-page PDF export
- Drag-and-drop web UI with live previews
- Docker deployment
- Pytest suite with GitHub Actions CI
git clone https://github.com/SultanAhmmed/camscanner-clone.git
cd camscanner-clone
docker build -t camscanner-api .
docker run -d -p 8000:8000 --name camscanner camscanner-apior
docker compose up --build
docker compose upOpen http://localhost:8000/static/index.html.
curl -LsSf https://astral.sh/uv/install.sh | sh
git clone https://github.com/YOUR_GITHUB_USERNAME/camscanner-clone.git
cd camscanner-clone
uv sync
uv run uvicorn app.main:app --reload| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Welcome message |
/health |
GET | Health check |
/scan-document |
POST | Process a single image |
/scan-to-pdf |
POST | Process multiple images into a PDF |
curl -X POST "http://localhost:8000/scan-document?mode=scan" \
-F "file=@document.jpg" \
--output scanned_result.jpgcurl -X POST "http://localhost:8000/scan-to-pdf?mode=scan" \
-F "files=@page1.jpg" \
-F "files=@page2.jpg" \
--output final_document.pdfcamscanner-clone/
├── app/ # FastAPI application
│ ├── __init__.py
│ └── main.py # Routes, static file mounting
├── src/ # Core CV logic
│ ├── __init__.py
│ ├── order_points.py # Corner ordering
│ ├── four_point_transform.py # Perspective warp
│ └── process_document.py # Main processing pipeline
├── static/ # Frontend assets
│ ├── index.html
│ ├── style.css
│ └── script.js
├── tests/
│ ├── test_api.py
│ └── test_processing.py
├── .github/workflows/ # CI
├── Dockerfile
├── pyproject.toml
└── README.md
uv run pytest tests/ -v
uv run pytest tests/ --cov=src --cov=app- Backend: FastAPI, Uvicorn
- Image processing: OpenCV, NumPy
- PDF generation: img2pdf
- Package management: uv
- Containerization: Docker
- Testing: pytest, httpx
- CI/CD: GitHub Actions
Pull requests welcome. For larger changes, open an issue first.
MIT - see LICENSE.