table 图像中的文本检测
Text detection in table images
我正在尝试从图像中的 table 中提取名称作为 OCR 项目的一部分。
对于每张图片,我都试图在名称字段周围设置边界框。我已经设法在名称列上获得边界框,但出于某种原因,它还在每个单元格内检测名称字符周围的轮廓。
我有两个问题:
为什么检测到字符周围的轮廓,我怎样才能让它们出现在单词周围?
现在,我必须指定边界框的位置。我怎样才能自动执行此操作?
这是我的代码:
import cv2
from matplotlib import pyplot as plt
import numpy as np
file = r'Corrected_images\table_deskew3.png'
table_image_contour = cv2.imread(file, 0)
table_image = cv2.imread(file)
ret, thresh_value = cv2.threshold(table_image_contour, 180, 255, cv2.THRESH_BINARY_INV)
kernel = np.ones((5, 5), np.uint8)
dilated_value = cv2.dilate(thresh_value, kernel, iterations=1)
contours, hierarchy = cv2.findContours(dilated_value, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
x, y, w, h = cv2.boundingRect(cnt)
# bounding the
if 842 < x < 2215 and 1288 < y:
table_image = cv2.rectangle(table_image, (x, y), (x + w, y + h), (0, 0, 255), 3)
roi = table_image[y: y + h, x: x + w]
#plt.imshow(roi)
#plt.show()
plt.imshow(table_image)
plt.show()
cv2.imwrite('target.png', table_image)
cv2.namedWindow('detectable', cv2.WINDOW_NORMAL)
您是否考虑过将图像设为灰度,然后让辉光滤镜穿过它?这样的话这个词就会合并成一个实体。
我正在尝试从图像中的 table 中提取名称作为 OCR 项目的一部分。
对于每张图片,我都试图在名称字段周围设置边界框。我已经设法在名称列上获得边界框,但出于某种原因,它还在每个单元格内检测名称字符周围的轮廓。
我有两个问题:
为什么检测到字符周围的轮廓,我怎样才能让它们出现在单词周围?
现在,我必须指定边界框的位置。我怎样才能自动执行此操作?
这是我的代码:
import cv2
from matplotlib import pyplot as plt
import numpy as np
file = r'Corrected_images\table_deskew3.png'
table_image_contour = cv2.imread(file, 0)
table_image = cv2.imread(file)
ret, thresh_value = cv2.threshold(table_image_contour, 180, 255, cv2.THRESH_BINARY_INV)
kernel = np.ones((5, 5), np.uint8)
dilated_value = cv2.dilate(thresh_value, kernel, iterations=1)
contours, hierarchy = cv2.findContours(dilated_value, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
x, y, w, h = cv2.boundingRect(cnt)
# bounding the
if 842 < x < 2215 and 1288 < y:
table_image = cv2.rectangle(table_image, (x, y), (x + w, y + h), (0, 0, 255), 3)
roi = table_image[y: y + h, x: x + w]
#plt.imshow(roi)
#plt.show()
plt.imshow(table_image)
plt.show()
cv2.imwrite('target.png', table_image)
cv2.namedWindow('detectable', cv2.WINDOW_NORMAL)
您是否考虑过将图像设为灰度,然后让辉光滤镜穿过它?这样的话这个词就会合并成一个实体。