Shapes:オンデバイスの単一ストローク図形認識
手描きのひと筆を、きれいな長方形、楕円、三角形、星、直線に変換する、オンデバイスの単一ストローク図形認識。
Shapes は、手描きの 1 ストローク、つまり [x, y] 座標のリストを受け取り、きれいな図形(長方形、楕円、三角形、星、直線)を返します。正確なベクター図形にフィットさせ、軸・真円・正方形・15 度単位の回転にスナップし、図形ではない走り書きは棄却します。
Apple では、1 回の呼び出しで PencilKit に「メモ」アプリ風のスマート図形スナップを追加でき、ライブプレビューもそのまま保てます。Apple 自身の「Snap to Shape」はサードパーティアプリが呼び出せないプライベート API のため、Shapes がその隙間を埋めます。モデルのダウンロードなしでアプリに同梱できるほど小さく、Web ビルドはローカルの WebAssembly パイプラインと LiteRT.js で推論します。
デモ
パフォーマンス
0.2 MB のモデルで、ストロークあたり 10 ms 未満。Web では推論ランタイムも不要です。
社内測定値。Web では純粋な JS、Apple では Core ML で推論します。
ユースケース
「メモ」アプリ風のスマート図形
canvasView.enableShapeSnapping() で PencilKit のキャンバスに図形スナップを追加します。ライブプレビュー、取り消し・やり直しはそのまま保たれ、Apple のプライベートな Snap to Shape API が残した隙間を埋めます。
図解・ホワイトボードツール
フリーハンドのストロークを正確な図形に整えます。tldraw や Excalidraw のストロークデータにも対応します。
クロスプラットフォームの描画
同じ認識エンジンが iOS、Android、Web で動作するため、描画機能がどこでも同じように振る舞います。
モデルのダウンロード不要
約 0.2 MB とアプリに同梱できるサイズです。Google ML Kit Digital Ink とは異なり、実行時に約 20 MB のモデルを取得する必要はありません。
できること
- 長方形、楕円、三角形、星、直線を認識し、図形でないものは棄却します。
- 軸、真円、正方形、15 度単位の回転にスナップします。
- 1 回の呼び出しで PencilKit のライブスナップ:
canvasView.enableShapeSnapping()。 - ローカルの WebAssembly パイプラインと LiteRT.js による Web 推論。
プラットフォームとインストール
// Swift Package Manager
.package(url: "https://github.com/Desert-Ant-Labs/shapes", from: "0.5.0")
import Shapes
let shapes = Shapes()
let shape = try await shapes.recognize(points: stroke)
// Shape? -> rectangle, ellipse, triangle, star, line
import PencilKit
import Shapes
// Live smart-shape snapping on a PencilKit canvas, in one line.
// Pause after a stroke to preview the fit, lift to snap. Undo-safe,
// and it uses the same recognizer, bundled by default.
canvasView.enableShapeSnapping()
// build.gradle.kts (Maven Central)
implementation("ai.desertant:shapes:0.5.0")
import ai.desertant.shapes.Shapes
val shapes = Shapes(context)
val shape = shapes.recognize(points)
// Shape? -> rectangle, ellipse, triangle, star, line
npm i @desert-ant-labs/shapes @litertjs/core
import { Shapes } from "@desert-ant-labs/shapes";
const shapes = await Shapes.load();
const shape = await shapes.recognize(points);
// { kind: "ellipse", center: {...}, ... } or null
Add Shapes from Desert Ant Labs to this project.
手描きのひと筆を、きれいな長方形、楕円、三角形、星、直線に変換する、オンデバイスの単一ストローク図形認識。
SDKs (use the one that matches this project's platform):
Swift (iOS, macOS)
Repo: https://github.com/Desert-Ant-Labs/shapes
// Swift Package Manager
.package(url: "https://github.com/Desert-Ant-Labs/shapes", from: "0.5.0")
Kotlin (Android)
Repo: https://github.com/Desert-Ant-Labs/shapes
// build.gradle.kts (Maven Central)
implementation("ai.desertant:shapes:0.5.0")
JavaScript / TypeScript (Web, Node.js)
Repo: https://github.com/Desert-Ant-Labs/shapes
npm i @desert-ant-labs/shapes @litertjs/core
Reference:
- Model page: https://desertant.com/models/shapes/
- Full catalog and other models: https://desertant.com/llms.txt
Add the SDK that matches this project's platform, then follow its README for the exact API and current version. Do not invent API names or method signatures; confirm them against the README.
仕様
- 図形
- 長方形、楕円、三角形、星、直線
- オンデバイスサイズ
- 0.2 MB(Apple では 4-bit Core ML)
- レイテンシ
- 10 ms 未満
- Web ランタイム
- WebAssembly + LiteRT.js
FAQ
Shapes とは?
手描きのひと筆を、きれいな長方形、楕円、三角形、星、直線に変換する、オンデバイスの単一ストローク図形認識。
Shapes はオンデバイスで動作しますか?
はい。Shapes は完全にオンデバイスで動作します。推論はローカルで行われ、サーバーへの通信は発生しないため、データがデバイスの外に出ることはありません。
Shapes はどのプラットフォームに対応していますか?
Shapes は Swift, Kotlin, JavaScript / TypeScript 向けのネイティブなオンデバイス SDK として提供されます。
Shapes の料金はいくらですか?
すべてのモデルは、SDK ごとに月間アクティブデバイス 100k 台まで無料です。ユーザーあたりの推論は無制限です。 カスタムライセンスについては、お問い合わせください。
Shapes の精度や速度はどれくらいですか?
0.2 MB のモデルで、ストロークあたり 10 ms 未満。Web では推論ランタイムも不要です。