segmentation fault extracting contour element in replacement statement
Hi I get a segmentation fault when I extract an element from a contour in a replace statement but not in cout.
The first line prints fine, but there is a segmentation fault with the second line.
std::cout << "inContour y: " << inContour[0].y << '\n';
Yold = inContour[0].y;
At the point in the above code, I have isolated the largest contour and sorted it by the y terms. All appears OK with the sorted contour.
Yold has been declared with int Yold;
and inContour has been declared as vector<point> inContour; several lines above this. Moving the declaration of Yold to this line did not help.
Point is supposed default as a 2 parameter integer. Specifically declaring it as Point2i did not help.
Any suggestions?
i can't see your replacement statement. this might need a bit mode code.
Declaration of vector of points vector<Point2i> inContour; vector<Point2i> sortedContour; vector<Point2i> prunedContour; NOTE: this was also done using Point, with the same results
The following is the code at issue: std::stable_sort (inContour.begin(), inContour.end(), compare_y); FileStorage fs("SortedContour.yml", FileStorage::WRITE); fs << "inContour" << inContour; fs.release(); std::cout << "inContour y: " << inContour[0].y << '\n';
While it handles the cout OK, it generates a segment fault with the line Yold = inContour[0].y;
If I comment it out, then it generates one with the next line.
stable_sort works OK.
stable_sort was verified by manually reading the YAML file.
I haven't figured out how to past code cleanly.