code_device/hgdriver/ImageProcess/ImageApplyMarkCrop.h

116 lines
4.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* ====================================================
* 功能Mark点定位裁剪。识别试卷中的mark点进行纠偏裁剪。该功能不能完全独立使用因为可能会识别失败然后需要继续用传统裁剪纠偏进行补充。
* 作者:刘丁维
* 生成时间2020/5/22
* 最近修改时间2020/5/22 v1.0
2020/7/29 v1.1 优化Mark点识别以及文稿方向判定
2020/7/30 v1.1.1 优化Mark点识别以及文稿方向判定
2020/8/3 v1.2 针对七天添加三Mark点识别文稿方向原来的方式定义为多边识别文稿方向
2020/8/12 v1.3 针对七天,添加了条码判断算法,用于判定试卷是否为指定试卷。该条码只是粗略识别是否是条码,而不进行准确识别。
apply接口增加barCode参数用于是否开启粗判断条码功能
2020/8/12 v1.4 针对七天,添加裁剪接口,可进行裁剪与不裁剪两种选择
* 版本号v1.4
* ====================================================
*/
#ifndef IMAGEMARKCROPAPPLY_H
#define IMAGEMARKCROPAPPLY_H
#include "ImageApply.h"
class GIMGPROC_LIBRARY_API CImageApplyMarkCrop
{
public:
//识别文稿方向方式
enum DirectionMethod
{
Trilateral_7Net, //三边定位文稿方向(针对七天需求)
Multilateral //多边定位文稿方向
};
enum DPI : ushort
{
DPI_200 = 200,
DPI_300 = 300
};
enum DeviceModel
{
G400 = 2,
G300 = 3
};
enum Orientation
{
Default = 0,
Left_RT, //多边文稿方向识别时靠左为正7天3mark识别时缺角在右上为正
Top_RB, //多边文稿方向识别时靠上为正7天3mark识别时缺角在右下为正
Right_LB, //多边文稿方向识别时靠右为正7天3mark识别时缺角在左下为正
Bottom_LT //多边文稿方向识别时靠下为正7天3mark识别时缺角在左上为正
};
public:
CImageApplyMarkCrop(DeviceModel device, bool isCropped = true, double threshold = 20, int noise = 40, DPI dpi = DPI::DPI_200, DirectionMethod direction = DirectionMethod::Multilateral);
/*
* src [in]: 原图
* dst [out]:处理成功时,返回的结果图像
* markOri [in]: 文稿方向判定方式
* barCode [in]: 是否判断条形码该功能只针对Trilateral_7Net模式
* angle [out]:返回文稿方向偏转角度。有0、90、180、270四种情况
* 返回值: 0成功
-1原图为空或者无法找到图片轮廓纯黑图会报该错误
-2mark小于3个
-3选择Multilateral模式时mark点小于4个
-4识别条形码时目标图像过小无法包含条形码
-5无条形码
*/
int apply(const cv::Mat& src, cv::Mat& dst, Orientation markOri, bool barCode, int& angle);
inline DeviceModel getDeviceModel() { return m_device; }
inline void setDeviceModel(DeviceModel device) { m_device = device; }
inline bool isCropped() { return m_b_isCropped; }
inline void setCropped(bool cropped) { m_b_isCropped = cropped; }
inline double getThreshold() { return m_threshold; }
inline void setThreshold(double threshold) { m_threshold = threshold; }
inline int getNoise() { return m_noise; }
inline void setNoise(int noise) { m_noise = noise; }
inline DPI getDPI() { return m_dpi; }
inline void setDPI(DPI dpi) { m_dpi = dpi; }
inline const cv::Range getSizeRange() { return m_range; }
inline void setSizeRange(const cv::Range& range) { m_range = range; }
inline void setSizeRange(int low, int up) { m_range = cv::Range(low, up); }
private:
void findMarks(const std::vector<std::vector<cv::Point>>& contours, const cv::RotatedRect& region, const cv::Range& range,
std::vector<std::vector<cv::Point>>& marks, std::vector<cv::RotatedRect>& rrect);
bool isContainBarCode(const cv::Mat& image);
private:
DeviceModel m_device;
bool m_b_isCropped;
double m_threshold;
int m_noise;
DPI m_dpi;
cv::Range m_range;
DirectionMethod m_direction;
};
#endif // IMAGEMARKCROPAPPLY_H