Skip to content

Commit 7faee26

Browse files
committed
refactor: streamline calibration result handling and improve canvas rendering
1 parent 9e4cc62 commit 7faee26

File tree

2 files changed

+280
-298
lines changed

2 files changed

+280
-298
lines changed

src/views/DoubleCalibrationRecord.vue

Lines changed: 78 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,18 @@
5151
<v-card-text class="text-center px-6 py-6">
5252
<v-icon size="50" color="#FF425A" class="mb-4">mdi-eye-settings</v-icon>
5353
<h2 class="text-h4 font-weight-bold mb-4">Eye Tracking Calibration</h2>
54-
54+
5555
<v-alert color="#002D51" dark class="mb-4 text-left">
5656
<div class="text-body-1">
5757
<p class="font-weight-bold mb-2">This calibration consists of two phases:</p>
5858
<ol class="pl-4">
59-
<li class="mb-1"><strong>Training Phase:</strong> The system learns your eye movement patterns</li>
59+
<li class="mb-1"><strong>Training Phase:</strong> The system learns your eye movement patterns
60+
</li>
6061
<li><strong>Validation Phase:</strong> The system verifies the calibration accuracy</li>
6162
</ol>
6263
</div>
6364
</v-alert>
64-
65+
6566
<v-row class="mb-4">
6667
<v-col cols="6">
6768
<v-alert color="#FF425A" dark dense>
@@ -96,14 +97,18 @@
9697
<v-card-text class="text-center px-6 py-6">
9798
<v-icon size="50" color="#FF425A" class="mb-4">mdi-school</v-icon>
9899
<h2 class="text-h4 font-weight-bold mb-4">Training Phase</h2>
99-
100+
100101
<v-card outlined class="pa-4 mb-4 text-left">
101102
<h3 class="text-h6 font-weight-bold mb-3 text-center">Instructions</h3>
102103
<div class="text-body-1">
103-
<p class="mb-2"><v-icon small color="#FF425A">mdi-eye</v-icon> <strong>Look at the red dot</strong> that appears on screen</p>
104-
<p class="mb-2"><v-icon small color="#FF425A">mdi-keyboard</v-icon> <strong>Press S</strong> when ready to record each point</p>
105-
<p class="mb-2"><v-icon small color="#FF425A">mdi-head</v-icon> <strong>Keep your head still</strong> during the entire process</p>
106-
<p class="mb-0"><v-icon small color="#FF425A">mdi-target</v-icon> <strong>Follow the points</strong> with your eyes only</p>
104+
<p class="mb-2"><v-icon small color="#FF425A">mdi-eye</v-icon> <strong>Look at the red
105+
dot</strong> that appears on screen</p>
106+
<p class="mb-2"><v-icon small color="#FF425A">mdi-keyboard</v-icon> <strong>Press S</strong> when
107+
ready to record each point</p>
108+
<p class="mb-2"><v-icon small color="#FF425A">mdi-head</v-icon> <strong>Keep your head
109+
still</strong> during the entire process</p>
110+
<p class="mb-0"><v-icon small color="#FF425A">mdi-target</v-icon> <strong>Follow the
111+
points</strong> with your eyes only</p>
107112
</div>
108113
</v-card>
109114

@@ -130,21 +135,25 @@
130135
<v-card-text class="text-center px-6 py-6">
131136
<v-icon size="50" color="#FF425A" class="mb-4">mdi-check-decagram</v-icon>
132137
<h2 class="text-h4 font-weight-bold mb-4">Validation Phase</h2>
133-
138+
134139
<v-alert color="#FF425A" dark class="mb-4">
135140
<div class="text-center">
136141
<p class="font-weight-bold mb-1">Training Complete!</p>
137142
<p class="mb-0">Successfully collected {{ circleIrisPoints.length }} training samples</p>
138143
</div>
139144
</v-alert>
140-
145+
141146
<v-card outlined class="pa-4 mb-4 text-left">
142147
<h3 class="text-h6 font-weight-bold mb-3 text-center">Validation Instructions</h3>
143148
<div class="text-body-1">
144-
<p class="mb-2"><v-icon small color="#FF425A">mdi-eye</v-icon> <strong>Look at the red dot</strong> that appears on screen</p>
145-
<p class="mb-2"><v-icon small color="#FF425A">mdi-keyboard</v-icon> <strong>Press S</strong> when ready to record each point</p>
146-
<p class="mb-2"><v-icon small color="#FF425A">mdi-head</v-icon> <strong>Keep your head still</strong> during the entire process</p>
147-
<p class="mb-0"><v-icon small color="#FF425A">mdi-target</v-icon> <strong>Follow the points</strong> with your eyes only</p>
149+
<p class="mb-2"><v-icon small color="#FF425A">mdi-eye</v-icon> <strong>Look at the red
150+
dot</strong> that appears on screen</p>
151+
<p class="mb-2"><v-icon small color="#FF425A">mdi-keyboard</v-icon> <strong>Press S</strong> when
152+
ready to record each point</p>
153+
<p class="mb-2"><v-icon small color="#FF425A">mdi-head</v-icon> <strong>Keep your head
154+
still</strong> during the entire process</p>
155+
<p class="mb-0"><v-icon small color="#FF425A">mdi-target</v-icon> <strong>Follow the
156+
points</strong> with your eyes only</p>
148157
</div>
149158
</v-card>
150159

@@ -167,21 +176,21 @@
167176
<v-card-text class="text-center px-6 py-8">
168177
<v-icon size="50" color="#FF425A" class="mb-4">mdi-check-circle</v-icon>
169178
<h2 class="text-h3 font-weight-bold mb-4">Calibration Complete!</h2>
170-
179+
171180
<v-alert color="#FF425A" dark class="mb-3">
172181
<div class="text-center">
173182
<p class="font-weight-bold mb-1">Training: {{ circleIrisPoints.length }} samples collected</p>
174183
<p class="mb-0">Validation: {{ calibPredictionPoints.length }} samples collected</p>
175184
</div>
176185
</v-alert>
177-
186+
178187
<v-alert color="#002D51" dark class="mb-4">
179188
<div class="text-center">
180189
<v-icon left>mdi-check-circle</v-icon>
181190
<span class="font-weight-bold">Your eye tracking calibration was successful!</span>
182191
</div>
183192
</v-alert>
184-
193+
185194
<p class="text-h6 grey--text mb-4">Processing your calibration data...</p>
186195
</v-card-text>
187196
<v-card-actions class="justify-center pb-8">
@@ -246,9 +255,6 @@ export default {
246255
predByPointCount() {
247256
return this.$store.state.calibration.samplePerPoint
248257
},
249-
pattern() {
250-
return this.$store.state.calibration.pattern
251-
},
252258
mockPattern() {
253259
return this.$store.state.calibration.mockPattern
254260
},
@@ -281,42 +287,17 @@ export default {
281287
},
282288
},
283289
async created() {
290+
console.log("rodou created");
284291
await this.verifyFromRuxailab()
285292
this.$store.commit('setIndex', 0)
286-
this.usedPattern = (this.mockPattern.length > 0) ? this.mockPattern : this.pattern
293+
this.usedPattern = this.generateRuntimePattern()
287294
288-
if (this.usedPattern.length === 0) {
289-
const width = window.innerWidth
290-
const height = window.innerHeight
291-
const offset = this.offset || 100
292-
293-
const cols = 3
294-
const rows = 3
295-
296-
const usableWidth = width - 2 * offset
297-
const usableHeight = height - 2 * offset
298-
299-
const stepX = usableWidth / (cols - 1)
300-
const stepY = usableHeight / (rows - 1)
301-
302-
const generatedPattern = []
303-
304-
for (let i = 0; i < rows; i++) {
305-
for (let j = 0; j < cols; j++) {
306-
generatedPattern.push({
307-
x: offset + j * stepX,
308-
y: offset + i * stepY,
309-
})
310-
}
311-
}
312-
313-
this.$store.commit('setMockPattern', generatedPattern)
314-
this.usedPattern = generatedPattern
315-
316-
}
317295
await this.startWebCamCapture();
296+
console.log("chamou drawPoint no created com os valores:", this.usedPattern[0].x, this.usedPattern[0].y);
318297
this.drawPoint(this.usedPattern[0].x, this.usedPattern[0].y, 1)
319298
this.advance(this.usedPattern, this.circleIrisPoints, this.msPerCapture)
299+
console.log("UsedPattern inteiro", this.usedPattern);
300+
320301
},
321302
methods: {
322303
startTraining() {
@@ -335,8 +316,8 @@ export default {
335316
if (th.showStepper) {
336317
return;
337318
}
338-
339-
if ((event.key === "s" || event.key === "S")) {
319+
320+
if ((event.key === "s" || event.key === "S" || event.key === "Enter")) {
340321
if (i < pattern.length) {
341322
document.removeEventListener('keydown', keydownHandler)
342323
th.isCollecting = true
@@ -345,7 +326,7 @@ export default {
345326
346327
th.$store.commit('setIndex', i)
347328
i++
348-
329+
349330
if (i < pattern.length) {
350331
await th.triggerAnimation(pattern[i - 1], pattern[i], this.animationRefreshRate)
351332
document.addEventListener('keydown', keydownHandler)
@@ -378,6 +359,9 @@ export default {
378359
this.stepperStep = 3;
379360
this.showStepper = true;
380361
this.calibrationStarted = false;
362+
363+
console.log("nextStep rodou drawPoint com os valores:", this.usedPattern[0].x, this.usedPattern[0].y);
364+
381365
this.drawPoint(this.usedPattern[0].x, this.usedPattern[0].y, 1)
382366
this.advance(this.usedPattern, this.calibPredictionPoints, this.msPerCapture)
383367
},
@@ -458,6 +442,9 @@ export default {
458442
},
459443
drawPoint(x, y, radius) {
460444
const canvas = document.getElementById('canvas');
445+
446+
console.log('Window size:', window.innerWidth, 'x', window.innerHeight);
447+
461448
canvas.width = window.innerWidth;
462449
canvas.height = window.innerHeight
463450
const ctx = canvas.getContext('2d');
@@ -504,8 +491,8 @@ export default {
504491
delete element.point_x;
505492
delete element.point_y;
506493
})
507-
const screenHeight = window.screen.height
508-
const screenWidth = window.screen.width
494+
const screenHeight = window.innerHeight
495+
const screenWidth = window.innerWidth
509496
510497
let predictions = await this.$store.dispatch('sendData', {
511498
fromRuxailab: false,
@@ -514,7 +501,7 @@ export default {
514501
screenHeight,
515502
screenWidth,
516503
k: this.$store.state.calibration.pointNumber,
517-
threshold: this.$store.state.calibration.threshold
504+
threshold: this.$store.state.calibration.threshold
518505
})
519506
520507
if (typeof predictions === 'string') {
@@ -527,6 +514,7 @@ export default {
527514
}
528515
for (var a = 0; a < this.usedPattern.length; a++) {
529516
const element = predictions[this.usedPattern[a].x.toString().split('.')[0]][this.usedPattern[a].y.toString().split('.')[0]]
517+
530518
this.usedPattern[a].precision = element.PrecisionSD.toFixed(2)
531519
this.usedPattern[a].accuracy = element.Accuracy.toFixed(2)
532520
this.usedPattern[a].predictionX = element.predicted_x
@@ -645,6 +633,39 @@ export default {
645633
await this.recordWebCam.stop();
646634
this.calibFinished = true;
647635
},
636+
637+
generateRuntimePattern() {
638+
const width = window.innerWidth
639+
const height = window.innerHeight
640+
const offset = this.offset || 100
641+
const points = this.$store.state.calibration.pointNumber || 9
642+
643+
const minCols = 3
644+
const cols = Math.max(minCols, Math.round(Math.sqrt(points)))
645+
const rows = Math.ceil(points / cols)
646+
647+
648+
const usableWidth = width - 2 * offset
649+
const usableHeight = height - 2 * offset
650+
651+
const stepX = usableWidth / (cols - 1)
652+
const stepY = usableHeight / (rows - 1)
653+
654+
const pattern = []
655+
656+
for (let i = 0; i < rows; i++) {
657+
for (let j = 0; j < cols; j++) {
658+
if (pattern.length < points) {
659+
pattern.push({
660+
x: offset + j * stepX,
661+
y: offset + i * stepY
662+
})
663+
}
664+
}
665+
}
666+
667+
return pattern
668+
}
648669
},
649670
};
650671
</script>
@@ -938,7 +959,7 @@ kbd {
938959
/* Fix dialog centering - without scoped */
939960
.v-dialog__content {
940961
width: 100% !important;
941-
align-items: center !important;
962+
align-items: center !important;
942963
justify-content: center !important;
943964
}
944965
</style>

0 commit comments

Comments
 (0)