python - 通过python 3将表从图像提取到另一个图像

标签 python image opencv image-processing

我想从图像 png 中提取表,并将此表保存在另一张图像中。
我有这张图片:

enter image description here

我想找到两个图像大洲表:

##第一张图片:

enter image description here
**

第二张图片:

**

enter image description here

我该如何解决?
提前致谢。

最佳答案

由于问题是用pythonopencv标记的,因此我假设您想要使用此管道的解决方案。请查看以下解决方案。免责声明:我是Python的新手,尤其是OpenCV(胜出的C++)的Python API。非常欢迎提出评论,改进和强调Python的执行!

import cv2

# Read input image
img = cv2.imread('images/B81om.png', cv2.IMREAD_COLOR)

# Convert to gray scale image
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

# Simple threshold
_, thr = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY)

# Morphological closing to improve mask
close = cv2.morphologyEx(255 - thr, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)))

# Find only outer contours
contours, _ = cv2.findContours(close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

# Save images for large enough contours
areaThr = 3000
i = 0
for cnt in contours:
    area = cv2.contourArea(cnt)
    if (area > areaThr):
        i = i + 1
        x, y, width, height = cv2.boundingRect(cnt)
        cv2.imwrite('output' + str(i) + '.png', img[y:y+height-1, x:x+width-1])

对于给定的示例图像,我得到以下两个输出图像:

Small table

Large table

关于python - 通过python 3将表从图像提取到另一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55279305/

相关文章:

python - 使用带槽的 Python 描述符

python - DataFrame 减去分组均值

python - opencv-python 中的 imshow 不起作用

python - 如何以垂直角度对 blob 上的一条线进行采样? (在 Python/OpenCV 中,除非你建议切换到其他东西)

c++ - 使用 OpenCV 修复混合 STL 实现

python - 如何将numpy数组中的元素随机设置为0

python - 如何从 pandas 数据帧的两个不同列添加值

java - 2 张图像叠加无法正常工作

html - 在中间的图像上添加文本

javascript - Javascript 中图像下落(图像下落太快)