使用opencv检测作物线

2024-05-19 00:20:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个车道检测项目,我想输入机器人在作物行之间的路径。我最初将图像转换为鸟瞰图以便更好地处理,并尝试了Hough变换,但Hough变换并没有给我带来好的效果

鸟瞰图像

Birds eye view of the image

有没有其他我错过的方法


Tags: 项目方法作物图像路径机器人效果鸟瞰图
1条回答
网友
1楼 · 发布于 2024-05-19 00:20:51

在应用Hough线算法之前,可以执行以下操作:

1)色移

应用颜色变换,将图像的颜色分割为蓝色、绿色和红色通道。因为裁剪行是绿色的,所以可以放大绿色以使其与其他通道更加突出

b,g,r = cv2.split(img) 
gscale = 2*g-r-b

2)Canny边缘检测

在cv2.Canny()函数中处理min和max参数,直到满意为止

gscale = cv2.Canny(gscale,minVal,maxValue)

3)骨骼化

骨架化是将感兴趣的区域变薄到其二元成分的过程。这使得执行模式识别更容易

size = np.size(gscale) #returns the product of the array dimensions
skel = np.zeros(gscale.shape,np.uint8) #array of zeros
ret,gscale = cv2.threshold(gscale,128,255,0) #thresholding the image
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
done = False
while( not done):
    eroded = cv2.erode(gscale,element)
    temp = cv2.dilate(eroded,element)
    temp = cv2.subtract(gscale,temp)
    skel = cv2.bitwise_or(skel,temp)
    gscale = eroded.copy()
zeros = size - cv2.countNonZero(gscale)
    if zeros==size:
        done = True

在按照各自的顺序应用所有这些之后,您应该可以在Hough lines算法中获得更好的性能

相关问题 更多 >

    热门问题