噪声图像上的矩形检测 Python

Rectangle detection on noisy image Python

伙计们!

我正在尝试在这张非常嘈杂的图像上检测矩形线。到目前为止,我能够检测到第一个矩形和外部矩形。但我找不到内部矩形。对我的问题有帮助吗?非常感谢!

# import the necessary packages
import cv2
import numpy as np
# Read image
img = cv2.imread('test8_2.jpg', cv2.IMREAD_COLOR) # road.png is the filename
# Convert the image to gray-scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Find the edges in the image using canny detector
edges = cv2.Canny(gray, 60, 120)
# Detect points that form a line
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 15, minLineLength=10, maxLineGap=40)
# Draw lines on the image
for line in lines:
    x1, y1, x2, y2 = line[0]
    cv2.line(img, (x1, y1), (x2, y2), (255, 0, 0), 3)
# Show result
cv2.imshow("Result Image", img)
cv2.waitKey(0)

output image input image

通过水平添加像素值,您可以获得一维轮廓。然后用高斯垂直平滑这个轮廓,你会得到一个干净的信号,你可以从中检测到 minima/maxima 并且你可以估计边缘的位置。