4

I used google ocr api for text extraction and measured the time taken by google ocr api, got following results.

mean     2684.05640 ms
std      1372.60204 ms
min      1690.95400 ms
25%      2111.69650 ms
50%      2271.03800 ms
75%      2644.83000 ms
max      8518.23700 ms

Code

import os
import cv2
from google.cloud import vision
from google.cloud.vision import types

class googleOCR:
    def __init__(self): 
        os.environ["GOOGLE_APPLICATION_CREDENTIALS"]= 'credentials.json'
        self.client = vision.ImageAnnotatorClient()

    def runOCR(self,image):
        '''
          image : opencv image
        '''
        try:
            _, im_arr = cv2.imencode('.jpg', image)  
            # im_arr: image in Numpy one-dim array format.
            im_string = im_arr.tostring()
            image = types.Image(content=im_string)
            # Performs text detection on the image file
            text_response = self.client.text_detection(image=image)
            if len(text_response.text_annotations)!=0:
                return text_response.text_annotations[0].description
            else:
                return None
        except Exception as e:
            print(str(e))

I have following questions

  • does google ocr api generally take this much time?
  • if no, is there any way i can reduce api time?
  • Hello, how are you inputting the images? Using image bytes or GCS instead of public image will be faster. And for timing purposes, prefetch the credentials before recording the timing helps target exactly how long vision api is taking. – Kim Dec 04 '20 at 09:28
  • Hey @Kim I am using s3 bucket with Amazon CloudFront. I have recorded timing after perfecting credentials. – Ankit Kumar Dec 07 '20 at 13:29
  • 1
    Have you tested it out using GCS instead of S3 in order to disregard the source from being the root cause of taking longer? – Joaquim Dec 14 '20 at 15:52

0 Answers0