Dat*_*ist 0 python opencv image image-processing
我想从图像png 中提取表格并将该表格保存在另一个图像中。我有这张图片:
我想找到两个图像大洲表:
**
我该如何解决这个问题?提前致谢。
由于问题用python和标记opencv,我假设您想要使用此管道的解决方案。请查看以下解决方案。免责声明:总的来说,我是 Python 的新手,特别是 OpenCV 的 Python API(C++ 用于 win)。非常欢迎评论、改进、突出显示 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])
Run Code Online (Sandbox Code Playgroud)
对于给定的示例图像,我得到以下两个输出图像: