最佳答案
由于问题是用python
和opencv
标记的,因此我假设您想要使用此管道的解决方案。请查看以下解决方案。免责声明:我是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])
对于给定的示例图像,我得到以下两个输出图像:
关于python - 通过python 3将表从图像提取到另一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55279305/