【发布时间】:2019-08-26 01:32:21
【问题描述】:
我目前有一份需要智能扫描的文档。
为此,我需要在任何背景中找到文档的适当轮廓,以便我可以使用该图像进行扭曲透视投影和检测。
这样做时面临的主要问题是文档边缘检测到任何类型的背景。
我曾尝试使用HoughLineP函数,并尝试在到目前为止通过canny边缘检测的灰度模糊图像上找到轮廓。
MORPH = 9
CANNY = 84
HOUGH = 25
IM_HEIGHT, IM_WIDTH, _ = rescaled_image.shape
# convert the image to grayscale and blur it slightly
gray = cv2.cvtColor(rescaled_image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (7,7), 0)
#dilate helps to remove potential holes between edge segments
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(MORPH,MORPH))
dilated = cv2.dilate(gray, kernel)
# find edges and mark them in the output map using the Canny algorithm
edged = cv2.Canny(dilated, 0, CANNY)
test_corners = self.get_corners(edged)
approx_contours = []
(_, cnts, hierarchy) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)[:5]
# loop over the contours
for c in cnts:
# approximate the contour
approx = cv2.approxPolyDP(c, 80, True)
if self.is_valid_contour(approx, IM_WIDTH, IM_HEIGHT):
approx_contours.append(approx)
break
如何通过 OpenCV 代码在文档周围找到合适的边界框。 任何帮助都感激不尽。 (文档以任何角度和任何彩色背景从相机拍摄。)
【问题讨论】:
-
请建议在 findcontours 的输入中应采用哪种类型的图像
-
是否有一些基于图像的规则可以让我们预测边界框,如果没有,您正在查看 ML 应用程序,如果是,请提及一些规则,最好的方法应该是梯度分析或 Graph Cut,但如果没有关于数据集的更多信息,就不能确定。
-
不,它不是某个数据集上基于 ML 的应用程序。它需要直接检测放置在任何背景中的文档的边缘。
-
没有规则,但它应该适用于任何文档,让我添加示例图像
-
stackoverflow.com/questions/51927043/…也有类似的问题,但是这里页面也是弯曲的,光照不一样。
标签: python-3.x transform background-color opencv3.0 perspective