【发布时间】:2019-09-11 06:44:12
【问题描述】:
我是 openCV 的新手,我必须检测卫星图像中的街道线
这是原图
我应用了不同的阈值,我能够区分背景和 fg
retval, threshold = cv2.threshold(img1,150, 255, cv2.THRESH_BINARY)
plt.imshow(threshold)
在此之后,我进行了平滑处理以消除 HoughLines 的噪声
# Initialize output
out = cv2.cvtColor(threshold, cv2.COLOR_GRAY2BGR)
# Median blurring to get rid of the noise; invert image
threshold_blur = 255 - cv2.medianBlur(threshold, 5)
plt.imshow(threshold_blur,cmap='gray', vmin = 0, vmax = 255)
现在当我应用霍夫线时,我得到了这个
# Detect and draw lines
lines = cv2.HoughLinesP(threshold_blur, 1, np.pi/180, 10, minLineLength=10, maxLineGap=100)
for line in lines:
for x1, y1, x2, y2 in line:
cv2.line(out, (x1, y1), (x2, y2), (0, 0, 255), 2)
plt.imshow(out)
我需要这样的线条
为什么它不起作用,我该怎么办?
【问题讨论】:
-
你试过反转图像吗?很可能是霍夫线变换期望图像具有深色背景和浅色线条。
标签: python opencv image-processing hough-transform