Skip to content

文字的坐标和图片背景的颜色相关,并且差异比较大 #105

@lhb2

Description

@lhb2

https://www.jkeiei.co.jp/m/column-media/wp-content/uploads/sp-chuushaku-jkeiei.png

在识别上面图片的时候,出现2个问题:
1.图片较大,高度超过1000,但ocr只返回量化[0-1000]的值,没有小数点,导致坐标误差大
2.这张图片有透明背景色,用不同的颜色填充后,返回的文字坐标也各不相同,差异比较大

不填充:
近畿財務局長(14)第00218号(15,375),(413,383)

绿色背景填充:
近畿財務局長(14)第00218号(13,452),(414,459)

白色背景填充:
近畿財務局長(14)第00218号(23,371),(412,377)

填充的代码如下:
img=img.convert("RGBA")
if img.mode == "RGBA" and img.getextrema()[3][0] < 255:
# 含透明像素,自定义背景颜色填充透明区域
background = Image.new("RGB", img.size, (220,220,220))
background.paste(img, mask=img.split()[3])
buffer = io.BytesIO()
background.save(buffer, format=format)
imageByteData = buffer.getvalue()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions