我尝试检测下图中的黄线,但阴影遮住了黄色道路。我们有什么方法可以处理吗?编码如下:import cv2import numpy as npimage = cv2.imread('Road.jpg')hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)low_yellow = np.array([18, 94, 140])up_yellow = np.array([48, 255, 255])mask = cv2.inRange(hsv, low_yellow, up_yellow)edges = cv2.Canny(mask, 75, 150)lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 50, maxLineGap=250)for line in lines: x1, y1, x2, y2 = line[0] cv2.line(image, (x1, y1), (x2, y2), (0, 255, 0), 5) # cv2.imshow('image', img) cv2.imwrite("result.jpg", edges)
1 回答
幕布斯6054654
TA贡献1876条经验 获得超7个赞
这是转换为实验室和自动阈值的代码您必须使用适当的方法检测线条。一种高级解决方案是训练数据集进行分割(神经网络 Ex:Unet)
import cv2
import numpy as np
img = cv2.imread('YourImagePath.jpg')
cv2.imshow("Original", img)
k = cv2.waitKey(0)
# Convert To lab
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
# display b channel
cv2.imshow("Lab", lab[:, :, 2])
k = cv2.waitKey(0)
# auto threshold using Otsu
ret , mask = cv2.threshold(lab[:, :, 2] , 0 , 255 , cv2.THRESH_BINARY+
cv2.THRESH_OTSU)
#display Binary
cv2.imshow("Binary", mask)
k = cv2.waitKey(0)
cv2.destroyAllWindows()
输出:
添加回答
举报
0/150
提交
取消