Shapes:设备端单笔画形状识别
设备端单笔画形状识别,把手绘线条变成规整的矩形、椭圆、三角形、星形或直线。
Shapes接收一笔手绘,即一组 [x, y] 点,返回规整的几何图形:矩形、椭圆、三角形、星形或直线。该模型拟合精确的矢量形状,对齐到坐标轴、正圆、正方形和15度旋转,并拒绝那些并非形状的涂鸦。
在Apple平台上,只需一次调用即可为PencilKit添加「备忘录」式的智能形状吸附,实时预览不受影响。Apple自家的「Snap to Shape」是第三方应用无法调用的私有API,Shapes正好填补了这一空缺。该模型足够小,可直接内置在应用中,无需下载模型;Web 版采用本地 WebAssembly 管线,通过 LiteRT.js 进行推理。
演示
性能
每笔用时不到10毫秒,来自一个0.2 MB的模型,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度旋转。
- 只需一次调用即可实现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毫秒
- Web运行时
- WebAssembly + LiteRT.js
常见问题
Shapes是什么?
设备端单笔画形状识别,把手绘线条变成规整的矩形、椭圆、三角形、星形或直线。
Shapes在设备上运行吗?
是的。Shapes完全在设备上运行:推理在本地完成,不调用任何服务器,因此数据不会离开设备。
Shapes支持哪些平台?
Shapes以原生设备端SDK的形式提供,支持Swift, Kotlin, JavaScript / TypeScript。
Shapes的价格是多少?
每个模型的每个SDK均可免费支持最多10万台月活跃设备。每位用户可无限次推理。 如需定制授权,请联系我们。
Shapes的准确度和速度如何?
每笔用时不到10毫秒,来自一个0.2 MB的模型,Web端无需推理运行时。