如何检测YCRCB中的颜色白色?

发布于 2025-02-02 17:58:24 字数 788 浏览 2 评论 0原文

我想在Python中使用开放式简历检测白对象,但是我有问题以定义YCBCR中的下白色和上部白色。我尝试制作程序,但该程序无法获得正确的结果来检测对象。这是我的代码:

 ycrcb = cv.cvtColor(rgb, cv.COLOR_BGR2YCrCb)
 lower_white = np.array([205, 128, 128], dtype=np.uint8)
 upper_white = np.array([235, 128, 128], dtype=np.uint8)
 img = cv.inRange(ycrcb, lower_white, upper_white)

我尝试检测使用结构元素并将其发送到形态:

se_3 = cv.getStructuringElement(cv.MORPH_RECT,(3,3))
dst_dilate = cv.dilate(img, se_3, iterations = 1)

并使用位置将其放在一起:

res = cv.bitwise_and(rgb,rgb, mask= dst_dilate)

我尽力而为,但结果是不正确的,我需要您的意见来改变哪一部分并获得更好的结果。

都是鸟“

i want to detect white object using open cv in python, but i have problem to define lower white and upper white in ycbcr. i try to make program but the program doesn't get right result to detect an object. this my code:

 ycrcb = cv.cvtColor(rgb, cv.COLOR_BGR2YCrCb)
 lower_white = np.array([205, 128, 128], dtype=np.uint8)
 upper_white = np.array([235, 128, 128], dtype=np.uint8)
 img = cv.inRange(ycrcb, lower_white, upper_white)

and i try to detect using structuring element and send to morphology :

se_3 = cv.getStructuringElement(cv.MORPH_RECT,(3,3))
dst_dilate = cv.dilate(img, se_3, iterations = 1)

and put it together using bitwise and:

res = cv.bitwise_and(rgb,rgb, mask= dst_dilate)

i try my best but the result is incorrect, i need your opinion which part to change and get better result.

the object is all birds

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2025-02-09 17:58:25

最简单的方法是加载图像,将其转换为所需的颜色空间,然后将通道分开,并并排放置。然后,使用系统的“ colour-dropper工具” “数字颜色仪表” 在macOS上)查看您感兴趣的区域中各个渠道的值:

import cv2

# Load image
im = cv2.imread('qAK68.jpg')

# Convert to YCrCb colourspace
YCrCb = cv2.cvtColor(im, cv2.COLOR_BGR2YCrCb)

# Split channels and lay out side-by-sise, Y on the left, Cr then Cb on the right
Y, Cr, Cb = cv2.split(YCrCb)
hstack = np.hstack((Y,Cr,Cb))

< a href =“ https://i.sstatic.net/ivr2b.png” rel =“ nofollow noreferrer”>

您应该看到您大致需要以下范围:

  • y 60..255
  • cr 120..136
  • cb 120 .. 136

如果您没有“彩色滴管” 工具,请转到 imagej 在线工具此处并在下面上传我的输出图像,然后鼠标在其上看到这样的值:

“


如果您在Linux上,您可以得到一个彩色滴管机称为gpick with:

sudo apt install gpick

The easiest way to do this is to load your image, convert it to your desired colourspace and split the channels, laying them out side-by-side. Then use your system's "colour-dropper tool" ("Digital Color Meter" on macOS) to look at the values of the individual channels in the areas that interest you:

import cv2

# Load image
im = cv2.imread('qAK68.jpg')

# Convert to YCrCb colourspace
YCrCb = cv2.cvtColor(im, cv2.COLOR_BGR2YCrCb)

# Split channels and lay out side-by-sise, Y on the left, Cr then Cb on the right
Y, Cr, Cb = cv2.split(YCrCb)
hstack = np.hstack((Y,Cr,Cb))

enter image description here

You should see you need roughly the following ranges:

  • Y 60..255
  • Cr 120..136
  • Cb 120..136

If you don't have a "Color Dropper" tool, just go to ImageJ online tool here and upload my output image below and mouse over it to see the values like this:

enter image description here


If you are on Linux, you can get a colour dropper called gpick with:

sudo apt install gpick
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文