-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisionApi.py
26 lines (22 loc) · 897 Bytes
/
visionApi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from google.cloud import vision
# import google.cloud.proto.vision.v1.image_annotator_pb2 as pvv
import google.cloud.vision_v1.proto.image_annotator_pb2 as pvv
import io
client = vision.ImageAnnotatorClient()
# def makeReqList(file_path):
# with io.open(file_path, 'rb') as image_file:
# content = image_file.read()
# im_obj = pvv.Image(content = content)
# return pvv.AnnotateImageRequest(image = im_obj, features = [{"type": "TEXT_DETECTION"}])
#
# def getresponse(file_path_list):
# req = map(makeReqList,file_path_list)
# response = client.batch_annotate_images(req)
# return response
def makeReqListImage(imageStr):
im_obj = pvv.Image(content = imageStr)
return pvv.AnnotateImageRequest(image = im_obj, features = [{"type": "TEXT_DETECTION"}])
def getresponseImage(imageList):
req = map(makeReqListImage,imageList)
response = client.batch_annotate_images(req)
return response