Merge branch 'dev' of http://192.168.10.5:8099/sane/code_device into dev
This commit is contained in:
commit
ef3792b131
|
@ -4,7 +4,6 @@
|
||||||
#include <opencv2/imgproc/hal/hal.hpp>
|
#include <opencv2/imgproc/hal/hal.hpp>
|
||||||
#include "ImageApplyDispersion.h"
|
#include "ImageApplyDispersion.h"
|
||||||
|
|
||||||
#define COLOR_BACKGROUND_THRE 20
|
|
||||||
#define FRONT_TOP 70
|
#define FRONT_TOP 70
|
||||||
#define FX_FY 0.5f
|
#define FX_FY 0.5f
|
||||||
|
|
||||||
|
@ -18,14 +17,13 @@ CImageApplyAutoCrop::CImageApplyAutoCrop()
|
||||||
, m_noise(8)
|
, m_noise(8)
|
||||||
, m_indent(5)
|
, m_indent(5)
|
||||||
, m_normalCrop(false)
|
, m_normalCrop(false)
|
||||||
, m_isDispersion(true)
|
|
||||||
, m_fx(1.0)
|
, m_fx(1.0)
|
||||||
, m_fy(1.0)
|
, m_fy(1.0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CImageApplyAutoCrop::CImageApplyAutoCrop(bool isCrop, bool isDesaskew, bool isFillBlank, const cv::Size& fixedSize, bool isConvex, bool isFillColor,
|
CImageApplyAutoCrop::CImageApplyAutoCrop(bool isCrop, bool isDesaskew, bool isFillBlank, const cv::Size& fixedSize, bool isConvex, bool isFillColor,
|
||||||
double threshold, int noise, int indent, bool normalCrop, bool dispersion, double fx, double fy)
|
double threshold, int noise, int indent, bool normalCrop, double fx, double fy)
|
||||||
: m_isCrop(isCrop)
|
: m_isCrop(isCrop)
|
||||||
, m_isDesaskew(isDesaskew)
|
, m_isDesaskew(isDesaskew)
|
||||||
, m_isFillBlank(isFillBlank)
|
, m_isFillBlank(isFillBlank)
|
||||||
|
@ -36,7 +34,6 @@ CImageApplyAutoCrop::CImageApplyAutoCrop(bool isCrop, bool isDesaskew, bool isFi
|
||||||
, m_indent(indent)
|
, m_indent(indent)
|
||||||
, m_fixedSize(fixedSize)
|
, m_fixedSize(fixedSize)
|
||||||
, m_normalCrop(normalCrop)
|
, m_normalCrop(normalCrop)
|
||||||
, m_isDispersion(dispersion)
|
|
||||||
, m_fx(fx)
|
, m_fx(fx)
|
||||||
, m_fy(fy)
|
, m_fy(fy)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +47,7 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side)
|
||||||
{
|
{
|
||||||
cv::Mat dst;
|
cv::Mat dst;
|
||||||
autoCrop_desaskew_fillBlank(pDib, dst, m_isCrop, m_isDesaskew, m_isFillBlank, m_fixedSize.width, m_fixedSize.height,
|
autoCrop_desaskew_fillBlank(pDib, dst, m_isCrop, m_isDesaskew, m_isFillBlank, m_fixedSize.width, m_fixedSize.height,
|
||||||
m_isConvexHull, m_isFillColor, m_threshold, m_noise, m_indent, m_normalCrop, m_isDispersion, m_fx, m_fy);
|
m_isConvexHull, m_isFillColor, m_threshold, m_noise, m_indent, m_normalCrop, m_fx, m_fy);
|
||||||
pDib = dst;
|
pDib = dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,14 +96,14 @@ void CImageApplyAutoCrop::myWarpAffine(cv::InputArray _src, cv::OutputArray _dst
|
||||||
M, interpolation, borderType, borderValue.val);
|
M, interpolation, borderType, borderValue.val);
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::Scalar CImageApplyAutoCrop::getBackGroudColor(const cv::Mat& image, int threshold)
|
cv::Scalar CImageApplyAutoCrop::getBackGroudColor(const cv::Mat& image)
|
||||||
{
|
{
|
||||||
if (image.channels() == 3)
|
if (image.channels() == 3)
|
||||||
{
|
{
|
||||||
uchar table[768] = { 0 };
|
uchar table[768] = { 0 };
|
||||||
int hist_bgr[3][256] = { 0 };
|
int hist_bgr[3][256] = { 0 };
|
||||||
int width = image.cols, height = image.rows, bytesPerLine = image.step;
|
int width = image.cols, height = image.rows, bytesPerLine = image.step;
|
||||||
memset(table + threshold * 3, 255, 768 - threshold * 3);
|
memset(table, 255, 768);
|
||||||
|
|
||||||
unsigned char* ptr_data = image.data;
|
unsigned char* ptr_data = image.data;
|
||||||
unsigned char b = 0;
|
unsigned char b = 0;
|
||||||
|
@ -136,7 +133,7 @@ cv::Scalar CImageApplyAutoCrop::getBackGroudColor(const cv::Mat& image, int thre
|
||||||
uchar table[256] = { 0 };
|
uchar table[256] = { 0 };
|
||||||
int hist_bgr[256] = { 0 };
|
int hist_bgr[256] = { 0 };
|
||||||
int width = image.cols, height = image.rows, bytesPerLine = image.step;
|
int width = image.cols, height = image.rows, bytesPerLine = image.step;
|
||||||
memset(table + threshold, 255, 256 - threshold);
|
memset(table, 255, 256);
|
||||||
unsigned char* ptr_data = image.data;
|
unsigned char* ptr_data = image.data;
|
||||||
unsigned char b = 0;
|
unsigned char b = 0;
|
||||||
for (uint i = 0; i < height; i++, ptr_data += bytesPerLine)
|
for (uint i = 0; i < height; i++, ptr_data += bytesPerLine)
|
||||||
|
@ -153,7 +150,7 @@ cv::Scalar CImageApplyAutoCrop::getBackGroudColor(const cv::Mat& image, int thre
|
||||||
}
|
}
|
||||||
|
|
||||||
void CImageApplyAutoCrop::autoCrop_desaskew_fillBlank(cv::Mat& src, cv::Mat& dst, bool isAutoCrop, bool isDesaskew, bool isFillBlank, int dWidth, int dHeight,
|
void CImageApplyAutoCrop::autoCrop_desaskew_fillBlank(cv::Mat& src, cv::Mat& dst, bool isAutoCrop, bool isDesaskew, bool isFillBlank, int dWidth, int dHeight,
|
||||||
bool isConvex, bool isColorBlank, double threshold, int noise, int indent, bool isNormalCrop, bool dispersion, double fx, double fy)
|
bool isConvex, bool isColorBlank, double threshold, int noise, int indent, bool isNormalCrop, double fx, double fy)
|
||||||
{
|
{
|
||||||
if (src.empty()) return;
|
if (src.empty()) return;
|
||||||
|
|
||||||
|
@ -186,7 +183,7 @@ void CImageApplyAutoCrop::autoCrop_desaskew_fillBlank(cv::Mat& src, cv::Mat& dst
|
||||||
hg::threshold_Mat(resizeMat, thre, threshold);
|
hg::threshold_Mat(resizeMat, thre, threshold);
|
||||||
|
|
||||||
if (noise > 0)
|
if (noise > 0)
|
||||||
cv::morphologyEx(thre, thre, cv::MORPH_OPEN, getStructuringElement(cv::MORPH_RECT, cv::Size(noise * FX_FY, 1)),
|
cv::morphologyEx(thre, thre, cv::MORPH_OPEN, getStructuringElement(cv::MORPH_RECT, cv::Size(cv::max(static_cast<int>(noise * FX_FY), 1), 1)),
|
||||||
cv::Point(-1, -1), 1, cv::BORDER_CONSTANT, cv::Scalar::all(0));
|
cv::Point(-1, -1), 1, cv::BORDER_CONSTANT, cv::Scalar::all(0));
|
||||||
|
|
||||||
std::vector<cv::Vec4i> hierarchy;
|
std::vector<cv::Vec4i> hierarchy;
|
||||||
|
@ -213,18 +210,24 @@ void CImageApplyAutoCrop::autoCrop_desaskew_fillBlank(cv::Mat& src, cv::Mat& dst
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::RotatedRect rect = hg::getBoundingRect(maxContour);
|
cv::RotatedRect rect = hg::getBoundingRect(maxContour);
|
||||||
|
if (rect.size.width < 1 || rect.size.height < 1)
|
||||||
if (dispersion)
|
|
||||||
{
|
{
|
||||||
CImageApplyDispersion m_dispersion_apply;
|
dst = src;
|
||||||
cv::Mat mat_dispersion = src(cv::boundingRect(maxContour));
|
return;
|
||||||
m_dispersion_apply.apply(mat_dispersion, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::Scalar blankColor;
|
cv::Scalar blankColor;
|
||||||
if (isFillBlank)
|
if (isFillBlank)
|
||||||
if (isColorBlank)
|
if (isColorBlank)
|
||||||
blankColor = getBackGroudColor(resizeMat, COLOR_BACKGROUND_THRE);
|
{
|
||||||
|
cv::Rect boudingRect = cv::boundingRect(maxContour);
|
||||||
|
boudingRect.x *= FX_FY;
|
||||||
|
boudingRect.y *= FX_FY;
|
||||||
|
boudingRect.width *= FX_FY;
|
||||||
|
boudingRect.height *= FX_FY;
|
||||||
|
|
||||||
|
blankColor = getBackGroudColor(resizeMat(boudingRect));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
blankColor = cv::Scalar::all(255);
|
blankColor = cv::Scalar::all(255);
|
||||||
else
|
else
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
* ====================================================
|
* ====================================================
|
||||||
|
|
||||||
* 功能:自动裁剪、纠偏、除黑底
|
* 功能:自动裁剪、纠偏、除黑底
|
||||||
* 作者:刘丁绿
|
* 作者:刘丁维
|
||||||
* 生成时间_020/4/21
|
* 生成时间:2020/4/21
|
||||||
* 最近修改时间:2020/4/21 v1.0
|
* 最近修改时间:2020/4/21 v1.0
|
||||||
2020/7/22 v1.1 增加获取图像有效区域轮廓的接口maxContour(用于配合一体机的“跳过空白页”算法,PC端暂时无需使用_
|
2020/7/22 v1.1 增加获取图像有效区域轮廓的接口maxContour(用于配合一体机的“跳过空白页”算法,PC端暂时无需使用_
|
||||||
2020/10/16 v1.2 修复自动裁剪尺寸精度丢失的BUG;提高除黑底缩进精度
|
2020/10/16 v1.2 修复自动裁剪尺寸精度丢失的BUG;提高除黑底缩进精度
|
||||||
|
@ -29,7 +29,12 @@
|
||||||
2022/10/31 v1.5 增加横纵DPI缩放参数fx,fy。
|
2022/10/31 v1.5 增加横纵DPI缩放参数fx,fy。
|
||||||
2022/11/19 v1.5.1 修复文稿背景色识别算法的BUG。
|
2022/11/19 v1.5.1 修复文稿背景色识别算法的BUG。
|
||||||
2022/11/19 v1.5.2 修复灰度文稿背景色识别算法的BUG。
|
2022/11/19 v1.5.2 修复灰度文稿背景色识别算法的BUG。
|
||||||
* 版本号:v1.5.2
|
2023/03/17 v1.5.3 修复背景除噪时,形态学处理kSize可能为0的BUG。
|
||||||
|
2023/04/19 v1.5.4 取消集成色散功能。
|
||||||
|
2023/05/15 v1.5.5 优化文稿背景色识别算法。
|
||||||
|
2023/05/23 v1.5.6 修复纯黑图找不到外界轮廓会导致崩溃的BUG。
|
||||||
|
2023/11/02 v1.6 优化抗噪能力。采用自适应背景色二值化。
|
||||||
|
* 版本号:v1.5.6
|
||||||
|
|
||||||
* ====================================================
|
* ====================================================
|
||||||
*/
|
*/
|
||||||
|
@ -39,29 +44,28 @@
|
||||||
|
|
||||||
#include "ImageApply.h"
|
#include "ImageApply.h"
|
||||||
|
|
||||||
class CImageApplyDispersion;
|
|
||||||
class GIMGPROC_LIBRARY_API CImageApplyAutoCrop : public CImageApply
|
class GIMGPROC_LIBRARY_API CImageApplyAutoCrop : public CImageApply
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CImageApplyAutoCrop();
|
CImageApplyAutoCrop();
|
||||||
|
|
||||||
/*
|
/// <summary>
|
||||||
* isCrop [in]:自动幅面裁剪使能,true自动裁剪,false为固定裁剿
|
/// 构造函数
|
||||||
* isDesaskew [in]:自动纠偏使能,true自动纠偏,false为不纠偏
|
/// </summary>
|
||||||
* isFillBlank [in]:黑底填充使能,true为填充,false为不填充
|
/// <param name="isCrop">自动幅面裁剪使能,true自动裁剪,false为固定裁切</param>
|
||||||
* fixedSize [in]:固定幅面尺寸,当isCrop为false时生效,结果尺寸按fixedSize大小输出,单位像紿
|
/// <param name="isDesaskew">自动纠偏使能,true自动纠偏,false为不纠偏</param>
|
||||||
* isConvex [in]:黑底填充时的填充方式,true为凸多边形填充,false为凹多边形填充,默认true
|
/// <param name="isFillBlank">黑底填充使能,true为填充,false为不填充</param>
|
||||||
* isFillColor [in]:黑底填充时采用自适应色彩填充,false为白色填充,true为自适应文稿底色填充,默认false
|
/// <param name="fixedSize">固定幅面尺寸,当isCrop为false时生效,结果尺寸按fixedSize大小输出,单位像素</param>
|
||||||
* threshold [in]:二值化阈值,取值范囿0, 255),默访0
|
/// <param name="isConvex">黑底填充时的填充方式,true为凸多边形填充,false为凹多边形填充,默认true</param>
|
||||||
* noise [in]:除噪像素,能够消除noise宽度的背景竖条纹干扰,默访
|
/// <param name="isFillColor">黑底填充时采用自适应色彩填充,false为白色填充,true为自适应文稿底色填充,默认false</param>
|
||||||
* indent [in]:轮廓缩进,裁剪、纠偏或者黑底填充时,对探索到的纸张轮廓进行缩进indent像素,默访
|
/// <param name="threshold">二值化阈值,取值范囿[-1, 255],默认40。当threshold<0时,采用根据背景自适应二值化。</param>
|
||||||
* normalCrop [in]:为true时,m_isCrop m_isDesaskew m_isFillBlank失效,固定裁切采用最传统的裁切方式,默认false
|
/// <param name="noise">除噪像素,能够消除noise宽度的背景竖条纹干扰,默认8。</param>
|
||||||
* dispersion [in]:为true时,除色散;false时不除色散。默认为true
|
/// <param name="indent">轮廓缩进,裁剪、纠偏或者黑底填充时,对探索到的纸张轮廓进行缩进indent像素,默认8</param>
|
||||||
* fx [in]:横向缩放比例。默认1.0
|
/// <param name="normalCrop">为true时,m_isCrop m_isDesaskew m_isFillBlank失效,固定裁切采用最传统的裁切方式,默认false</param>
|
||||||
* fy [in]:纵向缩放比例。默认1.0
|
/// <param name="fx">横向缩放比例。默认1.0</param>
|
||||||
*/
|
/// <param name="fy">纵向缩放比例。默认1.0</param>
|
||||||
CImageApplyAutoCrop(bool isCrop, bool isDesaskew, bool isFillBlank, const cv::Size& fixedSize, bool isConvex = true,
|
CImageApplyAutoCrop(bool isCrop, bool isDesaskew, bool isFillBlank, const cv::Size& fixedSize, bool isConvex = true,
|
||||||
bool isFillColor = false, double threshold = 40, int noise = 8, int indent = 5, bool normalCrop = false, bool dispersion = true, double fx = 1.0, double fy = 1.0);
|
bool isFillColor = false, double threshold = 40, int noise = 8, int indent = 5, bool normalCrop = false, double fx = 1.0, double fy = 1.0);
|
||||||
|
|
||||||
virtual ~CImageApplyAutoCrop();
|
virtual ~CImageApplyAutoCrop();
|
||||||
|
|
||||||
|
@ -105,23 +109,20 @@ public:
|
||||||
|
|
||||||
void setFixedSize(cv::Size size) { m_fixedSize = size; }
|
void setFixedSize(cv::Size size) { m_fixedSize = size; }
|
||||||
|
|
||||||
void setDispersion(bool enable) { m_isDispersion = enable; }
|
|
||||||
|
|
||||||
static void autoCrop_desaskew_fillBlank(cv::Mat& src, cv::Mat& dst, bool isAutoCrop, bool isDesaskew, bool isFillBlank, int dWidth, int dHeight,
|
static void autoCrop_desaskew_fillBlank(cv::Mat& src, cv::Mat& dst, bool isAutoCrop, bool isDesaskew, bool isFillBlank, int dWidth, int dHeight,
|
||||||
bool isConvex = true, bool isColorBlank = false, double threshold = 40, int noise = 8, int indent = 5, bool isNormalCrop = false, bool dispersion = true,
|
bool isConvex = true, bool isColorBlank = false, double threshold = 40, int noise = 8, int indent = 5, bool isNormalCrop = false,
|
||||||
double fx = 1.0, double fy = 1.0);
|
double fx = 1.0, double fy = 1.0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void myWarpAffine(cv::InputArray _src, cv::OutputArray _dst, cv::InputArray _M0, cv::Size dsize, int flags, int borderType, const cv::Scalar& borderValue);
|
static void myWarpAffine(cv::InputArray _src, cv::OutputArray _dst, cv::InputArray _M0, cv::Size dsize, int flags, int borderType, const cv::Scalar& borderValue);
|
||||||
|
|
||||||
static cv::Scalar getBackGroudColor(const cv::Mat& image, int threshold);
|
static cv::Scalar getBackGroudColor(const cv::Mat& image);
|
||||||
private:
|
private:
|
||||||
bool m_isCrop;
|
bool m_isCrop;
|
||||||
bool m_isDesaskew;
|
bool m_isDesaskew;
|
||||||
bool m_isFillBlank;
|
bool m_isFillBlank;
|
||||||
bool m_isConvexHull;
|
bool m_isConvexHull;
|
||||||
bool m_isFillColor;
|
bool m_isFillColor;
|
||||||
bool m_isDispersion;
|
|
||||||
|
|
||||||
double m_threshold;
|
double m_threshold;
|
||||||
int m_noise;
|
int m_noise;
|
||||||
|
|
|
@ -1,28 +1,5 @@
|
||||||
#include "ImageApplyColorRecognition.h"
|
#include "ImageApplyColorRecognition.h"
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测图像是否是彩色。当前逻辑仅针对红色像素进行判断,即存在红色像素则为彩色,否则为非彩色
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="image">待测图像</param>
|
|
||||||
/// <returns>true为彩色,false为非彩色</returns>
|
|
||||||
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(200, 200), 0, 0, cv::INTER_AREA);
|
|
||||||
|
|
||||||
cv::Mat hsv;
|
|
||||||
cv::cvtColor(pDib_resize, hsv, cv::COLOR_BGR2HSV_FULL);
|
|
||||||
std::vector<cv::Mat> hsv_channels;
|
|
||||||
cv::split(hsv, hsv_channels);
|
|
||||||
|
|
||||||
double minVal, maxVal;
|
|
||||||
cv::minMaxLoc(hsv_channels[1], &minVal, &maxVal);
|
|
||||||
|
|
||||||
return maxVal > threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isGray(const cv::Mat& image)
|
bool isGray(const cv::Mat& image)
|
||||||
{
|
{
|
||||||
//if (image.channels() == 3) return true;
|
//if (image.channels() == 3) return true;
|
||||||
|
@ -62,6 +39,7 @@ CImageApplyColorRecognition::~CImageApplyColorRecognition(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define HSV_S_THRE 30
|
||||||
void CImageApplyColorRecognition::apply(cv::Mat& pDib, int side)
|
void CImageApplyColorRecognition::apply(cv::Mat& pDib, int side)
|
||||||
{
|
{
|
||||||
if (pDib.channels() != 3)
|
if (pDib.channels() != 3)
|
||||||
|
@ -69,7 +47,7 @@ void CImageApplyColorRecognition::apply(cv::Mat& pDib, int side)
|
||||||
m_result = Gray;
|
m_result = Gray;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_result = isColor(pDib) ? Color : Gray;
|
m_result = isColor(pDib, HSV_S_THRE) ? Color : Gray;
|
||||||
if (m_result == Gray && pDib.channels() == 3)
|
if (m_result == Gray && pDib.channels() == 3)
|
||||||
cv::cvtColor(pDib, pDib, cv::COLOR_BGR2GRAY);
|
cv::cvtColor(pDib, pDib, cv::COLOR_BGR2GRAY);
|
||||||
|
|
||||||
|
@ -135,3 +113,26 @@ std::vector<CImageApplyColorRecognition::ColorType> CImageApplyColorRecognition:
|
||||||
{
|
{
|
||||||
return m_results;
|
return m_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检测图像是否是彩色。当前逻辑仅针对红色像素进行判断,即存在红色像素则为彩色,否则为非彩色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image">待测图像</param>
|
||||||
|
/// <returns>true为彩色,false为非彩色</returns>
|
||||||
|
bool CImageApplyColorRecognition::isColor(const cv::Mat& image, double threshold)
|
||||||
|
{
|
||||||
|
if (image.channels() != 3) return false;
|
||||||
|
|
||||||
|
cv::Mat pDib_resize;
|
||||||
|
cv::resize(image, pDib_resize, cv::Size(200, 200), 0, 0, cv::INTER_AREA);
|
||||||
|
//cv::imwrite("pDib_resize.bmp", pDib_resize);
|
||||||
|
cv::Mat hsv;
|
||||||
|
cv::cvtColor(pDib_resize, hsv, cv::COLOR_BGR2HSV_FULL);
|
||||||
|
std::vector<cv::Mat> hsv_channels;
|
||||||
|
cv::split(hsv, hsv_channels);
|
||||||
|
|
||||||
|
double minVal, maxVal;
|
||||||
|
cv::minMaxLoc(hsv_channels[1], &minVal, &maxVal);
|
||||||
|
|
||||||
|
return maxVal > threshold;
|
||||||
|
}
|
||||||
|
|
|
@ -4,13 +4,14 @@
|
||||||
* 功能:色彩识别,将识别会“灰度”的24位图转化为256色8位图, 把识别为“黑白”图转化为二值化的8位图
|
* 功能:色彩识别,将识别会“灰度”的24位图转化为256色8位图, 把识别为“黑白”图转化为二值化的8位图
|
||||||
* 作者:刘丁维
|
* 作者:刘丁维
|
||||||
* 生成时间:2020/7/17
|
* 生成时间:2020/7/17
|
||||||
* 最近修改时间:v1.0 2020/7/17
|
* 最近修改时间:v1.0 2020/7/17
|
||||||
* v1.1 2020/12/15 调整策略,仅判断红色像素,存在红色像素为彩色,否则为灰度;删除输出结果,直接转换图像。
|
* v1.1 2020/12/15 调整策略,仅判断红色像素,存在红色像素为彩色,否则为灰度;删除输出结果,直接转换图像。
|
||||||
* v1.2 2020/12/16 增加颜色限制模式(输出结果只可能两种),增加结果访问接口
|
* v1.2 2020/12/16 增加颜色限制模式(输出结果只可能两种),增加结果访问接口
|
||||||
* v1.3 2021/04/19 修改识别策略,能够识别占比1‰的彩色图像。只区分彩色和灰度图。
|
* v1.3 2021/04/19 修改识别策略,能够识别占比1‰的彩色图像。只区分彩色和灰度图。
|
||||||
* v1.4 2021/06/18 调整二级色彩区间,从原来的[90, 200]调整为[50, 200]。
|
* v1.4 2021/06/18 调整二级色彩区间,从原来的[90, 200]调整为[50, 200]。
|
||||||
* v1.5 2023/11/22 调整彩色判定策略。
|
* v1.5 2023/11/22 调整彩色判定策略。
|
||||||
* 版本号:v1.5
|
* v1.5.1 2023//11/28 调整饱和度判定阈值
|
||||||
|
* 版本号:v1.5.1
|
||||||
* ====================================================
|
* ====================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -60,6 +61,9 @@ public:
|
||||||
/// <returns>色彩类型数组</returns>
|
/// <returns>色彩类型数组</returns>
|
||||||
std::vector<ColorType> getResults();
|
std::vector<ColorType> getResults();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isColor(const cv::Mat& image, double threshold = 30);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ColorType m_result;
|
ColorType m_result;
|
||||||
std::vector<ColorType> m_results;
|
std::vector<ColorType> m_results;
|
||||||
|
|
|
@ -212,7 +212,7 @@ void CImageApplyOutHole::apply(std::vector<cv::Mat>& mats, bool isTwoSide)
|
||||||
for (size_t i = 0; i < hole_contours.size(); i++)
|
for (size_t i = 0; i < hole_contours.size(); i++)
|
||||||
{
|
{
|
||||||
std::vector<std::vector<cv::Point>> contourss_temp;
|
std::vector<std::vector<cv::Point>> contourss_temp;
|
||||||
dilateContour(hole_contours[i], 5);
|
dilateContour(hole_contours[i], m_borderSize / 4);
|
||||||
contourss_temp.push_back(hole_contours[i]);
|
contourss_temp.push_back(hole_contours[i]);
|
||||||
cv::Mat front_temp = mats[0](roi_front);
|
cv::Mat front_temp = mats[0](roi_front);
|
||||||
hg::fillPolys(front_temp, contourss_temp, color);
|
hg::fillPolys(front_temp, contourss_temp, color);
|
||||||
|
|
|
@ -6,28 +6,29 @@
|
||||||
* 生成时间:2020/11/21
|
* 生成时间:2020/11/21
|
||||||
* 最近修改时间:2020/05/12 v1.0
|
* 最近修改时间:2020/05/12 v1.0
|
||||||
* 2020/11/17 v1.1
|
* 2020/11/17 v1.1
|
||||||
* 2021/09/06 v1.2 调整默认二值化阈值,从原来的50调整为100。将填充颜色从局部颜色提取改为全局颜色提取。
|
* 2021/09/06 v1.2 调整默认二值化阈值,从原来的50调整为100。将填充颜色从局部颜色提取改为全局颜色提取。
|
||||||
* 2021/11/03 v1.3 增加逻辑,如果正反面图像尺寸差异超过10个像素,直接返回,不再进行除穿孔处理。
|
* 2021/11/03 v1.3 增加逻辑,如果正反面图像尺寸差异超过10个像素,直接返回,不再进行除穿孔处理。
|
||||||
* 2021/11/04 v1.4 增加背景抗噪机制,能够抗5像素的背景噪声。
|
* 2021/11/04 v1.4 增加背景抗噪机制,能够抗5像素的背景噪声。
|
||||||
* 2021/11/17 v1.5 调整代码格式,避免一些由于opencv版本导致的BUG。
|
* 2021/11/17 v1.5 调整代码格式,避免一些由于opencv版本导致的BUG。
|
||||||
* 2022/04/18 v1.6 修复由于图像超出边界导致的定位孔洞异常的BUG。
|
* 2022/04/18 v1.6 修复由于图像超出边界导致的定位孔洞异常的BUG。
|
||||||
* 2022/05/04 v1.6.1 增加逻辑判断,如果出现黑图,直接返回,不对原图进行任何处理。
|
* 2022/05/04 v1.6.1 增加逻辑判断,如果出现黑图,直接返回,不对原图进行任何处理。
|
||||||
* 2022/07/16 v1.6.2 修复自动识别填充颜色的BUG
|
* 2022/07/16 v1.6.2 修复自动识别填充颜色的BUG
|
||||||
* 2022/07/18 v1.6.3 修复mask的一些逻辑错误
|
* 2022/07/18 v1.6.3 修复mask的一些逻辑错误
|
||||||
* 2022/07/18 v1.7 修复逻辑BUG,替换构造函数borderSize逻辑,由原来面积改为边长,定义穿孔范围为[borderSize, borderSize * 6]
|
* 2022/07/18 v1.7 修复逻辑BUG,替换构造函数borderSize逻辑,由原来面积改为边长,定义穿孔范围为[borderSize, borderSize * 6]
|
||||||
* 2022/07/22 v1.7.1 修复自动识别填充颜色的BUG
|
* 2022/07/22 v1.7.1 修复自动识别填充颜色的BUG
|
||||||
* 2022/08/02 v1.7.2 调整部分默认参数以及参数命名
|
* 2022/08/02 v1.7.2 调整部分默认参数以及参数命名
|
||||||
* 2022/09/07 v1.8 去掉上下左右边缘范围的统一比例,取而代之是分别设置上下左右的边缘比例
|
* 2022/09/07 v1.8 去掉上下左右边缘范围的统一比例,取而代之是分别设置上下左右的边缘比例
|
||||||
* 2022/09/09 v1.8.1 修复边缘定位的精确BUG。
|
* 2022/09/09 v1.8.1 修复边缘定位的精确BUG。
|
||||||
* 2022/09/15 v1.8.2 修复一些逻辑BUG。
|
* 2022/09/15 v1.8.2 修复一些逻辑BUG。
|
||||||
* 2022/09/15 v1.8.3 提高抗背景噪声能力。
|
* 2022/09/15 v1.8.3 提高抗背景噪声能力。
|
||||||
* 2022/09/15 v1.8.4 修复导致崩溃的BUG
|
* 2022/09/15 v1.8.4 修复导致崩溃的BUG
|
||||||
* 2022/09/16 v1.9 优化内存消耗
|
* 2022/09/16 v1.9 优化内存消耗
|
||||||
* 2022/09/16 v1.9.1 修复缩放比例的逻辑错误。
|
* 2022/09/16 v1.9.1 修复缩放比例的逻辑错误。
|
||||||
* 2022/11/17 v1.9.2 修复寻找孔洞轮廓BUG。
|
* 2022/11/17 v1.9.2 修复寻找孔洞轮廓BUG。
|
||||||
* 2023/05/16 v1.9.3 修复提取纸张最大轮廓的逻辑BUG。
|
* 2023/05/16 v1.9.3 修复提取纸张最大轮廓的逻辑BUG。
|
||||||
* 2023/11/18 v1.10 替换形态学膨胀孔洞轮廓,改为特征矩阵膨胀轮廓说
|
* 2023/11/18 v1.10 替换形态学膨胀孔洞轮廓,改为特征矩阵膨胀轮廓说
|
||||||
* 版本号:v1.10
|
* 2023/11/28 v1.10.1 形态学kSize根据borderSize调整
|
||||||
|
* 版本号:v1.10.1
|
||||||
|
|
||||||
* ====================================================
|
* ====================================================
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -737,7 +737,10 @@ int hg_scanner_300::set_kernelsnap_ver()
|
||||||
if (atoi(fw.substr(4, 6).c_str()) >= 221106 && atoi(fw.substr(4, 6).c_str()) < 230210)
|
if (atoi(fw.substr(4, 6).c_str()) >= 221106 && atoi(fw.substr(4, 6).c_str()) < 230210)
|
||||||
firmware_sup_dpi_300 = true;
|
firmware_sup_dpi_300 = true;
|
||||||
else if (atoi(fw.substr(4, 6).c_str()) >= 230210)
|
else if (atoi(fw.substr(4, 6).c_str()) >= 230210)
|
||||||
|
{
|
||||||
|
firmware_sup_dpi_300 = true;
|
||||||
firmware_sup_dpi_600 = true;
|
firmware_sup_dpi_600 = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
firmware_sup_dpi_300 = false;
|
firmware_sup_dpi_300 = false;
|
||||||
|
|
Loading…
Reference in New Issue