Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (43 loc) · 1.69 KB
/
Copy pathapp.js
File metadata and controls
51 lines (43 loc) · 1.69 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
const webcamElement = document.getElementById("webcam");
navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
webcamElement.srcObject = stream;
});
// // Pehle model load karo
// async function loadModel() {
// const modelURL = 'path/to/your/model.json'; // Apne model ka correct path yahan lagao
// const classifier = await tmImage.load(modelURL);
// return classifier;
// }
// Ab predict karne ka function likho
async function predict() {
const classifier = await loadModel();
const prediction = await classifier.predict(webcamElement);
const highestPrediction = prediction.reduce((prev, current) =>
prev.probability > current.probability ? prev : current
);
document.getElementById(
"output"
).innerText = `Detected Gesture: ${highestPrediction.className}`;
}
// Predict function ko bar-bar run karne ke liye interval set karo
setInterval(predict, 1000); // Har 1 second ke baad predict karega
function handleGesture(gesture) {
if (gesture === "Open Hand") {
// Video Play karo ya koi aur action
console.log("Playing video");
} else if (gesture === "Closed Fist") {
// Video Pause karo ya koi aur action
console.log("Pausing video");
}
}
async function predict() {
const classifier = await loadModel();
const prediction = await classifier.predict(webcamElement);
const highestPrediction = prediction.reduce((prev, current) =>
prev.probability > current.probability ? prev : current
);
document.getElementById(
"output"
).innerText = `Detected Gesture: ${highestPrediction.className}`;
handleGesture(highestPrediction.className); // Gesture ke mutabiq action perform karo
}