78 lines
2.2 KiB
C++
78 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "i_contours_extractor.hpp"
|
|
|
|
namespace cvpr
|
|
{
|
|
class ContoursExtractorImpl : public IContoursExtractor {
|
|
public:
|
|
ContoursExtractorImpl();
|
|
|
|
~ContoursExtractorImpl() = default;
|
|
|
|
void init() override;
|
|
|
|
void destroy() override;
|
|
|
|
void setAreaThreshold(double threshold) override;
|
|
|
|
double areaThreshold() override;
|
|
|
|
void setContourOffset(int32_t offset) override;
|
|
|
|
int32_t contourOffset() override;
|
|
|
|
void setApproxPolyEpsilon(double epsilon) override;
|
|
|
|
double approxPolyEpsilon() override;
|
|
|
|
void setSmoothMethod(SMOOTH_METHOD method) override;
|
|
|
|
SMOOTH_METHOD smoothMethod() override;
|
|
|
|
void setAngelThreshold(double threshold) override;
|
|
|
|
double angelThreshold() override;
|
|
|
|
void setDefectThreshold(double threshold) override;
|
|
|
|
double defectThreshold() override;
|
|
|
|
void setSmoothStep(double step) override;
|
|
|
|
double smoothStep() override;
|
|
|
|
void extract(const cv::Mat& alpha, std::vector<std::vector<cv::Point>>& outputContours) override;
|
|
|
|
private:
|
|
double calculateAngle(const cv::Point& pt1, const cv::Point& pt2, const cv::Point& pt3);
|
|
|
|
double euclideanDistance(const cv::Point& p1, const cv::Point& p2);
|
|
|
|
double curveDistance(const std::vector<cv::Point>& contour, int startIdx, int endIdx);
|
|
|
|
void getSubCurves(const std::vector<cv::Point>& contour, double thresholdAngle, std::vector<std::vector<int>>& indices);
|
|
|
|
void getOptimalPoints(const std::vector<cv::Point>& contour, int& bestIdx1, int& bestIdx2, double& bestCurveDist, double& bestLineDist);
|
|
|
|
void replaceSubsequence(std::vector<cv::Point>& contour, int startIdx, int endIdx, const std::vector<cv::Point>& newSubsequence);
|
|
|
|
cv::Point getPointOnLine(const cv::Point& pt1, const cv::Point& pt2, int32_t x);
|
|
|
|
private:
|
|
double m_areaThreshold = 500.0;
|
|
|
|
int32_t m_contourOffset = 12;
|
|
|
|
double m_approxPolyEpsilon = 5;
|
|
|
|
SMOOTH_METHOD m_smoothMethod = SMOOTH_METHOD::BSPLINE;
|
|
|
|
double m_angelThreshold = 20.0;
|
|
|
|
double m_defectThreshold = 0.0;
|
|
|
|
double m_smoothStep = 0.001;
|
|
};
|
|
}
|