简体   繁体   English

如何在 cv2 中将图像分割为披萨?

[英]How can I split image as pizza in cv2?

比萨

I wanna split an image in cv2 as shown in the picture and get the dominant color for each of the parts of the picture.我想在 cv2 中分割图像,如图所示,并为图片的每个部分获取主色。 Is there any function so I can give it parameters (a, b, c, d) for the count of lines to up, right, bottom and down of the picture and it returns color in rgb space?是否有任何函数可以为它提供参数(a、b、c、d)来计算图片向上、向右、向下和向下的行数,并在 rgb 空间中返回颜色?

Usually this is done not by the count of lines (up, down, left, right), but by the angle of one pizza slice.通常这不是通过行数(上、下、左、右)来完成的,而是通过一个披萨片的角度来完成的。 The whole pizza is 360 degrees, so you may choose a number like 10-20-30 degrees, to make slices even.整个披萨是360度,所以你可以选择10-20-30度这样的数字,使切片均匀。 Then take the x, y coordinates of the image pixel and after subtracting the center pixel coordinates calculate the slice number as atan((y - y_center)/(x - x_center)) .然后取图像像素的x, y坐标,减去中心像素坐标后计算切片编号为atan((y - y_center)/(x - x_center))

To avoid calculation complications, you may want to split the calculation into the two similar, but separate cases when x > x_center and x < x_center to avoid ZeroDivide and make life easier.为避免计算复杂化,您可能希望将计算拆分为两个相似但分开的情况,即x > x_centerx < x_center以避免ZeroDivide并使生活更轻松。

Regarding the dominant colors, there are a bunch of articles on this site, just use the search, I don't want to copy-paste someone else's work.关于主色,本站有一堆文章,随便搜索一下,不想复制粘贴别人的作品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM