Delete script.js
Browse files
script.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 1 |
-
let timerInterval;
|
| 2 |
-
let capturing = false;
|
| 3 |
-
|
| 4 |
-
// Access the webcam
|
| 5 |
-
navigator.mediaDevices.getUserMedia({ video: true })
|
| 6 |
-
.then(stream => {
|
| 7 |
-
document.getElementById('webcam').srcObject = stream;
|
| 8 |
-
})
|
| 9 |
-
.catch(error => {
|
| 10 |
-
console.error('Error accessing the webcam', error);
|
| 11 |
-
});
|
| 12 |
-
|
| 13 |
-
// Function to start the timer for automatic image capture
|
| 14 |
-
function startTimer() {
|
| 15 |
-
if (!capturing) {
|
| 16 |
-
capturing = true;
|
| 17 |
-
timerInterval = setInterval(captureAndSendImage, 5000); // Capture image every 5 seconds
|
| 18 |
-
}
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
// Function to stop the timer
|
| 22 |
-
function stopTimer() {
|
| 23 |
-
if (capturing) {
|
| 24 |
-
capturing = false;
|
| 25 |
-
clearInterval(timerInterval);
|
| 26 |
-
}
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
// Function to capture image and send to backend
|
| 30 |
-
async function captureAndSendImage() {
|
| 31 |
-
const video = document.getElementById('webcam');
|
| 32 |
-
const canvas = document.createElement('canvas');
|
| 33 |
-
canvas.width = video.videoWidth;
|
| 34 |
-
canvas.height = video.videoHeight;
|
| 35 |
-
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 36 |
-
const image = canvas.toDataURL('image/jpeg');
|
| 37 |
-
|
| 38 |
-
try {
|
| 39 |
-
const response = await fetch('https://your-space-name.hf.space/api/recognize_pose', {
|
| 40 |
-
method: 'POST',
|
| 41 |
-
headers: {
|
| 42 |
-
'Content-Type': 'application/json',
|
| 43 |
-
},
|
| 44 |
-
body: JSON.stringify({ image: image })
|
| 45 |
-
});
|
| 46 |
-
|
| 47 |
-
if (!response.ok) {
|
| 48 |
-
throw new Error(`HTTP error! status: ${response.status}`);
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
const result = await response.json();
|
| 52 |
-
document.getElementById('output').innerText = result.pose || 'Pose not recognized';
|
| 53 |
-
} catch (error) {
|
| 54 |
-
console.error('Error recognizing pose:', error);
|
| 55 |
-
document.getElementById('output').innerText = 'Error recognizing pose';
|
| 56 |
-
}
|
| 57 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|