这是基于this question,它更多地关注OpenCV C++,所以我决定提出这个问题。这是我的程序的一部分:
vector<vector<Point> > contours;
vector<vector<Point> > largest_contours;
double largest_area = 0;
for(int i= 0; i < contours.size(); i++){
double area = contourArea(contours[i]);
if(area >= largest_area){
largest_area = area;
largest_contours = contours[i]; <---THIS is the problem
}
}
基本上该程序将执行以下操作:
- 扫描在图像序列/视频中检测到的每个轮廓
- 将轮廓标记为
contours[i] - 计算每个轮廓的面积
- 比较
contours[i]基于区域。面积越大largest_area,轮廓越大largest_contours - 最后,
DrawContours和imshow
有问题的行将在鼠标上显示此消息:
Error: No operator "=" matches these operands
问题是,为什么 contours[i] 不等于 largest_contours尽管它们具有相同的类 ( vector<vector<Point> >) 并且一次每个轮廓只有一个值?谁能解释为什么以及如何解决它?
提前致谢。
编辑(1):更改contourArea(contours)为contourArea(contours[i]). 添加了largest_contours和的声明contours。