How to use @google-cloud/vision - 10 common examples

To help you get started, we’ve selected a few @google-cloud/vision examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-vision / samples / productSearch / products.js View on Github external
async function listProducts(projectId, location) {
  // [START vision_product_search_list_products]
  // Imports the Google Cloud client library
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ProductSearchClient();

  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */
  // const projectId = 'Your Google Cloud project Id';
  // const location = 'A compute region name';

  // Resource path that represents Google Cloud Platform location.
  const locationPath = client.locationPath(projectId, location);

  const [products] = await client.listProducts({parent: locationPath});
  products.forEach(product => {
    console.log(`Product name: ${product.name}`);
    console.log(`Product id: ${product.name.split('/').pop()}`);
    console.log(`Product display name: ${product.displayName}`);
    console.log(`Product description: ${product.description}`);
github firebase / friendlypix-web / functions / blurOffensiveImages.js View on Github external
return vision.safeSearchDetection(image).then((batchAnnotateImagesResponse) => {
    console.log('SafeSearch results on image', batchAnnotateImagesResponse);
    const safeSearchResult = batchAnnotateImagesResponse[0].safeSearchAnnotation;
    const Likelihood = Vision.types.Likelihood;

    if (Likelihood[safeSearchResult.adult] >= Likelihood.LIKELY ||
        Likelihood[safeSearchResult.violence] >= Likelihood.LIKELY) {
      return blurImage(object.name, object.bucket, object.metadata).then(() => {
        const filePathSplit = object.name.split(path.sep);
        const uid = filePathSplit[0];
        const size = filePathSplit[1]; // 'thumb' or 'full'
        const postId = filePathSplit[2];

        return refreshImages(uid, postId, size);
      });
    }
    console.log('The image', object.name, 'has been detected as OK.');
  });
});
github googleapis / nodejs-vision / samples / productSearch / productSets.js View on Github external
async function listProductSets(projectId, location) {
  // [START vision_product_search_list_product_sets]
  // Imports the Google Cloud client library
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ProductSearchClient();

  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */
  // const projectId = 'Your Google Cloud project Id';
  // const location = 'A compute region name';

  // Resource path that represents Google Cloud Platform location.
  const locationPath = client.locationPath(projectId, location);

  const [productSets] = await client.listProductSets({parent: locationPath});
  productSets.forEach(productSet => {
    console.log(`Product Set name: ${productSet.name}`);
    console.log(`Product Set display name: ${productSet.displayName}`);
  });
  // [END vision_product_search_list_product_sets]
github googleapis / nodejs-vision / samples / detect.js View on Github external
async function detectPropertiesGCS(bucketName, fileName) {
  // [START vision_image_property_detection_gcs]
  // Imports the Google Cloud client libraries
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ImageAnnotatorClient();

  /**
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const bucketName = 'Bucket where the file resides, e.g. my-bucket';
  // const fileName = 'Path to file within bucket, e.g. path/to/image.png';

  // Performs property detection on the gcs file
  const [result] = await client.imageProperties(
    `gs://${bucketName}/${fileName}`
  );
  const colors = result.imagePropertiesAnnotation.dominantColors.colors;
  colors.forEach(color => console.log(color));
  // [END vision_image_property_detection_gcs]
}
github googleapis / nodejs-vision / samples / detect.js View on Github external
async function detectLandmarksGCS(bucketName, fileName) {
  // [START vision_landmark_detection_gcs]
  // Imports the Google Cloud client libraries
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ImageAnnotatorClient();

  /**
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const bucketName = 'Bucket where the file resides, e.g. my-bucket';
  // const fileName = 'Path to file within bucket, e.g. path/to/image.png';

  // Performs landmark detection on the gcs file
  const [result] = await client.landmarkDetection(
    `gs://${bucketName}/${fileName}`
  );
  const landmarks = result.landmarkAnnotations;
  console.log('Landmarks:');
  landmarks.forEach(landmark => console.log(landmark));
  // [END vision_landmark_detection_gcs]
}
github googleapis / nodejs-vision / samples / detect.js View on Github external
async function detectLabels(fileName) {
  // [START vision_label_detection]
  // Imports the Google Cloud client library
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ImageAnnotatorClient();

  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */
  // const fileName = 'Local image file, e.g. /path/to/image.png';

  // Performs label detection on the local file
  const [result] = await client.labelDetection(fileName);
  const labels = result.labelAnnotations;
  console.log('Labels:');
  labels.forEach(label => console.log(label.description));
  // [END vision_label_detection]
}
github googleapis / nodejs-vision / samples / detect.js View on Github external
async function detectFulltext(fileName) {
  // [START vision_fulltext_detection]

  // Imports the Google Cloud client library
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ImageAnnotatorClient();

  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */
  // const fileName = 'Local image file, e.g. /path/to/image.png';

  // Read a local image as a text document
  const [result] = await client.documentTextDetection(fileName);
  const fullTextAnnotation = result.fullTextAnnotation;
  console.log(`Full text: ${fullTextAnnotation.text}`);
  fullTextAnnotation.pages.forEach(page => {
    page.blocks.forEach(block => {
      console.log(`Block confidence: ${block.confidence}`);
      block.paragraphs.forEach(paragraph => {
        console.log(`Paragraph confidence: ${paragraph.confidence}`);
        paragraph.words.forEach(word => {
github googleapis / nodejs-vision / samples / detect.js View on Github external
async function detectLogos(fileName) {
  // [START vision_logo_detection]
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ImageAnnotatorClient();

  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */
  // const fileName = 'Local image file, e.g. /path/to/image.png';

  // Performs logo detection on the local file
  const [result] = await client.logoDetection(fileName);
  const logos = result.logoAnnotations;
  console.log('Logos:');
  logos.forEach(logo => console.log(logo));
  // [END vision_logo_detection]
}
github googleapis / nodejs-vision / samples / detect.js View on Github external
async function detectWebGCS(bucketName, fileName) {
  // [START vision_web_detection_gcs]

  // Imports the Google Cloud client libraries
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ImageAnnotatorClient();

  /**
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const bucketName = 'Bucket where the file resides, e.g. my-bucket';
  // const fileName = 'Path to file within bucket, e.g. path/to/image.png';

  // Detect similar images on the web to a remote file
  const [result] = await client.webDetection(`gs://${bucketName}/${fileName}`);
  const webDetection = result.webDetection;
  if (webDetection.fullMatchingImages.length) {
    console.log(
      `Full matches found: ${webDetection.fullMatchingImages.length}`
    );
    webDetection.fullMatchingImages.forEach(image => {
      console.log(`  URL: ${image.url}`);
github googleapis / nodejs-vision / samples / detect.js View on Github external
async function detectWeb(fileName) {
  // [START vision_web_detection]

  // Imports the Google Cloud client library
  const vision = require('@google-cloud/vision');

  // Creates a client
  const client = new vision.ImageAnnotatorClient();

  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */
  // const fileName = 'Local image file, e.g. /path/to/image.png';

  // Detect similar images on the web to a local file
  const [result] = await client.webDetection(fileName);
  const webDetection = result.webDetection;
  if (webDetection.fullMatchingImages.length) {
    console.log(
      `Full matches found: ${webDetection.fullMatchingImages.length}`
    );
    webDetection.fullMatchingImages.forEach(image => {
      console.log(`  URL: ${image.url}`);
      console.log(`  Score: ${image.score}`);