#pragma once #include #include #include #include #include "ContourSelector.h" using namespace std; using namespace cv; class PaperConfig { public: PaperConfig(); PaperConfig(int pst,int i, int s, double f, double st, double d, double r, double l); virtual ~PaperConfig(); public: int itemsNum; int paperSpatialType; int slicesNum; double firstPos; //real first postion == firstPos * avg slice's width double step; double distTimes;//(distance of 2 center points ) % ( height of paper) such as 21.2 (106.5 % 5 ) double whRRatio;//big locator : 2 / 3 double whLRatio;//small locator : 0.6 void Init(); }; class ImgLocateDryChemistry { public: ImgLocateDryChemistry(); ~ImgLocateDryChemistry(); private: enum BlockItems{ BI_14 = 14, BI_13 = 13, BI_12 = 12, BI_11 = 11, BI_10 = 10, BI_9 = 9, BI_8 = 8, BI_7 = 7, BI_6 = 6, BI_5 = 5, BI_4 = 4, }; enum BigLocatorType{ BLT_SHORT = 0,//10mm BLT_LONG = 1,//15mm }; //locator color: Red, Green, Blue enum LocatorColorClassification{ LCC_UNKNOWN = 0, LCC_RED = 1, LCC_GREEN = 2, LCC_BLUE = 3, }; enum PaperSpatialType{ PST_UNKNOWN = 0, PST_14_S = 1, // ON PST_14_L = 2, // ON PST_13_S = 3, PST_13_L = 4, PST_12_S = 5, // ON PST_12_L = 6, PST_11_S = 7, PST_11_L = 8, // ON PST_10_S = 9, // ON PST_10_L = 10, PST_9_S = 11, PST_9_L = 12, // ON PST_8_S = 13, // ON PST_8_L = 14, PST_7_S = 15, PST_7_L = 16, // ON PST_6_S = 17, // ON PST_6_L = 18, PST_5_S = 19, PST_5_L = 20, // ON PST_4_S = 21, // ON PST_4_L = 22, }; Mat src; /*保存原始图片 */ Mat roiSrc; /*由SRC裁剪而来,大小ROI */ Mat hsv; /*由rgb convert而来 */ Mat rgb; /*由roiSrc convert而来 */ Mat paperImg; /*定位出的进一步 裁剪后的图片 */ int recode; /* */ int score; /* */ int locatorColor; /*定位块颜色类型 1: green 2:red 3:blue */ int paperItems; int paperSpatialType;/*试纸类型*/ // int expectedPaperType; /* */ double avgDist; /* */ double totalDist; /* */ double distTimes; /* */ bool bRot; /* */ double topDefinitionValue;/* */ ContourSelector cs; /* 轮廓选择器 */ ContourSelector::VectorPT vecPt; /* */ ContourSelector::PairTExtend lRectContour; /* 左定位块外包轮廓 */ ContourSelector::PairTExtend rRectContour; /* */ cv::RotatedRect lRotRect; /* 左定位块 旋转矩形 */ cv::RotatedRect rRotRect; /* */ int lRotRectWidth; /* */ int rRotRectWidth; /* */ int lRotRectHeight; /* */ int rRotRectHeight; /* */ int paperHeight; /* */ map mapPaperConfig; PaperConfig* paperConfig; public: Mat& GetPosition(Mat& s, cv::Rect& roi, bool bDraw, cv::Scalar& wbAvgRgb, vector&roiPositions); int GetLastError() { return recode; } Mat& GetPaperImg() { return paperImg; } int GetLocatorColor() { return locatorColor; } int GetLocatorType(); int GetPaperItems(); double GetDefinition() { return topDefinitionValue; } int GetPaperHeight() { return paperHeight; } int GetScore() { return score; } private: int analyseLocatorColor(Mat& sImg, double& slope); bool analyseDefinition(Mat& sImg , cv::Rect& roi); Mat& warpAffineImg(Mat &img); // bool verifyDistance(); int verifyPaperConfig(double distRadio,double areaRadio); void initPaperConfig(); void savePaperImg(); bool calGrayImgDefinition(Mat &img,double m,int u); double calImgDefinition(Mat &img, double &diff, double &avg, int &lowLines, int &upLines); int readLocatorColor(ContourGfExtend* pContourGfE);//0: green 1:red 2:blue -1:other void releaseContoursGf(ContourSelector::VectorPT& vectorPt, int code = 0); int processImage(Mat& sImg, Mat& b, Mat&v, cv::Rect& roi, bool useSThres, bool bDraw, cv::Scalar& wbAvgRgb, vector&roiPositions); };