Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在OpenCV/C+中为Mat对象创建圆形遮罩+;?_C++_Opencv_Mat - Fatal编程技术网

C++ 如何在OpenCV/C+中为Mat对象创建圆形遮罩+;?

C++ 如何在OpenCV/C+中为Mat对象创建圆形遮罩+;?,c++,opencv,mat,C++,Opencv,Mat,我的目标是在Mat对象上创建一个圆形遮罩,例如,对于看起来像这样的Mat: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 …对其进行修改,以便我在其中获得一个1s的圆形,例如 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 我目前正在使用以下代码: typedef struct { double radius; Point center; } Circle; .

我的目标是在
Mat
对象上创建一个圆形遮罩,例如,对于看起来像这样的
Mat

0 0 0 0 0 
0 0 0 0 0 
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
…对其进行修改,以便我在其中获得一个
1
s的圆形,例如

0 0 0 0 0 
0 0 1 0 0 
0 1 1 1 0
0 0 1 0 0
0 0 0 0 0
我目前正在使用以下代码:

typedef struct {
    double radius;
    Point center;
} Circle;

...

for (Circle c : circles) {

    // get the circle's bounding rect
    Rect boundingRect(c.center.x-c.radius, c.center.y-c.radius, c.radius*2,c.radius*2);

    // obtain the image ROI:
    Mat circleROI(stainMask_, boundingRect);
    int radius = floor(radius);
    circle(circleROI, c.center, radius, Scalar::all(1), 0);
}
问题是,在我调用
circle
之后,
circleROI
中最多只有一个字段设置为
1
。。。根据我的理解,此代码应该有效,因为
应该使用有关
中心
半径
的信息来修改
,以便圆区域内的所有点都应该设置为
1
。。。有人能解释我做错了什么吗?我是否正确地处理了这个问题,但是实际问题可能在别的地方(这也是非常可能的,因为我是C++和OpenCv的新手)?< /P>
请注意,我还尝试将
circle
调用中的最后一个参数(即圆轮廓的厚度)修改为
1
-1
,但没有任何效果。

查看:
getStructuringElement


这是因为你在用大垫子中的圆坐标填充圆。圆内的圆坐标应相对于圆,在您的情况下,即:新的_中心=(c.radius,c.radius),新的_半径=c.radius

以下是循环的snipcode:

for (Circle c : circles) {

    // get the circle's bounding rect
    Rect boundingRect(c.center.x-c.radius, c.center.y-c.radius, c.radius*2+1,c.radius*2+1);

    // obtain the image ROI:
    Mat circleROI(stainMask_, boundingRect);

    //draw the circle
    circle(circleROI, Point(c.radius, c.radius), c.radius, Scalar::all(1), -1);

}