1 | initial version |
Ok, the problem is this one: the 4th parameter of fillPoly is the position of the contour to fill, which in your case is 0, because you have only one contour (for verification just put 2 contours, to see that you ar filling the second). Just change like this:
cv::fillPoly(p, contours, lengths, 0, cv::Scalar(100));
If you run under Debug, the initial values are all the same, so if you call the function for the element on position 1 you are attempting to fill the poly on the position "after last element" (because you have just one element). If you will run this in Release mode, you will always get different values and on different positions in the matrix. In C++ the first element is always on the position 0. You have seen that if you changed the contour values, you are getting new different values in matrix, this is because the element "after the last element" has changed. In fact you are not using vectors, to see that if you are calling the contours[contours.size()] (which in your case is contours[1]) you are getting an error. This is a problem of using pointers and arrays, please try to use vectors and other types of STL (like smart pointers) for better seeing the problem.