gpt4 book ai didi

python - 使用python opencv跟踪白色

转载 作者:IT老高 更新时间:2023-10-28 20:57:56 26 4
gpt4 key购买 nike

我想使用网络摄像头和 python opencv 跟踪白色。我已经有了跟踪蓝色的代码。

_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

# define range of blue color in HSV
lower_blue = np.array([110,100,100])
upper_blue = np.array([130,255,255])

#How to define this range for white color


# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_blue, upper_blue)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)

cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)

我应该给出什么作为下限和上限跟踪白色!!??我尝试改变值,我得到了其他颜色,但白色没有运气!!!

is that HSV values or BGR values specified as lower and upper bounds???

PS:我必须将最后的结果作为二进制图像进行进一步处理!!

请帮帮我!!!

最佳答案

我们来看看HSV色彩空间:

enter image description here

你需要白色,它靠近中心并且相当高。开始

sensitivity = 15
lower_white = np.array([0,0,255-sensitivity])
upper_white = np.array([255,sensitivity,255])

然后根据您的需要调整阈值。

您还可以考虑使用 HSL 色彩空间,它代表色相、饱和度、亮度。然后,您只需要查看亮度即可检测白色并识别其他颜色会很容易。 HSV 和 HSL 都保持相似的颜色接近。此外,HSL 可能会更准确地检测白色 - 这就是原因:

enter image description here

关于python - 使用python opencv跟踪白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22588146/

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