srivatsavdamaraju
commited on
Commit
•
5eb0816
1
Parent(s):
a75c56e
Update script.js
Browse files
script.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
let currentStream = null;
|
2 |
-
let currentFacingMode = 'user';
|
|
|
3 |
|
4 |
async function loadTFLiteModel() {
|
5 |
try {
|
@@ -90,14 +91,25 @@ async function startVideo(facingMode = 'user') {
|
|
90 |
const model = await loadTFLiteModel();
|
91 |
|
92 |
if (model) {
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
});
|
103 |
} catch (error) {
|
|
|
1 |
let currentStream = null;
|
2 |
+
let currentFacingMode = 'user';
|
3 |
+
let frameCount = 0;
|
4 |
|
5 |
async function loadTFLiteModel() {
|
6 |
try {
|
|
|
91 |
const model = await loadTFLiteModel();
|
92 |
|
93 |
if (model) {
|
94 |
+
function processFrame() {
|
95 |
+
frameCount++;
|
96 |
+
|
97 |
+
// Process every 3rd frame to reduce processing load
|
98 |
+
if (frameCount % 3 === 0) {
|
99 |
+
const preprocessedImage = preprocessImage(video);
|
100 |
+
predictDepth(model, preprocessedImage).then(depthMap => {
|
101 |
+
const canvas = document.getElementById('depthCanvas');
|
102 |
+
renderDepthMap(depthMap, canvas);
|
103 |
+
analyzeDepth(depthMap);
|
104 |
+
});
|
105 |
+
}
|
106 |
+
|
107 |
+
// Request next frame
|
108 |
+
requestAnimationFrame(processFrame);
|
109 |
+
}
|
110 |
+
|
111 |
+
// Start frame processing
|
112 |
+
requestAnimationFrame(processFrame);
|
113 |
}
|
114 |
});
|
115 |
} catch (error) {
|