a
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include "ColorReader.h"
|
||||
#include "PaperConfig.h"
|
||||
#include "GlobalParams.h"
|
||||
|
||||
class PaperRecognizer {
|
||||
public:
|
||||
PaperRecognizer();
|
||||
~PaperRecognizer();
|
||||
|
||||
// 识别试纸
|
||||
RecognitionResult recognize(const cv::Mat& image);
|
||||
|
||||
// 获取裁剪后的试纸图
|
||||
cv::Mat getPaperImg() const;
|
||||
|
||||
// 读取所有色块颜色
|
||||
std::vector<ColorResult> readAllColorBlocks(const cv::Mat& bgrImage);
|
||||
|
||||
private:
|
||||
// 定位块配对
|
||||
struct LocatorPair {
|
||||
bool isValid;
|
||||
LocatorInfo* big;
|
||||
LocatorInfo* small;
|
||||
LocatorPair() : isValid(false), big(nullptr), small(nullptr) {}
|
||||
};
|
||||
|
||||
void preprocessImage(const cv::Mat& image);
|
||||
bool detectLocators();
|
||||
void findCandidateContours(std::vector<std::vector<cv::Point>>& contours);
|
||||
bool filterLocatorCandidates(const std::vector<std::vector<cv::Point>>& contours);
|
||||
std::vector<std::vector<LocatorInfo*>> groupCandidatesByY(std::vector<LocatorInfo>& candidates);
|
||||
LocatorPair findValidLocatorPairInGroup(std::vector<LocatorInfo*>& group);
|
||||
bool validateLocatorPair();
|
||||
double calculateAspectRatio(const cv::RotatedRect& rect);
|
||||
bool isPotentialLocator(const cv::RotatedRect& rect, double area, double& aspectRatio);
|
||||
void sortLocatorsByPosition();
|
||||
BigLocatorType determineBigLocatorType(double areaRatio);
|
||||
bool matchPaperSpec();
|
||||
void calculateColorBlockCenters();
|
||||
BlurLevel assessLocatorBlur(const cv::Mat& gray, const cv::RotatedRect& locator, double& score);
|
||||
void drawAnnotations();
|
||||
void savePaperImg();
|
||||
LocatorColor determineLocatorColor(const cv::Rect& roi);
|
||||
LocatorColor determineLocatorColorByCenter(const cv::RotatedRect& rotatedRect);
|
||||
cv::Scalar getCenterRegionColor(const cv::RotatedRect& rotatedRect);
|
||||
cv::Scalar getAverageColor(const cv::Rect& roi);
|
||||
double measureSaturation(const cv::Mat& hsvRoi);
|
||||
double calculateColorDistance(const cv::Scalar& c1, const cv::Scalar& c2);
|
||||
|
||||
cv::Mat originalImage_; // 原图
|
||||
cv::Mat processImage_; // 处理用图像
|
||||
cv::Mat hsvImage_; // HSV图像
|
||||
cv::Mat grayImage_; // 灰度图像
|
||||
cv::Mat paperImg_; // 裁剪后的试纸图片(RGBA格式)
|
||||
|
||||
bool hasLocator1_;
|
||||
bool hasLocator2_;
|
||||
LocatorInfo locator1_;
|
||||
LocatorInfo locator2_;
|
||||
LocatorInfo* bigLocator_;
|
||||
LocatorInfo* smallLocator_;
|
||||
|
||||
std::vector<cv::Point2f> centers_;
|
||||
RecognitionResult result_;
|
||||
const PaperConfig* config_;
|
||||
ColorReader colorReader_;
|
||||
|
||||
size_t candidateCount_;
|
||||
};
|
||||
Reference in New Issue
Block a user