Browse Source

Training state: simplify

customisations
alemart 10 months ago
parent
commit
e5d6f6a4c2
1 changed files with 13 additions and 14 deletions
  1. 13
    14
      src/trackers/image-tracker/states/training.ts

+ 13
- 14
src/trackers/image-tracker/states/training.ts View File

53
 /** The training map maps keypoints to reference images */
53
 /** The training map maps keypoints to reference images */
54
 interface TrainingMap
54
 interface TrainingMap
55
 {
55
 {
56
-    /** maps a keypoint index to an image index */
57
-    readonly referenceImageIndex: number[];
58
-
59
-    /** maps an image index to a reference image */
60
-    readonly referenceImage: ReferenceImage[];
61
-
62
     /** the collection of all keypoints (of all images) */
56
     /** the collection of all keypoints (of all images) */
63
     readonly keypoints: SpeedyKeypoint[];
57
     readonly keypoints: SpeedyKeypoint[];
58
+
59
+    /** maps a keypoint index to an image index */
60
+    readonly referenceImageIndex: number[];
64
 }
61
 }
65
 
62
 
66
 
63
 
70
  */
67
  */
71
 export class ImageTrackerTrainingState extends ImageTrackerState
68
 export class ImageTrackerTrainingState extends ImageTrackerState
72
 {
69
 {
70
+    /** index of the image being used to train the tracker */
73
     private _currentImageIndex = 0;
71
     private _currentImageIndex = 0;
72
+
73
+    /** reference images */
74
     private _image: ReferenceImage[] = [];
74
     private _image: ReferenceImage[] = [];
75
+
76
+    /** training map */
75
     private _trainingMap: TrainingMap;
77
     private _trainingMap: TrainingMap;
76
 
78
 
77
 
79
 
86
 
88
 
87
         // initialize the training map
89
         // initialize the training map
88
         this._trainingMap = {
90
         this._trainingMap = {
89
-            referenceImageIndex: [],
90
-            referenceImage: [],
91
-            keypoints: []
91
+            keypoints: [],
92
+            referenceImageIndex: []
92
         };
93
         };
93
     }
94
     }
94
 
95
 
108
         this._currentImageIndex = 0;
109
         this._currentImageIndex = 0;
109
         this._image.length = 0;
110
         this._image.length = 0;
110
         this._trainingMap.referenceImageIndex.length = 0;
111
         this._trainingMap.referenceImageIndex.length = 0;
111
-        this._trainingMap.referenceImage.length = 0;
112
         this._trainingMap.keypoints.length = 0;
112
         this._trainingMap.keypoints.length = 0;
113
 
113
 
114
         // lock the database
114
         // lock the database
209
         Utils.log(`Image Tracker: found ${keypoints.length} keypoints in reference image "${referenceImage.name}"`);
209
         Utils.log(`Image Tracker: found ${keypoints.length} keypoints in reference image "${referenceImage.name}"`);
210
 
210
 
211
         // set the training map, so that we can map all keypoints of the current image to the current image
211
         // set the training map, so that we can map all keypoints of the current image to the current image
212
-        this._trainingMap.referenceImage.push(referenceImage);
213
         for(let i = 0; i < keypoints.length; i++) {
212
         for(let i = 0; i < keypoints.length; i++) {
214
             this._trainingMap.keypoints.push(keypoints[i]);
213
             this._trainingMap.keypoints.push(keypoints[i]);
215
             this._trainingMap.referenceImageIndex.push(this._currentImageIndex);
214
             this._trainingMap.referenceImageIndex.push(this._currentImageIndex);
313
         // keypoint description
312
         // keypoint description
314
         greyscale.output().connectTo(blur.input());
313
         greyscale.output().connectTo(blur.input());
315
         blur.output().connectTo(descriptor.input('image'));
314
         blur.output().connectTo(descriptor.input('image'));
316
-        clipper.output().connectTo(descriptor.input('keypoints'));
315
+        subpixel.output().connectTo(descriptor.input('keypoints'));
317
 
316
 
318
         // prepare output
317
         // prepare output
319
         descriptor.output().connectTo(keypointScaler.input());
318
         descriptor.output().connectTo(keypointScaler.input());
343
         if(imageIndex < 0)
342
         if(imageIndex < 0)
344
             return null;
343
             return null;
345
 
344
 
346
-        return this._trainingMap.referenceImage[imageIndex];
345
+        return this._image[imageIndex];
347
     }
346
     }
348
 
347
 
349
     /**
348
     /**
358
             return -1;
357
             return -1;
359
 
358
 
360
         const imageIndex = this._trainingMap.referenceImageIndex[keypointIndex];
359
         const imageIndex = this._trainingMap.referenceImageIndex[keypointIndex];
361
-        if(imageIndex < 0 || imageIndex >= this._trainingMap.referenceImage.length)
360
+        if(imageIndex < 0 || imageIndex >= this._image.length)
362
             return -1;
361
             return -1;
363
 
362
 
364
         return imageIndex;
363
         return imageIndex;

Loading…
Cancel
Save