개정판 ba6ef1c3
gcloud
Change-Id: I3eeba5a716a9ea1a4ebc1786be4588885ccc0d13
minorTools/gcloud_test.py | ||
---|---|---|
13 | 13 |
|
14 | 14 |
image = vision.Image(content=content) |
15 | 15 |
|
16 |
response = client.text_detection(image=image) |
|
16 |
response = client.text_detection(image=image, image_context={"language_hints": ["en"]})
|
|
17 | 17 |
#response = client.document_text_detection(image=image) |
18 |
|
|
19 |
bounds = [] |
|
20 |
document = response.full_text_annotation |
|
21 |
|
|
22 |
for page in document.pages: |
|
23 |
for block in page.blocks: |
|
24 |
for paragraph in block.paragraphs: |
|
25 |
for word in paragraph.words: |
|
26 |
''' |
|
27 |
for symbol in word.symbols: |
|
28 |
if feature == FeatureType.SYMBOL: |
|
29 |
bounds.append(symbol.bounding_box) |
|
30 |
|
|
31 |
if feature == FeatureType.WORD: |
|
32 |
bounds.append(word.bounding_box) |
|
33 |
''' |
|
34 |
_vertices = [(vertex.x,vertex.y) for vertex in word.bounding_box.vertices] |
|
35 |
cv2.rectangle(_image, _vertices[0], _vertices[2], (100, 100, 100), 2) |
|
36 |
cv2.putText(_image, ''.join([s.text for s in word.symbols]), (_vertices[0][0] + 30, (_vertices[0][1] - 10)), cv2.FONT_HERSHEY_PLAIN, 1, (100, 100, 100), 1) |
|
37 |
|
|
38 |
_vertices = [(vertex.x,vertex.y) for vertex in paragraph.bounding_box.vertices] |
|
39 |
cv2.rectangle(_image, _vertices[0], _vertices[2], (100, 100, 100), 2) |
|
40 |
|
|
41 |
#if feature == FeatureType.PARA: |
|
42 |
# bounds.append(paragraph.bounding_box) |
|
43 |
|
|
44 |
#if feature == FeatureType.BLOCK: |
|
45 |
# bounds.append(block.bounding_box) |
|
46 |
|
|
47 |
''' |
|
18 | 48 |
texts = response.text_annotations |
19 | 49 |
#print("Texts:") |
20 | 50 |
|
... | ... | |
27 | 57 |
_vertices = [(vertex.x,vertex.y) for vertex in text.bounding_poly.vertices] |
28 | 58 |
|
29 | 59 |
cv2.rectangle(_image, _vertices[0], _vertices[2], (100, 100, 100), 2) |
30 |
cv2.putText(_image, text.description, (_vertices[0][0], (_vertices[0][1] - 10)), cv2.FONT_HERSHEY_PLAIN, 1, (100, 100, 100), 1) |
|
60 |
cv2.putText(_image, text.description, (_vertices[0][0] + 30, (_vertices[0][1] - 10)), cv2.FONT_HERSHEY_PLAIN, 1, (100, 100, 100), 1) |
|
61 |
''' |
|
31 | 62 |
|
32 | 63 |
cv2.imwrite(path.replace('test', 'test_res'), _image) |
33 | 64 |
|
내보내기 Unified diff