4.0.6 • Published 5 months ago

@zappar/imagetraining v4.0.6

Weekly downloads
-
License
Proprietary
Repository
-
Last release
5 months ago

Image Training

Zappar's image tracking augmented reality technology lets you attach 3D content to known images in a camera view. This library provides an API that takes a source image, e.g. a PNG or JPEG, and produces a 'target file' that can be used for tracking with Zappar's Universal AR SDKs.

If you'd like to train images as part of your day-to-day workflow, you might like to use our ZapWorks command line tool which provides this functionality out-of-the-box.

Usage

First step is to grab the package from NPM:

npm i @zappar/imagetraining

Next is to import it into your JavaScript or TypeScript files:

import { train } from "@zappar/imagetraining";

Finally, call the function to convert an input PNG or JPEG into a target file:

train(myFile, options).then(res => {
  // res is a Uint8Array containing the target file data
});

Note that the training process is relatively intensive, so expect that it may take twenty or thirty seconds to complete.

The first argument is a node Buffer or a filesystem path of a PNG or JPEG file. The training process works best on images between around 200px and 500px in width and height. If an image larger than 500px (in either width or height) is provided, the function will automatically resize the image to fit 500px x 500px (or the maxWidth and maxHeight options). Images smaller than 128px in either dimensions will not be processed, and the function will reject the returned promise.

The optional second parameter can be used to specify additional options (see below).

The function returns a promise that resolves to a Buffer object, or is rejected if there's been an error processing the image.

Options

OptionDescriptiondefault
excludePreviewThe resulting target file has an embedded JPEG version of the original file for preview purposes. It's low-resolution, and highly compressed and so typically only increases the target file size by ~5kb. Pass true for this option to avoid embedding the preview image.false
maxWidth and maxHeightThe dimensions, in pixels, of the largest image size that will be processed by the function. If a larger image is provided, it will be resized to fit these values.500
radiusThe radius of the target, in target units (-1 to 1), this option should only be used for cylindrical targets.0
topRadius and bottomRadiusThe top and bottom radius of the target, only used if the target has non-matching top and bottom radii.if provided, radius otherwise 0
sideLengthThe side length of the target, in target units (-1 to 1).0

Example

This example loads a PNG file from the filesystem, trains it, then saves resulting target file. The example uses async/await.

import { train } from "@zappar/imagetraining";
import { promises as fs } from "fs";

async function perform() {
  let png = await fs.readFile("myfile.png");
  let target = await train(png);
  await fs.writeFile("myfile.zpt", target);
}
4.2.0-beta.0

5 months ago

4.2.0-beta.1

5 months ago

4.1.0-beta.1

9 months ago

4.1.0-beta.3

9 months ago

4.0.5

10 months ago

4.0.6

9 months ago

4.0.4

1 year ago

3.0.1

2 years ago

3.0.0

2 years ago

3.0.0-beta.6

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.0.0-beta.1

2 years ago

3.0.0-beta.0

2 years ago

3.0.0-beta.3

2 years ago

3.0.0-beta.2

2 years ago

3.0.0-beta.5

2 years ago

3.0.0-beta.4

2 years ago

2.0.0

2 years ago

1.0.4-alpha.1

3 years ago

1.0.4

3 years ago

1.0.4-alpha

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.8

3 years ago

0.0.2

3 years ago