#pragma once #include "Luffy.h" #include "lpbengine.h" using namespace cv; class RData { public: RData() {}; RData(const Mat &img, Point pt, double dAngleStep, int size) : mImgSrc(img) , mStartAngle(0) , mEndAngle(360) { init(img, pt, dAngleStep, size); }; void init(const Mat& img, Point pt, double dAngleStep, int size) { mImgSrc = img; mStartAngle = 0; mEndAngle = 360.0; mRImgVec.clear(); mRImgVec.resize(size); mDisValVec.clear(); mDisValVec.resize(size, FLT_MAX); mCenter = pt; mAngleStep = dAngleStep; } double angle(int index) { return index*mAngleStep + mStartAngle; } double bestAngle() { if (mDisValVec.empty()) { return -DBL_MAX; } size_t bestIndex = min_element(mDisValVec.begin(), mDisValVec.end()) - mDisValVec.begin(); double bestAngle = angle(bestIndex); return bestAngle; } Mat bestRImg() { if (mRImgVec.empty()) { return Mat(); } size_t bestIndex = min_element(mDisValVec.begin(), mDisValVec.end()) - mDisValVec.begin(); return mRImgVec[bestIndex]; } double mAngleStep; Mat mImgSrc; Point mCenter; vector mRImgVec; vector mDisValVec; float mStartAngle, mEndAngle; }; class modelVerfication { public: modelVerfication(double tarStddevVal, double tarMeanVal); ~modelVerfication(); Mat extractForegroundWheel(const Mat& background, const Mat& src); Mat findWheelObject(Mat src, Mat backGroundImg, int thresh); void rotateMatchData(const Mat& _img, const Mat &baseImage, RData* pData, float angleStep, float startAngle, float endAngle); void parallelDetect(int index, void *p, Mat templ); void preProcessImage(Mat& img, const Mat& mask, double dstMean, double dstStddev, int highlightsThreshold); Mat genMask(const Mat& img, Point2f center, float innerR = -1, float outterR = -1, int type = CV_32FC1); cv::Mat cocentricNorm(Mat& img, Point2f center, const Mat& weightMat, float dstMeanVal); float interpolate(float* pY, int n, float stepX, float x); bool objectVerification(const Mat &img, Mat& baseImage, double modelValidThresh, int endAngle, double & s); void setWeightMat(const Mat& img) { weightMat = img; weightMat.convertTo(weightMat, CV_32FC1); } static int h; private: Mat weightMat; Mat m32fMaskImg; double tarStddev; double tarMean; }; class ImageCompareModel2 : public cv::ParallelLoopBody { public: ImageCompareModel2(modelVerfication *m, void* pData, Mat T) : m_pData(pData), model(m), templ(T) {} private: void *m_pData; modelVerfication* model; Mat templ; virtual void operator() (const cv::Range& range) const; };