【发布时间】:2021-03-08 22:25:05
【问题描述】:
我正在尝试使用 opencv-python 中的 HoughLinesP 解析平面图以将它们转换为线坐标数组,并且该函数仅返回有角度的线,并且与我的图像中的实际线无关。
这是我的代码:
import cv2
# Read image and convert to grayscale
img = cv2.imread('C:/Data/images/floorplan/extremely basic.png', -1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Get lines with probabilistic hough lines
found_lines = cv2.HoughLinesP(gray, 1, 3.14 / 160, 100,
minLineLength=1, maxLineGap=10)
# Loop through found lines and draw each line on original image
for line in found_lines:
x1, y1, x2, y2 = line[0]
cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 1)
# Show image, wait until keypress, close windows.
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
以下是分别返回阈值 150 和 100 的内容:
我尝试修改所有选项并尝试非概率霍夫线无济于事。
【问题讨论】:
-
您的输入图像尺寸是多少?是不是很小?
-
我尝试了多张具有多种尺寸的图像,但出现了同样的错误:随机倾斜的线条与原始图像无关,但对阈值有反应。
-
我猜 maxLineGap=10 是问题所在。这些线之间的像素大于 10 尝试 40 或 50
-
你能分享源图像,我们也可以试试吗?这种问题通常是因为您分配给该函数的参数
-
我已将原始图像添加到 OP
标签: python opencv machine-learning computer-vision