From 6cca4a3278c30fb35e97dd0017c5a5a25a78bcf0 Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 2 Jun 2021 15:05:36 +0200 Subject: Port svg-flatten to nopencv --- svg-flatten/src/nopencv.hpp | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'svg-flatten/src/nopencv.hpp') diff --git a/svg-flatten/src/nopencv.hpp b/svg-flatten/src/nopencv.hpp index afebce5..8f399b9 100644 --- a/svg-flatten/src/nopencv.hpp +++ b/svg-flatten/src/nopencv.hpp @@ -39,30 +39,37 @@ namespace gerbolyze { typedef std::function ContourCallback; - class Image32 { + template class Image { public: - Image32() {} - Image32(int size_x, int size_y, const int32_t *data=nullptr); - Image32(const Image32 &other) : Image32(other.cols(), other.rows(), other.ptr()) {} + Image() {} + Image(int w, int h, const T *data=nullptr); + Image(const Image &other) : Image(other.cols(), other.rows(), other.ptr()) {} + template Image(const Image &other) : Image(other.cols(), other.rows()) { + for (size_t y=0; y= 0 && y >= 0 && x < m_cols && y < m_rows); assert(m_data != nullptr); return m_data[y*m_cols + x]; }; - void set_at(int x, int y, int val) { + void set_at(int x, int y, T val) { assert(x >= 0 && y >= 0 && x < m_cols && y < m_rows); assert(m_data != nullptr); @@ -70,14 +77,14 @@ namespace gerbolyze { cerr << "set_at " << x << " " << y << ": " << val << " -> " << at(x, y) << endl; }; - const int32_t &at(int x, int y) const { + const T &at(int x, int y) const { assert(x >= 0 && y >= 0 && x < m_cols && y < m_rows); assert(m_data != nullptr); return m_data[y*m_cols + x]; }; - int32_t at_default(int x, int y, int32_t default_value=0) const { + T at_default(int x, int y, T default_value=0) const { assert(m_data != nullptr); if (x >= 0 && y >= 0 && x < m_cols && y < m_rows) { @@ -88,19 +95,26 @@ namespace gerbolyze { } }; + void blur(int radius); + void resize(int new_w, int new_h); + int rows() const { return m_rows; } int cols() const { return m_cols; } int size() const { return m_cols*m_rows; } - const int32_t *ptr() const { return m_data; } + const T *ptr() const { return m_data; } private: bool stb_to_internal(uint8_t *data); - int32_t *m_data = nullptr; + T *m_data = nullptr; int m_rows=0, m_cols=0; }; - void find_blobs(Image32 &img, ContourCallback cb); + typedef Image Image8; + typedef Image Image32; + typedef Image Image32f; + + void find_contours(Image32 &img, ContourCallback cb); ContourCallback simplify_contours_teh_chin(ContourCallback cb); double polygon_area(Polygon_i &poly); -- cgit