contour is not equal to contour[i]?

不想你离开。 提交于 2019-12-02 09:59:31

You seem to be getting mixed up between when you have a collection of something and when you don't. I'm guessing that a vector<Point> is what you consider a "contour" and a vector<vector<Point>> is a set of contours.

As you loop from 0 to contours.size(), you are working out contourArea(contours) which will be exactly the same every time because you never modify contours. It seems to me that you want to work out the area of an individual contour and should be doing something like contourArea(contours[i]).

Then, if you want a list of your largest contours, which is also of type vector<vector<Point>>, then you need to push each of the contours you find into this vector. If contours[i] is the contour you want to add to the list, you would do that with largest_contours.push_back(contours[i]);.

There are several issues here, the exact reason for your issues can't be determined without full declarations, however there are a few things looking odd here:

double area = contourArea(contours);

This looks like you determine the area of all contours in total - every iteration. This sounds wrong.

largest_contours = contours[i]; 

This most likely fails as there's no assignment operator for contours. How about saving the index instead (unless you want to keep the whole structure(?)).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!