test.js
6.3 KB
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
// Imports the Google Cloud Video Intelligence library + Node's fs library
const video = require('@google-cloud/video-intelligence').v1;
const fs = require('fs');
const util = require('util');
async function getinfo(){
console.log('before client');
// Creates a client
const client = new video.VideoIntelligenceServiceClient();
console.log('after client');
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
const path = 'C:/Users/yunyoung/Desktop/temp/2016104137/source/forensic_tool/20190525_113617.mp4';
// Reads a local video file and converts it to base64
const readFile = util.promisify(fs.readFile);
const file = await readFile(path);
const inputContent = file.toString('base64');
// Constructs request
const request = {
inputContent: inputContent,
features: ['LABEL_DETECTION'],
};
// Detects labels in a video
const [operation] = await client.annotateVideo(request);
console.log('Waiting for operation to complete...');
const [operationResult] = await operation.promise();
// Gets annotations for video
const annotations = operationResult.annotationResults[0];
const labels = annotations.segmentLabelAnnotations;
labels.forEach(label => {
console.log(`Label ${label.entity.description} occurs at:`);
label.segments.forEach(segment => {
const time = segment.segment;
if (time.startTimeOffset.seconds === undefined) {
time.startTimeOffset.seconds = 0;
}
if (time.startTimeOffset.nanos === undefined) {
time.startTimeOffset.nanos = 0;
}
if (time.endTimeOffset.seconds === undefined) {
time.endTimeOffset.seconds = 0;
}
if (time.endTimeOffset.nanos === undefined) {
time.endTimeOffset.nanos = 0;
}
console.log(
`\tStart: ${time.startTimeOffset.seconds}` +
`.${(time.startTimeOffset.nanos / 1e6).toFixed(0)}s`
);
console.log(
`\tEnd: ${time.endTimeOffset.seconds}.` +
`${(time.endTimeOffset.nanos / 1e6).toFixed(0)}s`
);
console.log(`\tConfidence: ${segment.confidence}`);
});
});
}
//getinfo();
//get_videosaftey();
async function get_videosaftey(){
// Imports the Google Cloud Video Intelligence library
const video = require('@google-cloud/video-intelligence').v1;
console.log('before client');
// Creates a client
const client = new video.VideoIntelligenceServiceClient();
console.log('after client');
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const gcsUri = 'GCS URI of video to analyze, e.g. gs://my-bucket/my-video.mp4';
const path = 'C:/Users/yunyoung/Videos/20190525_113617.mp4';
// Reads a local video file and converts it to base64
const readFile = util.promisify(fs.readFile);
const file = await readFile(path);
const inputContent = file.toString('base64');
const request = {
inputContent: inputContent,
features: ['EXPLICIT_CONTENT_DETECTION'],
};
// Human-readable likelihoods
const likelihoods = [
'UNKNOWN',
'VERY_UNLIKELY',
'UNLIKELY',
'POSSIBLE',
'LIKELY',
'VERY_LIKELY',
];
// Detects unsafe content
const [opertaion] = await client.annotateVideo(request);
console.log('Waiting for operation to complete...');
const [operationResult] = await opertaion.promise();
// Gets unsafe content
const explicitContentResults =
operationResult.annotationResults[0].explicitAnnotation;
console.log('Explicit annotation results:');
explicitContentResults.frames.forEach(result => {
if (result.timeOffset === undefined) {
result.timeOffset = {};
}
if (result.timeOffset.seconds === undefined) {
result.timeOffset.seconds = 0;
}
if (result.timeOffset.nanos === undefined) {
result.timeOffset.nanos = 0;
}
console.log(
`\tTime: ${result.timeOffset.seconds}` +
`.${(result.timeOffset.nanos / 1e6).toFixed(0)}s`
);
console.log(
`\t\tPornography likelihood: ${likelihoods[result.pornographyLikelihood]}`
);
});
}
// var ss = `C:\\Users\\yunyoung\\Desktop\\temp\\2016104137\\source\\forensic_tool\\20190215_152731.mp4`
// var h = ss.split('\\');
// var c = '';
// for(var i = 0; i < h.length; i++){
// c += h[i] + '/';
// }
// console.log(c);
// const l = c.slice(0,-1);
// console.log(l);
// console.log(ss);
// var hell = ss.replace('/\\/g','/');
// console.log(hell);
const labels = [['landmark',[['0.0','17.17'],['0.0','17.17'],['0.0','17.17']]],['tourist destination',[['0.0','17.17'],['0.0','17.17'],['0.0','17.17']]],['tourism',[['0.0','17.17'],['0.0','17.17'],['0.0','17.17']]],['historic site',[['0.0','17.17'],['0.0','17.17'],['0.0','17.17']]],['building',[['0.0','17.17'],['0.0','17.17'],['0.0','17.17']]]];
console.log(labels);
var content = {video : '2020',labels : []}
labels.forEach(label => {
content['labels'].push(label[0]);
content[label[0]] = [];
label[1].forEach(segment => {
var temp = [segment[0],segment[1]];
content[label[0]].push(temp);
});
});
console.log(content);
var array = content['labels'];
array.forEach(label =>{
for(var i = 0; i < content[label].length; i++){
console.log(content[label][i]);
}
});
var likelihood_index = {'UNKNOWN': 0,'VERY_UNLIKELY': 1,'UNLIKELY': 2,'POSSIBLE': 3,'LIKELY': 4,'VERY_LIKELY': 5};
var det_dataset = [0,0,0,0,0,0]
det_dataset[likelihood_index[dt_dict['likelihood'][i][1]]] +=1;
var ctx = document.getElementById('det_piechart_'+lb_dict['video']);
var config = {
type: 'pie',
data: {
labels: ["UNKNOWN", "VERY_UNLIKELY", "UNLIKELY", "POSSIBLE","LIKELY",'VERY_LIKELY'],
datasets: [{
data: det_dataset,
backgroundColor: ["#F7464A", "#46BFBD", "#FDB45C", "#949FB1"],
hoverBackgroundColor: ["#FF5A5E", "#5AD3D1", "#FFC870", "#A8B3C5"]
}]
},
options: {
responsive: true
}
}