猿问

如何检测被阴影遮挡的黄色物体?

我尝试检测下图中的黄线,但阴影遮住了黄色道路。我们有什么方法可以处理吗?


编码如下:

import cv2

import numpy as np

image = 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)


白猪掌柜的
浏览 92回答 1
1回答

幕布斯6054654

这是转换为实验室和自动阈值的代码您必须使用适当的方法检测线条。一种高级解决方案是训练数据集进行分割(神经网络 Ex:Unet)import cv2import numpy as npimg = cv2.imread('YourImagePath.jpg')cv2.imshow("Original", img)k = cv2.waitKey(0)# Convert To lablab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)# display b channelcv2.imshow("Lab", lab[:, :, 2])k = cv2.waitKey(0)# auto threshold using Otsuret , mask = cv2.threshold(lab[:, :, 2] , 0 , 255 , cv2.THRESH_BINARY+ cv2.THRESH_OTSU)#display Binarycv2.imshow("Binary", mask)k = cv2.waitKey(0)cv2.destroyAllWindows()输出:
随时随地看视频慕课网APP

相关分类

Python
我要回答