Python:如何知道PIL中的边界框有多少种颜色?

发布于 2024-09-28 17:27:56 字数 68 浏览 0 评论 0原文

嘿,我有这么多 PIL 边界框(x,y,x1,y1)

我只想知道边界框中有多少种颜色,有什么快速的方法吗?

Hey, I've got so many PIL bounding box(x,y, x1,y1)

I just want to know how many colors are there in the bounding box, is there any fast way to do?

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

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

发布评论

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

评论(1

倾城月光淡如水﹏ 2024-10-05 17:27:56
>>> myimg = ...
>>> colors = myimg.crop((x0, y0, x1, y1)).getcolors()

根据 PIL 的文档 getcolors“返回未排序的列表(计数,颜色) 元组,其中计数是相应颜色在图像中出现的次数”。

>>> myimg = ...
>>> colors = myimg.crop((x0, y0, x1, y1)).getcolors()

According to PIL's docs getcolors "Returns an unsorted list of (count, color) tuples, where the count is the number of times the corresponding color occurs in the image".

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