-
Notifications
You must be signed in to change notification settings - Fork 70
/
index.html
492 lines (379 loc) · 15.7 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
<html>
<head>
<title>Video Intelligence API Visualiser</title>
<link rel="icon" type="image/png" href="assets/icon.png" />
<meta name="description" content="Interactive visualiser for the Google Cloud Video Intelligence API.">
<meta name="keywords" content="google cloud, video, intelligence, api, video intelligence api, google cloud">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vue-router.js"></script>
<!--
<script async src="https://www.googletagmanager.com/gtag/js?id=G-N80GH8KX9W"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-N80GH8KX9W', { client_storage: 'none' });
</script> -->
<style>
body {
text-align: center;
min-height: 1500px;
min-width: 1130px;
}
h1,
h2,
h3,
h4,
h5 {
color: #5d5d5d;
}
#video-conatiner {
position: relative;
width: 800px;
margin: 15px;
display: inline-block;
}
#video-conatiner>canvas {
width: 100%;
position: absolute;
opacity: 0.8;
left: 0;
height: 100%;
pointer-events: none;
}
video {
width: 100%;
margin: auto;
display: block;
}
video::-webkit-media-controls-fullscreen-button {
display: none !important;
}
.mdl-layout__header {
background-color: rgb(255 255 255);
color: #5d5d5d;
font-weight: 100;
}
#upload-data {
display: inline-block;
text-align: center;
vertical-align: top;
width: 250px;
}
#upload-data>p {
text-align: justify;
}
.feature-tabs {
margin: 30px;
text-align: center;
}
.feature-tabs>div {
display: inline-block;
font-size: 1.2em;
padding: 12px;
cursor: pointer;
color: #777777;
font-weight: 300;
border: solid #4285f4 1px;
border-radius: 5px;
margin: 5px;
}
.feature-tabs>div:hover {
background-color: #4285f41a;
}
.feature-tabs>.selected {
border-bottom: 2px solid #4285F4;
}
.feature-tabs>.disabled {
color: #cdcdcd;
}
.logo {
width: inherit;
}
.upload-area {
/* display: inline-block; */
width: 200px;
/* height: 62px; */
border: dashed #ededed 3px;
border-radius: 5px;
padding: 15px;
margin: 15px;
overflow: hidden;
}
.data-warning {
background-color: #ffffc3;
/* display: inline-block; */
margin: auto;
position: relative;
padding: 15px;
text-align: center;
}
.material-icons {
vertical-align: middle;
font-size: 19px;
}
.nav-tab>.material-icons {
color: #0F9D58;
}
</style>
</head>
<body>
<div id="app" class="mdl-layout--fixed-header">
<header class="mdl-layout__header">
<div class="mdl-layout-icon">
<img class="logo" src="assets/icon.png">
</div>
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">Video Intelligence API Visualiser</span>
</div>
</header>
<div id="video-conatiner">
<canvas id="my_canvas" width="800" height="500"></canvas>
<video id="video" controls autoplay></video>
</div>
<div id="upload-data">
<h5>Try with your data</h5>
<p>You can analyse a video using the following script <a target="_blank"
href="https://github.com/ZackAkil/video-intelligence-api-visualiser/blob/main/run_video_intelligence.py">here</a>
if you want to run all features at once.
</p>
<p>This app <b><u>doesn't</u></b> send or store any of your video or annotation data. It just visualises
local data files.</p>
<div class="upload-area" ondrop="drop_video(event)" ondragover="drag_enter(event)">
<p>Your video</p>
<input id="video_input" type="file" accept="video/*" />
</div>
<div class="upload-area" ondrop="drop_json(event)" ondragover="drag_enter(event)">
<p>Your .json</p>
<input id="json_input" type="file" accept="application/JSON" />
</div>
</div>
<div v-if="data_misaligned" class="data-warning">
It looks like the json data dosn't align with the video file, are you sure you have all of the right files
uploaded?
</div>
<annotations-nav v-bind:title_ids_dict="title_ids_dict" v-bind:detected_features="detected_features"
v-bind:current_view="current_view" v-on:nav-clicked="set_current_view">
</annotations-nav>
<object-tracking-viz v-if="current_view == 'Object Tracking'" id="object_tracks" v-bind:json_data="json_data"
v-bind:video_info="video_info" v-on:segment-clicked="jump_video"></object-tracking-viz>
<label-detection-viz v-if="current_view == 'Label Detection'" id="label_detection" v-bind:json_data="json_data"
v-bind:video_info="video_info" v-on:segment-clicked="jump_video"></label-detection-viz>
<shot-detection-viz v-if="current_view == 'Shot Detection'" id="shot_detection" v-bind:json_data="json_data"
v-bind:video_info="video_info" v-on:shot-clicked="jump_video"></shot-detection-viz>
<speech-transcription-viz v-if="current_view == 'Speech Transcription'" id="speech_transcription"
v-bind:json_data="json_data" v-bind:video_info="video_info" v-on:word-clicked="jump_video">
</speech-transcription-viz>
<person-detection-viz v-if="current_view == 'Person Detection'" id="person_detection"
v-bind:json_data="json_data" v-bind:video_info="video_info" v-on:segment-clicked="jump_video">
</person-detection-viz>
<face-detection-viz v-if="current_view == 'Face Detection'" id="face_detection" v-bind:json_data="json_data"
v-bind:video_info="video_info" v-on:segment-clicked="jump_video">
</face-detection-viz>
<logo-recognition-viz v-if="current_view == 'Logo Recognition'" id="logo_recognition"
v-bind:json_data="json_data" v-bind:video_info="video_info" v-on:segment-clicked="jump_video">
</logo-recognition-viz>
<text-detection-viz v-if="current_view == 'Text Detection'" id="text_detection" v-bind:json_data="json_data"
v-bind:video_info="video_info" v-on:segment-clicked="jump_video">
</text-detection-viz>
<explicit-content-detection-viz v-if="current_view == 'Explicit Content Detection'"
id="explicit_content_detection" v-bind:json_data="json_data" v-bind:video_info="video_info"
v-on:shot-clicked="jump_video">
</explicit-content-detection-viz>
</div>
<script src="utils/utils.js"></script>
<script src="components/object_tracking.js"></script>
<script src="components/label_detection.js"></script>
<script src="components/shot_detection.js"></script>
<script src="components/speech_transcription.js"></script>
<script src="components/person_detection.js"></script>
<script src="components/face_detection.js"></script>
<script src="components/logo_recognition.js"></script>
<script src="components/text_detection.js"></script>
<script src="components/explicit_content_detection.js"></script>
<script>
function jump_video_to_time(time) {
const video = document.querySelector('video')
video.currentTime = time
video.play()
}
// define component
Vue.component('annotations-nav-tab', {
props: ['title', 'current_view', 'data_id', 'detected_features'],
computed: {
has_data: function () {
return this.detected_features.includes(this.data_id)
}
},
template: `
<div class="nav-tab" v-bind:class="{selected:current_view == title, disabled:(!has_data)}">{{title}}
<span v-if="has_data" class="material-icons">
check_circle
</span>
</div>
`
})
Vue.component('annotations-nav', {
props: ['title_ids_dict', 'current_view', 'detected_features'],
methods: {
nav_clicked: function (title) {
this.$emit('nav-clicked', title)
},
},
template: `
<div class="feature-tabs">
<annotations-nav-tab v-for="id, title in title_ids_dict"
v-bind:title="title" v-bind:data_id="id"
v-bind:detected_features="detected_features" v-bind:current_view="current_view"
v-on:click.native="nav_clicked(title)">
</annotations-nav-tab>
</div>
`
})
var router = new VueRouter({
mode: 'history',
// routes: { path: '/match/:id', component: test_com}
});
var app = new Vue({
router,
el: '#app',
data: {
json_data: {},
video_info: { width: 800, height: 500, length: 252 },
video_length: 252,
current_view: 'Label Detection',
title_ids_dict: {
'Label Detection': 'shot_label_annotations',
'Shot Detection': 'shot_annotations',
'Object Tracking': 'object_annotations',
'Person Detection': 'person_detection_annotations',
'Face Detection': 'face_detection_annotations',
'Logo Recognition': 'logo_recognition_annotations',
'Speech Transcription': 'speech_transcriptions',
'Text Detection': 'text_annotations',
'Explicit Content Detection': 'explicit_annotation'
}
}, methods: {
jump_video: function (event_data) {
document.querySelector('video').scrollIntoView({ 'behavior': 'smooth', 'block': 'center' })
jump_video_to_time(event_data.seconds)
},
set_current_view: function (new_view) {
this.current_view = new_view
router.push({ hash: '#' + new_view })
}
},
computed: {
data_misaligned: function () {
console.log('delt')
if (this.json_data)
if (this.json_data.annotation_results) {
const delta = this.video_info.length - this.json_data.annotation_results[0].segment.end_time_offset.seconds
console.log('delt', delta)
if (Math.abs(delta) > 2) {
return true
}
}
return false
},
detected_features: function () {
var features = []
if (!this.json_data.annotation_results)
return features
this.json_data.annotation_results.forEach(annotations => {
console.log(Object.keys(annotations))
features = features.concat(Object.keys(annotations))
})
return features
}
}
})
const URL = window.URL || window.webkitURL
function fetch_json(url) {
var json = null
$.ajax({
'async': false,
'url': url,
'dataType': "json",
'success': function (data) {
json = data
}
})
return json
}
function load_video_from_url(url) {
video.src = url
}
function load_video_dragged(event) {
const file = this.files[0]
const file_url = URL.createObjectURL(file)
load_video_from_url(file_url)
}
function load_json_from_url(url) {
var json = null
$.ajax({
'async': false,
'url': url,
'dataType': "json",
'success': function (data) {
json = data
}
})
json_data = json
console.log(json_data)
app.json_data = json_data
console.log('keys ->>', Object.keys(json_data))
// check validity of json
if (!('annotation_results' in json_data)) {
alert("⚠️ Sorry, json output from shell not supported ⚠️ To fix set the 'output_uri' configuration when calling the Video Intelligence API so that it outputs a .json file to Google Cloud Storage, and then download that .json file. Find links to example script at the top right of the screen.")
json_input.value = null
}
}
function load_json_dragged(event) {
const file = this.files[0]
const file_url = URL.createObjectURL(file)
load_json_from_url(file_url);
}
var json_data = {}
const video = document.getElementById('video')
const video_input = document.getElementById('video_input')
const json_input = document.getElementById('json_input')
video.oncanplay = function () {
console.log("Can start playing video", video.duration, video.videoHeight, video.videoWidth)
app.video_info.length = video.duration
app.video_length.duration
app.video_info.height = 500
app.video_info.width = 800
}
function drag_enter(ev) {
ev.preventDefault()
}
function drop_video(ev) {
ev.preventDefault()
video_input.files = ev.dataTransfer.files
video_input.dispatchEvent(new Event('change'))
}
function drop_json(ev) {
ev.preventDefault()
json_input.files = ev.dataTransfer.files
json_input.dispatchEvent(new Event('change'))
}
video_input.addEventListener('change', load_video_dragged, false)
json_input.addEventListener('change', load_json_dragged, false)
load_json_from_url("assets/test_json.json")
load_video_from_url("assets/test_video.mp4")
// check for hash code in url
if (app.$route.hash) {
const hash_value = decodeURI(app.$route.hash.substring(1))
if (hash_value in app.title_ids_dict) {
app.current_view = hash_value
}
}
</script>
</body>
</html>