twain3.0/huagao/ImageProcess/ImageApplyFadeBackGroundCol...

65 lines
2.1 KiB
C++
Raw Permalink 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/30
* 最近修改时间2021/04/14 v2.0 改为档位设置
* 2021/04/14 v2.1 调整方案与LINUX方案保持一致。
* 2021/08/03 v2.2 自定义获取饱和度算法避免不同opencv版本结果存在偏差。
* 2021/10/12 v2.3 重构算法,去除原来分档设定改为自动识别颜色,并去除底色。
* 2021/10/23 v3.0 重构算法。避开黑色背景(制作掩模),计算文稿平均底色,并进行增白。
* 2021/10/26 v3.1 构造函数增加参数,可设置生成掩模时的阈值。
* 2021/10/28 v3.2 重构算法改用纯C++代码实现功能,提高处理速度。
* 2021/10/29 v3.3 优化算法增加range参数。针对复杂内容的图像能够有效甄别背景和非背景内容。
* 版本号v3.2
* ====================================================
*/
#ifndef IMAGE_APPLY_FADE_BACKGROUND_COLOR_H
#define IMAGE_APPLY_FADE_BACKGROUND_COLOR_H
#include "ImageApply.h"
class CImageApplyAdjustColors;
class CImageApplyFadeBackGroudColor : public CImageApply
{
public:
/// <summary>
/// 构造函数
/// </summary>
/// <param name="offset">在自动识别增白参数的基础上,增加的偏移量。取值范围[-255, 255]</param>
CImageApplyFadeBackGroudColor(int threshold = 100, int offset = 0, int range = 40);
virtual ~CImageApplyFadeBackGroudColor();
virtual void apply(cv::Mat& pDib, int side);
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
private:
/// <summary>
/// 除文稿底色算法仅支持24位图像
/// </summary>
/// <param name="data">图像数据头指针</param>
/// <param name="bytesPerLine">每行数据大小</param>
/// <param name="height">图像高度</param>
/// <param name="threshold">阈值参考值为100</param>
/// <param name="offset">文稿底色增亮偏移量默认为0。值越大背景越白反之越暗</param>
/// <param name="range">底色误差范围,色彩与识别到的底色误差在[-range, range]范围内,视为底色,否则不会被消除</param>
void fadeBackground(unsigned char* data, int bytesPerLine, int height, int threshold, int offset, int range);
private:
int m_threshold;
int m_offset;
int m_range;
uchar m_table1[768];
uchar m_table2[512];
uchar m_table_rgb[3][256];
};
#endif // !IMAGE_APPLY_FADE_BACKGROUND_COLOR_H