ImageEn, unit iexGoogleApi

TIEGoogleVision

Properties · Methods · Demos · Examples

Declaration

TIEGoogleVision = class;


Description

Provides access to the Google Vision web service to recognize objects, text, handwriting, faces, famous landmarks and logos in images.

Note:
You will need an API key that supports the "Google Cloud Vision API". See www.ImageEn.com/support/CreateGoogleAPIKey.html
TIEGoogleVision works best with Delphi/BCB 10.1 (Berlin) or newer. On older versions you must use your own REST components and parse content by setting ResponseJSON


Google Vision Features

Object localization (iegrObjectLocalization)
Detects objects in an image, and returns their label and bounding box.

See: ObjectAnnotations




Face detection (iegrFaceDetection)
Locates faces with bounding polygons, and identifies specific facial "landmarks" such as eyes, ears, nose, mouth, etc. along with their corresponding confidence values.
Also, returns likelihood ratings for emotion (joy, sorrow, anger, surprise) and general image properties (underexposed, blurred, headwear present).

See: FaceAnnotations
Also available locally using IEVision: TIEVisionObjectsFinder

  


Landmark detection (iegrLandmarkDetection)
Detects popular natural and human-made structures within an image, returning the name, GPS coordinates and bounding box for the landmark.

See: LandmarkAnnotations
Also see: GenerateGoogleStaticMapURL

  

  


Logo detection (iegrLogoDetection)
Recognizes popular product logos within an image, returning their name and bounding box.

See: LogoAnnotations

  


Label detection (iegrLabelDetection)
Detects information about entities in an image, such as general objects, locations, activities, animal species, products, and more.
Note: Labels are returned in English only

See: LabelAnnotations


Text detection (iegrTextDetection)
Recognizes text and handwriting within an image (OCR), returning the text and location.
Returns text in all Google-supported languages.
Note: iegrTextDetection is optimized for sparse areas of text within a larger image

See: TextAnnotations
For more advanced, local OCR, use IEVision: TIEVisionOCR

  

  


Document text detection (iegrDocumentTextDetection)
Optical character recognition (OCR) for a file (PDF/TIFF) or dense text image.
Note: iegrDocumentTextDetection is optimized for dense areas of text in an image (images that are documents), and images that contain handwriting.

See: TextContent
For more advanced, local OCR, use IEVision: TIEVisionOCR


Crop hint detection (iegrCropHintsDetection)
Suggests a crop region for the image and returns its importance relative to the original image for each request.
You can provide up to 16 image ratio values (width:height) for a single image.
See: CropHintsAnnotation


Web Entities and Pages (iegrWebDetection)
Detects references and related web information for an image, including:
Best guess label: A best guess as to the topic of the requested image inferred from similar images on the Internet
Inferred entities (labels/descriptions) from similar images on the Web
Full matching images: A list of URLs for fully matching images of any size on the Internet
Partial matching images: A list of URLs for images that share key-point features, such as a cropped version of the original image
Pages with matching images: A list of Webpages with an image that matches one of the above rules
Visually similar images: A list of URLs for images that share some features with the original image

See: WebDetection

  


SafeSearch: Explicit content detection (iegrSafeSearchDetection)
Detects explicit content such as adult content or violent content within an image.
Provides likelihood ratings for the following explicit content categories: adult, spoof, medical, violence, and racy.

See: SafeSearchAnnotation


Image properties (iegrImageProperties)
Returns the dominant colors in an image.
ImageEn does not currently parse iegrImageProperties results.

See: Response

More Information: cloud.google.com/vision/docs/features-list

Demo


Demo  Demos\InputOutput\GoogleVisionApi\GoogleVisionApi.dpr

Examples


Cursor := crHourglass;
lblSubmitting.Visible := True;
GVision := TIEGoogleVision.Create( MY_API_KEY );
try
  // Use recommended delivery size (for faster processing)
  GVision.SendImageWidth  := 640;
  GVision.SendImageHeight := 480;

  GVision.RequestTypes := [iegrWebDetection, iegrSafeSearchDetection, iegrLandmarkDetection];
  GVision.ProcessImage( edtFilename.Text );

  lbxResults.Clear();

  if Length( GVision.WebDetection.bestGuessLabels ) > 0 then
    lbxResults.Items.Add( 'This image is likely to be: ' + GVision.WebDetection.bestGuessLabels[0].webLabel );

  if GVision.HasLandmarkAnnotations then
  begin
    lbxResults.Items.Add( 'This image is the landmark: ' + GVision.LandmarkAnnotations[0].description );
    lbxResults.Items.Add( 'Latitude: '  + LatLongToStr( GVision.LandmarkAnnotations[0].latitude, True ));
    lbxResults.Items.Add( 'Longitude: ' + LatLongToStr( GVision.LandmarkAnnotations[0].longitude, False ));
  end;

  lbxResults.Items.Add( format( 'Found %d matching images on the web', [ GVision.WebDetection.fullMatchingImages.Count ]));
  lbxResults.Items.AddStrings( GVision.WebDetection.fullMatchingImages );

  lbxResults.Items.Add( format( 'Found %d pages on the web containing this image', [ GVision.WebDetection.pagesWithMatchingImages.Count ]));
  lbxResults.Items.AddStrings( GVision.WebDetection.pagesWithMatchingImages );

  if GVision.SafeSearchAnnotation.adult in [ieglLikely, ieglVeryLikely] then
    lbxResults.Items.Add( 'Likely to be an ADULT image' );

  if GVision.SafeSearchAnnotation.violence in [ieglLikely, ieglVeryLikely] then
    lbxResults.Items.Add( 'Likely to be a VIOLENT image' );

finally
  Cursor := crDefault;
  lblSubmitting.Visible := False;
  GVision.Free;
end;

Methods and Properties


General
Public Method  Create
Public Property  GoogleApiKey
Public Property  MaxResults
Public Method  ProcessImage
Public Property  RequestTypes
Public Property  ResampleFilter
Public Property  SendImageWidth
Public Property  SendImageHeight
Public Property  SendFormat
Public Property  TightFaceBounding

Results
Public Property  CropHintsAnnotation
Public Property  FaceAnnotations
Public Method  HasFaceAnnotations
Public Method  HasLandmarkAnnotations
Public Method  HasLogoAnnotations
Public Method  HasLabelAnnotations
Public Method  HasObjectAnnotations
Public Method  HasTextAnnotations
Public Method  HasSafeSearchAnnotation
Public Method  HasWebDetection
Public Method  HasCropHintsAnnotation
Public Property  LabelAnnotations
Public Property  LandmarkAnnotations
Public Property  LogoAnnotations
Public Property  ObjectAnnotations
Public Property  Response
Public Property  ResponseJSON
Public Property  SafeSearchAnnotation
Public Property  TextAnnotations
Public Property  TextContent
Public Property  WebDetection


See Also

GenerateGoogleStaticMapURL