Advertisement
jarekmor

VisionAI

Mar 5th, 2023
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. def detect_text(path):
  2.     """Detects text in the file."""
  3.    
  4.     import io, os
  5.     from google.cloud import vision
  6.     import json
  7.    
  8.     os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './GoogleVisionKeys.json'        # Autentykacja klienta
  9.     client = vision.ImageAnnotatorClient()
  10.  
  11.     with io.open(path, 'rb') as image_file:
  12.         content = image_file.read()
  13.  
  14.     image = vision.Image(content=content)
  15.  
  16.     response = client.text_detection(image=image)
  17.     texts = response.text_annotations
  18.    
  19.     print(float(texts[0].description))
  20.  
  21.     if response.error.message:
  22.         raise Exception('{}\nFor more info on error messages, check: ' 'https://cloud.google.com/apis/design/errors'.format(response.error.message))
  23.    
  24.     return float(texts[0].description)
  25.        
  26. detect_text('meter_digits_only.png')            # obrazek do detekcji cyferek
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement