This commit is contained in:
13038267101 2023-11-14 18:04:22 +08:00
commit 95f01e66d3
7 changed files with 174 additions and 150 deletions

View File

@ -3,87 +3,116 @@
#include <iostream>
#define JIANG_BAOHE
//#define G200
#define G300
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
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])
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(PreScheme ps)
: m_table_h(new uchar[SIZE_OF_TABLE])
, m_table_l(new uchar[SIZE_OF_TABLE])
, m_table_s(new uchar[SIZE_OF_TABLE])
{
std::vector<double> points_x, points_y;
switch (ps)
{
case CImageApplyColorCastCorrect::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 };
break;
case CImageApplyColorCastCorrect::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 };
break;
case CImageApplyColorCastCorrect::G300_D8:
points_x = { 0, 2, 5, 9, 15, 20, 26, 39, 54, 70, 83, 94, 102, 113, 128, 139, 146, 151, 156, 164, 177, 199, 232, 253 };
points_y = { 11, 17, 21, 26, 31, 33, 36, 40, 44, 56, 92, 104, 114, 126, 135, 141, 143, 146, 151, 169, 198, 218, 227, 252 };
break;
case CImageApplyColorCastCorrect::G400_402:
points_x = { 2, 8, 15, 20, 27, 41, 50, 67, 80, 91, 99, 109, 124, 138, 145, 150, 157, 164, 177, 202, 232, 250, 252, 255 };
points_y = { 21, 26, 31, 33, 36, 40, 44, 56, 92, 104, 114, 126, 135, 141, 143, 146, 151, 169, 198, 218, 227, 252, 266, 272 };
break;
case CImageApplyColorCastCorrect::G400_3288:
points_x = { 2, 3, 5, 7, 11, 16, 19, 25, 40, 57, 72, 84, 95, 101, 111, 126, 144, 148, 152, 157, 165, 179, 203, 234 };
points_y = { -3, 11, 17, 21, 26, 31, 33, 36, 40, 44, 56, 92, 104, 114, 126, 135, 141, 143, 146, 151, 169, 198, 218, 227 };
break;
case CImageApplyColorCastCorrect::Android302:
points_x = { 0, 6, 11, 19, 37, 48, 66, 79, 89, 97, 108, 122, 138, 143, 147, 150, 158, 170, 199, 233, 248, 249, 250, 252 };
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 };
break;
default:
points_x = { 0, 255 };
points_y = { 0, 255 };
break;
}
#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);
createTable_h(points_x, points_y);
points_x = { 0, 180, 210, 255 };
points_y = { 0, 180, 255, 265 };
createTable2(points_x, points_y);
createTable_l(points_x, points_y);
points_x = { 0, 230, 255 };
points_y = { 0, 210, 255 };
createTable3(points_x, points_y);
createTable_s(points_x, points_y);
}
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::vector<double>& h_x, const std::vector<double>& h_y,
const std::vector<double>& l_x, const std::vector<double>& l_y,
const std::vector<double>& s_x, const std::vector<double>& s_y)
: m_table_h(new uchar[SIZE_OF_TABLE])
, m_table_l(new uchar[SIZE_OF_TABLE])
, m_table_s(new uchar[SIZE_OF_TABLE])
{
if (!h_x.empty() && !h_y.empty())
createTable_h(h_x, h_y);
if (!l_x.empty() && !l_y.empty())
createTable_l(l_x, l_y);
if (!s_x.empty() && !s_y.empty())
createTable_s(s_x, s_y);
}
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::vector<double>& points_x, const std::vector<double>& points_y)
: m_table(new uchar[SIZE_OF_TABLE])
, m_table2(new uchar[SIZE_OF_TABLE])
, m_table3(new uchar[SIZE_OF_TABLE])
: m_table_h(new uchar[SIZE_OF_TABLE])
, m_table_l(new uchar[SIZE_OF_TABLE])
, m_table_s(new uchar[SIZE_OF_TABLE])
{
createTable(points_x, points_y);
createTable_h(points_x, points_y);
for (size_t i = 0; i < SIZE_OF_TABLE; i++)
m_table_l[i] = m_table_s[i] = i;
}
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::string& fileName)
: m_table(new uchar[SIZE_OF_TABLE])
, m_table2(new uchar[SIZE_OF_TABLE])
, m_table3(new uchar[SIZE_OF_TABLE])
: m_table_h(new uchar[SIZE_OF_TABLE])
, m_table_l(new uchar[SIZE_OF_TABLE])
, m_table_s(new uchar[SIZE_OF_TABLE])
{
std::fstream file(fileName, std::ios::in | std::ios::binary);
if (file)
file.read(reinterpret_cast<char*>(m_table), SIZE_OF_TABLE);
file.read(reinterpret_cast<char*>(m_table_h), SIZE_OF_TABLE);
file.close();
for (size_t i = 0; i < SIZE_OF_TABLE; i++)
m_table_l[i] = m_table_s[i] = i;
}
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const uchar* table_h)
: m_table(new uchar[SIZE_OF_TABLE])
, m_table2(new uchar[SIZE_OF_TABLE])
, m_table3(new uchar[SIZE_OF_TABLE])
: m_table_h(new uchar[SIZE_OF_TABLE])
, m_table_l(new uchar[SIZE_OF_TABLE])
, m_table_s(new uchar[SIZE_OF_TABLE])
{
memcpy(m_table, table_h, SIZE_OF_TABLE);
}
CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const int type)
: m_table(new uchar[SIZE_OF_TABLE])
{
if(type == 1)
memcpy(m_table,CIS_DN_PATCH1,SIZE_OF_TABLE);
else
memcpy(m_table,CIS_DN_PATCH2,SIZE_OF_TABLE);
memcpy(m_table_h, table_h, SIZE_OF_TABLE);
for (size_t i = 0; i < SIZE_OF_TABLE; i++)
m_table_l[i] = m_table_s[i] = i;
}
CImageApplyColorCastCorrect::~CImageApplyColorCastCorrect(void)
{
delete[] m_table;
delete[] m_table2;
delete[] m_table3;
}
void CImageApplyColorCastCorrect::setlutdata(const int type)
{
if(type == 1) memcpy(m_table,CIS_DN_PATCH1,SIZE_OF_TABLE);
else memcpy(m_table,CIS_DN_PATCH2,SIZE_OF_TABLE);
delete[] m_table_h;
delete[] m_table_l;
delete[] m_table_s;
}
void CImageApplyColorCastCorrect::apply(cv::Mat& pDib, int side)
@ -97,7 +126,7 @@ void CImageApplyColorCastCorrect::apply(cv::Mat& pDib, int side)
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_h);
cv::LUT(hsv_mv[0], lut, hsv_mv[0]);
#ifdef JIANG_BAOHE
@ -105,7 +134,7 @@ void CImageApplyColorCastCorrect::apply(cv::Mat& pDib, int side)
//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::Mat lut2(256, 1, CV_8UC1, m_table_l);
cv::LUT(hsv_mv[2], lut2, hsv_mv[2]);
//hsv_mv[1] -= 20;
@ -134,11 +163,11 @@ void CImageApplyColorCastCorrect::exportTableData(const std::string& fileName)
{
std::fstream file(fileName, std::ios::out | std::ios::binary);
if (file)
file.write(reinterpret_cast<char*>(m_table), SIZE_OF_TABLE);
file.write(reinterpret_cast<char*>(m_table_h), SIZE_OF_TABLE);
file.close();
}
void CImageApplyColorCastCorrect::createTable(const std::vector<double>& points_x, const std::vector<double>& points_y)
void CImageApplyColorCastCorrect::createTable_h(const std::vector<double>& points_x, const std::vector<double>& points_y)
{
int table_temp[256]{};
@ -170,16 +199,16 @@ void CImageApplyColorCastCorrect::createTable(const std::vector<double>& points_
for (size_t j = 0; j < 256; j++)
if (table_temp[j] > 255)
m_table[j] = table_temp[j] - 255;
m_table_h[j] = table_temp[j] - 255;
else
m_table[j] = table_temp[j];
m_table_h[j] = table_temp[j];
}
}
void CImageApplyColorCastCorrect::createTable2(const std::vector<double>& points_x, const std::vector<double>& points_y)
void CImageApplyColorCastCorrect::createTable_l(const std::vector<double>& points_x, const std::vector<double>& points_y)
{
memset(m_table2, 255, 256);
memset(m_table2, 0, 127);
memset(m_table_l, 255, 256);
memset(m_table_l, 0, 127);
int s = 1;
for (int i = 0; i < points_x.size() - s; i += s)
{
@ -192,14 +221,14 @@ void CImageApplyColorCastCorrect::createTable2(const std::vector<double>& points
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));
m_table_l[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)
void CImageApplyColorCastCorrect::createTable_s(const std::vector<double>& points_x, const std::vector<double>& points_y)
{
memset(m_table3, 255, 256);
memset(m_table3, 0, 127);
memset(m_table_s, 255, 256);
memset(m_table_s, 0, 127);
int s = 1;
for (int i = 0; i < points_x.size() - s; i += s)
{
@ -212,6 +241,6 @@ void CImageApplyColorCastCorrect::createTable3(const std::vector<double>& points
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));
m_table_s[start + j] = max(0.0, min(255.0, low + j * step));
}
}

View File

@ -11,7 +11,9 @@
* v1.3 2023/04/17
* v2.0 2023/05/15
* v2.1 2023/10/07
* v2.1
* v2.2 2023/11/13
* v2.2.1 2023/11/13
* v2.2.1
* ====================================================
*/
@ -24,47 +26,22 @@ class GIMGPROC_LIBRARY_API CImageApplyColorCastCorrect : public CImageApply
{
public:
CImageApplyColorCastCorrect();
const uchar CIS_DN_PATCH2[256] = //摩尔纹慢速扫描色偏参数
//预设方案
enum PreScheme
{
0x10, 0x11, 0x13, 0x14, 0x16, 0x17, 0x1B, 0x1B, 0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
0x20, 0x21, 0x21, 0x21, 0x22, 0x22, 0x22, 0x23, 0x23, 0x23, 0x24, 0x24, 0x24, 0x25, 0x25, 0x25,
0x26, 0x26, 0x26, 0x27, 0x27, 0x28, 0x28, 0x28, 0x29, 0x29, 0x29, 0x2A, 0x2A, 0x2A, 0x2B, 0x2B,
0x2B, 0x2C, 0x2C, 0x2C, 0x2D, 0x2D, 0x2D, 0x2E, 0x2E, 0x2E, 0x2F, 0x2F, 0x2F, 0x30, 0x30, 0x30,
0x31, 0x31, 0x31, 0x32, 0x33, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, 0x40, 0x42, 0x44, 0x46, 0x48,
0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5A, 0x5C, 0x5E, 0x62, 0x63, 0x65, 0x66, 0x68,
0x69, 0x6B, 0x6C, 0x6E, 0x6F, 0x71, 0x72, 0x74, 0x75, 0x77, 0x78, 0x7A, 0x7B, 0x7D, 0x7E, 0x82,
0x82, 0x82, 0x83, 0x83, 0x84, 0x84, 0x85, 0x85, 0x86, 0x86, 0x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 0xEB, 0xEB, 0xEC, 0xEC, 0xED, 0xED, 0xEE,
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
};
CImageApplyColorCastCorrect(PreScheme ps = G200);
CImageApplyColorCastCorrect(const std::vector<double>& h_x, const std::vector<double>& h_y,
const std::vector<double>& l_x, const std::vector<double>& l_y,
const std::vector<double>& s_x, const std::vector<double>& s_y);
/// <summary>
/// 用户自定义查值表
@ -85,14 +62,6 @@ public:
/// <param name="table_h"></param>
CImageApplyColorCastCorrect(const uchar* table_h);
/// <summary>
/// 选择设置HSV中H通道的LUT校正数据
/// </summary>
/// <param name="table_h"></param>
CImageApplyColorCastCorrect(const int type);
void setlutdata(const int type);
virtual ~CImageApplyColorCastCorrect(void);
virtual void apply(cv::Mat& pDib, int side);
@ -107,11 +76,11 @@ public:
private:
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);
void createTable_h(const std::vector<double>& points_x, const std::vector<double>& points_y);
void createTable_l(const std::vector<double>& points_x, const std::vector<double>& points_y);
void createTable_s(const std::vector<double>& points_x, const std::vector<double>& points_y);
private:
uchar* m_table, *m_table2, *m_table3;
uchar* m_table_h, *m_table_l, *m_table_s;
};
#endif

View File

@ -40,6 +40,7 @@
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
class MyFStream
{
@ -321,4 +322,4 @@ private:
int m_dilate;
};
#endif // !IMAGE_APPLY_DISCARD_BLANK_H
#endif // !IMAGE_APPLY_DISCARD_BLANK_H

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1411,16 +1411,27 @@ namespace hg_imgproc
int ret = SCANNER_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
if (pid_ == 0x300)
CImageApplyColorCastCorrect::PreScheme deviceType = CImageApplyColorCastCorrect::G200;
if (0x300 == pid_)
{
CImageApplyColorCastCorrect ColorCastCorrect;
ColorCastCorrect.apply(mats, true);
}
else
{
CImageApplyColorCastCorrect ColorCastCorrect(1);
ColorCastCorrect.apply(mats, true);
deviceType = CImageApplyColorCastCorrect::G300_D8;
}
else if (0x400 == pid_)
{
deviceType = CImageApplyColorCastCorrect::G400_3288;
}
else if (0x402 == pid_)
{
deviceType = CImageApplyColorCastCorrect::G400_402;
}
else if (0x302 == pid_)
{
deviceType = CImageApplyColorCastCorrect::Android302;
}
CImageApplyColorCastCorrect ColorCastCorrect(deviceType);
ColorCastCorrect.apply(mats, true);
//cv::imwrite(to_string(i) + "cis_test_image.jpg", mats[i]);