diff --git a/changelog.txt b/changelog.txt index 75a9625a..69ee9996 100644 --- a/changelog.txt +++ b/changelog.txt @@ -78,4 +78,6 @@ 2. 开放速度优先以及画质优先模式; 2022年11月28日 jzq 1.修复单面扫描 拆分 多流除红 出图不一致问题 -- 22.11.28 - 2.修复跳过空白页首选项配置保存问题 -- 22.11.28 \ No newline at end of file + 2.修复跳过空白页首选项配置保存问题 -- 22.11.28 + 3.调整msvc与mfc链接顺序,默认开启多核编译 + 4.添加色偏算法 \ No newline at end of file diff --git a/huagao/CMakeLists.txt b/huagao/CMakeLists.txt index 7052d0ef..c8eb1dc8 100644 --- a/huagao/CMakeLists.txt +++ b/huagao/CMakeLists.txt @@ -103,6 +103,17 @@ ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux") add_definitions(-DTWPP_IS_DS -D_CRT_SECURE_NO_WARNINGS -D_DIRECT_BUILD -D_NOT_USE -D_AFXDLL -D_UNICODE -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_CRT_NON_CONFORMING_SWPRINTFS -D_WIN32) #add_definitions(-DGIT_VERSION=\"${GIT_VERSION}\") +IF(CMAKE_BUILD_TYPE MATCHES "Debug") + SET(CMAKE_EXE_LINKER_FLAGS /NODEFAULTLIB:"MSVCRTd.lib;mfcs140ud.lib") +ELSE() + SET(CMAKE_EXE_LINKER_FLAGS /NODEFAULTLIB:"MSVCRT.lib;mfcs140u.lib") +ENDIF() + +RW_LINK_3RD_PART_LIBRARY(mfcs140u) +RW_LINK_3RD_PART_LIBRARY(MSVCRT) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") # 指定生成目标 add_library(huagaotwain SHARED ${DIR_SRCS} ${PROJECT_SOURCE_DIR}/exports.def ${DEV_SRC} ${IMGPROC_SRC} ${SRC} ${DIR_RC}) diff --git a/huagao/Device/ImageMatQueue.cpp b/huagao/Device/ImageMatQueue.cpp index bccfffa3..c7fba7c8 100644 --- a/huagao/Device/ImageMatQueue.cpp +++ b/huagao/Device/ImageMatQueue.cpp @@ -28,6 +28,7 @@ ImageMatQueue::ImageMatQueue(void) atm_orgin_image_remains = 0; m_dogear.reset(new CImageApplyDogEarDetection(40, 1.0, 200)); + m_colorcast.reset(new CImageApplyColorCastCorrect()); m_snowflake.init(1, 1); } @@ -202,6 +203,11 @@ void ImageMatQueue::setparam(const GScanCap& param) // m_iaList.push_back(shared_ptr(new CImageApplyHSVCorrect(CImageApplyHSVCorrect::CorrectOption::LowSaturation_Removal, true))); //} + if (param.pixtype == 2) + { + m_iaList.push_back(m_colorcast); + } + if (param.fadeback)//&& param.pixtype == 2 { m_iaList.push_back(shared_ptr(new CImageApplyFadeBackGroudColor(100,0,param.fadeback_range))); diff --git a/huagao/Device/ImageMatQueue.h b/huagao/Device/ImageMatQueue.h index b402b838..751815f0 100644 --- a/huagao/Device/ImageMatQueue.h +++ b/huagao/Device/ImageMatQueue.h @@ -249,6 +249,7 @@ private: GScanCap scanParam; Device::PaperSize papersize; std::shared_ptr m_dogear; + std::shared_ptr m_colorcast; std::vector> m_iaList; //ͼÏñ´¦Àíº¯Êý½Ó¿Ú float fx, fy; std::function m_DogEarDetection_callback; diff --git a/huagao/ImageProcess/ImageApplyColorCastCorrect.cpp b/huagao/ImageProcess/ImageApplyColorCastCorrect.cpp new file mode 100644 index 00000000..9b05ccd6 --- /dev/null +++ b/huagao/ImageProcess/ImageApplyColorCastCorrect.cpp @@ -0,0 +1,185 @@ +#include "ImageApplyColorCastCorrect.h" +#include +#include + + +#define max(a, b) ((a) > (b) ? (a) : (b)) +#define SIZE_OF_TABLE 256 * 256 * 256 + +CImageApplyColorCastCorrect::CImageApplyColorCastCorrect() + : m_table(new uint[SIZE_OF_TABLE]) +{ + std::vector points_x, points_y; + points_x = { 0, 80, 175, 255 }; + points_y = { 12, 85, 175, 270 }; + createTable(points_x, points_y); +} + +CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::vector& points_x, const std::vector& points_y) + : m_table(new uint[256 * 256 * 256]) +{ + createTable(points_x, points_y); +} + +CImageApplyColorCastCorrect::CImageApplyColorCastCorrect(const std::string& fileName) + : m_table(new uint[256 * 256 * 256]) +{ + std::fstream file(fileName, std::ios::in | std::ios::binary); + if (file) + file.read(reinterpret_cast(m_table), SIZE_OF_TABLE * sizeof(uint)); + file.close(); +} + +CImageApplyColorCastCorrect::~CImageApplyColorCastCorrect(void) +{ + delete[] m_table; +} + +void CImageApplyColorCastCorrect::apply(cv::Mat& pDib, int side) +{ + if (pDib.channels() != 3) + return; + + cv::Mat bgra; + cv::cvtColor(pDib, bgra, cv::COLOR_BGR2BGRA); + uint* ptr = bgra.ptr(); + int rows = bgra.rows, cols = bgra.cols; + for (int i = 0; i < rows; i++) + { + ptr = reinterpret_cast(bgra.ptr(i)); + for (int j = 0; j < cols; j++) + ptr[j] = m_table[ptr[j] & 0x00ffffff]; + } + cv::cvtColor(bgra, pDib, cv::COLOR_BGRA2BGR); + bgra.release(); +} + +void CImageApplyColorCastCorrect::apply(std::vector& mats, bool isTwoSide) +{ + (void)isTwoSide; + int i = 0; + for (cv::Mat& var : mats) { + if (i != 0 && isTwoSide == false) + break; + if (!var.empty()) + apply(var, 0); + i++; + } +} + +void CImageApplyColorCastCorrect::exportTableData(const std::string& fileName) +{ + std::fstream file(fileName, std::ios::out | std::ios::binary); + if (file) + file.write(reinterpret_cast(m_table), SIZE_OF_TABLE * sizeof(uint)); + file.close(); +} + +std::vector CImageApplyColorCastCorrect::caculate(const std::vector& points_x, const std::vector& points_y) +{ + int MaxElement = points_x.size() - 1; + //���㳣��f + double f = points_y[0]; + //��� + int n, m; + //double a[MaxElement][MaxElement+1]; + std::vector> a; + //a.resize(MaxElement); + for (int i = 0; i < MaxElement; i++) + { + std::vector b; + b.resize(MaxElement + 1); + a.push_back(b); + } + + for (int i = 0; i < MaxElement; i++) + { + for (int j = 0; j < MaxElement; j++) + a[i][j] = cv::pow(points_x[i + 1], MaxElement - j); + a[i][MaxElement] = points_y[i + 1] - f; + } + + int i, j; + n = MaxElement; + + for (j = 0; j < n; j++) + { + double max = 0; + double imax = 0; + for (i = j; i < n; i++) + if (imax < cv::abs(a[i][j])) + { + imax = cv::abs(a[i][j]); + max = a[i][j];//�õ����������������Ԫ�� + m = i; + } + + if (cv::abs(a[j][j]) != max) + { + double b = 0; + for (int k = j; k < n + 1; k++) + { + b = a[j][k]; + a[j][k] = a[m][k]; + a[m][k] = b; + } + } + + for (int r = j; r < n + 1; r++) + a[j][r] = a[j][r] / max;//�ø��е������г��������еĵ�һ��Ԫ�أ�Ŀ��������Ԫ��Ϊ1 + + for (i = j + 1; i < n; i++) + { + double c = a[i][j]; + if (c == 0.0) continue; + for (int s = j; s < n + 1; s++) + a[i][s] = a[i][s] - a[j][s] * c;//ǰ�����������ʹ��һ�л�����һ�е���Ԫ��Ϊ0 + } + } + + for (i = n - 2; i >= 0; i--) + for (j = i + 1; j < n; j++) + a[i][n] = a[i][n] - a[j][n] * a[i][j]; + + std::vector result; + for (int k = 0; k < n; k++) + result.push_back(a[k][n]); + result.push_back(f); + return result; +} + +void CImageApplyColorCastCorrect::createTable(const std::vector& points_x, const std::vector& points_y) +{ + cv::Mat mat_rgbTable(256 * 256, 256, CV_8UC3); + uchar* ptr_mat_rgbTable = mat_rgbTable.data; + for (size_t r = 0; r < 256; r++) + for (size_t g = 0; g < 256; g++) + for (size_t b = 0; b < 256; b++, ptr_mat_rgbTable += 3) + { + ptr_mat_rgbTable[0] = b; + ptr_mat_rgbTable[1] = g; + ptr_mat_rgbTable[2] = r; + } + + cv::cvtColor(mat_rgbTable, mat_rgbTable, cv::COLOR_BGR2HSV_FULL); + + uchar table_data[256]; + cv::Mat tableLUT(256, 1, CV_8UC1, table_data); + std::vector coefficient; + + coefficient = caculate(points_x, points_y); + for (int j = 0; j < 256; j++) + table_data[j] = static_cast(max(0, coefficient[0] * j * j * j + coefficient[1] * j * j + coefficient[2] * j + coefficient[3])); + + cv::Mat hsv_ms[3]; + cv::split(mat_rgbTable, hsv_ms); + cv::LUT(hsv_ms[0], tableLUT, hsv_ms[0]); + cv::merge(hsv_ms, 3, mat_rgbTable); + + cv::cvtColor(mat_rgbTable, mat_rgbTable, cv::COLOR_HSV2BGR_FULL); + + cv::Mat mat_bgr32(256, 256 * 256, CV_8UC4); + cv::cvtColor(mat_rgbTable, mat_bgr32, cv::COLOR_BGR2BGRA); + + memcpy(m_table, mat_bgr32.data, mat_bgr32.total() * sizeof(uint)); +} diff --git a/huagao/ImageProcess/ImageApplyColorCastCorrect.h b/huagao/ImageProcess/ImageApplyColorCastCorrect.h new file mode 100644 index 00000000..e47f61bf --- /dev/null +++ b/huagao/ImageProcess/ImageApplyColorCastCorrect.h @@ -0,0 +1,62 @@ +/* + * ==================================================== + + * 功能:色偏校正 + * 作者:刘丁维 + * 生成时间:2022/12/01 + * 最近修改时间:2022/12/01 + * 版本号:v1.0 2022/12/01 + * v1.1 2022/12/01 增加从文件中读取查值表数据接口;增加导出查值表数据接口 + + * ==================================================== + */ + +#ifndef IMAGE_APPLY_COLOR_CAST_CORRECT_H +#define IMAGE_APPLY_COLOR_CAST_CORRECT_H + +#include "ImageApply.h" + +class CImageApplyColorCastCorrect : public CImageApply +{ +public: + + /// + /// 默认使用 points_x = { 0, 80, 175, 255 } points_y = { 12, 85, 175, 270 }曲线创建查值表 + /// + CImageApplyColorCastCorrect(); + + /// + /// 用户自定义查值表 + /// + /// HSV色彩空间H通道曲线变换节点坐标X轴 + /// HSV色彩空间H通道曲线变换节点坐标Y轴 + CImageApplyColorCastCorrect(const std::vector& points_x, const std::vector& points_y); + + /// + /// 从文件中加载现有查值表数据 + /// + /// + CImageApplyColorCastCorrect(const std::string& fileName); + + virtual ~CImageApplyColorCastCorrect(void); + + virtual void apply(cv::Mat& pDib, int side); + + virtual void apply(std::vector& mats, bool isTwoSide); + + /// + /// 导出当前查值表数据 + /// + /// + void exportTableData(const std::string& fileName); + +private: + + std::vector caculate(const std::vector& points_x, const std::vector& points_y); + + void createTable(const std::vector& points_x, const std::vector& points_y); +private: + uint* m_table; +}; + +#endif \ No newline at end of file diff --git a/huagao/ImageProcess/ImageApplyHeaders.h b/huagao/ImageProcess/ImageApplyHeaders.h index 66e046a3..c1b3d2df 100644 --- a/huagao/ImageProcess/ImageApplyHeaders.h +++ b/huagao/ImageProcess/ImageApplyHeaders.h @@ -20,4 +20,5 @@ #include "ImageApplyUV.h" #include "ImageApplySplit.h" #include "ImageApplyFadeBackGroundColor.h" +#include "ImageApplyColorCastCorrect.h" #endif diff --git a/huagao/stdafx.h b/huagao/stdafx.h index 09645252..e8fe4b20 100644 Binary files a/huagao/stdafx.h and b/huagao/stdafx.h differ