-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
119 lines (95 loc) · 2.46 KB
/
Copy pathcontroller.js
File metadata and controls
119 lines (95 loc) · 2.46 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
let processing;
const setup = () => {
processing = true;
setupMap();
setupModel();
setupCameras();
};
//read depth and direction of all objects in images
const objectDetection = async () => {
if (cameras.length < 2) {
speak("Not enough cameras detected.");
processing = false;
return;
}
//take left and right pictures
await shutter();
//run tensorflow coco ssd on each image asynchronously
const leftPredictions = new Promise((resolve, reject) => {
resolve(analyze(leftCanvas));
reject;
});
const rightPredictions = new Promise((resolve, reject) => {
resolve(analyze(rightCanvas));
reject;
});
//determine which objects are the same across images
const pairs = await Promise.all([leftPredictions, rightPredictions]).then(vals => {
return match(vals[0], vals[1]);
});
//determine the depth of all objects
const objects = determineDepth(pairs);
//draw the different objects in 3D space on a radar-like map
drawMap(objects);
//group nearby objects of the same type
const groups = group(objects);
//speak objects aloud
listObjects(groups);
processing = false;
};
//read all text in image aloud
const textRecognition = async () => {
//take image from right camera
const rightImage = await getImage(0);
shutterSound.play();
//draw image to right canvas
drawCanvas(rightCanvas, rightImage, 1);
//detect all text from right canvas and read aloud
const text = await findText(rightCanvas);
if (text.length > 0) {
speak(text);
} else {
speak("No text detected.");
}
processing = false;
};
//on mouse click
document.onmousedown = e => {
e = window.event || e;
e.preventDefault();
let isRightClick;
if ("which" in e) {
isRightClick = e.which == 3;
} else if ("button" in e) {
isRightClick = e.button == 2;
}
if (!processing) {
processing = true;
if (isRightClick) {
textRecognition();
} else {
objectDetection();
}
}
};
document.getElementById("collect-button").onmousedown = e => {
e = window.event || e;
e.preventDefault();
setTimeout(downloadAll, 2000);
};
const downloadAll = () => {
if (processing) {
setTimeout(downloadAll, 250);
} else {
mapDownload.click();
leftDownload.click();
rightDownload.click();
}
};
//prevent right click menu
document.oncontextmenu = e => {
return false;
};
const shutterSound = new Audio();
shutterSound.src = "./shutter_click.mp3";
window.onload = setup();