@@ -593,4 +593,42 @@ TEST(Drawing, regression_16308)
593
593
EXPECT_NE (0 , (int )img.at <uchar>(99 , 50 ));
594
594
}
595
595
596
+ TEST (Drawing, fillpoly_circle)
597
+ {
598
+ Mat img_c (640 , 480 , CV_8UC3, Scalar::all (0 ));
599
+ Mat img_fp = img_c.clone (), img_fcp = img_c.clone (), img_fp3 = img_c.clone ();
600
+
601
+ Point center1 (img_c.cols /2 , img_c.rows /2 );
602
+ Point center2 (img_c.cols /10 , img_c.rows *3 /4 );
603
+ Point center3 = Point (img_c.cols , img_c.rows ) - center2;
604
+ int radius = img_c.rows /4 ;
605
+ int radius_small = img_c.cols /15 ;
606
+ Scalar color (0 , 0 , 255 );
607
+
608
+ circle (img_c, center1, radius, color, -1 );
609
+
610
+ // check that circle, fillConvexPoly and fillPoly
611
+ // give almost the same result then asked to draw a single circle
612
+ vector<Point> vtx;
613
+ ellipse2Poly (center1, Size (radius, radius), 0 , 0 , 360 , 1 , vtx);
614
+ fillConvexPoly (img_fcp, vtx, color);
615
+ fillPoly (img_fp, vtx, color);
616
+ double diff_fp = cv::norm (img_c, img_fp, NORM_L1)/(255 *radius*2 *CV_PI);
617
+ double diff_fcp = cv::norm (img_c, img_fcp, NORM_L1)/(255 *radius*2 *CV_PI);
618
+ EXPECT_LT (diff_fp, 1 .);
619
+ EXPECT_LT (diff_fcp, 1 .);
620
+
621
+ // check that fillPoly can draw 3 disjoint circles at once
622
+ circle (img_c, center2, radius_small, color, -1 );
623
+ circle (img_c, center3, radius_small, color, -1 );
624
+
625
+ vector<vector<Point> > vtx3 (3 );
626
+ vtx3[0 ] = vtx;
627
+ ellipse2Poly (center2, Size (radius_small, radius_small), 0 , 0 , 360 , 1 , vtx3[1 ]);
628
+ ellipse2Poly (center3, Size (radius_small, radius_small), 0 , 0 , 360 , 1 , vtx3[2 ]);
629
+ fillPoly (img_fp3, vtx3, color);
630
+ double diff_fp3 = cv::norm (img_c, img_fp3, NORM_L1)/(255 *(radius+radius_small*2 )*2 *CV_PI);
631
+ EXPECT_LT (diff_fp3, 1 .);
632
+ }
633
+
596
634
}} // namespace
0 commit comments