-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
349 lines (338 loc) · 11 KB
/
index.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
html, body {
margin: 0;
padding: 0;
}
#progress-bar {
transition: all, 0.5s linear 0s;
width: 50%;
background-color: #eee;
border-radius: 2px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
}
#drop-area {
width: 50%;
height: 100px;
box-sizing: border-box;
padding-bottom: 15px;
border: 0.25rem dashed #A5A5C7;
cursor: default;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#drop-area > h3 {
color: #868e96;
text-align: center;
}
#drop-area > .btn {
position: relative;
border-radius: 12px;
padding: 7px;
width: 50%;
margin: auto;
color: #fff;
background-color: #007bff;
cursor: pointer;
background-image: none;
}
#drop-area > .btn > span {
color: #fff;
}
#drop-area > .btn input[type=file] {
position: absolute;
top: 0;
right: 0;
margin: 0;
border: solid transparent;
width: 100%;
opacity: 0;
cursor: pointer;
}
h1 {
margin-top: 0;
padding-top: 0.67em;
}
#loading {
position: fixed;
width: 100%;
height: 100%;
z-index: 5;
transition: all, 0.5s linear 0s;
display: none;
}
.sk-folding-cube {
top: 50%;
margin: auto;
width: 40px;
height: 40px;
position: relative;
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
.sk-folding-cube .sk-cube {
float: left;
width: 50%;
height: 50%;
position: relative;
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
.sk-folding-cube .sk-cube:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #333;
-webkit-animation: sk-foldCubeAngle 2.4s infinite linear both;
animation: sk-foldCubeAngle 2.4s infinite linear both;
-webkit-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
.sk-folding-cube .sk-cube2 {
-webkit-transform: scale(1.1) rotateZ(90deg);
transform: scale(1.1) rotateZ(90deg);
}
.sk-folding-cube .sk-cube3 {
-webkit-transform: scale(1.1) rotateZ(180deg);
transform: scale(1.1) rotateZ(180deg);
}
.sk-folding-cube .sk-cube4 {
-webkit-transform: scale(1.1) rotateZ(270deg);
transform: scale(1.1) rotateZ(270deg);
}
.sk-folding-cube .sk-cube2:before {
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.sk-folding-cube .sk-cube3:before {
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.sk-folding-cube .sk-cube4:before {
-webkit-animation-delay: 0.9s;
animation-delay: 0.9s;
}
@-webkit-keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%, 75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%, 100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
@keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%, 75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%, 100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
</style>
<title>CannyJS Remake to ECM6</title>
<script src="public/js/CannyJS.js"></script>
<script src="https://code.jquery.com/jquery-3.6.4.min.js" integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="public/js/jquery.dm-uploader.js"></script>
<script type="text/javascript">
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js').then(function(registration) {
console.log('Registration successful, scope is:', registration.scope);
}).catch(function(error) {
console.log('Service worker registration failed, error:', error);
});
}
function getRandomColor() {
let letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function changeLoadingIndicatorToRandomColor() {
let loadingElements = document.getElementsByClassName("sk-cube");
let randomColor = getRandomColor();
for (let i = 0, size = loadingElements.length; i < size; i++) {
loadingElements[i].style.backgroundColor = randomColor;
}
}
function showLoadingIndicator() {
// changeLoadingIndicatorToRandomColor();
loading.style.display = 'block';
}
function hideLoadingIndicator() {
//
loading.style.display = 'none';
}
window.onload = function() {
let canvas1 = document.getElementById('canvas1');
let canvas2 = document.getElementById('canvas2');
let ctx = canvas1.getContext('2d');
let image1Btn = document.getElementById("image1");
let image2Btn = document.getElementById("image2");
let image3Btn = document.getElementById("image3");
// let uploadBtn = document.getElementById("custom-image");
let htInput = document.getElementById("high-threshold");
let ltInput = document.getElementById("low-threshold");
let sigmmaInput = document.getElementById("sigmma");
let kernelSizeInput = document.getElementById("kernelSize");
let executeBtn = document.getElementById("execute");
const loading = document.getElementById("loading");
const uploadingProgress = document.getElementById("progress-bar");
let loadImage = function(url) {
let img = new Image();
img.src = url;
// draw loading here
showLoadingIndicator();
img.onload= function() {
canvas1.width = img.width;
canvas2.width = img.width;
canvas1.height = img.height;
canvas2.height = img.height;
ctx.drawImage(img, 0, 0);
// hide loading here
hideLoadingIndicator();
}
}
let onButtonClick = function(e) {
loadImage(e.target.value);
}
$("#drop-area").dmUploader({
url: 'upload.php',
onFallbackMode: function() {
console.log("shit do happens");
},
onInit: function(){
console.log('Callback: Plugin initialized');
},
onUploadProgress: function(id, percent) {
uploadingProgress.value = percent;
},
onBeforeUpload: function(id) {
uploadingProgress.value = '0';
console.log('before uploading');
},
onUploadSuccess: function(id, data) {
console.log('finished uploading');
loadImage(data.path);
},
onUploadError: function(id, xhr, status, errorThrown) {
console.log(errorThrown);
}
});
image1Btn.addEventListener("click", onButtonClick);
image2Btn.addEventListener("click", onButtonClick);
image3Btn.addEventListener("click", onButtonClick);
// uploadBtn.addEventListener("click", uploadImage);
let execute = function() {
let ht = parseInt(htInput.value);
let lt = parseInt(ltInput.value);
let sigmma = parseFloat(sigmmaInput.value);
let kernelSize = parseInt(kernelSizeInput.value);
if (typeof(Worker) !== "undefined" && window.Worker) {
// Yes! Web worker support!
let start = new Date;
let worker = new Worker("public/js/worker.js");
let canvasWidth = canvas1.width;
let canvasHeight = canvas1.height;
let canvasRawDate = canvas1.getContext('2d').getImageData(0, 0, canvas1.width, canvas1.height).data;
// draw loading here
showLoadingIndicator();
worker.postMessage([canvasWidth, canvasHeight, canvasRawDate, ht, lt, sigmma, kernelSize]);
worker.onmessage = function(e) {
console.log('Message received from worker');
let finish = new Date;
let duration = (finish-start)/1000;
console.log("Detection finished. Duration: "+duration+" seconds.");
let image = new GrayImageData(canvas1.width, canvas1.height);
image.setData(e.data.data);
image.drawOn(canvas2);
// hide loading here
hideLoadingIndicator();
};
} else {
let start = new Date;
let CannyJS = new CannyEdgeDetection();
let image = CannyJS.canny(canvas1, ht, lt, sigmma, kernelSize);
let finish = new Date;
let duration = (finish-start)/1000;
console.log("Detection finished. Duration: "+duration+" seconds.");
image.drawOn(canvas2);
}
}
executeBtn.addEventListener("click", execute);
loadImage("ukiyo-e.png");
}
</script>
</head>
<body>
<div id="loading">
<div class="sk-folding-cube">
<div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube4 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div>
</div>
</div>
<h1>Canny JS: A JavaScript Implementation of Canny Edge Detection</h1>
<div>
<label>Switch image:</label>
<button id="image1" value="ukiyo-e.png">Image 1</button>
<button id="image2" value="car.jpg">Image 2</button>
<button id="image3" value="nishida_2.jpeg">Image 3</button><br/>
<div id="drop-area">
<h3>Drag and Drop Files Here</h3>
<div class="btn">
<span>Open the file Browser</span>
<input name="image_field" type="file" title="Click to add Files" />
</div>
</div>
<progress id="progress-bar" value="0" max="100">
</div>
<div>
<label>high threshold (0-255):</label>
<input type="text" id="high-threshold" value="100"><br/>
<label>low threshold (0-255):</label>
<input type="text" id="low-threshold" value="50"><br/>
<label>sigmma (0.0-):</label>
<input type="text" id="sigmma" value="1.4"><br/>
<label>kernel size (odd number):</label>
<input type="text" id="kernelSize" value="3"><br/>
</div>
<div>
<button id="execute">Detect edges</button>
</div>
<canvas id="canvas1" width="400px" height="600px"></canvas>
<canvas id="canvas2" width="400px" height="600px"></canvas>
</body>
</html>