From ee265962b2ea9abef5111f64f76f617554f7b473 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 7 Dec 2016 22:04:25 +0300 Subject: [PATCH 1/5] test: move test_drawing into imgproc module --- modules/{imgcodecs => imgproc}/test/test_drawing.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename modules/{imgcodecs => imgproc}/test/test_drawing.cpp (100%) diff --git a/modules/imgcodecs/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp similarity index 100% rename from modules/imgcodecs/test/test_drawing.cpp rename to modules/imgproc/test/test_drawing.cpp From 781ab3d481d6b2dff61ea441a00085c8659cf6ca Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 7 Dec 2016 22:17:35 +0300 Subject: [PATCH 2/5] test: minor refactoring in test_drawing --- modules/imgproc/test/test_drawing.cpp | 34 +++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/modules/imgproc/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp index 1a5ff06676..37045022c5 100644 --- a/modules/imgproc/test/test_drawing.cpp +++ b/modules/imgproc/test/test_drawing.cpp @@ -42,6 +42,8 @@ #include "test_precomp.hpp" +namespace { + using namespace std; using namespace cv; @@ -60,7 +62,7 @@ protected: void CV_DrawingTest::run( int ) { Mat testImg, valImg; - const string fname = "drawing/image.png"; + const string fname = "../highgui/drawing/image.png"; string path = ts->get_data_path(), filename; filename = path + fname; @@ -69,9 +71,15 @@ void CV_DrawingTest::run( int ) valImg = imread( filename ); if( valImg.empty() ) { - imwrite( filename, testImg ); - //ts->printf( ts->LOG, "test image can not be read"); - //ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + //imwrite( filename, testImg ); + ts->printf( ts->LOG, "test image can not be read"); +#ifdef HAVE_PNG + ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); +#else + ts->printf( ts->LOG, "PNG image support is not available"); + ts->set_failed_test_info(cvtest::TS::OK); +#endif + return; } else { @@ -543,11 +551,9 @@ void CV_DrawingTest_Far::draw(Mat& img) img = img(Rect(32768, 0, 600, 400)).clone(); } -#ifdef HAVE_JPEG -TEST(Imgcodecs_Drawing, cpp_regression) { CV_DrawingTest_CPP test; test.safe_run(); } -TEST(Imgcodecs_Drawing, c_regression) { CV_DrawingTest_C test; test.safe_run(); } -TEST(Imgcodecs_Drawing, far_regression) { CV_DrawingTest_Far test; test.safe_run(); } -#endif +TEST(Drawing, cpp_regression) { CV_DrawingTest_CPP test; test.safe_run(); } +TEST(Drawing, c_regression) { CV_DrawingTest_C test; test.safe_run(); } +TEST(Drawing, far_regression) { CV_DrawingTest_Far test; test.safe_run(); } class CV_FillConvexPolyTest : public cvtest::BaseTest { @@ -581,7 +587,7 @@ protected: } }; -TEST(Imgcodecs_Drawing, fillconvexpoly_clipping) { CV_FillConvexPolyTest test; test.safe_run(); } +TEST(Drawing, fillconvexpoly_clipping) { CV_FillConvexPolyTest test; test.safe_run(); } class CV_DrawingTest_UTF8 : public cvtest::BaseTest { @@ -655,8 +661,12 @@ protected: img->copyTo(sub); shift += img->size().height + 1; } - imwrite("/tmp/all_fonts.png", result); + //imwrite("/tmp/all_fonts.png", result); } }; -TEST(Highgui_Drawing, utf8_support) { CV_DrawingTest_UTF8 test; test.safe_run(); } +TEST(Drawing, utf8_support) { CV_DrawingTest_UTF8 test; test.safe_run(); } + + + +} // namespace From bcbe2f123f2bbde60ecd3b35def3656570733d4d Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 8 Dec 2016 03:45:30 +0300 Subject: [PATCH 3/5] test: move more drawing tests --- modules/imgproc/test/test_contours.cpp | 41 ------------------------- modules/imgproc/test/test_drawing.cpp | 42 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/modules/imgproc/test/test_contours.cpp b/modules/imgproc/test/test_contours.cpp index 7b0eafbc8b..d5c4e44275 100644 --- a/modules/imgproc/test/test_contours.cpp +++ b/modules/imgproc/test/test_contours.cpp @@ -410,47 +410,6 @@ _exit_: TEST(Imgproc_FindContours, accuracy) { CV_FindContourTest test; test.safe_run(); } -TEST(Core_Drawing, _914) -{ - const int rows = 256; - const int cols = 256; - - Mat img(rows, cols, CV_8UC1, Scalar(255)); - - line(img, Point(0, 10), Point(255, 10), Scalar(0), 2, 4); - line(img, Point(-5, 20), Point(260, 20), Scalar(0), 2, 4); - line(img, Point(10, 0), Point(10, 255), Scalar(0), 2, 4); - - double x0 = 0.0/pow(2.0, -2.0); - double x1 = 255.0/pow(2.0, -2.0); - double y = 30.5/pow(2.0, -2.0); - - line(img, Point(int(x0), int(y)), Point(int(x1), int(y)), Scalar(0), 2, 4, 2); - - int pixelsDrawn = rows*cols - countNonZero(img); - ASSERT_EQ( (3*rows + cols)*3 - 3*9, pixelsDrawn); -} - -TEST(Core_Drawing, polylines_empty) -{ - Mat img(100, 100, CV_8UC1, Scalar(0)); - vector pts; // empty - polylines(img, pts, false, Scalar(255)); - int cnt = countNonZero(img); - ASSERT_EQ(cnt, 0); -} - -TEST(Core_Drawing, polylines) -{ - Mat img(100, 100, CV_8UC1, Scalar(0)); - vector pts; - pts.push_back(Point(0, 0)); - pts.push_back(Point(20, 0)); - polylines(img, pts, false, Scalar(255)); - int cnt = countNonZero(img); - ASSERT_EQ(cnt, 21); -} - //rotate/flip a quadrant appropriately static void rot(int n, int *x, int *y, int rx, int ry) { diff --git a/modules/imgproc/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp index 37045022c5..a5321c673f 100644 --- a/modules/imgproc/test/test_drawing.cpp +++ b/modules/imgproc/test/test_drawing.cpp @@ -668,5 +668,47 @@ protected: TEST(Drawing, utf8_support) { CV_DrawingTest_UTF8 test; test.safe_run(); } +TEST(Drawing, _914) +{ + const int rows = 256; + const int cols = 256; + + Mat img(rows, cols, CV_8UC1, Scalar(255)); + + line(img, Point(0, 10), Point(255, 10), Scalar(0), 2, 4); + line(img, Point(-5, 20), Point(260, 20), Scalar(0), 2, 4); + line(img, Point(10, 0), Point(10, 255), Scalar(0), 2, 4); + + double x0 = 0.0/pow(2.0, -2.0); + double x1 = 255.0/pow(2.0, -2.0); + double y = 30.5/pow(2.0, -2.0); + + line(img, Point(int(x0), int(y)), Point(int(x1), int(y)), Scalar(0), 2, 4, 2); + + int pixelsDrawn = rows*cols - countNonZero(img); + ASSERT_EQ( (3*rows + cols)*3 - 3*9, pixelsDrawn); +} + +TEST(Drawing, polylines_empty) +{ + Mat img(100, 100, CV_8UC1, Scalar(0)); + vector pts; // empty + polylines(img, pts, false, Scalar(255)); + int cnt = countNonZero(img); + ASSERT_EQ(cnt, 0); +} + +TEST(Drawing, polylines) +{ + Mat img(100, 100, CV_8UC1, Scalar(0)); + vector pts; + pts.push_back(Point(0, 0)); + pts.push_back(Point(20, 0)); + polylines(img, pts, false, Scalar(255)); + int cnt = countNonZero(img); + ASSERT_EQ(cnt, 21); +} + + } // namespace From 7e0f1ec00a9893152928d839d38b36a838d5dc18 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 7 Dec 2016 01:34:27 +0300 Subject: [PATCH 4/5] test: putText regression garbage test --- modules/imgproc/test/test_drawing.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/imgproc/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp index a5321c673f..1d6a2a8388 100644 --- a/modules/imgproc/test/test_drawing.cpp +++ b/modules/imgproc/test/test_drawing.cpp @@ -710,5 +710,20 @@ TEST(Drawing, polylines) } +TEST(Drawing, putText_no_garbage) +{ + Size sz(640, 480); + Mat mat = Mat::zeros(sz, CV_8UC1); + + mat = Scalar::all(0); + putText(mat, "029", Point(10, 350), 0, 10, Scalar(128), 15); + + EXPECT_EQ(0, cv::countNonZero(mat(Rect(0, 0, 10, sz.height)))); + EXPECT_EQ(0, cv::countNonZero(mat(Rect(sz.width-10, 0, 10, sz.height)))); + EXPECT_EQ(0, cv::countNonZero(mat(Rect(205, 0, 10, sz.height)))); + EXPECT_EQ(0, cv::countNonZero(mat(Rect(405, 0, 10, sz.height)))); +} + + } // namespace From 98181e9d7f3477adf3e4c945887c47c3be5b9354 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 7 Dec 2016 03:43:02 +0300 Subject: [PATCH 5/5] imgproc/drawing: minor refactoring in FillConvexPoly --- modules/imgproc/src/drawing.cpp | 62 ++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/modules/imgproc/src/drawing.cpp b/modules/imgproc/src/drawing.cpp index bd838c6c5d..113f499d98 100644 --- a/modules/imgproc/src/drawing.cpp +++ b/modules/imgproc/src/drawing.cpp @@ -1099,7 +1099,7 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin edge[2]; int delta = 1 << shift >> 1; - int i, y, imin = 0, left = 0, right = 1; + int i, y, imin = 0; int edges = npts; int64 xmin, xmax, ymin, ymax; uchar* ptr = img.ptr(); @@ -1181,44 +1181,46 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin { if( y >= edge[i].ye ) { - int idx = edge[i].idx, di = edge[i].di; - int64 xs = 0, xe; + int idx0 = edge[i].idx, di = edge[i].di; + int idx = idx0 + di; + if (idx >= npts) idx -= npts; int ty = 0; - for(;;) + for (; edges-- > 0; ) { ty = (int)((v[idx].y + delta) >> shift); - if( ty > y || edges == 0 ) + if (ty > y) + { + int64 xs = v[idx0].x; + int64 xe = v[idx].x; + if (shift != XY_SHIFT) + { + xs <<= XY_SHIFT - shift; + xe <<= XY_SHIFT - shift; + } + + edge[i].ye = ty; + edge[i].dx = ((xe - xs)*2 + (ty - y)) / (2 * (ty - y)); + edge[i].x = xs; + edge[i].idx = idx; break; - xs = v[idx].x; + } + idx0 = idx; idx += di; - idx -= ((idx < npts) - 1) & npts; /* idx -= idx >= npts ? npts : 0 */ - edges--; + if (idx >= npts) idx -= npts; } - - xs <<= XY_SHIFT - shift; - xe = v[idx].x << (XY_SHIFT - shift); - - /* no more edges */ - if( y >= ty) - return; - - edge[i].ye = ty; - edge[i].dx = ((xe - xs)*2 + (ty - y)) / (2 * (ty - y)); - edge[i].x = xs; - edge[i].idx = idx; } } } - if( edge[left].x > edge[right].x ) + if (y >= 0) { - left ^= 1; - right ^= 1; - } + int left = 0, right = 1; + if (edge[0].x > edge[1].x) + { + left = 1, right = 0; + } - if( y >= 0 ) - { int xx1 = (int)((edge[left].x + delta1) >> XY_SHIFT); int xx2 = (int)((edge[right].x + delta2) >> XY_SHIFT); @@ -1231,9 +1233,13 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin ICV_HLINE( ptr, xx1, xx2, color, pix_size ); } } + else + { + // TODO optimize scan for negative y + } - edge[left].x += edge[left].dx; - edge[right].x += edge[right].dx; + edge[0].x += edge[0].dx; + edge[1].x += edge[1].dx; ptr += img.step; } while( ++y <= (int)ymax );