speedcontroller/imageprocess/ImageApplyHSVCorrect.h

88 lines
2.8 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.

/*
* ====================================================
* 功能彩色图像色彩校正。基于LUT实现预设BGR查值表表达所有HVS对BGR原图进行查值校正。
* 作者:刘丁维
* 生成时间2020/3/21
* 最近修改时间v1.0 2020/3/21
v1.1 2020/6/15 调整除红效果的HSV取值范围
* 版本号v1.1
* ====================================================
*/
#ifndef IMAGE_APPLY_COLOR_CORRECT_H
#define IMAGE_APPLY_COLOR_CORRECT_H
#include "ImageApply.h"
class CImageApplyHSVCorrect : public CImageApply
{
public:
enum CorrectOption
{
Red_Removal //除掉红色。红色定义H:[0, 85][170, 255],S:[10, 255],V:[120,255]
};
public:
CImageApplyHSVCorrect();
/*
* mode [in]:预设初色模式
*/
CImageApplyHSVCorrect(CorrectOption mode);
virtual ~CImageApplyHSVCorrect();
virtual void apply(cv::Mat& pDib,int side);
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
/*
* 函数功能初始化查值表按照RGBR在高位B在低位的32位数据进行索引值与索引一致。
表中索引范围[00x00FFFFFF]。在构造函数中会默认调用该函数。
*/
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在高位
*/
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);
/*
* 函数功能:设置外部查值表,表默认长度为 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