gpt4 book ai didi

opencv - 从图像中提取表结构

转载 作者:行者123 更新时间:2023-12-02 16:47:04 26 4
gpt4 key购买 nike

我有一堆像Table Sample的图片

从图像中仅提取表结构的好方法是什么?我只想提取直线。

我一直在研究OpenCV Finding Contours代码示例,结果非常有希望。我只是想知道是否有更好的方法?

最佳答案

OpenCV具有检测线段的好方法。这是python中的代码片段:

import math
import numpy as np
import cv2

img = cv2.imread('page2.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

lsd = cv2.createLineSegmentDetector(0)
dlines = lsd.detect(gray)

for dline in dlines[0]:
x0 = int(round(dline[0][0]))
y0 = int(round(dline[0][1]))
x1 = int(round(dline[0][2]))
y1 = int(round(dline[0][3]))
cv2.line(img, (x0, y0), (x1,y1), 255, 1, cv2.LINE_AA)

# print line segment length
a = (x0-x1) * (x0-x1)
b = (y0-y1) * (y0-y1)
c = a + b
print(math.sqrt(c))

cv2.imwrite('page2_lines.png', img)

关于opencv - 从图像中提取表结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45088134/

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