gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:58:46 27 4
gpt4 key购买 nike

我尝试在下图中检测到黄线,但阴影遮盖了黄色道路。我们有什么方法可以解决吗?
enter image description here
我们可以在这个问题中检测到黄色:About Line detection by using OpenCVHow to delete the other object from figure by using opencv?
编码如下:

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)

最佳答案

这是转换为实验室和自动阈值的代码
您必须使用适当的方法来检测行。
一个高级的解决方案是训练数据集进行分割(神经网络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()
输出:
enter image description here

关于python - 如何检测被阴影遮挡的黄色物体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63571466/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com