code_device/hgdriver/ImageProcess/ImageApplyOutHole.h

75 lines
2.3 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.

/*
* ====================================================
* 功能:装订孔填充
* 作者:刘丁维
* 生成时间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。
* 版本号v1.5
* ====================================================
*/
#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, cv::Size srcSize, 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