# Perspective Transform Document Deskew

> Detects 4-point polygon document corners and rectifies skewed perspectives using OpenCV homography matrices. Use when flattening photographed receipts, forms, a

- Skill: `bishnucd/perspective-transform-document-deskew` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx get-skill add bishnucd/perspective-transform-document-deskew`
- Raw SKILL.md: https://api.skillmd.com/api/skills/bishnucd/perspective-transform-document-deskew/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: Bishnucd (https://skillmd.com/u/bishnucd)
- Updated: 2026-12-03
- Page: https://skillmd.com/skills/bishnucd/perspective-transform-document-deskew

---

---
name: perspective-transform-document-deskew
description: Detects 4-point polygon document corners and rectifies skewed perspectives using OpenCV homography matrices. Use when flattening photographed receipts, forms, and documents.
license: MIT
metadata:
  author: Community List Maintainers
  version: "1.0.0"
  source: "https://docs.opencv.org/4.x/da/d6e/tutorial_py_geometric_transformations.html"
---
# Perspective Transform Document Deskew

## Overview
Photographs of paper documents taken at an angle suffer from keystone distortion. Finding the 4 document corners and applying getPerspectiveTransform maps the warped quad back to a flat rectangle.

## Operational Workflow

1. **Detect paper document boundary contour using thresholding and polygon approximation (cv2.approxPolyDP).**:
   - Detect paper document boundary contour using thresholding and polygon approximation (cv2.approxPolyDP).

2. **Sort corner coordinates into top-left, top-right, bottom-right, and bottom-left order.**:
   - Sort corner coordinates into top-left, top-right, bottom-right, and bottom-left order.

3. **Compute perspective transformation matrix using cv2.getPerspectiveTransform(src_pts, dst_pts).**:
   - Compute perspective transformation matrix using cv2.getPerspectiveTransform(src_pts, dst_pts).

4. **Warp image using cv2.warpPerspective to produce a perfectly rectangular, front-facing document.**:
   - Warp image using cv2.warpPerspective to produce a perfectly rectangular, front-facing document.

## Recommended Tools & Environments
- OpenCV
- Perspective Transform
- Homography
- Document Scanning

## Verification & Execution Criteria
- Pre-execution validation verifies all prerequisites and inputs.
- Step-by-step progress logging confirms intermediate state transitions.
- Post-execution checks verify output integrity and clean exit codes.

