Google OCR API taking too much time

Viewed 232

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?
0 Answers
Related