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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<title>Synchronized 3D Motion Capture Visualization with Video</title>
|
| 8 |
+
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
| 9 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
body {
|
| 12 |
+
font-family: Arial, sans-serif;
|
| 13 |
+
margin: 0;
|
| 14 |
+
padding: 20px;
|
| 15 |
+
display: flex;
|
| 16 |
+
flex-direction: column;
|
| 17 |
+
align-items: center;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
#plotDiv {
|
| 21 |
+
width: 100%;
|
| 22 |
+
height: 600px;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.video-container {
|
| 26 |
+
display: flex;
|
| 27 |
+
justify-content: space-around;
|
| 28 |
+
width: 100%;
|
| 29 |
+
margin-bottom: 20px;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.video-wrapper {
|
| 33 |
+
width: 45%;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
video {
|
| 37 |
+
width: 100%;
|
| 38 |
+
height: auto;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.controls {
|
| 42 |
+
display: flex;
|
| 43 |
+
justify-content: center;
|
| 44 |
+
margin-top: 10px;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
button {
|
| 48 |
+
margin: 0 5px;
|
| 49 |
+
font-size: 20px;
|
| 50 |
+
}
|
| 51 |
+
</style>
|
| 52 |
+
</head>
|
| 53 |
+
|
| 54 |
+
<body>
|
| 55 |
+
<h1>Synchronized 3D Motion Capture Visualization with Video</h1>
|
| 56 |
+
|
| 57 |
+
<div class="video-container">
|
| 58 |
+
<div class="video-wrapper">
|
| 59 |
+
<video id="laptopVideo">
|
| 60 |
+
<source src="video.mp4" type="video/mp4">
|
| 61 |
+
Your browser does not support the video tag.
|
| 62 |
+
</video>
|
| 63 |
+
</div>
|
| 64 |
+
<!--
|
| 65 |
+
<div class="video-wrapper">
|
| 66 |
+
<video id="phoneVideo">
|
| 67 |
+
<source src="video.mp4" type="video/mp4">
|
| 68 |
+
Your browser does not support the video tag.
|
| 69 |
+
</video>
|
| 70 |
+
</div>
|
| 71 |
+
-->
|
| 72 |
+
</div>
|
| 73 |
+
|
| 74 |
+
<div class="controls">
|
| 75 |
+
<button id="playPauseBtn">▶️</button>
|
| 76 |
+
<button id="rewindBtn">⏪</button>
|
| 77 |
+
<button id="forwardBtn">⏩</button>
|
| 78 |
+
<button id="restartBtn">↩️</button>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<div id="plotDiv"></div>
|
| 82 |
+
|
| 83 |
+
<script>
|
| 84 |
+
const csvFilePath = 'MoCap_mocap.csv';
|
| 85 |
+
const body_part_names = [
|
| 86 |
+
'Left Shoulder', 'Right Upper Arm', 'Left Lower Leg', 'Spine1', 'Right Upper Leg',
|
| 87 |
+
'Spine3', 'Right Lower Arm', 'Left Foot', 'Right Lower Leg', 'Right Shoulder',
|
| 88 |
+
'Left Hand', 'Left Upper Leg', 'Right Foot', 'Spine', 'Spine2', 'Left Lower Arm',
|
| 89 |
+
'Left Toe', 'Neck', 'Right Hand', 'Right Toe', 'Head', 'Left Upper Arm', 'Hips'
|
| 90 |
+
];
|
| 91 |
+
|
| 92 |
+
const laptopVideo = document.getElementById('laptopVideo');
|
| 93 |
+
//const phoneVideo = document.getElementById('phoneVideo');
|
| 94 |
+
const playPauseBtn = document.getElementById('playPauseBtn');
|
| 95 |
+
const rewindBtn = document.getElementById('rewindBtn');
|
| 96 |
+
const forwardBtn = document.getElementById('forwardBtn');
|
| 97 |
+
const restartBtn = document.getElementById('restartBtn');
|
| 98 |
+
|
| 99 |
+
let animationFrameId;
|
| 100 |
+
let isPlaying = false;
|
| 101 |
+
|
| 102 |
+
function togglePlayPause() {
|
| 103 |
+
if (!isPlaying) {
|
| 104 |
+
laptopVideo.play();
|
| 105 |
+
//phoneVideo.play();
|
| 106 |
+
playPauseBtn.textContent = '⏸️';
|
| 107 |
+
isPlaying = true;
|
| 108 |
+
animate3DVisualization();
|
| 109 |
+
} else {
|
| 110 |
+
laptopVideo.pause();
|
| 111 |
+
//phoneVideo.pause();
|
| 112 |
+
playPauseBtn.textContent = '▶️';
|
| 113 |
+
isPlaying = false;
|
| 114 |
+
cancelAnimationFrame(animationFrameId);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
function rewind() {
|
| 119 |
+
laptopVideo.currentTime -= 5;
|
| 120 |
+
//phoneVideo.currentTime -= 5;
|
| 121 |
+
update3DVisualization();
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function forward() {
|
| 125 |
+
laptopVideo.currentTime += 5;
|
| 126 |
+
//phoneVideo.currentTime += 5;
|
| 127 |
+
update3DVisualization();
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
function restart() {
|
| 131 |
+
laptopVideo.currentTime = 0;
|
| 132 |
+
//phoneVideo.currentTime = 0;
|
| 133 |
+
update3DVisualization();
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
playPauseBtn.addEventListener('click', togglePlayPause);
|
| 137 |
+
rewindBtn.addEventListener('click', rewind);
|
| 138 |
+
forwardBtn.addEventListener('click', forward);
|
| 139 |
+
restartBtn.addEventListener('click', restart);
|
| 140 |
+
|
| 141 |
+
function getCoordinates(data, coordinate) {
|
| 142 |
+
return body_part_names.map(part => parseFloat(data[`${part}_${coordinate}`]));
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
let frames;
|
| 146 |
+
|
| 147 |
+
function processData(results) {
|
| 148 |
+
console.log("Processing data:", results);
|
| 149 |
+
|
| 150 |
+
const motion_capture_data = results.data.filter((_, index) => index % 3 === 0);
|
| 151 |
+
frames = motion_capture_data.map((row, index) => ({
|
| 152 |
+
name: index.toString(),
|
| 153 |
+
data: [{
|
| 154 |
+
x: getCoordinates(row, 'x'),
|
| 155 |
+
y: getCoordinates(row, 'y'),
|
| 156 |
+
z: getCoordinates(row, 'z'),
|
| 157 |
+
mode: 'markers',
|
| 158 |
+
type: 'scatter3d',
|
| 159 |
+
marker: { size: 5, color: 'blue' }
|
| 160 |
+
}]
|
| 161 |
+
}));
|
| 162 |
+
if (frames.length === 0) {
|
| 163 |
+
console.error("No frames were created from the data");
|
| 164 |
+
return;
|
| 165 |
+
}
|
| 166 |
+
const initialFrame = frames[0].data[0];
|
| 167 |
+
|
| 168 |
+
const layout = {
|
| 169 |
+
title: '3D Motion Capture',
|
| 170 |
+
scene: {
|
| 171 |
+
xaxis: { title: 'X' },
|
| 172 |
+
yaxis: { title: 'Y' },
|
| 173 |
+
zaxis: { title: 'Z' }
|
| 174 |
+
}
|
| 175 |
+
};
|
| 176 |
+
|
| 177 |
+
Plotly.newPlot('plotDiv', [initialFrame], layout);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
function update3DVisualization() {
|
| 181 |
+
if (!frames) return;
|
| 182 |
+
const currentTime = laptopVideo.currentTime;
|
| 183 |
+
const totalDuration = laptopVideo.duration;
|
| 184 |
+
const frameIndex = Math.floor((currentTime / totalDuration) * frames.length);
|
| 185 |
+
const frame = frames[Math.min(frameIndex, frames.length - 1)];
|
| 186 |
+
Plotly.animate('plotDiv', frame, {
|
| 187 |
+
transition: { duration: 0 },
|
| 188 |
+
frame: { duration: 0, redraw: true }
|
| 189 |
+
});
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
function animate3DVisualization() {
|
| 193 |
+
update3DVisualization();
|
| 194 |
+
if (isPlaying) {
|
| 195 |
+
animationFrameId = requestAnimationFrame(animate3DVisualization);
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
fetch(csvFilePath)
|
| 200 |
+
.then(response => {
|
| 201 |
+
if (!response.ok) {
|
| 202 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
| 203 |
+
}
|
| 204 |
+
return response.text();
|
| 205 |
+
})
|
| 206 |
+
.then(csvString => {
|
| 207 |
+
console.log("CSV data loaded successfully");
|
| 208 |
+
Papa.parse(csvString, {
|
| 209 |
+
header: true,
|
| 210 |
+
dynamicTyping: true,
|
| 211 |
+
complete: processData
|
| 212 |
+
});
|
| 213 |
+
})
|
| 214 |
+
.catch(error => console.error('Error loading the CSV file:', error));
|
| 215 |
+
</script>
|
| 216 |
+
</body>
|
| 217 |
+
|
| 218 |
+
</html>
|