小编ran*_*ndy的帖子

如何找到最大的轮廓?

我在python中编写了一个使用max()方法的脚本,我试图在c ++中重新创建一个类似的程序,但是我无法获得掩码中最大轮廓的值.

我试图在C++中使用算法库中的max_element()函数,但无济于事.我也尝试取消引用迭代器但收到一系列错误,这是我的代码:

if (contours.size() > 0)
{
    c = *max_element(contours.begin(), contours.end());
    //not compiling
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

no match for 'operator=' (operand types are 'std::vector<std::vector<cv::Point_<int> > >' and 'std::vector<cv::Point_<int> >')
Run Code Online (Sandbox Code Playgroud)

以下是我在Python中的使用方法:

if len(contours) > 0;
        #find largest contour in mask, use to compute minEnCircle 
        c = max(contours, key = cv2.contourArea)
        (x,y), radius) = cv2.minEnclosingCircle(c)
        M = cv2.moments(c)
Run Code Online (Sandbox Code Playgroud)

c++ python opencv

2
推荐指数
1
解决办法
5559
查看次数

标签 统计

c++ ×1

opencv ×1

python ×1