You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.5 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef REMOVE_BORDER_H
#define REMOVE_BORDER_H
#include <opencv2/opencv.hpp>
#include <string>
#include <vector>
#include "../common.h"
#include "../image_utilities.h"
using namespace std;
/**
* 偏移参数结构体
* 对应Python中的offset元组(tx, ty, ws, hs, ta)
*/
struct Offset {
float tx; // x方向平移
float ty; // y方向平移
float ws; // 宽度缩放
float hs; // 高度缩放
float ta; // 角度调整
Offset(float tx = 0.0f, float ty = 0.0f, float ws = 0.0f, float hs = 0.0f, float ta = 0.0f)
: tx(tx), ty(ty), ws(ws), hs(hs), ta(ta) {}
};
/**
* 根据边框内边缘获取去除边框所用掩膜
*
* args:
* imgshape: 图片宽高信息
* shapeType: 印章形状信息
* filter_border: 边框内边缘
* returns:
* filterMask: 除边框外的印章掩码
*/
cv::Mat get_filterBorderMask(const cv::Size& imgshape, const string& shapeType, const cv::RotatedRect& filter_border);
/**
* 枚举offsets找到最合适的边界
*
* args:
* img: 图
* shapeType: 形状类型
* mrect: 一个最小包围矩形
* offsets: 平移变换组合
* inverse: True以背景点数量最大时为最佳False以前景点数量最大时为最佳
* bg_val: 背景值
* returns:
* best_mrect: 最佳边界,是一个最小包围矩形
*/
cv::RotatedRect _find_bestfit(const cv::Mat& img, const string& shapeType, const cv::RotatedRect& mrect,
const vector<Offset>& offsets, bool inverse = false, int bg_val = 255);
/**
* 获取去除边框所用掩膜
*
* args:
* img: 图
* shapeinfo: 形状信息
* bg_val: 图片背景色
* returns:
* filterMask: 用来去掉边框的掩膜mask
* new_shapeinfo: 新形状信息
* inner_border: 边框内边缘
*/
cv::Mat _getFilterMask(const cv::Mat& img, const ShapeInfo& shapeinfo, cv::RotatedRect& inner_border, int bg_val = 255);
/**
* 去除边框
*
* args:
* img: 图片
* shapeinfo: 形状信息
* bg_val: 图片的背景颜色,默认是白底黑字, 如果是黑底白字的二值图请设置bg_val为0
* returns:
* img1: 去掉边框后的图片
* mask: 去掉边框所用掩膜
* new_shapeinfo: 拟合得更好的形状
* inner_border: 边框内边缘
*/
cv::Mat remove_border(const cv::Mat& img, const ShapeInfo& shapeinfo, cv::Mat& mask, ShapeInfo& new_shapeinfo, cv::RotatedRect& inner_border, int bg_val = 255);
#endif // REMOVE_BORDER_H