0.0.2 • Published 3 years ago

@nest-excalibur/google-cloud-vision v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Google Cloud Vision

Installation

npm i @nest-excalibur/google-cloud-vision --save

Import module: GoogleCloudVisionModule : Installation

import { GoogleCloudVisionModule } from '@nest-excalibur/google-cloud-vision/lib';
 
@Module({
    imports: [
        GoogleCloudVisionModule,
    ],
})
export class SomeModule {
}

Don't forget to export your google-cloud credentials before start the server.

Inject the GoogleCloudVisionService in your controller

 import { GoogleCloudVisionService } from '@nest-excalibur/google-cloud-vision/lib';

@Controller('some')
export class SomeController {
 
    constructor(
        private readonly googleCloudVisionAService: GoogleCloudVisionService,
    ) {
    }

    @Get('inspect-image')
      @UseInterceptors(
        FileInterceptor('image'),
      )
      async inspectImage(@UploadedFile() imageFile) {
        // Fecth the file and get it's buffer.  
        const imageBuffer = imageFile.buffer;
        // Invoke the respective service methods
        const text = await this.googleCloudVisionAService.detectText(imageBuffer);
        const faces = await this.googleCloudVisionAService.detectFaces(imageBuffer);
        const explictContent = await this.googleCloudVisionAService.detectExplicitContent(imageBuffer);
        const objects = await this.googleCloudVisionAService.detectMultipleObjects(imageBuffer);
        const properties = await this.googleCloudVisionAService.detectProperties(imageBuffer);
        return {
          text,
          faces,
          explictContent,
          objects,
          properties,
        };
      }
    }

Service Methods

Method NameDescriptionParameters
detectLabelsDetects labels that are in the imageimage-url or buffer
detectFacesDetects faces that are in the imageimage-url or buffer
detectPropertiesGets the more representative properties from the image such as the most relevant colorsimage-url or buffer
detectLandMarksDetects places such as names of buildings, monuments, among other things.image-url or buffer
detectLogosDetects all logos that are in the imageimage-url or buffer
detectExplicitContentDetect some type of explicit content in the image such as violence, racism, etc.image-url or buffer
detectMultipleObjectsDetects all objects that are in the image with their respective ubication polygon coordinatesimage-url or buffer
detectTextDetects all text contained in the imageimage-url or buffer
detectHandwrittenTextDetects get handwritten text in an imageimage-url or buffer