【问题标题】:Create an array of Rectangles : Opencv , Android创建一个矩形数组:Opencv,Android
【发布时间】:2015-07-12 23:17:35
【问题描述】:

我有从 findcontours() 中提取的轮廓,现在我想创建一个包含所有轮廓边界的数组。

int area,total=0;

for(int i=0; i<contours.size(); i++)
{
    area = (int) Imgproc.contourArea(contours.get(i));

    if(area>4600 && area<5100)
    {
        Rect abc = Imgproc.boundingRect(contours.get(i));                          
    }
}

这里只在 Rect 中保存 1 个轮廓,我想要一个包含所有轮廓的 Rect 数组。

【问题讨论】:

    标签: java android opencv contour bounding-box


    【解决方案1】:

    这样应该更好:

    int area,total=0;
    List<Rect> contourRects = new ArrayList();
    
    for(int i=0; i<contours.size(); i++)
    {
        area = (int) Imgproc.contourArea(contours.get(i));
    
        if(area>4600 && area<5100)
        {
            contourRects.add(Imgproc.boundingRect(contours.get(i)));                          
        }
    }
    

    【讨论】:

    • 你的答案是正确的 (+1),但你应该向 OP 解释他错了什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 2022-01-22
    • 2013-04-27
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多