@srsergio/taptapp-ar 1.0.36 → 1.0.37
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.
|
@@ -70,7 +70,11 @@ export class Controller {
|
|
|
70
70
|
targetIndex: any;
|
|
71
71
|
modelViewTransform: any;
|
|
72
72
|
}>;
|
|
73
|
-
_trackAndUpdate(inputData: any, lastModelViewTransform: any, targetIndex: any): Promise<
|
|
73
|
+
_trackAndUpdate(inputData: any, lastModelViewTransform: any, targetIndex: any): Promise<{
|
|
74
|
+
modelViewTransform: any;
|
|
75
|
+
inliers: number;
|
|
76
|
+
octaveIndex: any;
|
|
77
|
+
} | null>;
|
|
74
78
|
processVideo(input: any): void;
|
|
75
79
|
stopProcessVideo(): void;
|
|
76
80
|
detect(input: any): Promise<{
|
|
@@ -181,14 +181,18 @@ class Controller {
|
|
|
181
181
|
return { targetIndex: matchedTargetIndex, modelViewTransform };
|
|
182
182
|
}
|
|
183
183
|
async _trackAndUpdate(inputData, lastModelViewTransform, targetIndex) {
|
|
184
|
-
const { worldCoords, screenCoords } = this.tracker.track(inputData, lastModelViewTransform, targetIndex);
|
|
184
|
+
const { worldCoords, screenCoords, debugExtra } = this.tracker.track(inputData, lastModelViewTransform, targetIndex);
|
|
185
185
|
if (worldCoords.length < 6)
|
|
186
186
|
return null; // Umbral de puntos mínimos para mantener el seguimiento
|
|
187
187
|
const modelViewTransform = await this._workerTrackUpdate(lastModelViewTransform, {
|
|
188
188
|
worldCoords,
|
|
189
189
|
screenCoords,
|
|
190
190
|
});
|
|
191
|
-
return
|
|
191
|
+
return {
|
|
192
|
+
modelViewTransform,
|
|
193
|
+
inliers: worldCoords.length,
|
|
194
|
+
octaveIndex: debugExtra.octaveIndex
|
|
195
|
+
};
|
|
192
196
|
}
|
|
193
197
|
processVideo(input) {
|
|
194
198
|
if (this.processingVideo)
|
|
@@ -202,6 +206,7 @@ class Controller {
|
|
|
202
206
|
currentModelViewTransform: null,
|
|
203
207
|
trackCount: 0,
|
|
204
208
|
trackMiss: 0,
|
|
209
|
+
stabilityCount: 0, // Nuevo: Contador para Live Adaptation
|
|
205
210
|
filter: new OneEuroFilter({ minCutOff: this.filterMinCF, beta: this.filterBeta }),
|
|
206
211
|
});
|
|
207
212
|
}
|
|
@@ -234,12 +239,28 @@ class Controller {
|
|
|
234
239
|
for (let i = 0; i < this.trackingStates.length; i++) {
|
|
235
240
|
const trackingState = this.trackingStates[i];
|
|
236
241
|
if (trackingState.isTracking) {
|
|
237
|
-
let
|
|
238
|
-
if (
|
|
242
|
+
let result = await this._trackAndUpdate(inputData, trackingState.currentModelViewTransform, i);
|
|
243
|
+
if (result === null) {
|
|
239
244
|
trackingState.isTracking = false;
|
|
245
|
+
trackingState.stabilityCount = 0;
|
|
240
246
|
}
|
|
241
247
|
else {
|
|
242
|
-
trackingState.currentModelViewTransform = modelViewTransform;
|
|
248
|
+
trackingState.currentModelViewTransform = result.modelViewTransform;
|
|
249
|
+
// --- LIVE MODEL ADAPTATION LOGIC ---
|
|
250
|
+
// Si el tracking es muy sólido (muchos inliers) y estable, refinamos el modelo
|
|
251
|
+
if (result.inliers > 25) {
|
|
252
|
+
trackingState.stabilityCount++;
|
|
253
|
+
if (trackingState.stabilityCount > 20) { // 20 frames de estabilidad absoluta
|
|
254
|
+
this.tracker.applyLiveFeedback(i, result.octaveIndex, 0.1); // 10% de mezcla real
|
|
255
|
+
if (this.debugMode)
|
|
256
|
+
console.log(`✨ Live Reification: Target ${i} (Octave ${result.octaveIndex}) updated with real-world textures.`);
|
|
257
|
+
trackingState.stabilityCount = 0; // Reset para la siguiente actualización
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
trackingState.stabilityCount = Math.max(0, trackingState.stabilityCount - 1);
|
|
262
|
+
}
|
|
263
|
+
// -----------------------------------
|
|
243
264
|
}
|
|
244
265
|
}
|
|
245
266
|
// if not showing, then show it once it reaches warmup number of frames
|
|
@@ -33,4 +33,11 @@ export class Tracker {
|
|
|
33
33
|
* Pure JS implementation of Bilinear Warping
|
|
34
34
|
*/
|
|
35
35
|
_computeProjection(M: any, inputData: any, prebuilt: any): void;
|
|
36
|
+
/**
|
|
37
|
+
* Refines the target data (Living Mind Map) using actual camera feedback
|
|
38
|
+
* @param {number} targetIndex
|
|
39
|
+
* @param {number} octaveIndex
|
|
40
|
+
* @param {number} alpha - Blending factor (e.g. 0.1 for 10% new data)
|
|
41
|
+
*/
|
|
42
|
+
applyLiveFeedback(targetIndex: number, octaveIndex: number, alpha: number): void;
|
|
36
43
|
}
|
|
@@ -232,5 +232,25 @@ class Tracker {
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Refines the target data (Living Mind Map) using actual camera feedback
|
|
237
|
+
* @param {number} targetIndex
|
|
238
|
+
* @param {number} octaveIndex
|
|
239
|
+
* @param {number} alpha - Blending factor (e.g. 0.1 for 10% new data)
|
|
240
|
+
*/
|
|
241
|
+
applyLiveFeedback(targetIndex, octaveIndex, alpha) {
|
|
242
|
+
const prebuilt = this.prebuiltData[targetIndex][octaveIndex];
|
|
243
|
+
if (!prebuilt || !prebuilt.projectedImage)
|
|
244
|
+
return;
|
|
245
|
+
const markerPixels = prebuilt.data;
|
|
246
|
+
const projectedPixels = prebuilt.projectedImage;
|
|
247
|
+
const count = markerPixels.length;
|
|
248
|
+
// Blend the projected (camera-sourced) pixels into the marker reference data
|
|
249
|
+
// This allows the NCC matching to adapt to real-world lighting and print quality
|
|
250
|
+
for (let i = 0; i < count; i++) {
|
|
251
|
+
// Simple linear blend
|
|
252
|
+
markerPixels[i] = (1 - alpha) * markerPixels[i] + alpha * projectedPixels[i];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
235
255
|
}
|
|
236
256
|
export { Tracker };
|
package/package.json
CHANGED
|
@@ -226,7 +226,7 @@ class Controller {
|
|
|
226
226
|
return { targetIndex: matchedTargetIndex, modelViewTransform };
|
|
227
227
|
}
|
|
228
228
|
async _trackAndUpdate(inputData, lastModelViewTransform, targetIndex) {
|
|
229
|
-
const { worldCoords, screenCoords } = this.tracker.track(
|
|
229
|
+
const { worldCoords, screenCoords, debugExtra } = this.tracker.track(
|
|
230
230
|
inputData,
|
|
231
231
|
lastModelViewTransform,
|
|
232
232
|
targetIndex,
|
|
@@ -236,7 +236,11 @@ class Controller {
|
|
|
236
236
|
worldCoords,
|
|
237
237
|
screenCoords,
|
|
238
238
|
});
|
|
239
|
-
return
|
|
239
|
+
return {
|
|
240
|
+
modelViewTransform,
|
|
241
|
+
inliers: worldCoords.length,
|
|
242
|
+
octaveIndex: debugExtra.octaveIndex
|
|
243
|
+
};
|
|
240
244
|
}
|
|
241
245
|
|
|
242
246
|
processVideo(input) {
|
|
@@ -252,6 +256,7 @@ class Controller {
|
|
|
252
256
|
currentModelViewTransform: null,
|
|
253
257
|
trackCount: 0,
|
|
254
258
|
trackMiss: 0,
|
|
259
|
+
stabilityCount: 0, // Nuevo: Contador para Live Adaptation
|
|
255
260
|
filter: new OneEuroFilter({ minCutOff: this.filterMinCF, beta: this.filterBeta }),
|
|
256
261
|
});
|
|
257
262
|
}
|
|
@@ -291,15 +296,30 @@ class Controller {
|
|
|
291
296
|
const trackingState = this.trackingStates[i];
|
|
292
297
|
|
|
293
298
|
if (trackingState.isTracking) {
|
|
294
|
-
let
|
|
299
|
+
let result = await this._trackAndUpdate(
|
|
295
300
|
inputData,
|
|
296
301
|
trackingState.currentModelViewTransform,
|
|
297
302
|
i,
|
|
298
303
|
);
|
|
299
|
-
if (
|
|
304
|
+
if (result === null) {
|
|
300
305
|
trackingState.isTracking = false;
|
|
306
|
+
trackingState.stabilityCount = 0;
|
|
301
307
|
} else {
|
|
302
|
-
trackingState.currentModelViewTransform = modelViewTransform;
|
|
308
|
+
trackingState.currentModelViewTransform = result.modelViewTransform;
|
|
309
|
+
|
|
310
|
+
// --- LIVE MODEL ADAPTATION LOGIC ---
|
|
311
|
+
// Si el tracking es muy sólido (muchos inliers) y estable, refinamos el modelo
|
|
312
|
+
if (result.inliers > 25) {
|
|
313
|
+
trackingState.stabilityCount++;
|
|
314
|
+
if (trackingState.stabilityCount > 20) { // 20 frames de estabilidad absoluta
|
|
315
|
+
this.tracker.applyLiveFeedback(i, result.octaveIndex, 0.1); // 10% de mezcla real
|
|
316
|
+
if (this.debugMode) console.log(`✨ Live Reification: Target ${i} (Octave ${result.octaveIndex}) updated with real-world textures.`);
|
|
317
|
+
trackingState.stabilityCount = 0; // Reset para la siguiente actualización
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
trackingState.stabilityCount = Math.max(0, trackingState.stabilityCount - 1);
|
|
321
|
+
}
|
|
322
|
+
// -----------------------------------
|
|
303
323
|
}
|
|
304
324
|
}
|
|
305
325
|
|
|
@@ -300,6 +300,28 @@ class Tracker {
|
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Refines the target data (Living Mind Map) using actual camera feedback
|
|
306
|
+
* @param {number} targetIndex
|
|
307
|
+
* @param {number} octaveIndex
|
|
308
|
+
* @param {number} alpha - Blending factor (e.g. 0.1 for 10% new data)
|
|
309
|
+
*/
|
|
310
|
+
applyLiveFeedback(targetIndex, octaveIndex, alpha) {
|
|
311
|
+
const prebuilt = this.prebuiltData[targetIndex][octaveIndex];
|
|
312
|
+
if (!prebuilt || !prebuilt.projectedImage) return;
|
|
313
|
+
|
|
314
|
+
const markerPixels = prebuilt.data;
|
|
315
|
+
const projectedPixels = prebuilt.projectedImage;
|
|
316
|
+
const count = markerPixels.length;
|
|
317
|
+
|
|
318
|
+
// Blend the projected (camera-sourced) pixels into the marker reference data
|
|
319
|
+
// This allows the NCC matching to adapt to real-world lighting and print quality
|
|
320
|
+
for (let i = 0; i < count; i++) {
|
|
321
|
+
// Simple linear blend
|
|
322
|
+
markerPixels[i] = (1 - alpha) * markerPixels[i] + alpha * projectedPixels[i];
|
|
323
|
+
}
|
|
324
|
+
}
|
|
303
325
|
}
|
|
304
326
|
|
|
305
327
|
export { Tracker };
|