mirror of http://192.168.1.51:8099/lmh188/twain3.0
95 lines
3.1 KiB
C++
95 lines
3.1 KiB
C++
/*
|
||
* ====================================================
|
||
*
|
||
* 功能:彩色图像,色彩校正。基于LUT实现,预设BGR查值表(表达所有HVS),对BGR原图进行查值校正。
|
||
* 作者:刘丁维
|
||
* 生成时间:2020/3/21
|
||
* 最近修改时间:v1.0 2020/03/21
|
||
v1.1 2020/06/15 调整除红效果的HSV取值范围
|
||
v1.2 2021/08/02 调整内存指针,适应ROI图像的内存偏移。
|
||
v1.3 2021/08/26 替换答题卡除红Red_Removal实现方案。
|
||
v1.4 2022/04/22 增加功能,支持用像素灰度值填充原来彩色像素;删除默认构造函数;增加校正选项Deafault和LowSaturation_Removal
|
||
* 版本号:v1.4
|
||
*
|
||
* ====================================================
|
||
*/
|
||
|
||
#ifndef IMAGE_APPLY_COLOR_CORRECT_H
|
||
#define IMAGE_APPLY_COLOR_CORRECT_H
|
||
|
||
#include "ImageApply.h"
|
||
|
||
class CImageApplyHSVCorrect : public CImageApply
|
||
{
|
||
public:
|
||
enum CorrectOption
|
||
{
|
||
Deafault, //默认,无任何除色效果
|
||
LowSaturation_Removal, //除掉低饱和度像素
|
||
Red_Removal //除掉红色。红色定义H:[0, 85]∪[170, 255],S:[10, 255],V:[120,255]
|
||
};
|
||
public:
|
||
/*
|
||
* mode [in]:预设初色模式
|
||
* cvtColor [in]:替代像素使用默认值,还是使用灰度值。true为灰度值,false为默认值
|
||
* bgr:[in] 用uint表示BGR值,B在低位,R在高位。(当cvtGray 为false时生效)
|
||
*/
|
||
CImageApplyHSVCorrect(CorrectOption mode = CorrectOption::Deafault, bool cvtColor = false, uint bgr = 0x00FFFFFF);
|
||
|
||
virtual ~CImageApplyHSVCorrect();
|
||
|
||
virtual void apply(cv::Mat& pDib, int side);
|
||
|
||
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
|
||
|
||
/*
|
||
* 函数功能:初始化查值表,按照RGB(R在高位,B在低位)的32位数据进行索引,值与索引一致。
|
||
表中索引范围[0,0x00FFFFFF]。在构造函数中会默认调用该函数。
|
||
*/
|
||
void initLUT();
|
||
|
||
/*
|
||
* 函数功能:将查值表指定RGB索引值设置为目标值。
|
||
索引 = src_b | (src_g << 8) | (src_r << 16)
|
||
值 = dst_b | (dst_g << 8) | (dst_r << 16)
|
||
* src_b:[in] 原查值表B通道索引
|
||
* src_g:[in] 原查值表G通道索引
|
||
* src_r:[in] 原查值表R通道索引
|
||
* dst_b:[in] 目标查值表B通道值
|
||
* dst_g:[in] 目标查值表G通道值
|
||
* dst_r:[in] 目标查值表R通道值
|
||
*/
|
||
void set_single(const uint src_b, const uint src_g, const uint src_r,
|
||
const uint dst_b, const uint dst_g, const uint dst_r);
|
||
|
||
/*
|
||
* 函数功能:按照HSV色彩空间描述色彩范围,将该范围对应的BGR索引设置为0x00FFFFFF(默认白色)
|
||
* range_h:[in] H分量范围,取值范围[0, 255]
|
||
* range_s:[in] S分量范围,取值范围[0, 255]
|
||
* range_v:[in] V分量范围,取值范围[0, 255]
|
||
* bgr:[in] 用uint表示BGR值,B在低位,R在高位。(当cvtGray 为false时生效)
|
||
* cvtGray:[in] 为true时,根据RGB值转换为灰度值
|
||
*/
|
||
void set_HSV_value(const std::pair<uchar, uchar>& range_h,
|
||
const std::pair<uchar, uchar>& range_s,
|
||
const std::pair<uchar, uchar>& range_v,
|
||
uint bgr = 0x00FFFFFF, bool cvtGray = false);
|
||
|
||
/*
|
||
* 函数功能:设置外部查值表,表默认长度为 256 * 256 * 256 * sizeof(uint)
|
||
* table:[in] 数组指针
|
||
*/
|
||
void set_table(const uint* table);
|
||
|
||
private:
|
||
static bool contained(uchar value, const std::pair<uchar, uchar>& range);
|
||
|
||
static void RGB_2_HSV_full(int r, int g, int b, uchar& h, uchar& s, uchar& v);
|
||
|
||
private:
|
||
uint* m_table;
|
||
};
|
||
|
||
#endif
|
||
|