Img2Num C++ (Internal Developer Docs)  dev
API Documentation
contours.h
1 #ifndef CONTOURS_H
2 #define CONTOURS_H
3 
4 #include <array>
5 #include <cstdint>
6 #include <cstdlib>
7 #include <stdexcept>
8 #include <vector>
9 
10 #include "internal/Image.h"
11 #include "internal/PixelConverters.h"
12 #include "internal/Point.h"
13 #include "internal/RGBAPixel.h"
14 #include "internal/SavitskyGolay.h"
15 
16 struct QuadBezier {
17  Point p0{0, 0}; // Start
18  Point p1{0, 0}; // Control
19  Point p2{0, 0}; // End
20 };
21 
22 struct Rect {
23  float x, y, width, height;
24 };
25 
27  // contours[k] is a sequence of boundary pixels (x,y) in image coordinates
28  // (0..w-1, 0..h-1)
29  std::vector<std::vector<Point>> contours;
30  std::vector<std::vector<QuadBezier>> curves;
31 
32  // hierarchy[k] = { next_sibling, prev_sibling, first_child, parent }
33  // -1 means "none"
34  std::vector<std::array<int, 4>> hierarchy;
35 
36  // is_hole[k] == true if contour k is a hole border
37  std::vector<bool> is_hole;
38 };
39 
41  // inherits: contours, hierarchy, is_hole
42 
43  std::vector<ImageLib::RGBAPixel<uint8_t>> colors;
44 };
45 
46 namespace contours {
47 ContoursResult find_contours(const std::vector<uint8_t> &binary, int width, int height);
48 
49 void stitch_smooth(std::vector<Point> &vecA, std::vector<Point> &vecB);
50 void coupled_smooth(std::vector<std::vector<Point>> &contours, Rect bounds);
51 
52 void pack_with_boundary_constraints(std::vector<std::vector<Point>> &contours, Rect bounds,
53  int iterations = 15);
54 
55 } // namespace contours
56 
57 #endif
Definition: Point.h:5
Definition: contours.h:22