77 lines
2.6 KiB
C
77 lines
2.6 KiB
C
|
/*
|
|||
|
* ====================================================
|
|||
|
|
|||
|
* 功能:装订孔填充
|
|||
|
* 作者:刘丁维
|
|||
|
* 生成时间:2020/11/21
|
|||
|
* 最近修改时间:2020/05/12 v1.0
|
|||
|
* 2020/11/17 v1.1
|
|||
|
* 2021/09/06 v1.2 调整默认二值化阈值,从原来的50调整为100。将填充颜色从局部颜色提取改为全局颜色提取。
|
|||
|
* 2021/11/03 v1.3 增加逻辑,如果正反面图像尺寸差异超过10个像素,直接返回,不再进行除穿孔处理。
|
|||
|
* 2021/11/04 v1.4 增加背景抗噪机制,能够抗5像素的背景噪声。
|
|||
|
* 2021/11/17 v1.5 调整代码格式,避免一些由于opencv版本导致的BUG。
|
|||
|
* 2022/04/18 v1.6 修复由于图像超出边界导致的定位孔洞异常的BUG。
|
|||
|
* 2022/05/04 v1.6.1 增加逻辑判断,如果出现黑图,直接返回,不对原图进行任何处理。
|
|||
|
* 版本号:v1.6.1
|
|||
|
|
|||
|
* ====================================================
|
|||
|
*/
|
|||
|
|
|||
|
#ifndef IMAGE_APPLY_OUT_HOLE_H
|
|||
|
#define IMAGE_APPLY_OUT_HOLE_H
|
|||
|
|
|||
|
#include "ImageApply.h"
|
|||
|
|
|||
|
class CImageApplyOutHole : public CImageApply
|
|||
|
{
|
|||
|
public:
|
|||
|
|
|||
|
CImageApplyOutHole();
|
|||
|
|
|||
|
/*
|
|||
|
* borderSize [in]:孔洞面积阈值
|
|||
|
* edgeScale [in]:纸张边缘区域比例,取值范围(0,0.5),默认值0.1
|
|||
|
* threshold [in]:二值化阈值
|
|||
|
*/
|
|||
|
CImageApplyOutHole(float borderSize, float edgeScale, double threshold);
|
|||
|
|
|||
|
~CImageApplyOutHole(void);
|
|||
|
|
|||
|
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
|
|||
|
|
|||
|
float getBorderSize() { return m_borderSize; }
|
|||
|
|
|||
|
float getEdgeScale() { return m_edgeScale; }
|
|||
|
|
|||
|
double getThreshold() { return m_threshold; }
|
|||
|
|
|||
|
void setBorderSize(float size) { m_borderSize = size; }
|
|||
|
|
|||
|
void setEdgeScale(float scale) { m_edgeScale = scale; }
|
|||
|
|
|||
|
void setThreshold(double threshold) { m_threshold = (std::min)((std::max)(threshold, 1.0), 254.0); }
|
|||
|
|
|||
|
private:
|
|||
|
|
|||
|
virtual void apply(cv::Mat& pDib, int side);
|
|||
|
|
|||
|
void getRoi(cv::RotatedRect rrect_front, cv::RotatedRect rrect_back, const cv::Size& srcSize_front, const cv::Size& srcSize_back, cv::Rect& roi_front,
|
|||
|
cv::Rect& roi_back, cv::RotatedRect& mask_rotatedRect);
|
|||
|
|
|||
|
std::vector<std::vector<cv::Point> > filterPoly(std::vector<std::vector<cv::Point>>& contours, const std::vector<cv::Vec4i>& m, cv::RotatedRect roi,
|
|||
|
float edgeScale, float areaThreshold);
|
|||
|
|
|||
|
cv::Scalar getBackGroudColor(const cv::Mat& image, const std::vector<cv::Point> pixelPoints);
|
|||
|
|
|||
|
cv::Scalar getBackGroudColor(const cv::Mat& image, int total);
|
|||
|
|
|||
|
uchar getBackGroudChannelMean(const cv::Mat& gray, int total);
|
|||
|
|
|||
|
private:
|
|||
|
float m_borderSize;
|
|||
|
float m_edgeScale;
|
|||
|
double m_threshold;
|
|||
|
};
|
|||
|
|
|||
|
#endif // !IMAGE_APPLY_OUT_HOLE_H
|