1#include <VVT-V2/contour_handler.h>
4 minimal_distance_{ 5.0f }
7 std::vector<Vec4i> hierarchy = { 0 };
11 prep_frame = Mat(frame, *ROI);
13 frame.copyTo(prep_frame);
16 if (frame.channels() > 2)
17 cvtColor(prep_frame, prep_frame, COLOR_BGR2GRAY);
20 GaussianBlur(prep_frame, prep_frame, Size(7, 7), 0);
21 threshold(prep_frame, prep_frame, 80, 255, cv::THRESH_BINARY);
22 Canny(prep_frame, prep_frame, 64, 192);
23 Canny(prep_frame, prep_frame, 64, 192);
28 findContours(prep_frame,
contour_shapes_, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, ROI->tl());
30 findContours(prep_frame,
contour_shapes_, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
48 std::vector<Point2f> continous_contour_shapes;
54 std::vector<Point> shape = *extern_itt;
56 auto intern_itt = shape.begin();
57 while (intern_itt != shape.end())
62 continous_contour_shapes.push_back(*intern_itt);
71 while (continous_contour_shapes.size() > 500)
74 return continous_contour_shapes;
82 auto it = src.begin();
83 while (it != src.end() - 1)
85 if ((std::distance(src.begin(), it)) % 2 == 0)
96 return sqrt((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y));
float minimal_distance_
Минимальное расстояние между точками контура, при котором "левая" ("первая") точка будет сохранена
ContourHandler(Mat frame, Rect *ROI=nullptr)
Конструктор этого класса
std::vector< std::vector< Point2i > > GetContours()
Возвращает найденные контура в виде { { contour_1 }, { contour_2 }, ... , { contour_n } }.
void DrawContours(Mat &frame)
Отрисовывает контура на изображении
std::vector< Point2f > GetContinousContours()
Возвращает найденные контура в виде { contour_1, contour_2, ... , contour_n }.
float CalculateDistance(T point1, T point2)
Вычисляет расстояние между двумя точками
std::vector< T > MakeTwiceThinner(std::vector< T > src)
Удаляет каждый второй элемент вектора (уменьшает размер в два раза)
std::vector< std::vector< Point > > contour_shapes_
Контуры в виде { { contour_1 }, { contour_2 }, ... , { contour_n } }.