-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (48 loc) · 1.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
let result = getElement("#result")
let info = getElement(".info")
let scan = getElement(".btn-scan")
let btnUp = getElement(".btn-up")
let btnLeft = getElement(".btn-left")
let btnRight = getElement(".btn-right")
let btnDown = getElement(".btn-down")
function getElement(dom) {
let element = document.querySelector(dom)
return element
}
(async function () {
boardReady({ board: 'Smart', device: config.smartDeviceId, transport: 'mqtt' }, async function (board) {
board.samplingInterval = 50
console.log("ready!")
let imageClassifier = getVideoClassifier(config.model, config.webEyeIp, false, 1083)
let woodycar = getWoodyCar(board)
let pokemon = ''
woodycar.setAllSpeed(100)
for (let i = 0; i < config.dataSetAmount; i++) {
imageClassifier.onLabel(i, idx => {
if (pokemon === imageClassifier.getClassName()) return
pokemon = imageClassifier.getClassName()
result.src = `./pokemon/${pokemon}_b.png`
})
}
scan.onclick = () => {
if(pokemon === "誰") return
info.innerHTML = pokemon
result.src = `./pokemon/${pokemon}.png`
}
btnUp.ontouchstart = () => {
woodycar.goFront()
}
btnLeft.ontouchstart = () => {
woodycar.turnLeft()
}
btnRight.ontouchstart = () => {
woodycar.turnRight()
}
btnDown.ontouchstart = () => {
woodycar.goBack()
}
btnUp.ontouchend = btnLeft.ontouchend = btnRight.ontouchend = btnDown.ontouchend = () => {
woodycar.stop()
}
})
}())