mirror of http://192.168.1.51:8099/lmh188/twain3.0
112 lines
4.0 KiB
C++
112 lines
4.0 KiB
C++
/*
|
||
* ====================================================
|
||
|
||
* 功能:自动裁剪、纠偏、除黑底
|
||
* 作者:刘丁维
|
||
* 生成时间:2020/4/21
|
||
* 最近修改时间:2020/4/21 v1.0
|
||
2020/7/22 v1.1 增加获取图像有效区域轮廓的接口maxContour(用于配合一体机的“跳过空白页”算法,PC端暂时无需使用)
|
||
2020/10/16 v1.2 修复自动裁剪尺寸精度丢失的BUG;提高除黑底缩进精度。
|
||
2020/10/28 v1.2.1 修复凹凸多边形填充背景的逻辑BUG。
|
||
2020/10/28 v1.2.2 修复图像处理必定会缩小尺寸的BUG。
|
||
2020/10/29 v1.2.3 避免无谓的纠偏(0°纠偏)
|
||
2020/11/30 v1.3.0 增加功能,可识别文稿颜色进行填充黑底。
|
||
* 版本号:v1.3.0
|
||
|
||
* ====================================================
|
||
*/
|
||
|
||
#ifndef IMAGE_APPLY_AUTO_CROP_H
|
||
#define IMAGE_APPLY_AUTO_CROP_H
|
||
|
||
#include "ImageApply.h"
|
||
|
||
class CImageApplyAutoCrop : public CImageApply
|
||
{
|
||
public:
|
||
CImageApplyAutoCrop();
|
||
|
||
|
||
/*
|
||
* isCrop [in]:自动幅面裁剪使能,true自动裁剪,false为固定裁剪
|
||
* isDesaskew [in]:自动纠偏使能,true自动纠偏,false为不纠偏
|
||
* isFillBlank [in]:黑底填充使能,true为填充,false为不填充
|
||
* fixedSize [in]:固定幅面尺寸,当isCrop为false时生效,结果尺寸按fixedSize大小输出,单位像素
|
||
* isConvex [in]:黑底填充时的填充方式,true为凸多边形填充,false为凹多边形填充,默认true
|
||
* isFillColor [in]:黑底填充时采用自适应色彩填充,false为白色填充,true为自适应文稿底色填充,默认false
|
||
* threshold [in]:二值化阈值,取值范围(0, 255),默认40
|
||
* noise [in]:除噪像素,能够消除noise宽度的背景竖条纹干扰,默认2
|
||
* indent [in]:轮廓缩进,裁剪、纠偏或者黑底填充时,对探索到的纸张轮廓进行缩进indent像素,默认5
|
||
* normalCrop [in]:为true且m_isCrop m_isDesaskew m_isFillBlank均为false时生效,固定裁切采用最传统的裁切方式,默认false
|
||
*/
|
||
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);
|
||
|
||
virtual ~CImageApplyAutoCrop();
|
||
|
||
virtual void apply(cv::Mat& pDib, int side);
|
||
|
||
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
|
||
|
||
bool isAutoCrop() { return m_isCrop; }
|
||
|
||
bool isFillBlank() { return m_isFillBlank; }
|
||
|
||
bool isDesaskew() { return m_isDesaskew; }
|
||
|
||
bool isConvexHull() { return m_isConvexHull; }
|
||
|
||
double threshold() { return m_threshold; }
|
||
|
||
const cv::RotatedRect& rotatedROI() { return m_rect; }
|
||
|
||
const std::vector<cv::RotatedRect>& rotatedROIs() { return m_rects; }
|
||
|
||
int noise() { return m_noise; }
|
||
|
||
int indent() { return m_indent; }
|
||
|
||
cv::Size fixedSize() { return m_fixedSize; }
|
||
|
||
const std::vector<cv::Point>& maxContour() { return m_maxContour; }
|
||
|
||
void setAutoCrop(bool enabled) { m_isCrop = enabled; }
|
||
|
||
void setFillBlank(bool enabled) { m_isFillBlank = enabled; }
|
||
|
||
void setDesaskew(bool enabled) { m_isDesaskew = enabled; }
|
||
|
||
void setConvexHull(bool convex) { m_isConvexHull = convex; }
|
||
|
||
void setThreshold(double value) { m_threshold = value; }
|
||
|
||
void setNoise(int value) { m_noise = value; }
|
||
|
||
void setIndent(int value) { m_indent = value; }
|
||
|
||
void setFixedSize(cv::Size size) { m_fixedSize = size; }
|
||
|
||
private:
|
||
cv::Scalar getBackGroudColor(const cv::Mat& image, int total);
|
||
|
||
uchar getBackGroudChannelMean(const cv::Mat& gray, int total);
|
||
|
||
private:
|
||
bool m_isCrop;
|
||
bool m_isDesaskew;
|
||
bool m_isFillBlank;
|
||
bool m_isConvexHull;
|
||
bool m_isFillColor;
|
||
|
||
double m_threshold;
|
||
int m_noise;
|
||
int m_indent;
|
||
bool m_normalCrop; //为true且m_isCrop m_isDesaskew m_isFillBlank均为false时生效,固定裁切采用最传统的裁切方式
|
||
cv::Size m_fixedSize;
|
||
cv::RotatedRect m_rect;
|
||
std::vector<cv::Point> m_maxContour;
|
||
std::vector<cv::RotatedRect> m_rects;
|
||
};
|
||
|
||
#endif // !IMAGE_APPLY_AUTO_CROP_H
|