개정판 65eb78a7
gcloud test
Change-Id: I71c5b6e1d2c62590b3f7cf4cf754a1b78e3a632f
DTI_PID/WebServer/CRAFT_pytorch_master/text_craft.py | ||
---|---|---|
29 | 29 |
import json |
30 | 30 |
import zipfile |
31 | 31 |
|
32 |
from google.cloud import vision |
|
33 |
|
|
32 | 34 |
#from CRAFT_pytorch_master.craft import CRAFT |
33 | 35 |
from craft import CRAFT |
34 | 36 |
|
... | ... | |
113 | 115 |
return boxes_list |
114 | 116 |
|
115 | 117 |
def get_gcloud_ocr(img): |
116 |
return ['test'] |
|
118 |
#path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'gcloud.png') |
|
119 |
#cv2.imwrite(path, img) |
|
120 |
|
|
121 |
client = vision.ImageAnnotatorClient() |
|
122 |
|
|
123 |
#content = img.tobytes() |
|
124 |
content = cv2.imencode('.jpg', img)[1].tostring() |
|
125 |
image = vision.Image(content=content) |
|
126 |
|
|
127 |
#response = client.text_detection(image=image) |
|
128 |
response = client.document_text_detection(image=image) |
|
129 |
texts = response.text_annotations |
|
130 |
|
|
131 |
infos = [] |
|
132 |
for text in texts[1:]: |
|
133 |
_vertices = [(vertex.x,vertex.y) for vertex in text.bounding_poly.vertices] |
|
134 |
_vertices.insert(0, text.description) |
|
135 |
infos.append(_vertices) |
|
136 |
|
|
137 |
return infos |
|
117 | 138 |
|
118 | 139 |
def get_text_box(img, img_path=None, score_path=None, trained_model=None): |
119 | 140 |
if img.shape[0] == 2: img = img[0] |
minorTools/gcloud_test.py | ||
---|---|---|
24 | 24 |
#vertices = [ f"({vertex.x},{vertex.y})" for vertex in text.bounding_poly.vertices ] |
25 | 25 |
#print("bounds: {}".format(",".join(vertices))) |
26 | 26 |
|
27 |
_vertices = [(vertex.x,vertex.y) for vertex in text.bounding_poly.vertices ]
|
|
27 |
_vertices = [(vertex.x,vertex.y) for vertex in text.bounding_poly.vertices] |
|
28 | 28 |
|
29 | 29 |
cv2.rectangle(_image, _vertices[0], _vertices[2], (100, 100, 100), 2) |
30 | 30 |
cv2.putText(_image, text.description, (_vertices[0][0], (_vertices[0][1] - 10)), cv2.FONT_HERSHEY_PLAIN, 1, (100, 100, 100), 1) |
내보내기 Unified diff