【发布时间】:2021-04-14 14:25:44
【问题描述】:
我完成了关于 OpenCv 寻找车道的教程,我正在尝试将其应用于在地板上寻找一块胶带。我让代码运行并设置了感兴趣的区域,但它只找到了磁带的一些边缘。我认为这与厚度有关,但我不是 100% 确定。任何帮助将不胜感激。
import cv2
import numpy as np
import matplotlib.pyplot as plt
def canny(image):
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
blur = cv2.GaussianBlur(gray, (5,5), 0)
canny = cv2.Canny(blur, 50, 150)
return canny
def display_lines(image, lines):
line_image = np.zeros_like(image)
if lines is not None:
for line in lines:
x1, y1, x2, y2 = line.reshape(4)
cv2.line(line_image, (x1, y1), (x2, y2), (255, 0, 0), 10)
return line_image
def region_of_interest(image):
height = image.shape[0]
polygons = np.array([
[(200, height), (400, height), (355, 0)]
])
mask = np.zeros_like(image)
cv2.fillPoly(mask, polygons, 255)
masked_image = cv2.bitwise_and(image, mask)
return masked_image
image = cv2.imread('tape3.jpg')
lane_image = np.copy(image)
canny_image = canny(image)
cropped_image = region_of_interest(canny_image)
lines = cv2.HoughLinesP(cropped_image, 2, np.pi/180, 100, np.array([]), minLineLength=40, maxLineGap=5)
line_image = display_lines(lane_image, lines)
combo_image = cv2.addWeighted(lane_image, 0.8, line_image, 1, 1)
# cv2 print image
print(region_of_interest(image))
cv2.imshow("result", combo_image)
cv2.waitKey(0)
【问题讨论】:
-
车道总是黑胶带吗?对于感兴趣的区域,你不能做一些简单的颜色分析+阈值来找到胶带的位置吗?
-
最终,它将是带有红色条带的黑色胶带(红色条带是水平的)所以我真的不知道阈值是否适用。
-
霍夫线使用 Canny 边缘检测器。检查 Canny 图像是否正确找到整个磁带上的边缘。胶带不是完全笔直的,因此您将无法将整个边界检测为单个线段。您必须微调阈值和参数才能获得正确的结果。
-
@SembeiNorimaki 我将更新代码以包含我使用的 canny 函数。
-
感谢您的更新。请更新您的帖子以提供曲目开头、中间和结尾的示例图像。一张图片不足以让我们相信我们的建议会奏效。
标签: python opencv image-processing hough-transform