nim_duilib/examples/contour/i_contours_extractor.hpp
2025-03-16 16:42:44 +08:00

80 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <vector>
#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.01.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<std::vector<cv::Point>>& outputContours) = 0;
};
}