diff --git a/hgdriver/ImageProcess/ImageApplyColorRecognition.cpp b/hgdriver/ImageProcess/ImageApplyColorRecognition.cpp
index ad1446e..c25a460 100644
--- a/hgdriver/ImageProcess/ImageApplyColorRecognition.cpp
+++ b/hgdriver/ImageProcess/ImageApplyColorRecognition.cpp
@@ -1,44 +1,26 @@
#include "ImageApplyColorRecognition.h"
-#include "ImageApplyHeaders.h"
-
-//static CImageApplyBWBinaray m_bw;
-//static CImageApplyAdjustColors m_ac(0, 50, 1.0f);
///
/// 检测图像是否是彩色。当前逻辑仅针对红色像素进行判断,即存在红色像素则为彩色,否则为非彩色
///
/// 待测图像
/// true为彩色,false为非彩色
-bool isColor(const cv::Mat& image)
+bool isColor(const cv::Mat& image, double threshold = 60)
{
if (image.channels() != 3) return false;
cv::Mat pDib_resize;
- cv::resize(image, pDib_resize, cv::Size(image.cols / 4, image.rows / 4), 0, 0, cv::INTER_NEAREST);
+ cv::resize(image, pDib_resize, cv::Size(200, 200), 0, 0, cv::INTER_AREA);
cv::Mat hsv;
cv::cvtColor(pDib_resize, hsv, cv::COLOR_BGR2HSV_FULL);
std::vector hsv_channels;
cv::split(hsv, hsv_channels);
- cv::Mat range_s1, range_s2;
- cv::inRange(hsv_channels[1], 220, 255, range_s1); //饱和度在[220, 255]的像素
- cv::inRange(hsv_channels[1], 50, 220, range_s2); //饱和度在[50, 220]的像素
-#if 0
- cv::imwrite("range_s1.bmp", range_s1);
- cv::imwrite("range_s2.bmp", range_s2);
-#endif
- double sum = cv::sum(range_s1)[0] / 255;
- double total = range_s1.total();
+ double minVal, maxVal;
+ cv::minMaxLoc(hsv_channels[1], &minVal, &maxVal);
- // if (sum / total > 0.0001)
- if (sum / total > 0.001)
- return true;
- sum += cv::sum(range_s2)[0] / 255;
- // if (sum / total > 0.001)
- if (sum / total > 0.03)
- return true;
- return false;
+ return maxVal > threshold;
}
bool isGray(const cv::Mat& image)
diff --git a/hgdriver/ImageProcess/ImageApplyColorRecognition.h b/hgdriver/ImageProcess/ImageApplyColorRecognition.h
index d0cbfb9..eae6b50 100644
--- a/hgdriver/ImageProcess/ImageApplyColorRecognition.h
+++ b/hgdriver/ImageProcess/ImageApplyColorRecognition.h
@@ -4,12 +4,13 @@
* 功能:色彩识别,将识别会“灰度”的24位图转化为256色8位图, 把识别为“黑白”图转化为二值化的8位图
* 作者:刘丁维
* 生成时间:2020/7/17
- * 最近修改时间:2021/04/19
- * 版本号:v1.0 2020/7/17
- * v1.1 2020/12/15 调整策略,仅判断红色像素,存在红色像素为彩色,否则为灰度;删除输出结果,直接转换图像。
- * v1.2 2020/12/16 增加颜色限制模式(输出结果只可能两种),增加结果访问接口
- * v1.3 2021/04/19 修改识别策略,能够识别占比1‰的彩色图像。只区分彩色和灰度图。
- * v1.4 2021/06/18 调整二级色彩区间,从原来的[90, 200]调整为[50, 200]。
+ * 最近修改时间:v1.0 2020/7/17
+ * v1.1 2020/12/15 调整策略,仅判断红色像素,存在红色像素为彩色,否则为灰度;删除输出结果,直接转换图像。
+ * v1.2 2020/12/16 增加颜色限制模式(输出结果只可能两种),增加结果访问接口
+ * v1.3 2021/04/19 修改识别策略,能够识别占比1‰的彩色图像。只区分彩色和灰度图。
+ * v1.4 2021/06/18 调整二级色彩区间,从原来的[90, 200]调整为[50, 200]。
+ * v1.5 2023/11/22 调整彩色判定策略。
+ * 版本号:v1.5
* ====================================================
*/
diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp
index d4c4706..73fe831 100644
--- a/hgdriver/hgdev/hg_scanner.cpp
+++ b/hgdriver/hgdev/hg_scanner.cpp
@@ -5262,7 +5262,7 @@ void hg_scanner::image_process(std::shared_ptr& buffer, uint32_t id
if (img_conf_.is_colorcast && pid_ != 0x239 && pid_ != 0x439)
{
ret = hg_imgproc::color_cast_correction(ImagePrc_pHandle_);
- (this->*dump_img_)(ImagePrc_pHandle_, "discardBlank");
+ (this->*dump_img_)(ImagePrc_pHandle_, "color_cast_correction");
}
if ((img_conf_.is_autodiscradblank_normal || img_conf_.is_autodiscradblank_vince || img_conf_.detect_size_diascard_blank) && (pid_ != 0x239 && pid_ != 0x439))
{
@@ -5292,7 +5292,7 @@ void hg_scanner::image_process(std::shared_ptr& buffer, uint32_t id
if ((img_conf_.cropRect.enable && !img_conf_.is_autocrop) && (pid_ != 0x239 && pid_ != 0x439))
{
hg_imgproc::croprect(ImagePrc_pHandle_);
- (this->*dump_img_)(ImagePrc_pHandle_, "resolution_change");
+ (this->*dump_img_)(ImagePrc_pHandle_, "croprect");
}
if ((img_conf_.filter != ColorFilter::FILTER_NONE