xtract.bot

Image perspective

Try it interactively →
POST /api/image-perspective

Auto-rectify a photo of a rectangle (document, whiteboard, painting): detects the four corners and warps the image so the rectangle is straight-on.

Looks for a rectangular subject in the image (a document on a desk, a painting on a wall, a sign at an angle), detects its four corners, and warps the image so the rectangle is straight-on. Used as a building block in `image-detect-document` and `ocr-prep-id-card`. For specialised pre-OCR pipelines those higher-level tools are usually a better fit; use this one when you need raw rectified output.

Inputs

NameTypeDefaultDescription
image*fileInput image (PNG / JPEG / WebP).
points*stringJSON-encoded array of 16 numbers (4 source/dest pairs in TL,TR,BR,BL order).
formatenum (png | jpeg | webp)Output format. Defaults to the input's.

Response

Modes: binary, base64-json. Cache: yes (24h TTL).

Code samples

Built from the tilt example.

# Download or substitute the example input:
#   curl -O https://xtract.bot/examples/image-png-to-webp/sample.png
IMAGE=$(base64 -w0 < sample.png)

curl -X POST https://api.xtract.bot/api/image-perspective \
  -H "Content-Type: application/json" \
  -H "Accept: application/octet-stream" \
  -H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
  -H "X-Api-Key: $XTRACT_API_KEY" \
  -d '{
  "points": "[0,0,20,0, 100,0,80,0, 100,100,100,100, 0,100,0,100]",
  "image": "'"$IMAGE"'"
}'