Skip to main content

YotsukaD API Guide

This page explains how to use the YotsukaD API from EdgeOCRExtensions to detect labels and optionally obtain perspective-corrected images.

API Reference

See the Swift API Reference / Kotlin API Reference for detailed API specifications.

YotsukaD API Overview​

  1. Create a YotsukaD instance.
  2. Call load() once.
  3. Pass a UIImage for still images, or a CMSampleBuffer / ImageProxy for camera frames.
  4. Retrieve the score, corner coordinates, and corrected image (UIImage or Bitmap) from result.documents.

1. Initialize and load the model​

import AVFoundation
import EVKit
import UIKit

func loadYotsukaD() -> YotsukaD {
// Create the detector once and reuse it for subsequent frames.
let detector = YotsukaD(
modelPath: "",
inputSize: (3, 640, 640),
scoreThreshold: 0.25,
numClasses: 3,
useGPU: true
)

// Detect load failures before running inference.
guard detector.load() else {
fatalError("Failed to load YotsukaD")
}

// Verify the state after loading.
guard detector.isLoaded() else {
fatalError("YotsukaD is not ready")
}

return detector
}
  • modelPath — Pass an empty string "" to use the bundled model. Specify a file path to use a custom model.
  • inputSize — The model input size in (channels, height, width) order.
  • scoreThreshold — The detection score threshold. Increase this value if there are too many false positives.
  • numClasses — The number of classes the model can distinguish.
  • useGPU / useGpu — Set to true to use the GPU.

2. Run inference on camera input​

import AVFoundation
import CoreGraphics
import EVKit

// Configure scan options.
let options = DocScanOptions(
transformMode: .auto,
centerOnly: false
)

// Run real-time inference on the camera frame.
let result = try detector.scan(
sampleBuffer,
viewBounds: viewBounds,
cropRect: cropRect,
rotation: .rotate0,
options: options
)

For camera input, specify the target area within the preview using cropRect and pass it to scan(...). On both platforms, retrieve the results from result.documents.

  • cropRect uses normalized coordinates from 0.0 to 1.0.
  • Swift requires viewBounds (the preview display area) and rotation (the frame orientation) as additional parameters. Kotlin reads rotation automatically from ImageProxy, so these are not needed.

Use transformMode: .auto or TransformMode.Auto to automatically estimate the document size.

Use .fixedSize(width:height:) or FixedSize(width, height) to save the corrected image at a fixed size. Use centerOnly: true or centerOnly = true to detect only the document closest to the center.

3. Read the result​

for document in result.documents {
print("score: \(document.score)")
print("keypoints: \(document.keypoints)")

// Use the corrected image for display or saving.
if let cropped = document.cropped {
imageView.image = cropped
}
}

result.documents contains the list of detected documents. Each Document has the following properties:

  • score — Detection confidence (0.0–1.0)
  • keypoints — Four corner coordinates (normalized)
  • cropped — Perspective-corrected image (Swift: PlatformImage? / Kotlin: Bitmap?)

If documents is empty, no targets were detected. Review the capture angle or cropRect range.

4. Run inference on a still image (Swift only)​

To process a still image or a pre-processed image instead of a camera frame, pass a PlatformImage to scan(...).

import EVKit

// Configure scan options.
let options = DocScanOptions(
transformMode: .auto,
centerOnly: false
)

// Run inference on the full image.
let result = try detector.scan(
image,
cropRect: CGRect(x: 0, y: 0, width: 1, height: 1),
rotation: .rotate0,
options: options
)

for document in result.documents {
print("score: \(document.score)")
print("keypoints: \(document.keypoints)")

if let cropped = document.cropped {
imageView.image = cropped
}
}
  • Passing (0, 0, 1, 1) to cropRect targets the entire image.
  • To restrict inference to a specific region, specify the area in normalized coordinates.