From 3b553b3a1dcbecb684e4d7eb00dac1c26874247b Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 2 Jun 2021 00:02:36 +0200 Subject: Chain approximation approximately working --- svg-flatten/src/nopencv.cpp | 43 ++++++++++++++++++++++++++++++---------- svg-flatten/src/nopencv.hpp | 2 +- svg-flatten/src/nopencv_test.cpp | 2 +- 3 files changed, 34 insertions(+), 13 deletions(-) (limited to 'svg-flatten/src') diff --git a/svg-flatten/src/nopencv.cpp b/svg-flatten/src/nopencv.cpp index f42b6ad..afe4881 100644 --- a/svg-flatten/src/nopencv.cpp +++ b/svg-flatten/src/nopencv.cpp @@ -156,7 +156,7 @@ void gerbolyze::nopencv::find_blobs(gerbolyze::nopencv::Image32 &img, gerbolyze: } else if (val_xy >= 1 && img.at_default(x+1, y) == 0) { /* hole border starting point */ nbd += 1; - follow(img, x, y, D_E, nbd, 8, poly); + follow(img, x, y, D_E, nbd, 8, poly); /* FIXME should be 4? */ cb(poly, CP_HOLE); poly.clear(); } @@ -170,7 +170,8 @@ static size_t region_of_support(Polygon_i poly, size_t i) { double last_l = 0; double last_r = 0; size_t k; - for (k=0; k 0) ? (r < last_r) : (r > last_r); + bool cond_b = ((d > 0) && (r < last_r)) || ((d < 0) && (r > last_r)); - if (cond_a || cond_b) + if (k > 2 && (cond_a || cond_b)) break; last_l = l; last_r = r; } + //cerr << endl; k -= 1; return k; } @@ -228,7 +231,7 @@ double k_curvature(const Polygon_i &poly, size_t i, size_t k) { for (size_t idx = 0; idx < k; idx++) { acc += freeman_angle(poly, (i + 2*sz - idx) % sz) - freeman_angle(poly, (i+idx + 1) % sz); } - return acc / (2*k); + return acc / k; } double k_cos(const Polygon_i &poly, size_t i, size_t k) { @@ -244,15 +247,17 @@ double k_cos(const Polygon_i &poly, size_t i, size_t k) { return dp / (sqrt(sq_a)*sqrt(sq_b)); } -ContourCallback gerbolyze::nopencv::simplify_contours_teh_chin(int kcos, ContourCallback cb) { - return [&cb, kcos](Polygon_i &poly, ContourPolarity cpol) { +ContourCallback gerbolyze::nopencv::simplify_contours_teh_chin(ContourCallback cb) { + return [&cb](Polygon_i &poly, ContourPolarity cpol) { size_t sz = poly.size(); vector ros(sz); vector sig(sz); + vector cur(sz); vector retain(sz); for (size_t i=0; i" << endl; svg << "" << endl; - gerbolyze::nopencv::find_blobs(ref_img, simplify_contours_teh_chin(2, [&svg](Polygon_i &poly, ContourPolarity pol) { + gerbolyze::nopencv::find_blobs(ref_img, simplify_contours_teh_chin([&svg](Polygon_i &poly, ContourPolarity pol) { svg << "