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

Function localizeObjects

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

Source from the content-addressed store, hash-verified

739}
740
741async function localizeObjects(fileName) {
742 // [START vision_localize_objects]
743 // Imports the Google Cloud client libraries
744 const vision = require('@google-cloud/vision');
745 const fs = require('fs');
746
747 // Creates a client
748 const client = new vision.ImageAnnotatorClient();
749
750 /**
751 * TODO(developer): Uncomment the following line before running the sample.
752 */
753 // const fileName = `/path/to/localImage.png`;
754 const request = {
755 image: {content: fs.readFileSync(fileName)},
756 };
757
758 const [result] = await client.objectLocalization(request);
759 const objects = result.localizedObjectAnnotations;
760 objects.forEach(object => {
761 console.log(`Name: ${object.name}`);
762 console.log(`Confidence: ${object.score}`);
763 const vertices = object.boundingPoly.normalizedVertices;
764 vertices.forEach(v => console.log(`x: ${v.x}, y:${v.y}`));
765 });
766 // [END vision_localize_objects]
767}
768
769async function localizeObjectsGCS(gcsUri) {
770 // [START vision_localize_objects_gcs]

Callers 1

detect.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected