Img2Num C++ (Internal Developer Docs) dev
API Documentation
Loading...
Searching...
No Matches
contours.h
1#ifndef CONTOURS_H
2#define CONTOURS_H
3
4#include "internal/Image.h"
5#include "internal/PixelConverters.h"
6#include "internal/Point.h"
7#include "internal/RGBAPixel.h"
8#include "internal/SavitskyGolay.h"
9
10#include <array>
11#include <cstdint>
12#include <cstdlib>
13#include <stdexcept>
14#include <vector>
15
16struct QuadBezier {
17 Point p0 {0, 0}; // Start
18 Point p1 {0, 0}; // Control
19 Point p2 {0, 0}; // End
20};
21
22struct 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
46namespace contours {
47ContoursResult find_contours(const std::vector<uint8_t>& binary, int width, int height);
48
49void stitch_smooth(std::vector<Point>& vecA, std::vector<Point>& vecB);
50void coupled_smooth(std::vector<std::vector<Point>>& contours, Rect bounds);
51
64void coupled_smooth_junctions(
65 std::vector<std::vector<Point>>& contours, Rect bounds, std::vector<uint8_t> junctions,
66 int width
67);
68
69void pack_with_boundary_constraints(
70 std::vector<std::vector<Point>>& contours, Rect bounds, int iterations = 15
71);
72
73} // namespace contours
74
75#endif
Definition Point.h:5