Google Cloud Vision is a machine learning service that allows you to analyze images and videos for content. This example shows how to use Google Cloud Vision with a Next.js project hosted on Vercel.
Make sure you have installed the Vercel integration as described in the Installation guide. You can install it directly from the integration page.
You'll need the Google Cloud Vision node.js client library (@google-cloud/vision
). First, install it:
npm install @google-cloud/vision
After installing the Google Cloud Platform integration on Vercel, you can access the credentials using our helper function getGCPCredentials
. See the Usage section for more information.
The following code shows how to analyze an image using Google Cloud Vision:
import { ImageAnnotatorClient } from '@google-cloud/vision';
export const visionClient = new ImageAnnotatorClient(getGCPCredentials());
const [result] = await visionClient.labelDetection('https://example.com/image.jpg');
const labels = result.labelAnnotations;
console.log('Labels:');
labels.forEach((label) => console.log(label.description));
The following code shows how to analyze a video using Google Cloud Vision:
import { VideoIntelligenceServiceClient } from '@google-cloud/video-intelligence';
export const videoClient = new VideoIntelligenceServiceClient(getGCPCredentials());
const [operation] = await videoClient.annotateVideo({
inputUri: 'gs://my-bucket/my-video.mp4',
features: ['LABEL_DETECTION'],
});
const [operationResult] = await operation.promise();
const labels = operationResult.annotationResults[0].segmentLabelAnnotations;
console.log('Labels:');
labels.forEach((label) => console.log(label.entity.description));
Image Recognition: Use Google Cloud Vision to recognize objects, people, text, and more in your Vercel applications. Analyze images and videos to extract valuable information and enhance user experience.
Content Moderation: Utilize Google Cloud Vision to moderate content in your Vercel applications. Detect inappropriate content and take action to protect your users and brand.
Image Search: Set up Google Cloud Vision to enable image search in your Vercel applications. Use image content to search for similar images or products and enhance user experience.