twain2/hugaotwainds/AutoCrop.h

44 lines
1.5 KiB
C++

#pragma once
#include "ImageApply.h"
#include "opencv2/opencv.hpp"
#include "opencv/cv.h"
#include "opencv2/core/core.hpp"
using namespace cv;
class CAutoCrop : public CImageApply
{
public:
CAutoCrop( bool bFill = true,bool bautoDeScrew = true,bool bCrop = true,SIZE dstsize = CSize(0, 0),SIZE originsize=CSize(0,0));
virtual ~CAutoCrop();
void apply(cv::Mat& dib,int side);
void setFill(bool val);
bool getFill();
void setCrop(bool val);
bool getCrop();
int m_side;
private:
cv::Point2f RotateP2P(cv::Point2f p, cv::Point2f center, double Angle);
void RotateImage(cv::Mat& image, cv::RotatedRect rotatedRect, bool bCrop = true,bool fillBlack=true);
int ProcessRect(cv::Mat& image, cv::RotatedRect &rotatedRect, std::vector<cv::Point> & maxContour, double scale, double thresh, int blobAreaSize);
void fillBlack(cv:: Mat & dib, std::vector<cv::Point>& contour, int edge = 10);
cv::Mat AutomaticDeskew(cv::Mat image,int thres,float scale);
cv::Mat FixedCut(cv::Mat image,int side);
void MyFillPoly(Mat& img, vector<vector<Point>> contours, const Scalar& color, int lineType=8, int shift=0,
Point offset=Point() );
//void fillrect(InputOutputArray img, InputArrayOfArrays pts,
// const Scalar& color, int lineType, int shift, Point offset);
int range(int low, int up, int value);
void GetContours(const Mat& src, cv::vector<cv::vector<Point>>& contours, cv::vector<Vec4i>& hierarchy, int retr = RETR_CCOMP);
bool m_bCrop;
bool m_bFill;
bool m_bAutoDescrew;
SIZE m_dstSize;
SIZE m_originSize;
};