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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import DeviceDetector from "https://cdn.skypack.dev/[email protected]";
|
| 2 |
+
// ์ฌ์ฉ ๋ฐฉ๋ฒ: testSupport({client?: string, os?: string}[])
|
| 3 |
+
// client์ os๋ ์ ๊ท ํํ์์
๋๋ค.
|
| 4 |
+
// ์ฐธ๊ณ : https://cdn.jsdelivr.net/npm/[email protected]/README.md
|
| 5 |
+
// client์ os์ ์ ํจ ๊ฐ ํ์ธ
|
| 6 |
+
|
| 7 |
+
// ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ํฌํธ
|
| 8 |
+
|
| 9 |
+
// ์๋์ ๊ฐ์๋ ์ฐจํธ๋ฅผ ์ด๊ธฐํ
|
| 10 |
+
let speedChart, accelerationChart;
|
| 11 |
+
let previousPoseData = null;
|
| 12 |
+
let lastTimestamp = 0;
|
| 13 |
+
|
| 14 |
+
testSupport([
|
| 15 |
+
{ client: 'Chrome' },
|
| 16 |
+
]);
|
| 17 |
+
|
| 18 |
+
// ์ฐจํธ ๊ด๋ จ ์์ ์ค์
|
| 19 |
+
const CHART_CONFIG = {
|
| 20 |
+
maxDataPoints: 50,
|
| 21 |
+
updateInterval: 100, // ์ฐจํธ ์
๋ฐ์ดํธ ๊ฐ๊ฒฉ(ms)
|
| 22 |
+
colors: {
|
| 23 |
+
speed: {
|
| 24 |
+
primary: 'rgba(75, 192, 192, 1)',
|
| 25 |
+
background: 'rgba(75, 192, 192, 0.1)'
|
| 26 |
+
},
|
| 27 |
+
acceleration: {
|
| 28 |
+
primary: 'rgba(255, 99, 132, 1)',
|
| 29 |
+
background: 'rgba(255, 99, 132, 0.1)'
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
// ์ฐจํธ ์ด๊ธฐํ
|
| 35 |
+
function initCharts() {
|
| 36 |
+
// ์ฐจํธ๋ฅผ ๋ด์ ์ปจํ
์ด๋ ์์ฑ
|
| 37 |
+
const chartsContainer = document.createElement('div');
|
| 38 |
+
chartsContainer.className = 'charts-container';
|
| 39 |
+
document.querySelector('.container').appendChild(chartsContainer);
|
| 40 |
+
|
| 41 |
+
// ์๋ ์ฐจํธ ์ปจํ
์ด๋
|
| 42 |
+
const speedChartContainer = document.createElement('div');
|
| 43 |
+
speedChartContainer.className = 'chart-card';
|
| 44 |
+
const speedCanvas = document.createElement('canvas');
|
| 45 |
+
speedCanvas.id = 'speedChart';
|
| 46 |
+
speedChartContainer.appendChild(speedCanvas);
|
| 47 |
+
chartsContainer.appendChild(speedChartContainer);
|
| 48 |
+
|
| 49 |
+
// ๊ฐ์๋ ์ฐจํธ ์ปจํ
์ด๋
|
| 50 |
+
const accelerationChartContainer = document.createElement('div');
|
| 51 |
+
accelerationChartContainer.className = 'chart-card';
|
| 52 |
+
const accelerationCanvas = document.createElement('canvas');
|
| 53 |
+
accelerationCanvas.id = 'accelerationChart';
|
| 54 |
+
accelerationChartContainer.appendChild(accelerationCanvas);
|
| 55 |
+
chartsContainer.appendChild(accelerationChartContainer);
|
| 56 |
+
|
| 57 |
+
// ์๋ ์ฐจํธ ์ค์
|
| 58 |
+
speedChart = new Chart(speedCanvas.getContext('2d'), {
|
| 59 |
+
type: 'line',
|
| 60 |
+
data: {
|
| 61 |
+
labels: [],
|
| 62 |
+
datasets: [{
|
| 63 |
+
label: '์ด๋ ์๋ (ํฝ์
/์ด)',
|
| 64 |
+
data: [],
|
| 65 |
+
borderColor: CHART_CONFIG.colors.speed.primary,
|
| 66 |
+
backgroundColor: CHART_CONFIG.colors.speed.background,
|
| 67 |
+
tension: 0.4,
|
| 68 |
+
borderWidth: 2,
|
| 69 |
+
fill: true,
|
| 70 |
+
pointRadius: 0,
|
| 71 |
+
pointHitRadius: 10
|
| 72 |
+
}]
|
| 73 |
+
},
|
| 74 |
+
options: {
|
| 75 |
+
responsive: true,
|
| 76 |
+
maintainAspectRatio: false,
|
| 77 |
+
animation: {
|
| 78 |
+
duration: 0
|
| 79 |
+
},
|
| 80 |
+
interaction: {
|
| 81 |
+
intersect: false,
|
| 82 |
+
mode: 'index'
|
| 83 |
+
},
|
| 84 |
+
plugins: {
|
| 85 |
+
legend: {
|
| 86 |
+
position: 'top',
|
| 87 |
+
labels: {
|
| 88 |
+
font: {
|
| 89 |
+
family: '"Titillium Web", sans-serif',
|
| 90 |
+
size: 14
|
| 91 |
+
},
|
| 92 |
+
color: '#333'
|
| 93 |
+
}
|
| 94 |
+
},
|
| 95 |
+
tooltip: {
|
| 96 |
+
enabled: true,
|
| 97 |
+
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
| 98 |
+
titleFont: {
|
| 99 |
+
family: '"Titillium Web", sans-serif'
|
| 100 |
+
},
|
| 101 |
+
bodyFont: {
|
| 102 |
+
family: '"Titillium Web", sans-serif'
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
},
|
| 106 |
+
scales: {
|
| 107 |
+
y: {
|
| 108 |
+
beginAtZero: true,
|
| 109 |
+
grid: {
|
| 110 |
+
color: 'rgba(0, 0, 0, 0.1)'
|
| 111 |
+
},
|
| 112 |
+
ticks: {
|
| 113 |
+
font: {
|
| 114 |
+
family: '"Titillium Web", sans-serif'
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
},
|
| 118 |
+
x: {
|
| 119 |
+
grid: {
|
| 120 |
+
display: false
|
| 121 |
+
},
|
| 122 |
+
ticks: {
|
| 123 |
+
maxRotation: 0,
|
| 124 |
+
maxTicksLimit: 5,
|
| 125 |
+
font: {
|
| 126 |
+
family: '"Titillium Web", sans-serif'
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
});
|
| 133 |
+
|
| 134 |
+
// ๊ฐ์๋ ์ฐจํธ ์ค์
|
| 135 |
+
accelerationChart = new Chart(accelerationCanvas.getContext('2d'), {
|
| 136 |
+
type: 'line',
|
| 137 |
+
data: {
|
| 138 |
+
labels: [],
|
| 139 |
+
datasets: [{
|
| 140 |
+
label: '๊ฐ์๋ (ํฝ์
/์ดยฒ)',
|
| 141 |
+
data: [],
|
| 142 |
+
borderColor: CHART_CONFIG.colors.acceleration.primary,
|
| 143 |
+
backgroundColor: CHART_CONFIG.colors.acceleration.background,
|
| 144 |
+
tension: 0.4,
|
| 145 |
+
borderWidth: 2,
|
| 146 |
+
fill: true,
|
| 147 |
+
pointRadius: 0,
|
| 148 |
+
pointHitRadius: 10
|
| 149 |
+
}]
|
| 150 |
+
},
|
| 151 |
+
options: {
|
| 152 |
+
responsive: true,
|
| 153 |
+
maintainAspectRatio: false,
|
| 154 |
+
animation: {
|
| 155 |
+
duration: 0
|
| 156 |
+
},
|
| 157 |
+
interaction: {
|
| 158 |
+
intersect: false,
|
| 159 |
+
mode: 'index'
|
| 160 |
+
},
|
| 161 |
+
plugins: {
|
| 162 |
+
legend: {
|
| 163 |
+
position: 'top',
|
| 164 |
+
labels: {
|
| 165 |
+
font: {
|
| 166 |
+
family: '"Titillium Web", sans-serif',
|
| 167 |
+
size: 14
|
| 168 |
+
},
|
| 169 |
+
color: '#333'
|
| 170 |
+
}
|
| 171 |
+
},
|
| 172 |
+
tooltip: {
|
| 173 |
+
enabled: true,
|
| 174 |
+
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
| 175 |
+
titleFont: {
|
| 176 |
+
family: '"Titillium Web", sans-serif'
|
| 177 |
+
},
|
| 178 |
+
bodyFont: {
|
| 179 |
+
family: '"Titillium Web", sans-serif'
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
},
|
| 183 |
+
scales: {
|
| 184 |
+
y: {
|
| 185 |
+
beginAtZero: true,
|
| 186 |
+
grid: {
|
| 187 |
+
color: 'rgba(0, 0, 0, 0.1)'
|
| 188 |
+
},
|
| 189 |
+
ticks: {
|
| 190 |
+
font: {
|
| 191 |
+
family: '"Titillium Web", sans-serif'
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
},
|
| 195 |
+
x: {
|
| 196 |
+
grid: {
|
| 197 |
+
display: false
|
| 198 |
+
},
|
| 199 |
+
ticks: {
|
| 200 |
+
maxRotation: 0,
|
| 201 |
+
maxTicksLimit: 5,
|
| 202 |
+
font: {
|
| 203 |
+
family: '"Titillium Web", sans-serif'
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
});
|
| 210 |
+
|
| 211 |
+
// ๋ฐ์ํ ์ฒ๋ฆฌ
|
| 212 |
+
window.addEventListener('resize', () => {
|
| 213 |
+
speedChart.resize();
|
| 214 |
+
accelerationChart.resize();
|
| 215 |
+
});
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
// ์์ธ ๋ณํ์ ์๋์ ๊ฐ์๋๋ฅผ ๊ณ์ฐ
|
| 219 |
+
function calculateMotionMetrics(results, timestamp) {
|
| 220 |
+
// ๊ธฐ๋ณธ ๊ฒ์ฆ
|
| 221 |
+
if (!results || !results.poseLandmarks || !Array.isArray(results.poseLandmarks)) {
|
| 222 |
+
return { speed: 0, acceleration: 0 };
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// ์ด๊ธฐ ์ํ
|
| 226 |
+
if (!previousPoseData || !previousPoseData.poseLandmarks) {
|
| 227 |
+
previousPoseData = {
|
| 228 |
+
poseLandmarks: [...results.poseLandmarks]
|
| 229 |
+
};
|
| 230 |
+
lastTimestamp = timestamp;
|
| 231 |
+
return { speed: 0, acceleration: 0 };
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
const deltaTime = (timestamp - lastTimestamp) / 1000; // ์ด ๋จ์๋ก ๋ณํ
|
| 235 |
+
if (deltaTime === 0) {
|
| 236 |
+
return { speed: 0, acceleration: 0 };
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// ํคํฌ์ธํธ ํ๊ท ์ด๋๊ฑฐ๋ฆฌ ๊ณ์ฐ
|
| 240 |
+
let totalDisplacement = 0;
|
| 241 |
+
let validPoints = 0;
|
| 242 |
+
|
| 243 |
+
try {
|
| 244 |
+
// ์ ํจํ ํคํฌ์ธํธ๋ง ์ฌ์ฉ
|
| 245 |
+
results.poseLandmarks.forEach((landmark, index) => {
|
| 246 |
+
const prevLandmark = previousPoseData.poseLandmarks[index];
|
| 247 |
+
|
| 248 |
+
if (
|
| 249 |
+
landmark && prevLandmark &&
|
| 250 |
+
typeof landmark.x === 'number' &&
|
| 251 |
+
typeof landmark.y === 'number' &&
|
| 252 |
+
typeof prevLandmark.x === 'number' &&
|
| 253 |
+
typeof prevLandmark.y === 'number' &&
|
| 254 |
+
// ์ ํ ์ฌํญ: ๊ฐ์์ฑ(visibility) ๊ฐ์ด ์ผ์ ๊ธฐ์ค ์ด์์ผ ๋๋ง
|
| 255 |
+
(!landmark.visibility || landmark.visibility > 0.5) &&
|
| 256 |
+
(!prevLandmark.visibility || prevLandmark.visibility > 0.5)
|
| 257 |
+
) {
|
| 258 |
+
const dx = landmark.x - prevLandmark.x;
|
| 259 |
+
const dy = landmark.y - prevLandmark.y;
|
| 260 |
+
const displacement = Math.sqrt(dx * dx + dy * dy);
|
| 261 |
+
|
| 262 |
+
// ๋น์ ์์ ์ผ๋ก ํฐ ์ด๋ ๊ฑฐ๋ฆฌ๋ ํํฐ๋ง
|
| 263 |
+
if (displacement < 1.0) {
|
| 264 |
+
totalDisplacement += displacement;
|
| 265 |
+
validPoints++;
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
});
|
| 269 |
+
} catch (error) {
|
| 270 |
+
console.warn('์ด๋ ๊ฑฐ๋ฆฌ ๊ณ์ฐ ์ค ์ค๋ฅ:', error);
|
| 271 |
+
return { speed: 0, acceleration: 0 };
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// ์ ํจ ํฌ์ธํธ๊ฐ ์๋ค๋ฉด 0 ๋ฐํ
|
| 275 |
+
if (validPoints === 0) {
|
| 276 |
+
return { speed: 0, acceleration: 0 };
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
// ํ๊ท ์ด๋๊ฑฐ๋ฆฌ ๋ฐ ์๋ ๊ณ์ฐ
|
| 280 |
+
const averageDisplacement = totalDisplacement / validPoints;
|
| 281 |
+
const currentSpeed = averageDisplacement / deltaTime;
|
| 282 |
+
|
| 283 |
+
// ์ด์ ์๋๊ฐ ์์ผ๋ฉด 0
|
| 284 |
+
let previousSpeed = 0;
|
| 285 |
+
try {
|
| 286 |
+
previousSpeed = speedChart.data.datasets[0].data[
|
| 287 |
+
speedChart.data.datasets[0].data.length - 1
|
| 288 |
+
] || 0;
|
| 289 |
+
} catch (error) {
|
| 290 |
+
console.warn('์ด์ ์๋ ์ ๊ทผ ์ค ์ค๋ฅ:', error);
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
// ๊ฐ์๋ ๊ณ์ฐ
|
| 294 |
+
const acceleration = (currentSpeed - previousSpeed) / deltaTime;
|
| 295 |
+
|
| 296 |
+
// ๋ค์ ํ๋ ์ ๊ณ์ฐ์ ์ํด ์ด์ ๋ฐ์ดํฐ ์
๋ฐ์ดํธ
|
| 297 |
+
previousPoseData = {
|
| 298 |
+
poseLandmarks: [...results.poseLandmarks]
|
| 299 |
+
};
|
| 300 |
+
lastTimestamp = timestamp;
|
| 301 |
+
|
| 302 |
+
// ๊ฐ ๊ฒ์ฆ ๋ฐ ์ ํ
|
| 303 |
+
const metrics = {
|
| 304 |
+
speed: isFinite(currentSpeed) ? Math.min(Math.max(currentSpeed, 0), 1000) : 0,
|
| 305 |
+
acceleration: isFinite(acceleration) ? Math.min(Math.max(acceleration, -1000), 1000) : 0
|
| 306 |
+
};
|
| 307 |
+
|
| 308 |
+
return metrics;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
// ์ฐจํธ ๋ฐ์ดํฐ๋ฅผ ์
๋ฐ์ดํธํ๋ ํจ์ (์ค๋ฅ ์ฒ๋ฆฌ ํฌํจ)
|
| 312 |
+
function updateCharts(metrics) {
|
| 313 |
+
if (!metrics || typeof metrics.speed !== 'number' || typeof metrics.acceleration !== 'number') {
|
| 314 |
+
console.warn('์๋ชป๋ metrics ๋ฐ์ดํฐ:', metrics);
|
| 315 |
+
return;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
try {
|
| 319 |
+
const timestamp = new Date().toLocaleTimeString('ko-KR', {
|
| 320 |
+
hour: '2-digit',
|
| 321 |
+
minute: '2-digit',
|
| 322 |
+
second: '2-digit'
|
| 323 |
+
});
|
| 324 |
+
|
| 325 |
+
// ์ฐจํธ ๊ฐ์ฒด๊ฐ ์ ๋๋ก ์ด๊ธฐํ๋์๋์ง ํ์ธ
|
| 326 |
+
if (!speedChart || !speedChart.data || !speedChart.data.labels) {
|
| 327 |
+
console.warn('์๋ ์ฐจํธ๊ฐ ์ ์์ ์ผ๋ก ์ด๊ธฐํ๋์ง ์์์ต๋๋ค.');
|
| 328 |
+
return;
|
| 329 |
+
}
|
| 330 |
+
if (!accelerationChart || !accelerationChart.data || !accelerationChart.data.labels) {
|
| 331 |
+
console.warn('๊ฐ์๋ ์ฐจํธ๊ฐ ์ ์์ ์ผ๋ก ์ด๊ธฐํ๋์ง ์์์ต๋๋ค.');
|
| 332 |
+
return;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
// ์๋ ์ฐจํธ ์
๋ฐ์ดํธ
|
| 336 |
+
speedChart.data.labels.push(timestamp);
|
| 337 |
+
speedChart.data.datasets[0].data.push(metrics.speed);
|
| 338 |
+
if (speedChart.data.labels.length > CHART_CONFIG.maxDataPoints) {
|
| 339 |
+
speedChart.data.labels.shift();
|
| 340 |
+
speedChart.data.datasets[0].data.shift();
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
// ๊ฐ์๋ ์ฐจํธ ์
๋ฐ์ดํธ
|
| 344 |
+
accelerationChart.data.labels.push(timestamp);
|
| 345 |
+
accelerationChart.data.datasets[0].data.push(metrics.acceleration);
|
| 346 |
+
if (accelerationChart.data.labels.length > CHART_CONFIG.maxDataPoints) {
|
| 347 |
+
accelerationChart.data.labels.shift();
|
| 348 |
+
accelerationChart.data.datasets[0].data.shift();
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
// requestAnimationFrame์ ์ฌ์ฉํด ์ฐจํธ ์
๋ฐ์ดํธ ์ต์ ํ
|
| 352 |
+
requestAnimationFrame(() => {
|
| 353 |
+
try {
|
| 354 |
+
speedChart.update('none');
|
| 355 |
+
accelerationChart.update('none');
|
| 356 |
+
} catch (error) {
|
| 357 |
+
console.warn('์ฐจํธ ์
๋ฐ์ดํธ ์ค ์ค๋ฅ:', error);
|
| 358 |
+
}
|
| 359 |
+
});
|
| 360 |
+
} catch (error) {
|
| 361 |
+
console.warn('updateCharts์์ ์ค๋ฅ ๋ฐ์:', error);
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
function testSupport(supportedDevices) {
|
| 366 |
+
const deviceDetector = new DeviceDetector();
|
| 367 |
+
const detectedDevice = deviceDetector.parse(navigator.userAgent);
|
| 368 |
+
let isSupported = false;
|
| 369 |
+
for (const device of supportedDevices) {
|
| 370 |
+
if (device.client !== undefined) {
|
| 371 |
+
const re = new RegExp(`^${device.client}$`);
|
| 372 |
+
if (!re.test(detectedDevice.client.name)) {
|
| 373 |
+
continue;
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
if (device.os !== undefined) {
|
| 377 |
+
const re = new RegExp(`^${device.os}$`);
|
| 378 |
+
if (!re.test(detectedDevice.os.name)) {
|
| 379 |
+
continue;
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
isSupported = true;
|
| 383 |
+
break;
|
| 384 |
+
}
|
| 385 |
+
if (!isSupported) {
|
| 386 |
+
alert(`์ด ๋ฐ๋ชจ๋ ${detectedDevice.client.name}/${detectedDevice.os.name} ์์ ์คํ๋ ๋ ` +
|
| 387 |
+
`์์ ํ ์ง์๋์ง ์์ต๋๋ค. ๊ณ์ ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ณธ์ธ ์ฑ
์ ํ์ ์งํํ์๊ธฐ ๋ฐ๋๋๋ค.`);
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
const controls = window;
|
| 392 |
+
const mpHolistic = window;
|
| 393 |
+
const drawingUtils = window;
|
| 394 |
+
const config = { locateFile: (file) => {
|
| 395 |
+
return `https://cdn.jsdelivr.net/npm/@mediapipe/holistic@` +
|
| 396 |
+
`${mpHolistic.VERSION}/${file}`;
|
| 397 |
+
} };
|
| 398 |
+
|
| 399 |
+
// ์
๋ ฅ ํ๋ ์์ ์ฌ๊ธฐ์ ๊ฐ์ ธ์ต๋๋ค.
|
| 400 |
+
const videoElement = document.getElementsByClassName('input_video')[0];
|
| 401 |
+
const canvasElement = document.getElementsByClassName('output_canvas')[0];
|
| 402 |
+
const controlsElement = document.getElementsByClassName('control-panel')[0];
|
| 403 |
+
const canvasCtx = canvasElement.getContext('2d');
|
| 404 |
+
|
| 405 |
+
// ์ดํ tick()์ด ํธ์ถ๋ ๋๋ง๋ค ์ฐธ์กฐํ FPS ์ปจํธ๋กค
|
| 406 |
+
const fpsControl = new controls.FPS();
|
| 407 |
+
|
| 408 |
+
// ๋ก๋ฉ ์คํผ๋๋ฅผ ์จ๊ธฐ๋ ์ต์ ํ
|
| 409 |
+
const spinner = document.querySelector('.loading');
|
| 410 |
+
spinner.ontransitionend = () => {
|
| 411 |
+
spinner.style.display = 'none';
|
| 412 |
+
};
|
| 413 |
+
|
| 414 |
+
function removeElements(landmarks, elements) {
|
| 415 |
+
for (const element of elements) {
|
| 416 |
+
delete landmarks[element];
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
function removeLandmarks(results) {
|
| 421 |
+
if (results.poseLandmarks) {
|
| 422 |
+
removeElements(results.poseLandmarks, [
|
| 423 |
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
| 424 |
+
15, 16, 17, 18, 19, 20, 21, 22
|
| 425 |
+
]);
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
function connect(ctx, connectors) {
|
| 430 |
+
const canvas = ctx.canvas;
|
| 431 |
+
for (const connector of connectors) {
|
| 432 |
+
const from = connector[0];
|
| 433 |
+
const to = connector[1];
|
| 434 |
+
if (from && to) {
|
| 435 |
+
if (from.visibility && to.visibility &&
|
| 436 |
+
(from.visibility < 0.1 || to.visibility < 0.1)) {
|
| 437 |
+
continue;
|
| 438 |
+
}
|
| 439 |
+
ctx.beginPath();
|
| 440 |
+
ctx.moveTo(from.x * canvas.width, from.y * canvas.height);
|
| 441 |
+
ctx.lineTo(to.x * canvas.width, to.y * canvas.height);
|
| 442 |
+
ctx.stroke();
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
let activeEffect = 'mask';
|
| 448 |
+
|
| 449 |
+
function onResults(results) {
|
| 450 |
+
// ๋ก๋ฉ ์คํผ๋ ์จ๊ธฐ๊ธฐ
|
| 451 |
+
document.body.classList.add('loaded');
|
| 452 |
+
|
| 453 |
+
// ๊ทธ๋ฆด ํ์ ์๋ ๋๋๋งํฌ ์ ๊ฑฐ
|
| 454 |
+
removeLandmarks(results);
|
| 455 |
+
|
| 456 |
+
// FPS ์
๋ฐ์ดํธ
|
| 457 |
+
fpsControl.tick();
|
| 458 |
+
|
| 459 |
+
// ์บ๋ฒ์ค์ ๊ทธ๋ฆฌ๊ธฐ
|
| 460 |
+
canvasCtx.save();
|
| 461 |
+
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 462 |
+
|
| 463 |
+
if (results.segmentationMask) {
|
| 464 |
+
canvasCtx.drawImage(
|
| 465 |
+
results.segmentationMask,
|
| 466 |
+
0, 0, canvasElement.width, canvasElement.height
|
| 467 |
+
);
|
| 468 |
+
|
| 469 |
+
// ๊ธฐ์กด ํฝ์
๋ง ๋ฎ์ด์ฐ๊ธฐ
|
| 470 |
+
if (activeEffect === 'mask' || activeEffect === 'both') {
|
| 471 |
+
canvasCtx.globalCompositeOperation = 'source-in';
|
| 472 |
+
canvasCtx.fillStyle = '#00FF007F';
|
| 473 |
+
canvasCtx.fillRect(0, 0, canvasElement.width, canvasElement.height);
|
| 474 |
+
} else {
|
| 475 |
+
canvasCtx.globalCompositeOperation = 'source-out';
|
| 476 |
+
canvasCtx.fillStyle = '#0000FF7F';
|
| 477 |
+
canvasCtx.fillRect(0, 0, canvasElement.width, canvasElement.height);
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
// ๋๋ฝ๋ ํฝ์
๋ง ๋ฎ์ด์ฐ๊ธฐ
|
| 481 |
+
canvasCtx.globalCompositeOperation = 'destination-atop';
|
| 482 |
+
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 483 |
+
canvasCtx.globalCompositeOperation = 'source-over';
|
| 484 |
+
} else {
|
| 485 |
+
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
// ๋์ ์งํ ๊ณ์ฐ ํ ์ฐจํธ ์
๋ฐ์ดํธ
|
| 489 |
+
const metrics = calculateMotionMetrics(results, performance.now());
|
| 490 |
+
updateCharts(metrics);
|
| 491 |
+
|
| 492 |
+
// ์์ ๊ฒ์ฌ
|
| 493 |
+
if (!results.poseLandmarks || !mpHolistic.POSE_LANDMARKS) {
|
| 494 |
+
canvasCtx.restore();
|
| 495 |
+
return;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
// ํ๊ฟ์น์์ ์๊น์ง ์ฐ๊ฒฐ
|
| 499 |
+
canvasCtx.lineWidth = 5;
|
| 500 |
+
if (results.poseLandmarks) {
|
| 501 |
+
if (results.rightHandLandmarks && results.poseLandmarks[mpHolistic.POSE_LANDMARKS.RIGHT_ELBOW]) {
|
| 502 |
+
canvasCtx.strokeStyle = 'white';
|
| 503 |
+
connect(canvasCtx, [[
|
| 504 |
+
results.poseLandmarks[mpHolistic.POSE_LANDMARKS.RIGHT_ELBOW],
|
| 505 |
+
results.rightHandLandmarks[0]
|
| 506 |
+
]]);
|
| 507 |
+
}
|
| 508 |
+
if (results.leftHandLandmarks && results.poseLandmarks[mpHolistic.POSE_LANDMARKS.LEFT_ELBOW]) {
|
| 509 |
+
canvasCtx.strokeStyle = 'white';
|
| 510 |
+
connect(canvasCtx, [[
|
| 511 |
+
results.poseLandmarks[mpHolistic.POSE_LANDMARKS.LEFT_ELBOW],
|
| 512 |
+
results.leftHandLandmarks[0]
|
| 513 |
+
]]);
|
| 514 |
+
}
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
// ์ ์ ์์ธ ์ฐ๊ฒฐ
|
| 518 |
+
if (results.poseLandmarks && mpHolistic.POSE_CONNECTIONS) {
|
| 519 |
+
drawingUtils.drawConnectors(
|
| 520 |
+
canvasCtx,
|
| 521 |
+
results.poseLandmarks,
|
| 522 |
+
mpHolistic.POSE_CONNECTIONS,
|
| 523 |
+
{ color: 'white' }
|
| 524 |
+
);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
// ์ผ์ชฝ ์์ธ ๋๋๋งํฌ
|
| 528 |
+
if (results.poseLandmarks && mpHolistic.POSE_LANDMARKS_LEFT) {
|
| 529 |
+
const leftLandmarks = Object.values(mpHolistic.POSE_LANDMARKS_LEFT)
|
| 530 |
+
.map(index => results.poseLandmarks[index])
|
| 531 |
+
.filter(landmark => landmark !== undefined);
|
| 532 |
+
|
| 533 |
+
if (leftLandmarks.length > 0) {
|
| 534 |
+
drawingUtils.drawLandmarks(canvasCtx, leftLandmarks, {
|
| 535 |
+
visibilityMin: 0.65,
|
| 536 |
+
color: 'white',
|
| 537 |
+
fillColor: 'rgb(255,138,0)'
|
| 538 |
+
});
|
| 539 |
+
}
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
// ์ค๋ฅธ์ชฝ ์์ธ ๋๋๋งํฌ
|
| 543 |
+
if (results.poseLandmarks && mpHolistic.POSE_LANDMARKS_RIGHT) {
|
| 544 |
+
const rightLandmarks = Object.values(mpHolistic.POSE_LANDMARKS_RIGHT)
|
| 545 |
+
.map(index => results.poseLandmarks[index])
|
| 546 |
+
.filter(landmark => landmark !== undefined);
|
| 547 |
+
|
| 548 |
+
if (rightLandmarks.length > 0) {
|
| 549 |
+
drawingUtils.drawLandmarks(canvasCtx, rightLandmarks, {
|
| 550 |
+
visibilityMin: 0.65,
|
| 551 |
+
color: 'white',
|
| 552 |
+
fillColor: 'rgb(0,217,231)'
|
| 553 |
+
});
|
| 554 |
+
}
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
// ์ ๋๋๋งํฌ
|
| 558 |
+
if (results.rightHandLandmarks && mpHolistic.HAND_CONNECTIONS) {
|
| 559 |
+
drawingUtils.drawConnectors(
|
| 560 |
+
canvasCtx,
|
| 561 |
+
results.rightHandLandmarks,
|
| 562 |
+
mpHolistic.HAND_CONNECTIONS,
|
| 563 |
+
{ color: 'white' }
|
| 564 |
+
);
|
| 565 |
+
drawingUtils.drawLandmarks(canvasCtx, results.rightHandLandmarks, {
|
| 566 |
+
color: 'white',
|
| 567 |
+
fillColor: 'rgb(0,217,231)',
|
| 568 |
+
lineWidth: 2,
|
| 569 |
+
radius: (data) => {
|
| 570 |
+
return drawingUtils.lerp(data.from.z, -0.15, .1, 10, 1);
|
| 571 |
+
}
|
| 572 |
+
});
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
if (results.leftHandLandmarks && mpHolistic.HAND_CONNECTIONS) {
|
| 576 |
+
drawingUtils.drawConnectors(
|
| 577 |
+
canvasCtx,
|
| 578 |
+
results.leftHandLandmarks,
|
| 579 |
+
mpHolistic.HAND_CONNECTIONS,
|
| 580 |
+
{ color: 'white' }
|
| 581 |
+
);
|
| 582 |
+
drawingUtils.drawLandmarks(canvasCtx, results.leftHandLandmarks, {
|
| 583 |
+
color: 'white',
|
| 584 |
+
fillColor: 'rgb(255,138,0)',
|
| 585 |
+
lineWidth: 2,
|
| 586 |
+
radius: (data) => {
|
| 587 |
+
return drawingUtils.lerp(data.from.z, -0.15, .1, 10, 1);
|
| 588 |
+
}
|
| 589 |
+
});
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
// ์ผ๊ตด ๋๋๋งํฌ
|
| 593 |
+
if (results.faceLandmarks && mpHolistic.FACEMESH_TESSELATION) {
|
| 594 |
+
drawingUtils.drawConnectors(
|
| 595 |
+
canvasCtx,
|
| 596 |
+
results.faceLandmarks,
|
| 597 |
+
mpHolistic.FACEMESH_TESSELATION,
|
| 598 |
+
{ color: '#C0C0C070', lineWidth: 1 }
|
| 599 |
+
);
|
| 600 |
+
if (mpHolistic.FACEMESH_RIGHT_EYE) {
|
| 601 |
+
drawingUtils.drawConnectors(
|
| 602 |
+
canvasCtx,
|
| 603 |
+
results.faceLandmarks,
|
| 604 |
+
mpHolistic.FACEMESH_RIGHT_EYE,
|
| 605 |
+
{ color: 'rgb(0,217,231)' }
|
| 606 |
+
);
|
| 607 |
+
}
|
| 608 |
+
if (mpHolistic.FACEMESH_RIGHT_EYEBROW) {
|
| 609 |
+
drawingUtils.drawConnectors(
|
| 610 |
+
canvasCtx,
|
| 611 |
+
results.faceLandmarks,
|
| 612 |
+
mpHolistic.FACEMESH_RIGHT_EYEBROW,
|
| 613 |
+
{ color: 'rgb(0,217,231)' }
|
| 614 |
+
);
|
| 615 |
+
}
|
| 616 |
+
if (mpHolistic.FACEMESH_LEFT_EYE) {
|
| 617 |
+
drawingUtils.drawConnectors(
|
| 618 |
+
canvasCtx,
|
| 619 |
+
results.faceLandmarks,
|
| 620 |
+
mpHolistic.FACEMESH_LEFT_EYE,
|
| 621 |
+
{ color: 'rgb(255,138,0)' }
|
| 622 |
+
);
|
| 623 |
+
}
|
| 624 |
+
if (mpHolistic.FACEMESH_LEFT_EYEBROW) {
|
| 625 |
+
drawingUtils.drawConnectors(
|
| 626 |
+
canvasCtx,
|
| 627 |
+
results.faceLandmarks,
|
| 628 |
+
mpHolistic.FACEMESH_LEFT_EYEBROW,
|
| 629 |
+
{ color: 'rgb(255,138,0)' }
|
| 630 |
+
);
|
| 631 |
+
}
|
| 632 |
+
if (mpHolistic.FACEMESH_FACE_OVAL) {
|
| 633 |
+
drawingUtils.drawConnectors(
|
| 634 |
+
canvasCtx,
|
| 635 |
+
results.faceLandmarks,
|
| 636 |
+
mpHolistic.FACEMESH_FACE_OVAL,
|
| 637 |
+
{ color: '#E0E0E0', lineWidth: 5 }
|
| 638 |
+
);
|
| 639 |
+
}
|
| 640 |
+
if (mpHolistic.FACEMESH_LIPS) {
|
| 641 |
+
drawingUtils.drawConnectors(
|
| 642 |
+
canvasCtx,
|
| 643 |
+
results.faceLandmarks,
|
| 644 |
+
mpHolistic.FACEMESH_LIPS,
|
| 645 |
+
{ color: '#E0E0E0', lineWidth: 5 }
|
| 646 |
+
);
|
| 647 |
+
}
|
| 648 |
+
}
|
| 649 |
+
|
| 650 |
+
canvasCtx.restore();
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
// ์์ ์
๋ก๋ ์ฒ๋ฆฌ
|
| 654 |
+
function handleVideoUpload(file) {
|
| 655 |
+
// ๋น๋์ค URL ์์ฑ
|
| 656 |
+
const videoUrl = URL.createObjectURL(file);
|
| 657 |
+
|
| 658 |
+
// ์ฐจํธ ๋ฐ์ดํฐ ์ด๊ธฐํ
|
| 659 |
+
speedChart.data.labels = [];
|
| 660 |
+
speedChart.data.datasets[0].data = [];
|
| 661 |
+
accelerationChart.data.labels = [];
|
| 662 |
+
accelerationChart.data.datasets[0].data = [];
|
| 663 |
+
previousPoseData = null;
|
| 664 |
+
lastTimestamp = 0;
|
| 665 |
+
|
| 666 |
+
// ์์ธ ๊ฐ์ง ๋ฆฌ์
|
| 667 |
+
holistic.reset();
|
| 668 |
+
|
| 669 |
+
// ๋น๋์ค ์์ค ์
๋ฐ์ดํธ
|
| 670 |
+
videoElement.src = videoUrl;
|
| 671 |
+
|
| 672 |
+
// ๋น๋์ค ๋ก๋ ์๋ฃ ํ ์ฒ๋ฆฌ
|
| 673 |
+
videoElement.onloadedmetadata = () => {
|
| 674 |
+
// ๋น๋์ค ๋น์จ์ ๋ง์ถฐ ์บ๋ฒ์ค ์ฌ์ด์ฆ ์กฐ์
|
| 675 |
+
const aspect = videoElement.videoHeight / videoElement.videoWidth;
|
| 676 |
+
let width, height;
|
| 677 |
+
if (window.innerWidth > window.innerHeight) {
|
| 678 |
+
height = window.innerHeight;
|
| 679 |
+
width = height / aspect;
|
| 680 |
+
} else {
|
| 681 |
+
width = window.innerWidth;
|
| 682 |
+
height = width * aspect;
|
| 683 |
+
}
|
| 684 |
+
canvasElement.width = width;
|
| 685 |
+
canvasElement.height = height;
|
| 686 |
+
|
| 687 |
+
// ์์์ ์ฒ๋ฆฌํ๊ธฐ ์ํ animation frame ์์ฑ
|
| 688 |
+
let animationId;
|
| 689 |
+
|
| 690 |
+
async function processFrame() {
|
| 691 |
+
if (videoElement.paused || videoElement.ended) {
|
| 692 |
+
cancelAnimationFrame(animationId);
|
| 693 |
+
return;
|
| 694 |
+
}
|
| 695 |
+
// ํ์ฌ ํ๋ ์์ ์์ธ ๊ฐ์ง์ ์ ์ก
|
| 696 |
+
await holistic.send({
|
| 697 |
+
image: videoElement
|
| 698 |
+
});
|
| 699 |
+
animationId = requestAnimationFrame(processFrame);
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
// ๋น๋์ค ์ฌ์ ์ฒ๋ฆฌ
|
| 703 |
+
videoElement.onplay = () => {
|
| 704 |
+
processFrame();
|
| 705 |
+
};
|
| 706 |
+
|
| 707 |
+
// ์ฌ์/์ผ์์ ์ง ๋ฒํผ
|
| 708 |
+
const playPauseBtn = document.createElement('button');
|
| 709 |
+
playPauseBtn.textContent = '์ฌ์/์ผ์์ ์ง';
|
| 710 |
+
playPauseBtn.className = 'control-button';
|
| 711 |
+
playPauseBtn.onclick = () => {
|
| 712 |
+
if (videoElement.paused) {
|
| 713 |
+
videoElement.play();
|
| 714 |
+
} else {
|
| 715 |
+
videoElement.pause();
|
| 716 |
+
}
|
| 717 |
+
};
|
| 718 |
+
|
| 719 |
+
// ๋ค์ ์์ ๋ฒํผ
|
| 720 |
+
const restartBtn = document.createElement('button');
|
| 721 |
+
restartBtn.textContent = '์ฒ์๋ถํฐ ์ฌ์';
|
| 722 |
+
restartBtn.className = 'control-button';
|
| 723 |
+
restartBtn.onclick = () => {
|
| 724 |
+
videoElement.currentTime = 0;
|
| 725 |
+
if (videoElement.paused) {
|
| 726 |
+
videoElement.play();
|
| 727 |
+
}
|
| 728 |
+
};
|
| 729 |
+
|
| 730 |
+
// ๋ฒํผ์ ํ๋ฉด์ ์ถ๊ฐ
|
| 731 |
+
const controlsContainer = document.createElement('div');
|
| 732 |
+
controlsContainer.className = 'video-controls';
|
| 733 |
+
controlsContainer.appendChild(playPauseBtn);
|
| 734 |
+
controlsContainer.appendChild(restartBtn);
|
| 735 |
+
|
| 736 |
+
// ์ ์ ํ ์์น์ ๋ฒํผ ์ฝ์
|
| 737 |
+
const container = document.querySelector('.container') || document.body;
|
| 738 |
+
container.appendChild(controlsContainer);
|
| 739 |
+
};
|
| 740 |
+
|
| 741 |
+
// ์๋ฌ ์ฒ๋ฆฌ
|
| 742 |
+
videoElement.onerror = () => {
|
| 743 |
+
console.error('๋น๋์ค ๋ก๋ ์คํจ');
|
| 744 |
+
alert('๋น๋์ค ๋ก๋์ ์คํจํ์ต๋๋ค. ๋ค๋ฅธ ๋น๋์ค ํ์ผ์ ์๋ํด๋ณด์ธ์.');
|
| 745 |
+
};
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
// ์ผ๋ถ ๊ธฐ๋ณธ ์คํ์ผ ์ถ๊ฐ
|
| 749 |
+
const style = document.createElement('style');
|
| 750 |
+
style.textContent = `
|
| 751 |
+
.video-controls {
|
| 752 |
+
position: fixed;
|
| 753 |
+
bottom: 20px;
|
| 754 |
+
left: 50%;
|
| 755 |
+
transform: translateX(-50%);
|
| 756 |
+
z-index: 1000;
|
| 757 |
+
display: flex;
|
| 758 |
+
gap: 10px;
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
.control-button {
|
| 762 |
+
padding: 10px 20px;
|
| 763 |
+
background-color: rgba(0, 0, 0, 0.7);
|
| 764 |
+
color: white;
|
| 765 |
+
border: none;
|
| 766 |
+
border-radius: 5px;
|
| 767 |
+
cursor: pointer;
|
| 768 |
+
font-size: 14px;
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
.control-button:hover {
|
| 772 |
+
background-color: rgba(0, 0, 0, 0.9);
|
| 773 |
+
}
|
| 774 |
+
`;
|
| 775 |
+
document.head.appendChild(style);
|
| 776 |
+
|
| 777 |
+
const holistic = new mpHolistic.Holistic(config);
|
| 778 |
+
holistic.onResults(onResults);
|
| 779 |
+
|
| 780 |
+
// ์ปจํธ๋กค ํจ๋์ ๊ทธ๋ ค์ ์ฌ์ฉ์์๊ฒ ์ต์
์ ์ด ์ ๊ณต
|
| 781 |
+
new controls
|
| 782 |
+
.ControlPanel(controlsElement, {
|
| 783 |
+
selfieMode: true,
|
| 784 |
+
modelComplexity: 1,
|
| 785 |
+
smoothLandmarks: true,
|
| 786 |
+
enableSegmentation: false,
|
| 787 |
+
smoothSegmentation: true,
|
| 788 |
+
minDetectionConfidence: 0.5,
|
| 789 |
+
minTrackingConfidence: 0.5,
|
| 790 |
+
effect: 'background',
|
| 791 |
+
})
|
| 792 |
+
.add([
|
| 793 |
+
new controls.StaticText({ title: 'MediaPipe ์ ์ ์์ธ ๊ฐ์ง' }),
|
| 794 |
+
fpsControl,
|
| 795 |
+
new controls.Toggle({ title: '์
ํผ ๋ชจ๋', field: 'selfieMode' }),
|
| 796 |
+
new controls.SourcePicker({
|
| 797 |
+
onSourceChanged: () => {
|
| 798 |
+
// ์์ค ๋ณ๊ฒฝ ์ ๋ฆฌ์
. ๋ฆฌ์
ํ ์์ธ๋ฅผ ๋ ์ ๊ฐ์งํ ์ ์์
|
| 799 |
+
holistic.reset();
|
| 800 |
+
},
|
| 801 |
+
onFrame: async (input, size) => {
|
| 802 |
+
const aspect = size.height / size.width;
|
| 803 |
+
let width, height;
|
| 804 |
+
if (window.innerWidth > window.innerHeight) {
|
| 805 |
+
height = window.innerHeight;
|
| 806 |
+
width = height / aspect;
|
| 807 |
+
} else {
|
| 808 |
+
width = window.innerWidth;
|
| 809 |
+
height = width * aspect;
|
| 810 |
+
}
|
| 811 |
+
canvasElement.width = width;
|
| 812 |
+
canvasElement.height = height;
|
| 813 |
+
await holistic.send({ image: input });
|
| 814 |
+
},
|
| 815 |
+
}),
|
| 816 |
+
new controls.Slider({
|
| 817 |
+
title: '๋ชจ๋ธ ๋ณต์ก๋',
|
| 818 |
+
field: 'modelComplexity',
|
| 819 |
+
discrete: ['๊ฒฝ๋', '์์ ', '๊ณ ๊ธ'],
|
| 820 |
+
}),
|
| 821 |
+
new controls.Toggle({ title: '๋๋๋งํฌ ํํํ', field: 'smoothLandmarks' }),
|
| 822 |
+
new controls.Toggle({ title: '์ธ๊ทธ๋จผํ
์ด์
์ฌ์ฉ', field: 'enableSegmentation' }),
|
| 823 |
+
new controls.Toggle({ title: '์ธ๊ทธ๋จผํ
์ด์
ํํํ', field: 'smoothSegmentation' }),
|
| 824 |
+
new controls.Slider({
|
| 825 |
+
title: '์ต์ ๊ฐ์ง ์ ๋ขฐ๋',
|
| 826 |
+
field: 'minDetectionConfidence',
|
| 827 |
+
range: [0, 1],
|
| 828 |
+
step: 0.01
|
| 829 |
+
}),
|
| 830 |
+
new controls.Slider({
|
| 831 |
+
title: '์ต์ ์ถ์ ์ ๋ขฐ๋',
|
| 832 |
+
field: 'minTrackingConfidence',
|
| 833 |
+
range: [0, 1],
|
| 834 |
+
step: 0.01
|
| 835 |
+
}),
|
| 836 |
+
new controls.Slider({
|
| 837 |
+
title: 'ํจ๊ณผ',
|
| 838 |
+
field: 'effect',
|
| 839 |
+
discrete: { 'background': '๋ฐฐ๊ฒฝ', 'mask': '์ ๊ฒฝ' },
|
| 840 |
+
}),
|
| 841 |
+
])
|
| 842 |
+
.on(x => {
|
| 843 |
+
const options = x;
|
| 844 |
+
videoElement.classList.toggle('selfie', options.selfieMode);
|
| 845 |
+
activeEffect = x['effect'];
|
| 846 |
+
holistic.setOptions(options);
|
| 847 |
+
});
|
| 848 |
+
|
| 849 |
+
// ์ด๊ธฐํ ํจ์
|
| 850 |
+
function initialize() {
|
| 851 |
+
// ์ฐจํธ ์ด๊ธฐํ
|
| 852 |
+
initCharts();
|
| 853 |
+
|
| 854 |
+
// ๋น๋์ค ์
๋ก๋ ์ฒ๋ฆฌ
|
| 855 |
+
const videoUploadInput = document.querySelector('#video-upload');
|
| 856 |
+
if (videoUploadInput) {
|
| 857 |
+
videoUploadInput.addEventListener('change', (e) => {
|
| 858 |
+
if (e.target.files.length > 0) {
|
| 859 |
+
handleVideoUpload(e.target.files[0]);
|
| 860 |
+
}
|
| 861 |
+
});
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
// ์์ธ ๊ฐ์ง ์ด๊ธฐํ
|
| 865 |
+
const holistic = new mpHolistic.Holistic(config);
|
| 866 |
+
holistic.onResults(onResults);
|
| 867 |
+
|
| 868 |
+
// ... ๊ธฐ์กด ์ด๊ธฐํ ๋ก์ง์ ์ ์ง ...
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
+
// ์ ํ๋ฆฌ์ผ์ด์
์์
|
| 872 |
+
window.addEventListener('load', initialize);
|
| 873 |
+
|
| 874 |
+
// ์ฐฝ ํฌ๊ธฐ ๋ณ๊ฒฝ ์ฒ๋ฆฌ
|
| 875 |
+
window.addEventListener('resize', () => {
|
| 876 |
+
const aspect = videoElement.videoHeight / videoElement.videoWidth;
|
| 877 |
+
let width, height;
|
| 878 |
+
if (window.innerWidth > window.innerHeight) {
|
| 879 |
+
height = window.innerHeight;
|
| 880 |
+
width = height / aspect;
|
| 881 |
+
} else {
|
| 882 |
+
width = window.innerWidth;
|
| 883 |
+
height = width * aspect;
|
| 884 |
+
}
|
| 885 |
+
canvasElement.width = width;
|
| 886 |
+
canvasElement.height = height;
|
| 887 |
+
|
| 888 |
+
// ์ฐจํธ ํฌ๊ธฐ ์ฌ์กฐ์
|
| 889 |
+
speedChart.resize();
|
| 890 |
+
accelerationChart.resize();
|
| 891 |
+
});
|