Skip to content

dalion619/apple-vision-swift-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

All credit to Alex Chan (post)

Summary

This is a collection of eight standalone Swift CLI tools wrapping Apple's Vision framework. Each tool is purpose-built for one detection/extraction task:

  • Face detection, landmarks, quality scoring
  • Barcode/QR code scanning
  • Document boundary detection
  • Body pose estimation
  • Image classification
  • OCR text extraction

Pattern: All tools follow the same I/O contract — accept file paths, PDFs, or base64 images, output unified JSON (meta, code, data). Compile individually to native binaries. Zero external dependencies beyond macOS + Xcode CLI. PDF handling built-in (renders at 300 DPI for clarity).

What's happening: This is a pragmatic toolkit for local, offline vision tasks. No API calls, no cloud dependencies, no licensing friction — just system frameworks compiled to portable binaries. Common use case: batch processing documents, scanning barcodes, extracting text, analyzing photos in workflows that can't leave the machine or hit external services.

What This Is

A collection of single-purpose Swift command-line tools that run Apple's Vision framework requests on local files. Each tool:

  • Compiles to a standalone binary (15–30s per tool)
  • Accepts file paths, PDFs, or base64-encoded images
  • Returns structured JSON (200 = results found, 404 = no results, 400 = error)
  • Handles multi-page PDFs (renders each page separately)

No networking, no API calls, no third-party dependencies. Everything runs locally on macOS.

Tools

Tool Vision Request Detects Output
get_live_text_enhanced_v1 VNRecognizeTextRequest OCR text Array of text strings
vision_face_detect_v1 VNDetectFaceRectanglesRequest Face bounding boxes {x, y, width, height, confidence} per face
vision_face_landmarks_v1 VNDetectFaceLandmarksRequest Face landmarks (eyes, lips, nose, contour, eyebrows) Per-face arrays of landmark points
vision_face_quality_v1 VNDetectFaceCaptureQualityRequest Face capture quality {boundingBox, confidence, faceCaptureQuality} (0.0–1.0)
vision_barcode_detect_v1 VNDetectBarcodesRequest Barcodes & QR codes {type, payload, symbology, boundingBox, confidence}
vision_document_detect_v1 VNDetectDocumentSegmentationRequest Document boundaries {boundingBox, confidence, cornerPoints}
vision_body_pose_v1 VNDetectHumanBodyPoseRequest Human body pose Per-person keypoints with {joint, x, y, confidence}
vision_image_classify_v1 VNClassifyImageRequest Image classification Array of {identifier, confidence}

Quick Start

Compile a Tool

swiftc vision_face_detect_v1.swift -o face_detect

Run on File

./face_detect photo.jpg
./face_detect document.pdf

Run on Base64

./face_detect --base64 iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==

Check Version

./face_detect --version

Output Format

{
  "meta": {
    "description": "tool-specific description"
  },
  "code": 200,
  "data": [
    { "x": 0.1, "y": 0.2, "width": 0.3, "height": 0.4, "confidence": 0.95 }
  ]
}
  • code: 200 — Results found
  • code: 404 — No results found
  • code: 400 — Input error (file not found, invalid base64, etc.)

Requirements

  • macOS 10.15+ (Catalina or later)
  • Xcode Command Line Toolsxcode-select --install
  • Swift 5.0+ (ships with Xcode)

Compilation Times

Expect 15–30 seconds per tool. No precompiled binaries — compilation is part of deployment.

Usage Examples

Detect Faces in a Photo

swiftc vision_face_detect_v1.swift -o face_detect
./face_detect portrait.jpg

Output: Face bounding boxes with confidence scores.

Extract Text from a PDF

swiftc get_live_text_enhanced_v1.swift -o ocr
./ocr invoice.pdf

Output: Text extracted from each page.

Scan QR Codes

swiftc vision_barcode_detect_v1.swift -o barcode
./barcode qr_poster.png

Output: QR code payloads and symbology types.

Analyze Document Shape

swiftc vision_document_detect_v1.swift -o doc_detect
./doc_detect scanned_receipt.jpg

Output: Document boundaries (corner points for perspective correction).

Pose Estimation

swiftc vision_body_pose_v1.swift -o pose
./pose person.jpg

Output: Joint keypoints (shoulders, elbows, wrists, hips, knees, ankles) with confidence.

Known Limitations

  • Face Quality: Single opaque metric (0.0–1.0). No breakdown of blur/exposure/contrast. macOS 13+ only.
  • Face Landmarks: Returns outerLips and innerLips, not mouth. All landmarks optional.
  • PDF Rendering: Pages rendered at 2x scale (300 DPI equivalent) for text clarity.
  • Base64 Decoding: Supports JPEG, PNG, GIF, BMP, WebP.
  • Barcode Symbology: Supports .qr, .code128, .code39, .upce, .ean13, .ean8, .pdf417, .aztec.
  • Not Implemented: Object detection (requires Core ML), saliency, animal pose, hand pose, text rectangles, optical flow, homography, contour detection, object tracking.

Integration

Each tool outputs valid JSON to stdout. Redirect to a file or pipe to another process:

./face_detect photo.jpg > results.json
./face_detect photo.jpg | jq '.data[0].confidence'

About

This is a collection of eight standalone Swift CLI tools wrapping Apple's Vision framework.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages