deepar 5.0.0-alpha-4 → 5.0.0-alpha-744

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,12 +11,13 @@ DeepAR Web supports:
11
11
  - Shoe try-on.
12
12
  - AR mini-games.
13
13
 
14
- > ❗ DeepAR Web requires an internet connection.
14
+ > ❗ DeepAR Web works only in the **browser** (not Node.js).
15
15
 
16
16
  ## Documentation
17
17
 
18
18
  - Visit the official DeepAR docs for Web SDK here: https://docs.deepar.ai/category/deepar-sdk-for-web
19
19
  - See the official example here: https://github.com/DeepARSDK/quickstart-web-js-npm
20
+ - Full API reference [here](https://s3.eu-west-1.amazonaws.com/sdk.developer.deepar.ai/doc/web/index.html).
20
21
 
21
22
  ## License key
22
23
 
@@ -101,22 +102,26 @@ or [Rollup](https://rollupjs.org/guide/en).
101
102
  Add the following code to an HTML file:
102
103
  ```html
103
104
  <html>
104
- <head>
105
- <!-- Load deepar.js -->
106
- <script src="https://cdn.jsdelivr.net/npm/deepar/js/deepar.js"> </script>
107
- <script>
105
+ <head>
106
+ <!-- Load deepar.js -->
107
+ <script src="https://cdn.jsdelivr.net/npm/deepar/js/deepar.js"> </script>
108
+ </head>
109
+
110
+ <body>
111
+ <!-- Canvas element for AR preview -->
112
+ <canvas width="640" height="360" id="deepar-canvas"></canvas>
113
+ <!-- Initialize DeepAR and load AR effect/filter -->
114
+ <script>
115
+ (async function() {
108
116
  const deepAR = await deepar.initialize({
109
117
  licenseKey: 'your_license_key_here',
110
118
  canvas: document.getElementById('deepar-canvas'),
111
- effect: 'https://cdn.jsdelivr.net/npm/deepar/effects/aviators'
119
+ effect: 'https://cdn.jsdelivr.net/npm/deepar/effects/aviators'
112
120
  });
113
- </script>
114
- </head>
115
-
116
- <body>
117
- <canvas width="1280" height="720" id="deepar-canvas"></canvas>
121
+ })();
122
+ </script>
118
123
  </body>
119
- </html>>
124
+ </html>
120
125
  ```
121
126
 
122
127
  ### via NPM
@@ -130,18 +135,17 @@ understand. However, you are free to use any build tool that you prefer.
130
135
 
131
136
  ```javascript
132
137
  import * as deepar from 'deepar';
133
- import deeparEffect from './effects/effectFile'
134
138
 
135
139
  const deepAR = await deepar.initialize({
136
- licenseKey: 'your_license_key_here',
137
- canvas: document.getElementById('deepar-canvas'),
138
- effect: deeparEffect
140
+ licenseKey: 'your_license_key_here',
141
+ canvas: document.getElementById('deepar-canvas'),
142
+ effect: 'https://cdn.jsdelivr.net/npm/deepar/effects/aviators'
139
143
  });
140
144
  ```
141
145
 
142
146
  ## Switch effects
143
147
 
144
- All filters are represented by effect files in DeepAR. You can load them to preview the effect.
148
+ AR filters are represented by effect files in DeepAR. You can load them to preview the effect.
145
149
 
146
150
  Places you can get DeepAR effects:
147
151
  - Download a free filter pack: https://docs.deepar.ai/deep-ar-studio/free-filter-pack.
@@ -150,13 +154,14 @@ Places you can get DeepAR effects:
150
154
 
151
155
  Load an effect using the `switchEffect` method:
152
156
  ```javascript
153
- deepAR.switchEffect('path/to/effect/alien');
157
+ await deepAR.switchEffect('path/to/effect/alien');
154
158
  ```
155
159
 
156
160
  ## Take screenshot or video
157
161
 
158
162
  Take a screenshot.
159
163
  ```javascript
164
+ // The image is a data url.
160
165
  const image = await deepAR.takeScreenshot();
161
166
  ```
162
167
 
@@ -168,6 +173,30 @@ deepAR.startVideoRecording();
168
173
  const video = await deepAR.finishVideoRecording();
169
174
  ```
170
175
 
176
+ ## Callbacks
177
+
178
+ DeepAR has some callbacks you can implement for addition information. For example,
179
+ to check if feet are visible in the camera preview.
180
+ ```javascript
181
+ await deepAR.switchEffect('https://cdn.jsdelivr.net/npm/deepar/effects/Shoe');
182
+ deepAR.callbacks.onFeetTracked = (leftFoot, rightFoot) => {
183
+ if(leftFoot.detected && rightFoot.detected) {
184
+ console.log('Both foot detected!');
185
+ } else if (leftFoot.detected) {
186
+ console.log('Left foot detected!');
187
+ } else if (rightFoot.detected) {
188
+ console.log('Right foot detected!');
189
+ } else {
190
+ console.log('No feet detected!');
191
+ }
192
+ };
193
+ ```
194
+
195
+ To remove callback if you don't need it anymore.
196
+ ```javascript
197
+ deepAR.callbacks.onFeetTracked = undefined;
198
+ ```
199
+
171
200
  ## Different video sources
172
201
 
173
202
  DeepAR will by default use the user facing camera. It will also ask the
@@ -206,18 +235,95 @@ Initialize DeepAR but start the camera later.
206
235
  This is used when you do not want to ask the camera permission right away.
207
236
  ```javascript
208
237
  const deepAR = await deepar.initialize({
209
- // ...
210
- additionalOptions: {
211
- cameraConfig: {
212
- disableDefaultCamera: true
213
- }
214
- }
238
+ // ...
239
+ additionalOptions: {
240
+ cameraConfig: {
241
+ disableDefaultCamera: true
242
+ }
243
+ }
215
244
  });
216
245
 
217
246
  // When you want to ask the camera permission and start the camera.
218
247
  await deepAR.startCamera();
219
248
  ```
220
249
 
250
+ ## Download speed optimizations for DeepAR Web
251
+
252
+ Apart from the main *deepar.js* file and AR effect files, DeepAR uses additional files like:
253
+ - WebAssembly (WASM) files.
254
+ - ML model files.
255
+
256
+ Some of them are required and will be downloaded every time. The others will be lazy
257
+ downloaded when/if needed.
258
+
259
+ > ⚠️ DeepAR will by default automatically fetch all additional resources from the [JsDelivr](https://www.jsdelivr.com/) CDN.
260
+
261
+ Fetching files from JsDelivr is not recommended if you care about download
262
+ speeds of DeepAR Web resources. This is because the files on JsDelivr are not compressed.
263
+
264
+ ### Compression
265
+
266
+ To optimize download speeds, all the DeepAR files should be compressed.
267
+ It is recommended to serve DeepAR files from your own server or some CDN which supports file compression.
268
+
269
+ > If it is supported, you should use [GZip](https://developer.mozilla.org/en-US/docs/Glossary/GZip_compression) or
270
+ > [Brotli](https://developer.mozilla.org/en-US/docs/Glossary/Brotli_compression) compression on all DeepAR files which will significantly reduce the
271
+ > SDK size. Check out your server/CDN options for compressing files.
272
+
273
+ ### Custom deployment of DeepAR Web
274
+
275
+ DeepAR Web can be downloaded from [DeepAR Developer Portal](https://developer.deepar.ai/downloads).
276
+ But since most users will install DeepAR through NPM, follow the next instructions.
277
+
278
+ It is recommended to copy `./node_modules/deepar` directory which contains all the DeepAR
279
+ files into your distribution (dist) folder.
280
+ You can use `rootPath` to set a path to the custom root of the DeepAR SDK. All additional files
281
+ that need to be fetched by DeepAR will be resolved against the given `rootPath`.
282
+
283
+ ```javascript
284
+ const deepAR = await deepar.initialize({
285
+ // ...
286
+ rootPath: 'path/to/root/deepar/directory'
287
+ });
288
+ ```
289
+
290
+ > It is recommended to setup the copying of the DeepAR directory as part of you bundler build scripts,
291
+ > in case you ever need to updated to a newer version of DeepAR.
292
+
293
+ #### Specifying paths for each file
294
+
295
+ Another option, instead of using the DeepAR directory and copying it as-is, is to specify
296
+ a path to each file. The advantage of this is that you can use the bundler to keep track of your files.
297
+
298
+ For example, if using [Webpack](https://webpack.js.org/), you can use it's
299
+ [asset modules](https://webpack.js.org/guides/asset-modules/) to import all the files needed.
300
+
301
+ Pass the file paths in `additionalOptions`.
302
+
303
+ ```javascript
304
+ const deepAR = await deepar.initialize({
305
+ // ...
306
+ additinalOptions: {
307
+ faceTrackingConfig: {
308
+ modelPath: "path/to/deepar/models/face/models-68-extreme.bin"
309
+ },
310
+ segmentationConfig: {
311
+ modelPath: "path/to/deepar/models/segmentation/segmentation-160x160-opt.bin"
312
+ },
313
+ footTrackingConfig: {
314
+ poseEstimationWasmPath: "path/to/deepar/wasm/libxzimgPoseEstimation.wasm",
315
+ detectorPath: "path/to/deepar/models/foot/foot-detection-96x96x6.bin",
316
+ trackerPath: "path/to/deepar/models/foot/foot-tracker-96x96x18-test.bin",
317
+ objPath: "path/to/deepar/models/foot/foot-model.obj",
318
+ tfjsBackendWasmPath: "path/to/deepar/wasm/tfjs-backend-wasm.wasm",
319
+ tfjsBackendWasmSimdPath: "path/to/deepar/wasm/tfjs-backend-wasm-simd.wasm",
320
+ tfjsBackendWasmThreadedSimdPath: "path/to/deepar/wasm/tfjs-backend-wasm-threaded-simd.wasm",
321
+ },
322
+ deeparWasmPath: 'path/to/deepar/wasm/deepar.wasm'
323
+ }
324
+ });
325
+ ```
326
+
221
327
  ## License
222
328
 
223
329
  Please see: https://developer.deepar.ai/customer-agreement
package/effects/Shoe ADDED
Binary file
Binary file