forked from antimatter15/evm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color2.html
151 lines (129 loc) · 4.79 KB
/
color2.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Eulerian Video Magnification</title>
</head>
<body>
<style>
label {
width: 50px;
}
</style>
<label for="exa">exa: </label><input type="range" id="exa" style="width: 700px" min="0" max="5" step="0.01" oninput="updateR12()"><br>
<label for="alpha">α: </label><input type="range" id="alpha" style="width: 700px" min="1" max="100" step="0.01" oninput="updateR12()"><br>
<label for="lambdac">λc: </label><input type="range" id="lambdac" style="width: 700px" min="1" max="90" step="0.01" oninput="updateR12()"><br>
<label for="chroma">chr: </label><input type="range" id="chroma" style="width: 700px" min="0" max="10" step="0.01" oninput="updateR12()"><br>
<label for="r1">r1: </label><input type="range" id="r1" style="width: 700px" min="0" max="1" step="0.01" oninput="updateR12()"><br>
<label for="r2">r2: </label><input type="range" id="r2" style="width: 700px" min="0" max="1" step="0.01" oninput="updateR12()">
<br>
<video id="webcam"></video>
<canvas id="canvas"></canvas>
<canvas id="savnac"></canvas>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="jsfeat.js"></script>
<script type="text/javascript" src="compat.js"></script>
<script type="text/javascript" src="color.js"></script>
<script type="text/javascript">
// lets do some fun
var video = document.getElementById('webcam');
var canvas = document.getElementById('canvas');
var savnac = document.getElementById('savnac');
// var alpha = 50,
// lambda_c = 4,
// r1 = 0.4,
// r2 = 0.05,
// chromAttenuation = 1;
var alpha = 10,
lambda_c = 16,
r1 = 0.4,
r2 = 0.05,
chromAttenuation = 1;
var exaggeration_factor = 2;
document.getElementById('r1').value = r1;
document.getElementById('r2').value = r2;
document.getElementById('alpha').value = alpha;
document.getElementById('lambdac').value = lambda_c;
document.getElementById('chroma').value = chromAttenuation;
document.getElementById('exa').value = exaggeration_factor;
function updateR12(){
r1 = +document.getElementById('r1').value;
r2 = +document.getElementById('r2').value;
alpha = +document.getElementById('alpha').value;
lambda_c = +document.getElementById('lambdac').value;
chromAttenuation = +document.getElementById('chroma').value;
exaggeration_factor = +document.getElementById('exa').value;
}
try {
var attempts = 0;
var readyListener = function(event) {
findVideoSize();
};
var findVideoSize = function() {
if(video.videoWidth > 0 && video.videoHeight > 0) {
video.removeEventListener('loadeddata', readyListener);
onDimensionsReady(video.videoWidth, video.videoHeight);
} else {
if(attempts < 10) {
attempts++;
setTimeout(findVideoSize, 200);
} else {
onDimensionsReady(640, 480);
}
}
};
var onDimensionsReady = function(width, height) {
// demo_app(width, height);
var s = Math.min(640 / video.videoWidth, 480 / video.videoHeight)
var w = Math.floor(video.videoWidth * s >> 3) << 3,
h = Math.floor(video.videoHeight * s >> 3) << 3;
video.style.width = w + 'px'
// demo_app(Math.max(480, w), Math.max(480, h))
// demo_app(640, 480)
demo_app(Math.max(480, w), h)
compatibility.requestAnimationFrame(tick);
};
video.addEventListener('loadeddata', readyListener);
compatibility.getUserMedia({video: true}, function(stream) {
try {
video.src = compatibility.URL.createObjectURL(stream);
} catch (error) {
video.src = stream;
}
setTimeout(function() {
video.play();
}, 500);
}, function (error) {
video.src = 'baby.mp4'
video.loop = 'loop'
video.autoplay = 'autoplay'
});
} catch (error) {
}
var current_frame = 0;
var frames_processed = 0;
function tick() {
compatibility.requestAnimationFrame(tick);
// stat.new_frame();
if (video.readyState === video.HAVE_ENOUGH_DATA) {
// ctx.drawImage(video, 0, 0, 640, 480);
ctx.fillRect(0, 0, 640, 480)
var s = Math.min(640 / video.videoWidth, 480 / video.videoHeight)
// var s = 0.01 // call this number for fun times
ctx.drawImage(video, 0, 0, video.videoWidth * s, video.videoHeight * s)
evm()
if(frames_processed == 0){
lowpass1.iirFilter(img_pyr, 1);
lowpass2.iirFilter(img_pyr, 1);
}
frames_processed++
}
}
// demo_app(640, 480)
onclick = function(){
lowpass1.iirFilter(img_pyr, 1);
lowpass2.iirFilter(img_pyr, 1);
}
</script>
</body>
</html>