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

Function detectWebGCS

vision/detect.js:496–551  ·  view source on GitHub ↗
(bucketName, fileName)

Source from the content-addressed store, hash-verified

494}
495
496async function detectWebGCS(bucketName, fileName) {
497 // [START vision_web_detection_gcs]
498
499 // Imports the Google Cloud client libraries
500 const vision = require('@google-cloud/vision');
501
502 // Creates a client
503 const client = new vision.ImageAnnotatorClient();
504
505 /**
506 * TODO(developer): Uncomment the following lines before running the sample.
507 */
508 // const bucketName = 'Bucket where the file resides, e.g. my-bucket';
509 // const fileName = 'Path to file within bucket, e.g. path/to/image.png';
510
511 // Detect similar images on the web to a remote file
512 const [result] = await client.webDetection(`gs://${bucketName}/${fileName}`);
513 const webDetection = result.webDetection;
514 if (webDetection.fullMatchingImages.length) {
515 console.log(
516 `Full matches found: ${webDetection.fullMatchingImages.length}`
517 );
518 webDetection.fullMatchingImages.forEach(image => {
519 console.log(` URL: ${image.url}`);
520 console.log(` Score: ${image.score}`);
521 });
522 }
523
524 if (webDetection.partialMatchingImages.length) {
525 console.log(
526 `Partial matches found: ${webDetection.partialMatchingImages.length}`
527 );
528 webDetection.partialMatchingImages.forEach(image => {
529 console.log(` URL: ${image.url}`);
530 console.log(` Score: ${image.score}`);
531 });
532 }
533
534 if (webDetection.webEntities.length) {
535 console.log(`Web entities found: ${webDetection.webEntities.length}`);
536 webDetection.webEntities.forEach(webEntity => {
537 console.log(` Description: ${webEntity.description}`);
538 console.log(` Score: ${webEntity.score}`);
539 });
540 }
541
542 if (webDetection.bestGuessLabels.length) {
543 console.log(
544 `Best guess labels found: ${webDetection.bestGuessLabels.length}`
545 );
546 webDetection.bestGuessLabels.forEach(label => {
547 console.log(` Label: ${label.label}`);
548 });
549 }
550 // [END vision_web_detection_gcs]
551}
552
553async function detectWebGeo(fileName) {

Callers 1

detect.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected