-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia.js
43 lines (36 loc) · 1.11 KB
/
media.js
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
let currentMat;
let originalMat;
let isVideo = false;
let videoInterval;
function loadMedia() {
if (isVideo) {
clearInterval(videoInterval);
videoInterval = setInterval(updatePreview, 1000 / 30); // 30 fps
} else {
updatePreview();
}
}
function updatePreview() {
const canvas = document.createElement('canvas');
canvas.width = videoPreview.videoWidth || videoPreview.width;
canvas.height = videoPreview.videoHeight || videoPreview.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(videoPreview, 0, 0, canvas.width, canvas.height);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
originalMat = cv.matFromImageData(imageData);
currentMat = originalMat.clone();
applyColorChannelToggles();
cv.imshow('videoPreview', currentMat);
originalMat.delete();
currentMat.delete();
}
function processVideo() {
if (!originalMat) {
alert('Please upload a file first');
return;
}
// Process the video using OpenCV.js
// This is a placeholder for the actual video processing logic
console.log('Processing video...');
alert('Video processing complete!');
}