-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_yape06.html
executable file
·185 lines (157 loc) · 7.16 KB
/
sample_yape06.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="A JavaScript Computer Vision Library">
<meta name="author" content="Eugene Zatepyakin">
<title>JSFeat - JavaScript Computer Vision Library.</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Droid+Sans:regular,bold|Inconsolata|PT+Sans:400,700">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/jsfeat.css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36419199-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<video id="webcam" width="640" height="480" style="display:none;"></video>
<div style=" width:640px;height:480px;margin: 10px auto;">
<canvas id="canvas" width="640" height="480"></canvas>
<div id="no_rtc" class="alert alert-error" style="display:none;"></div>
<div id="log" class="alert alert-info"></div>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jsfeat-min.js"></script>
<script type="text/javascript" src="js/compatibility.js"></script>
<script type="text/javascript" src="js/profiler.js"></script>
<script type="text/javascript" src="js/dat.gui.min.js"></script>
<script type="text/javascript">
$(window).load(function() {
"use strict";
// lets do some fun
var video = document.getElementById('webcam');
var canvas = document.getElementById('canvas');
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);
compatibility.requestAnimationFrame(tick);
};
video.addEventListener('loadeddata', readyListener);
compatibility.getUserMedia({video: true}, function(stream) {
try {
video.src = compatibility.URL.createObjectURL(stream);
} catch (error) {
video.srcObject = stream;
}
setTimeout(function() {
video.play();
}, 500);
}, function (error) {
$('#canvas').hide();
$('#log').hide();
$('#no_rtc').html('<h4>WebRTC not available.</h4>');
$('#no_rtc').show();
});
} catch (error) {
$('#canvas').hide();
$('#log').hide();
$('#no_rtc').html('<h4>Something goes wrong...</h4>');
$('#no_rtc').show();
}
var stat = new profiler();
var gui,options,ctx,canvasWidth,canvasHeight;
var img_u8, corners;
var demo_opt = function(){
this.lap_thres = 30;
this.eigen_thres = 25;
}
function demo_app(videoWidth, videoHeight) {
canvasWidth = canvas.width;
canvasHeight = canvas.height;
ctx = canvas.getContext('2d');
ctx.fillStyle = "rgb(0,255,0)";
ctx.strokeStyle = "rgb(0,255,0)";
img_u8 = new jsfeat.matrix_t(640, 480, jsfeat.U8_t | jsfeat.C1_t);
corners = [];
var i = 640*480;
while(--i >= 0) {
corners[i] = new jsfeat.keypoint_t(0,0,0,0);
}
options = new demo_opt();
gui = new dat.GUI();
gui.add(options, "lap_thres", 1, 100);
gui.add(options, "eigen_thres", 1, 100);
stat.add("grayscale");
stat.add("box blur");
stat.add("yape06");
}
function tick() {
compatibility.requestAnimationFrame(tick);
stat.new_frame();
if (video.readyState === video.HAVE_ENOUGH_DATA) {
ctx.drawImage(video, 0, 0, 640, 480);
var imageData = ctx.getImageData(0, 0, 640, 480);
stat.start("grayscale");
jsfeat.imgproc.grayscale(imageData.data, 640, 480, img_u8);
stat.stop("grayscale");
stat.start("box blur");
jsfeat.imgproc.box_blur_gray(img_u8, img_u8, 2, 0);
stat.stop("box blur");
jsfeat.yape06.laplacian_threshold = options.lap_thres|0;
jsfeat.yape06.min_eigen_value_threshold = options.eigen_thres|0;
stat.start("yape06");
var count = jsfeat.yape06.detect(img_u8, corners);
stat.stop("yape06");
// render result back to canvas
var data_u32 = new Uint32Array(imageData.data.buffer);
render_corners(corners, count, data_u32, 640);
ctx.putImageData(imageData, 0, 0);
$('#log').html(stat.log());
}
}
function render_corners(corners, count, img, step) {
var pix = (0xff << 24) | (0x00 << 16) | (0xff << 8) | 0x00;
for(var i=0; i < count; ++i)
{
var x = corners[i].x;
var y = corners[i].y;
var off = (x + y * step);
img[off] = pix;
img[off-1] = pix;
img[off+1] = pix;
img[off-step] = pix;
img[off+step] = pix;
}
}
$(window).unload(function() {
video.pause();
video.src=null;
});
});
</script>
</body>
</html>