From 3386e586ac0f0ae07535036efe6293f6118f7e2b Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 1 Jun 2021 23:36:32 +0200 Subject: Work on chain approx --- svg-flatten/src/nopencv_test.cpp | 52 +++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'svg-flatten/src/nopencv_test.cpp') diff --git a/svg-flatten/src/nopencv_test.cpp b/svg-flatten/src/nopencv_test.cpp index 21710b9..901c7a8 100644 --- a/svg-flatten/src/nopencv_test.cpp +++ b/svg-flatten/src/nopencv_test.cpp @@ -40,7 +40,7 @@ MU_TEST(test_complex_example_from_paper) { }; Image32 test_img(9, 6, static_cast(img_data)); - const Polygon expected_polys[3] = { + const Polygon_i expected_polys[3] = { { {1,1}, {1,2}, {1,3}, {1,4}, {1,5}, {2,5}, {3,5}, {4,5}, {5,5}, {6,5}, {7,5}, {8,5}, @@ -64,18 +64,18 @@ MU_TEST(test_complex_example_from_paper) { const ContourPolarity expected_polarities[3] = {CP_CONTOUR, CP_HOLE, CP_HOLE}; int invocation_count = 0; - gerbolyze::nopencv::find_blobs(test_img, [&invocation_count, &expected_polarities, &expected_polys](Polygon poly, ContourPolarity pol) { + gerbolyze::nopencv::find_blobs(test_img, [&invocation_count, &expected_polarities, &expected_polys](Polygon_i &poly, ContourPolarity pol) { invocation_count += 1; mu_assert((invocation_count <= 3), "Too many contours returned"); mu_assert(poly.size() > 0, "Empty contour returned"); mu_assert_int_eq(pol, expected_polarities[invocation_count-1]); - d2p last; + i2p last; bool first = true; - Polygon exp = expected_polys[invocation_count-1]; + Polygon_i exp = expected_polys[invocation_count-1]; //cout << "poly: "; - for (d2p &p : poly) { + for (auto &p : poly) { //cout << "(" << p[0] << ", " << p[1] << "), "; if (!first) { mu_assert((fabs(p[0] - last[0]) + fabs(p[1] - last[1]) == 1), "Subsequent contour points have distance other than one"); @@ -149,7 +149,7 @@ static void testdata_roundtrip(const char *fn) { << "xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << endl; svg << "" << endl; - gerbolyze::nopencv::find_blobs(ref_img, [&svg](Polygon poly, ContourPolarity pol) { + gerbolyze::nopencv::find_blobs(ref_img, [&svg](Polygon_i &poly, ContourPolarity pol) { mu_assert(poly.size() > 0, "Empty contour returned"); mu_assert(poly.size() > 2, "Contour has less than three points, no area"); mu_assert(pol == CP_CONTOUR || pol == CP_HOLE, "Contour has invalid polarity"); @@ -212,7 +212,45 @@ MU_TEST(test_round_trip_two_px) { testdata_roundtrip("testdata/two-p MU_TEST(test_round_trip_two_px_inv) { testdata_roundtrip("testdata/two-px-inv.png"); } +static void chain_approx_test(const char *fn) { + int x, y; + uint8_t *data = stbi_load(fn, &x, &y, nullptr, 1); + Image32 ref_img(x, y); + for (int cy=0; cy" << endl; + svg << "" << endl; + + gerbolyze::nopencv::find_blobs(ref_img, simplify_contours_teh_chin(2, [&svg](Polygon_i &poly, ContourPolarity pol) { + svg << "" << endl; + })); + svg << "" << endl; + svg.close(); +} + + +MU_TEST(chain_approx_test_chromosome) { chain_approx_test("testdata/chain-approx-teh-chin-chromosome.png"); } + + MU_TEST_SUITE(nopencv_contours_suite) { + /* MU_RUN_TEST(test_complex_example_from_paper); MU_RUN_TEST(test_round_trip_blank); MU_RUN_TEST(test_round_trip_white); @@ -229,6 +267,8 @@ MU_TEST_SUITE(nopencv_contours_suite) { MU_RUN_TEST(test_round_trip_two_blobs); MU_RUN_TEST(test_round_trip_two_px); MU_RUN_TEST(test_round_trip_two_px_inv); + */ + MU_RUN_TEST(chain_approx_test_chromosome); }; int main(int argc, char **argv) { -- cgit