#pragma once #include #include "opencv2/opencv.hpp" namespace cvpr { enum class SMOOTH_METHOD { NONE = 0, BSPLINE //DEANGEL }; class __declspec(dllexport) IContoursExtractor { public: virtual ~IContoursExtractor() = default; virtual void init() = 0; virtual void destroy() = 0; /* * threshold, 轮廓检测结果中小于该阈值的轮廓将被剔除 */ virtual void setAreaThreshold(double threshold = 500.0) = 0; virtual double areaThreshold() = 0; /* * contourOffset, 轮廓的偏置距离(单位:像素),当contourOffset取值为0时,该函数自动忽略setSmoothMethod()的method参数,不做平滑直接返回原始轮廓 */ virtual void setContourOffset(int32_t offset = 12) = 0; virtual int32_t contourOffset() = 0; /* * epsilon, 原始轮廓偏置后的轮廓线的多边形逼近精度 */ virtual void setApproxPolyEpsilon(double epsilon = 5) = 0; virtual double approxPolyEpsilon() = 0; /* * method, 原始轮廓偏置后的轮廓线的平滑方法,默认采用b样条曲线 */ virtual void setSmoothMethod(SMOOTH_METHOD method = SMOOTH_METHOD::BSPLINE) = 0; virtual SMOOTH_METHOD smoothMethod() = 0; /* * threshold, 采用多边形逼近之后,如果折线的夹角小于该阈值,则采用b样条曲线进行平滑。该参数仅在SMOOTH_METHOD::DEANGEL模式下有效 */ virtual void setAngelThreshold(double threshold = 20.0) = 0; virtual double angelThreshold() = 0; /* * threshold, 采用多边形逼近之后,如果缺陷处的开口小于该阈值,则封闭该缺陷 */ virtual void setDefectThreshold(double threshold = 0.0) = 0; virtual double defectThreshold() = 0; /* * smoothStep, 原始轮廓偏置后的轮廓线的平滑步长,取值范围(0.0,1.0) */ virtual void setSmoothStep(double step = 0.001) = 0; virtual double smoothStep() = 0; /* 描述: 提取轮廓或轮廓偏置线 * 参数: * alpha, 图像alpha通道 * outputContours, 输出轮廓集合 */ virtual void extract(const cv::Mat& alpha, std::vector>& outputContours) = 0; }; }