开发者

Python: how to know how many colors in a bounding box in PIL?

开发者 https://www.devze.com 2023-01-20 22:01 出处:网络
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?>>> myimg = ...

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?


>>> 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".

0

精彩评论

暂无评论...
验证码 换一张
取 消