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

Function detectWeb

vision/detect.js:440–494  ·  view source on GitHub ↗
(fileName)

Source from the content-addressed store, hash-verified

438}
439
440async function detectWeb(fileName) {
441 // [START vision_web_detection]
442
443 // Imports the Google Cloud client library
444 const vision = require('@google-cloud/vision');
445
446 // Creates a client
447 const client = new vision.ImageAnnotatorClient();
448
449 /**
450 * TODO(developer): Uncomment the following line before running the sample.
451 */
452 // const fileName = 'Local image file, e.g. /path/to/image.png';
453
454 // Detect similar images on the web to a local file
455 const [result] = await client.webDetection(fileName);
456 const webDetection = result.webDetection;
457 if (webDetection.fullMatchingImages.length) {
458 console.log(
459 `Full matches found: ${webDetection.fullMatchingImages.length}`
460 );
461 webDetection.fullMatchingImages.forEach(image => {
462 console.log(` URL: ${image.url}`);
463 console.log(` Score: ${image.score}`);
464 });
465 }
466
467 if (webDetection.partialMatchingImages.length) {
468 console.log(
469 `Partial matches found: ${webDetection.partialMatchingImages.length}`
470 );
471 webDetection.partialMatchingImages.forEach(image => {
472 console.log(` URL: ${image.url}`);
473 console.log(` Score: ${image.score}`);
474 });
475 }
476
477 if (webDetection.webEntities.length) {
478 console.log(`Web entities found: ${webDetection.webEntities.length}`);
479 webDetection.webEntities.forEach(webEntity => {
480 console.log(` Description: ${webEntity.description}`);
481 console.log(` Score: ${webEntity.score}`);
482 });
483 }
484
485 if (webDetection.bestGuessLabels.length) {
486 console.log(
487 `Best guess labels found: ${webDetection.bestGuessLabels.length}`
488 );
489 webDetection.bestGuessLabels.forEach(label => {
490 console.log(` Label: ${label.label}`);
491 });
492 }
493 // [END vision_web_detection]
494}
495
496async function detectWebGCS(bucketName, fileName) {
497 // [START vision_web_detection_gcs]

Callers 1

detect.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected