gpt4 book ai didi

python - 在 python 中,是否可以在删除图像中的线条时阻止文本的像素?

转载 作者:行者123 更新时间:2023-12-02 17:22:09 25 4
gpt4 key购买 nike

我正在表格内进行文本提取过程。但是在删除表格行时,它会影响文本的像素。可以保留覆盖在表格行像素上的文本像素。

原始图像为 RGB
enter image description here

此图像是从原始图像裁剪以供引用

输出区域
enter image description here

最佳答案

使用腐 eclipse (或膨胀的黑色物体)第二张图像作为第一张图像的掩码。

import cv2
import numpy as np
#images need equal size
original=cv2.imread('RdfpD.png')
mask = cv2.imread('zxLX4.png', cv2.IMREAD_GRAYSCALE)
se=cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,5))
ret,thresh = cv2.threshold(mask,60,255,cv2.THRESH_BINARY_INV)

dilate = cv2.dilate(thresh,se,iterations = 1)
dilate=cv2.bitwise_not(dilate)
dilate=cv2.cvtColor(dilate, cv2.COLOR_GRAY2BGR)
out=cv2.max(dilate, original)
cv2.imwrite('out_5.png', out)

enter image description here

关于python - 在 python 中,是否可以在删除图像中的线条时阻止文本的像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61633435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com