Python 3.x 使用Google Cloud Vision API和手动填写的表单
我正试图用谷歌云视觉API分析试卷。下面是我正在使用的测试表 Cloud Vision可以很好地识别名称和问题11和12,包括笔迹。然而,它完全忽略了问题1到9。没有数字,没有字母,什么都没有 输出文本是Python 3.x 使用Google Cloud Vision API和手动填写的表单,python-3.x,google-cloud-platform,google-cloud-vision,Python 3.x,Google Cloud Platform,Google Cloud Vision,我正试图用谷歌云视觉API分析试卷。下面是我正在使用的测试表 Cloud Vision可以很好地识别名称和问题11和12,包括笔迹。然而,它完全忽略了问题1到9。没有数字,没有字母,什么都没有 输出文本是“Name\nJohn\ndooe\n11\n我不知道\n正确的\n答案。\n对我来说。\n12\n这\n是\n错误的\n” 有没有办法强迫Cloud Vision看到问题1到9 代码非常简单: def detect_document(path): """Detects document
“Name\nJohn\ndooe\n11\n我不知道\n正确的\n答案。\n对我来说。\n12\n这\n是\n错误的\n”
有没有办法强迫Cloud Vision看到问题1到9
代码非常简单:
def detect_document(path):
"""Detects document features in an image."""
from google.cloud import vision
import io
client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.document_text_detection(image=image)
print (response.full_text_annotation)
detect_document('resources/scan_letters.jpg')
如果对照片设置阈值,云视觉将更容易检测图像中的文本 我使用我在下面写的代码,它在很大程度上解决了我的问题
import cv2
from PIL import Image, ImageFilter
def threshold():
img = cv2.imread("menu.jpg") #path of unmodified image.
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh1 = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
#ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) #You can change values for best result.
cv2.imshow('Otsu', thresh1)
cv2.imwrite("test.png",thresh1) #saving path of the modified version of the photograph.
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()
threshold()
谢谢!这是一个很好的主意,但是上面的例子对我没有帮助。