srivatsavdamaraju commited on
Commit
5eb0816
1 Parent(s): a75c56e

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +21 -9
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
- setInterval(async () => {
94
- const preprocessedImage = preprocessImage(video);
95
- const depthMap = await predictDepth(model, preprocessedImage);
96
-
97
- const canvas = document.getElementById('depthCanvas');
98
- renderDepthMap(depthMap, canvas);
99
- analyzeDepth(depthMap);
100
- }, 500); // Run depth prediction every 500ms
 
 
 
 
 
 
 
 
 
 
 
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) {