我想检测这里输入图像描述中的所有补丁,我附上了用于检测它们的代码:
import cv2
import numpy as np
import matplotlib.pyplot as plt
image=cv2.imread("bw2.jpg",0)
# convert to RGB
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
# create a binary thresholded image
_, binary = cv2.threshold(gray, 0, 500, cv2.THRESH_BINARY_INV)
# show it
plt.imshow(gray, cmap="gray")
plt.show()
# find the contours from the thresholded image
contours, hierarchy = cv2.findContours(gray, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
print("contours:",contours)
# draw all contours
for c in contours:
if cv2.contourArea(c) < 3000:
continue
(x, y, w, …Run Code Online (Sandbox Code Playgroud) 我有一张尺寸为 3500x5000 的图像,现在我只想检测整个图像中的表格部分,如果不能直接进行 OCR 处理,则对其进行裁剪和旋转。经过所有搜索后,我得到了使用https://medium.com/coinmonks/a-box-detection-algorithm-for-any-image-containing-boxes-756c15d7ed26裁剪图像中每个单元格的想法,但不这样做知道如何裁剪图像中的表格部分。
我在这里使用的图像:
现在我只想要这样的部分:(手动裁剪)
提前致谢!..