gpt4 book ai didi

opencv - 找出一个圆的所有点

转载 作者:行者123 更新时间:2023-12-02 17:45:19 24 4
gpt4 key购买 nike

我画一个带有固定输入点的圆。现在,我真的想得到该圆圈中所有点的 vector ,其中包括内部填充区域。我尝试了下面的代码,但它只能得到边框。我不能使用轮廓函数,因为我已经使用了很多次,所以它将非常复杂。请给我建议,非常感谢

 vector<Point> allpoints;
Point center = Point(370, 200);

void getPoints()
{
Size axes(20, 20);
ellipse2Poly(center, axes, 0, 0, 360, 1, allpoints);
}

void draw(Mat &BGR_frame)
{
circle(BGR_frame, center, 20, Scalar(0, 255, 0),CV_FILLED ,2);
getPoints();
}

最佳答案

一种简单的方法是在初始化为黑色的蒙版上绘制圆,然后从那里检索非黑点:

void draw(Mat &BGR_frame)
{
circle(BGR_frame, center, 20, Scalar(0, 255, 0),CV_FILLED ,2);

// Black initialized mask, same size as 'frame'
Mat1b mask(frame.rows, frame.cols, uchar(0));

// Draw white circle on mask
circle(mask, center, 20, Scalar(255), CV_FILLED, 2);

// Find non zero points on mask, and put them in 'allpoints'
findNonZero(mask, allpoints);
}

另外,您可以扫描矩阵的所有像素,并保留满足以下条件的点作为圆的内部点:
Point c(370, 200);
int r = 20;

void draw(Mat &BGR_frame)
{
circle(BGR_frame, c, r, Scalar(0, 255, 0),CV_FILLED ,2);

for (int y = 0; y < mask.rows; ++y) {
for (int x = 0; x < mask.cols; ++x) {

// Check if this is an internal point
if ((x - c.x)*(x - c.x) + (y - c.y)*(y - c.y) <= (r*r)) {
allpoints.push_back(Point(x,y));
}
}
}
}

关于opencv - 找出一个圆的所有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36951873/

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