|
27 | 27 | </div>
|
28 | 28 | <button
|
29 | 29 | class="waves-effect waves-light btn"
|
30 |
| - onclick="onDecreaseThreshold()" |
| 30 | + onclick="onDecreaseMinConfidence()" |
31 | 31 | >
|
32 | 32 | <i class="material-icons left">-</i>
|
33 | 33 | </button>
|
34 | 34 | <button
|
35 | 35 | class="waves-effect waves-light btn"
|
36 |
| - onclick="onIncreaseThreshold()" |
| 36 | + onclick="onIncreaseMinConfidence()" |
| 37 | + > |
| 38 | + <i class="material-icons left">+</i> |
| 39 | + </button> |
| 40 | + <div class="row"> |
| 41 | + <label for="maxDistance">Max Descriptor Distance:</label> |
| 42 | + <input disabled value="0.8" id="maxDistance" type="text" class="bold"> |
| 43 | + </div> |
| 44 | + <button |
| 45 | + class="waves-effect waves-light btn" |
| 46 | + onclick="onDecreaseMaxDistance()" |
| 47 | + > |
| 48 | + <i class="material-icons left">-</i> |
| 49 | + </button> |
| 50 | + <button |
| 51 | + class="waves-effect waves-light btn" |
| 52 | + onclick="onIncreaseMaxDistance()" |
37 | 53 | >
|
38 | 54 | <i class="material-icons left">+</i>
|
39 | 55 | </button>
|
40 | 56 | </div>
|
41 | 57 | </div>
|
42 | 58 |
|
43 | 59 | <script>
|
44 |
| - const threshold = 0.8 |
| 60 | + let maxDistance = 0.8 |
45 | 61 | let minConfidence = 0.7
|
46 | 62 | let detectionNet, recognitionNet
|
47 | 63 | let trainDescriptorsByClass = []
|
48 | 64 |
|
49 |
| - function onIncreaseThreshold() { |
| 65 | + function onIncreaseMinConfidence() { |
50 | 66 | minConfidence = Math.min(faceapi.round(minConfidence + 0.1), 1.0)
|
51 | 67 | $('#minConfidence').val(minConfidence)
|
52 | 68 | updateResults()
|
53 | 69 | }
|
54 | 70 |
|
55 |
| - function onDecreaseThreshold() { |
| 71 | + function onDecreaseMinConfidence() { |
56 | 72 | minConfidence = Math.max(faceapi.round(minConfidence - 0.1), 0.1)
|
57 | 73 | $('#minConfidence').val(minConfidence)
|
58 | 74 | updateResults()
|
59 | 75 | }
|
60 | 76 |
|
| 77 | + function onIncreaseMaxDistance() { |
| 78 | + maxDistance = Math.min(faceapi.round(maxDistance + 0.1), 1.0) |
| 79 | + $('#maxDistance').val(maxDistance) |
| 80 | + updateResults() |
| 81 | + } |
| 82 | + |
| 83 | + function onDecreaseMaxDistance() { |
| 84 | + maxDistance = Math.max(faceapi.round(maxDistance - 0.1), 0.1) |
| 85 | + $('#maxDistance').val(maxDistance) |
| 86 | + updateResults() |
| 87 | + } |
| 88 | + |
61 | 89 | async function updateResults() {
|
62 | 90 | const inputImgEl = $('#inputImg').get(0)
|
63 | 91 | const { width, height } = inputImgEl
|
|
79 | 107 |
|
80 | 108 | descriptors.forEach((descriptor, i) => {
|
81 | 109 | const bestMatch = getBestMatch(trainDescriptorsByClass, descriptor)
|
82 |
| - const text = `${bestMatch.distance < threshold ? bestMatch.className : 'unkown'} (${bestMatch.distance})` |
83 |
| - const { x, y } = detectionsForSize[i].box |
84 |
| - faceapi.drawText(canvas.getContext('2d'), x, y, text, faceapi.getDefaultDrawOptions()) |
| 110 | + const text = `${bestMatch.distance < maxDistance ? bestMatch.className : 'unkown'} (${bestMatch.distance})` |
| 111 | + const { x, y, height: boxHeight } = detectionsForSize[i].box |
| 112 | + faceapi.drawText( |
| 113 | + canvas.getContext('2d'), |
| 114 | + x, |
| 115 | + y + boxHeight, |
| 116 | + text, |
| 117 | + Object.assign(faceapi.getDefaultDrawOptions(), { color: 'red', fontSize: 16 }) |
| 118 | + ) |
85 | 119 | })
|
86 | 120 | }
|
87 | 121 |
|
|
0 commit comments