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.

146 lines
3.3 KiB
C

#ifndef LP_VALVE_DETECTOR_H
#define LP_VALVE_DETECTOR_H
#include "Luffy.h"
#include "lpbengine.h"
#define ALG_RESIZE_IMAGE_WIDTH 416.0
//#define VEIW_HISTGRAM
using namespace luffy_base;
struct InputParam
{
QString strObj;
Mat imgTemplate; //<2F><><EFBFBD><EFBFBD>оģ<D0BE><C4A3>
int nValveOffset;
float fValveWidth;
float fValveDis;
Point2f ptCenter;
double dScoreThres;
int nMaxAngle;
int nCenterAlg; // <20><><EFBFBD><EFBFBD>У׼<D0A3>
int nBarScore;
Mat barTemplate; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//int bgThresh;
int withinOffset;
int barNum; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Mat centerRoi;
int flagCircle;
Mat baseImage; //<2F><><EFBFBD><EFBFBD>о<EFBFBD>ͺ<EFBFBD>ȷ<EFBFBD><C8B7>ģ<EFBFBD><C4A3>ͼ
int backgroundThresh; // <20><>ͼ<EFBFBD><CDBC>ֵ
int modelMatchScore; //ģ<><C4A3>ƥ<EFBFBD><C6A5>ֵ
LP_DETECTOR_ROI_DATA roi;
cv::Mat backGround;
Point2f originalPoint;
Mat weightMat;
double cMatchScore;
int wheelType;
};
struct OutputParam
{
double dTime;
double dAngle;
double dAngleRes;
double dScore;
int nErrorType;
bool bIsFind;
QString strResultTip;
Point2f rstPoint;
int flag;
double showMatchScore;
};
class ValveDetector
{
public:
ValveDetector();
~ValveDetector();
bool detect(Mat & imgSrc, InputParam &paramIn, OutputParam &paramOut, Mat &imgDst = Mat());
void drawResult(Mat &img, InputParam &paramIn, OutputParam &paramOut);
Point2f getCenter(Mat & imgSrc, Point2f pt, InputParam &paramIn);
double ruleData(double, int);
QString genResultTip(QString str, int nType);
Point2f getCenterPoints(Mat &_img, const Mat &centerTempl, InputParam paramIn, Point2f pt, Mat& rstMat);
bool saveResult(Mat &img, InputParam &paramIn, OutputParam &paramOut, QString modelStr);
bool isValid(Mat target, Mat templ, Point2f pt, int validThresh);
void drawToImage(Mat &img, InputParam &paramIn, OutputParam &paramOut);
cv::Mat findCircleObject(const Mat &src, const Mat& backgroundImg, int nThres = 20, luffy_base::luffyCircle *pCircle = NULL);
cv::Mat getForeImage(const Mat & src, const Mat &backgroundImg);
};
/*class RotateData
{
public:
RotateData() {};
RotateData(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<Mat> mRImgVec;
vector<float> mDisValVec;
float mStartAngle, mEndAngle;
};
class ImageCompareModelInvoker : public cv::ParallelLoopBody
{
public:
ImageCompareModelInvoker(Mat &templ, void* pData)
: m_pData(pData), temp(templ)
{}
private:
void *m_pData;
Mat temp;
virtual void operator() (const cv::Range& range) const;
};*/
#endif //LP_VALVE_DETECTOR_H