1 | initial version |
This is because Point is Point2i, an int type, and your floats are rounded to ints implicitly in the constructor. In your case, all points are halfway between two ints, and the default rounds to the nearest even int. Thus the polygon actually being rendered is degenerate, and only touches 3 pixels:
[(6,2), (6,2), (6,4), (6,4)]
fillPoly won't take floats; however, you can use the shift parameter to get a similar effect.
Modifying your example to multiply the points by 2 (a bit shift of 1) when converting the Point2f array to Point2i:
cv::Point points[4] = { A*2, B*2, C*2, D*2 };
And then the fillPoly command looks like:
cv::fillPoly(p, contours, lengths, 1, cv::Scalar(100), 0, 1);
Resulting in:
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 100, 100, 0, 0;
0, 0, 0, 0, 0, 0, 100, 100, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
and with CV_AA,
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 4, 10, 6, 0, 0;
0, 0, 0, 0, 0, 57, 100, 62, 0, 0;
0, 0, 0, 0, 0, 60, 87, 63, 0, 0;
0, 0, 0, 0, 0, 6, 12, 6, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
...still a weird blob, but closer to being proportional.