开放300d8设备偏色校正,更新偏色校正算法
This commit is contained in:
parent
34d854cc56
commit
2d7d9b5e52
|
@ -2,18 +2,53 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#define JIANG_BAOHE
|
||||||
|
//#define G200
|
||||||
|
#define G300
|
||||||
|
|
||||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||||
constexpr auto SIZE_OF_TABLE = 256;
|
constexpr auto SIZE_OF_TABLE = 256;
|
||||||
|
|
||||||
|
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect()
|
||||||
|
: m_table(new uchar[SIZE_OF_TABLE])
|
||||||
|
, m_table2(new uchar[SIZE_OF_TABLE])
|
||||||
|
, m_table3(new uchar[SIZE_OF_TABLE])
|
||||||
|
{
|
||||||
|
std::vector<double> points_x, points_y;
|
||||||
|
|
||||||
|
#ifdef G200
|
||||||
|
points_x = { 2, 9, 15, 18, 22, 34, 50, 63, 78, 92, 103, 114, 126, 137, 140, 147, 154, 163, 176, 200, 225, 248, 251, 254 };
|
||||||
|
points_y = { 11, 17, 24, 28, 32, 41, 56, 81, 106, 115, 119, 124, 131, 138, 141, 145, 153, 166, 186, 201, 217, 251, 259, 264 };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef G300
|
||||||
|
points_x = { 1, 7, 12, 18, 33, 52, 68, 81, 91, 100, 111, 125, 138, 142, 147, 153, 161, 172, 198, 230, 248, 250, 252, 253 };
|
||||||
|
points_y = { 26, 31, 33, 36, 40, 44, 56, 92, 104, 114, 126, 135, 141, 143, 146, 151, 169, 198, 218, 227, 252, 266, 272, 276 };
|
||||||
|
#endif
|
||||||
|
createTable(points_x, points_y);
|
||||||
|
|
||||||
|
points_x = { 0, 180, 210, 255 };
|
||||||
|
points_y = { 0, 180, 255, 265 };
|
||||||
|
createTable2(points_x, points_y);
|
||||||
|
|
||||||
|
points_x = { 0, 230, 255 };
|
||||||
|
points_y = { 0, 210, 255 };
|
||||||
|
createTable3(points_x, points_y);
|
||||||
|
}
|
||||||
|
|
||||||
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::vector<double>& points_x, const std::vector<double>& points_y)
|
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::vector<double>& points_x, const std::vector<double>& points_y)
|
||||||
: m_table(new uchar[SIZE_OF_TABLE])
|
: m_table(new uchar[SIZE_OF_TABLE])
|
||||||
|
, m_table2(new uchar[SIZE_OF_TABLE])
|
||||||
|
, m_table3(new uchar[SIZE_OF_TABLE])
|
||||||
{
|
{
|
||||||
createTable(points_x, points_y);
|
createTable(points_x, points_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::string& fileName)
|
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::string& fileName)
|
||||||
: m_table(new uchar[SIZE_OF_TABLE])
|
: m_table(new uchar[SIZE_OF_TABLE])
|
||||||
|
, m_table2(new uchar[SIZE_OF_TABLE])
|
||||||
|
, m_table3(new uchar[SIZE_OF_TABLE])
|
||||||
{
|
{
|
||||||
std::fstream file(fileName, std::ios::in | std::ios::binary);
|
std::fstream file(fileName, std::ios::in | std::ios::binary);
|
||||||
if (file)
|
if (file)
|
||||||
|
@ -23,6 +58,8 @@ CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::string& file
|
||||||
|
|
||||||
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const uchar* table_h)
|
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const uchar* table_h)
|
||||||
: m_table(new uchar[SIZE_OF_TABLE])
|
: m_table(new uchar[SIZE_OF_TABLE])
|
||||||
|
, m_table2(new uchar[SIZE_OF_TABLE])
|
||||||
|
, m_table3(new uchar[SIZE_OF_TABLE])
|
||||||
{
|
{
|
||||||
memcpy(m_table, table_h, SIZE_OF_TABLE);
|
memcpy(m_table, table_h, SIZE_OF_TABLE);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +76,8 @@ CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const int type)
|
||||||
CImageApplyColorCastCorrect::~CImageApplyColorCastCorrect(void)
|
CImageApplyColorCastCorrect::~CImageApplyColorCastCorrect(void)
|
||||||
{
|
{
|
||||||
delete[] m_table;
|
delete[] m_table;
|
||||||
|
delete[] m_table2;
|
||||||
|
delete[] m_table3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CImageApplyColorCastCorrect::setlutdata(const int type)
|
void CImageApplyColorCastCorrect::setlutdata(const int type)
|
||||||
|
@ -51,18 +90,31 @@ void CImageApplyColorCastCorrect::apply(cv::Mat& pDib, int side)
|
||||||
{
|
{
|
||||||
if (pDib.channels() != 3)
|
if (pDib.channels() != 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cv::Mat hsv;
|
cv::Mat hsv;
|
||||||
cv::cvtColor(pDib, hsv, cv::COLOR_BGR2HSV_FULL);
|
cv::cvtColor(pDib, hsv, cv::COLOR_BGR2HLS_FULL);
|
||||||
|
|
||||||
cv::Mat hsv_mv[3];
|
cv::Mat hsv_mv[3];
|
||||||
cv::split(hsv, hsv_mv);
|
cv::split(hsv, hsv_mv);
|
||||||
|
|
||||||
|
cv::imwrite("hsv_0.jpg", hsv_mv[0]);
|
||||||
cv::Mat lut(256, 1, CV_8UC1, m_table);
|
cv::Mat lut(256, 1, CV_8UC1, m_table);
|
||||||
cv::LUT(hsv_mv[0], lut, hsv_mv[0]);
|
cv::LUT(hsv_mv[0], lut, hsv_mv[0]);
|
||||||
|
|
||||||
|
#ifdef JIANG_BAOHE
|
||||||
|
//hsv_mv[2] -= 20;
|
||||||
|
//cv::imwrite("hsv_0.jpg", hsv_mv[0]);
|
||||||
|
//cv::imwrite("hsv_1.jpg", hsv_mv[1]);
|
||||||
|
//cv::imwrite("hsv_2.jpg", hsv_mv[2]);
|
||||||
|
cv::Mat lut2(256, 1, CV_8UC1, m_table2);
|
||||||
|
cv::LUT(hsv_mv[2], lut2, hsv_mv[2]);
|
||||||
|
|
||||||
|
//hsv_mv[1] -= 20;
|
||||||
|
//cv::Mat lut3(256, 1, CV_8UC1, m_table3);
|
||||||
|
//cv::LUT(hsv_mv[1], lut3, hsv_mv[1]);
|
||||||
|
#endif
|
||||||
cv::merge(hsv_mv, 3, pDib);
|
cv::merge(hsv_mv, 3, pDib);
|
||||||
|
|
||||||
cv::cvtColor(pDib, pDib, cv::COLOR_HSV2BGR_FULL);
|
cv::cvtColor(pDib, pDib, cv::COLOR_HLS2BGR_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CImageApplyColorCastCorrect::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
|
void CImageApplyColorCastCorrect::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
|
||||||
|
@ -124,3 +176,42 @@ void CImageApplyColorCastCorrect::createTable(const std::vector<double>& points_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CImageApplyColorCastCorrect::createTable2(const std::vector<double>& points_x, const std::vector<double>& points_y)
|
||||||
|
{
|
||||||
|
memset(m_table2, 255, 256);
|
||||||
|
memset(m_table2, 0, 127);
|
||||||
|
int s = 1;
|
||||||
|
for (int i = 0; i < points_x.size() - s; i += s)
|
||||||
|
{
|
||||||
|
double low = points_y[i];
|
||||||
|
double up = points_y[i + s];
|
||||||
|
|
||||||
|
int start = points_x[i];
|
||||||
|
int end = points_x[i + s];
|
||||||
|
|
||||||
|
int length = end - start;
|
||||||
|
double step = (up - low) / length;
|
||||||
|
for (int j = 0; j < length; j++)
|
||||||
|
m_table2[start + j] = max(0.0, min(255.0, low + j * step));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CImageApplyColorCastCorrect::createTable3(const std::vector<double>& points_x, const std::vector<double>& points_y)
|
||||||
|
{
|
||||||
|
memset(m_table3, 255, 256);
|
||||||
|
memset(m_table3, 0, 127);
|
||||||
|
int s = 1;
|
||||||
|
for (int i = 0; i < points_x.size() - s; i += s)
|
||||||
|
{
|
||||||
|
double low = points_y[i];
|
||||||
|
double up = points_y[i + s];
|
||||||
|
|
||||||
|
int start = points_x[i];
|
||||||
|
int end = points_x[i + s];
|
||||||
|
|
||||||
|
int length = end - start;
|
||||||
|
double step = (up - low) / length;
|
||||||
|
for (int j = 0; j < length; j++)
|
||||||
|
m_table3[start + j] = max(0.0, min(255.0, low + j * step));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
* v1.2 2023/04/04 提高曲线拐点数,增加预设方案CIS_DN_PATCH3
|
* v1.2 2023/04/04 提高曲线拐点数,增加预设方案CIS_DN_PATCH3
|
||||||
* v1.3 2023/04/17 增加新查值表导入方式。
|
* v1.3 2023/04/17 增加新查值表导入方式。
|
||||||
* v2.0 2023/05/15 重构查值表算法。
|
* v2.0 2023/05/15 重构查值表算法。
|
||||||
* 版本号:v2.0
|
* v2.1 2023/10/07 添加饱和度、亮度调节,当前暂不开放参数设置接口。
|
||||||
|
* 版本号:v2.1
|
||||||
* ====================================================
|
* ====================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -23,6 +24,8 @@ class GIMGPROC_LIBRARY_API CImageApplyColorCastCorrect : public CImageApply
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
CImageApplyColorCastCorrect();
|
||||||
|
|
||||||
const uchar CIS_DN_PATCH2[256] = //摩尔纹慢速扫描色偏参数
|
const uchar CIS_DN_PATCH2[256] = //摩尔纹慢速扫描色偏参数
|
||||||
{
|
{
|
||||||
0x10, 0x11, 0x13, 0x14, 0x16, 0x17, 0x1B, 0x1B, 0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
|
0x10, 0x11, 0x13, 0x14, 0x16, 0x17, 0x1B, 0x1B, 0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
|
||||||
|
@ -62,6 +65,7 @@ public:
|
||||||
0xEF, 0xEF, 0xF0, 0xF0, 0xF1, 0xF1, 0xF2, 0xF3, 0xF3, 0xF4, 0xF4, 0xF5, 0xF5, 0xF6, 0xF7, 0xF7,
|
0xEF, 0xEF, 0xF0, 0xF0, 0xF1, 0xF1, 0xF2, 0xF3, 0xF3, 0xF4, 0xF4, 0xF5, 0xF5, 0xF6, 0xF7, 0xF7,
|
||||||
0xF8, 0xF8, 0xF9, 0xF9, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC, 0xFD, 0xFD, 0xFE, 0x02, 0x05, 0x08, 0x0A
|
0xF8, 0xF8, 0xF9, 0xF9, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC, 0xFD, 0xFD, 0xFE, 0x02, 0x05, 0x08, 0x0A
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用户自定义查值表
|
/// 用户自定义查值表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -104,8 +108,10 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void createTable(const std::vector<double>& points_x, const std::vector<double>& points_y);
|
void createTable(const std::vector<double>& points_x, const std::vector<double>& points_y);
|
||||||
|
void createTable2(const std::vector<double>& points_x, const std::vector<double>& points_y);
|
||||||
|
void createTable3(const std::vector<double>& points_x, const std::vector<double>& points_y);
|
||||||
private:
|
private:
|
||||||
uchar* m_table;
|
uchar* m_table, *m_table2, *m_table3;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
File diff suppressed because one or more lines are too long
|
@ -1396,11 +1396,20 @@ namespace hg_imgproc
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
std::vector<cv::Mat> mats(mats_);
|
std::vector<cv::Mat> mats(mats_);
|
||||||
mats_.clear();
|
mats_.clear();
|
||||||
CImageApplyColorCastCorrect ColorCastCorrect(1);
|
if (pid_ == 0x300)
|
||||||
|
{
|
||||||
|
CImageApplyColorCastCorrect ColorCastCorrect;
|
||||||
|
ColorCastCorrect.apply(mats, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CImageApplyColorCastCorrect ColorCastCorrect(1);
|
||||||
|
ColorCastCorrect.apply(mats, true);
|
||||||
|
}
|
||||||
|
|
||||||
//cv::imwrite(to_string(i) + "cis_test_image.jpg", mats[i]);
|
//cv::imwrite(to_string(i) + "cis_test_image.jpg", mats[i]);
|
||||||
|
|
||||||
ColorCastCorrect.apply(mats,true);
|
|
||||||
mats_ = mats;
|
mats_ = mats;
|
||||||
|
|
||||||
if (mats_.empty())
|
if (mats_.empty())
|
||||||
|
@ -1416,7 +1425,7 @@ namespace hg_imgproc
|
||||||
{
|
{
|
||||||
return SCANNER_ERR_NO_DATA;
|
return SCANNER_ERR_NO_DATA;
|
||||||
}
|
}
|
||||||
return LineContinuityDetection::isContinuous(mats_[0], 100); //检测一面就行
|
return LineContinuityDetection::isContinuous(mats_[0], 100); //检测一面就�
|
||||||
}
|
}
|
||||||
int correction_image(cv::Mat &flat_lut, cv::Mat black_mat, cv::Mat white_mat)
|
int correction_image(cv::Mat &flat_lut, cv::Mat black_mat, cv::Mat white_mat)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue