MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / analyzeTextGCS

Function analyzeTextGCS

video-intelligence/analyze.js:320–372  ·  view source on GitHub ↗
(gcsUri)

Source from the content-addressed store, hash-verified

318}
319
320async function analyzeTextGCS(gcsUri) {
321 //gcsUri - GCS URI of the video to analyze, e.g. gs://my-bucket/my-video.mp4
322 //[START video_detect_text_gcs]
323 // Imports the Google Cloud Video Intelligence library
324 const Video = require('@google-cloud/video-intelligence');
325 // Creates a client
326 const video = new Video.VideoIntelligenceServiceClient();
327
328 /**
329 * TODO(developer): Uncomment the following line before running the sample.
330 */
331 // const gcsUri = 'GCS URI of the video to analyze, e.g. gs://my-bucket/my-video.mp4';
332
333 const request = {
334 inputUri: gcsUri,
335 features: ['TEXT_DETECTION'],
336 };
337 // Detects text in a video
338 const [operation] = await video.annotateVideo(request);
339 const results = await operation.promise();
340 console.log('Waiting for operation to complete...');
341 // Gets annotations for video
342 const textAnnotations = results[0].annotationResults[0].textAnnotations;
343 textAnnotations.forEach(textAnnotation => {
344 console.log(`Text ${textAnnotation.text} occurs at:`);
345 textAnnotation.segments.forEach(segment => {
346 const time = segment.segment;
347 console.log(
348 ` Start: ${time.startTimeOffset.seconds || 0}.${(
349 time.startTimeOffset.nanos / 1e6
350 ).toFixed(0)}s`
351 );
352 console.log(
353 ` End: ${time.endTimeOffset.seconds || 0}.${(
354 time.endTimeOffset.nanos / 1e6
355 ).toFixed(0)}s`
356 );
357 console.log(` Confidence: ${segment.confidence}`);
358 segment.frames.forEach(frame => {
359 const timeOffset = frame.timeOffset;
360 console.log(
361 `Time offset for the frame: ${timeOffset.seconds || 0}` +
362 `.${(timeOffset.nanos / 1e6).toFixed(0)}s`
363 );
364 console.log('Rotated Bounding Box Vertices:');
365 frame.rotatedBoundingBox.vertices.forEach(vertex => {
366 console.log(`Vertex.x:${vertex.x}, Vertex.y:${vertex.y}`);
367 });
368 });
369 });
370 });
371 // [END video_detect_text_gcs]
372}
373
374async function analyzeObjectTrackingGCS(gcsUri) {
375 //gcsUri - GCS URI of the video to analyze, e.g. gs://my-bucket/my-video.mp4

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected