我目前有一份需要智能扫描的文档。
为此,我需要在任何背景下找到文档的正确轮廓,以便我可以对该图像进行扭曲的透视投影和检测。
这样做时面临的主要问题是文档边缘检测任何类型的背景。
到目前为止,我一直尝试使用函数 HoughLineP 并尝试在通过精明边缘检测的灰度模糊图像上找到轮廓。
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 = [] …Run Code Online (Sandbox Code Playgroud)