【问题标题】:Using Google Cloud Vision API with a hand-filled form将 Google Cloud Vision API 与手动填写的表单一起使用
【发布时间】:2020-04-28 15:33:03
【问题描述】:

我正在尝试使用 Google Cloud Vision API 分析考试表。下面是我正在使用的测试表。

Cloud Vision 可以很好地识别姓名和问题 #11 和 #12,包括笔迹。但是,它完全忽略了问题 #1 到 #9。没有数字,没有字母,什么都没有。

输出文本是"Name\nJohn\nDoe\n11\nI don\'t\nknow\nthe right\nanswer.\nfor me.\n12\nThis\nis\ntoo\ndifficult\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')

【问题讨论】:

    标签: python-3.x google-cloud-platform google-cloud-vision


    【解决方案1】:

    如果对照片进行阈值处理,Cloud Vision 将更容易检测图像中的文本。

    我使用下面写的代码,它在很大程度上解决了我的问题。

    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()
    

    【讨论】:

    • 谢谢!这是个好主意,但对我上面的例子没有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-04
    • 2017-12-01
    • 1970-01-01
    • 2017-07-07
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    相关资源
    最近更新 更多