|
|
#include "algEg.h"
|
|
|
#include "CaliValve.h"
|
|
|
#include "qtcvutils.h"
|
|
|
using namespace luffy_base;
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
algEg::algEg()
|
|
|
{
|
|
|
luffy_triangle::createNewTrigValue(360);
|
|
|
}
|
|
|
|
|
|
algEg::~algEg()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
bool algEg::Exec(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm)
|
|
|
{
|
|
|
qDebug() << "start cali valve";
|
|
|
//<! detect
|
|
|
CaliValve m_objDetect;
|
|
|
InputParam paramInput;
|
|
|
OutputParam paramOutput;
|
|
|
int nID = lpTask->GetTaskInfo()->nCameraID;
|
|
|
QString strObj = lpTask->GetTaskInfo()->strName;
|
|
|
if (strObj.isEmpty()) {
|
|
|
qWarning() << "cali valve, obj is empty";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
paramInput.roi = lpAlgorithm->GetParamValue("ROI", LP_ROI).value<LP_DETECTOR_ROI_DATA>();
|
|
|
paramInput.barROI = lpAlgorithm->GetParamValue("barROI", LP_ROI).value<LP_DETECTOR_ROI_DATA>();
|
|
|
paramInput.barNum = lpAlgorithm->GetParamValue("barNum", LP_INT).toInt();
|
|
|
paramInput.flagCircle = lpAlgorithm->GetParamValue("flagCircle", LP_INT).toInt();
|
|
|
paramInput.backgroundThresh = lpAlgorithm->GetParamValue("backgroundThresh", LP_INT).toInt();
|
|
|
paramInput.ifClasify = lpAlgorithm->GetParamValue("ifClasify", LP_INT).toInt();
|
|
|
paramInput.ibackground = lpAlgorithm->GetParamValue("ibackground", LP_INT).toInt();
|
|
|
QPointF pt = lpAlgorithm->GetParamValue("center", LP_POINTF).toPointF();
|
|
|
paramInput.ptCenter = Point2f(pt.x(), pt.y());
|
|
|
if (pt.x()==0 || pt.y() == 0) {
|
|
|
qWarning() << "cali valve, center is zero";
|
|
|
}
|
|
|
Mat mask;Mat gray;
|
|
|
if (!lpTask->GetTaskInfo()->detectImg.empty()) {
|
|
|
luffy_imageProc::createImage(lpTask->GetTaskInfo()->detectImg, gray, luffy_imageProc::emCreateGray);
|
|
|
}
|
|
|
// else {
|
|
|
// luffy_imageProc::createImage(paramInput.roi.img, gray, luffy_imageProc::emCreateGray);
|
|
|
// }
|
|
|
|
|
|
if (gray.empty()) {
|
|
|
qWarning() << "cali valve, gray is empty";
|
|
|
return false;
|
|
|
}
|
|
|
if (gray.size() != paramInput.roi.img.size())
|
|
|
{
|
|
|
qWarning() << "img size not compare";
|
|
|
return false;
|
|
|
}
|
|
|
//if (paramInput.ifClasify == 1)
|
|
|
if (paramInput.ibackground == 1)
|
|
|
{
|
|
|
QString str = qApp->applicationDirPath() + QString("\\backGround\\%1.BMP").arg(nID);//imread("E:\\1.BMP");
|
|
|
if (str.isEmpty())
|
|
|
{
|
|
|
qDebug() << "cali valve : cannot background dir ";
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
std::string starName = str.toLocal8Bit().toStdString();
|
|
|
paramOutput.background = imread(starName,0);
|
|
|
}
|
|
|
if (paramOutput.background.empty())
|
|
|
{
|
|
|
qDebug() << "cali valve : background image is empty";
|
|
|
//return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
luffy_imageProc::createImage(gray, mask, luffy_imageProc::emCreateColor);
|
|
|
|
|
|
m_objDetect.detect(gray, paramInput, paramOutput, mask);
|
|
|
QVariant img, barImg, baseImg, weightMat, backgroundImage;
|
|
|
img.setValue(paramOutput.imgTemplate);
|
|
|
barImg.setValue(paramOutput.barTemplate);
|
|
|
baseImg.setValue(paramOutput.baseImage);
|
|
|
weightMat.setValue(paramOutput.weightMat);
|
|
|
backgroundImage.setValue(paramOutput.background);
|
|
|
lpAlgorithm->SetOutParamValue("valveTemplate", img);
|
|
|
lpAlgorithm->SetOutParamValue("image", lp::QtCVUtils::cvMatToQImage(mask));
|
|
|
lpAlgorithm->SetOutParamValue("center", pt);
|
|
|
lpAlgorithm->SetOutParamValue("valveDis", paramOutput.fValveDis);
|
|
|
lpAlgorithm->SetOutParamValue("valveWidth", paramOutput.fValveWidth);
|
|
|
lpAlgorithm->SetOutParamValue("valveOffset", paramOutput.nValveOffset);
|
|
|
lpAlgorithm->SetOutParamValue("barTemplate", barImg);
|
|
|
lpAlgorithm->SetOutParamValue("withinOffset", paramOutput.withinOffset);
|
|
|
lpAlgorithm->SetOutParamValue("barNum", paramInput.barNum);
|
|
|
lpAlgorithm->SetOutParamValue("flagCircle", paramInput.flagCircle);
|
|
|
lpAlgorithm->SetOutParamValue("baseImage", baseImg);
|
|
|
lpAlgorithm->SetOutParamValue("weightMat", weightMat);
|
|
|
lpAlgorithm->SetOutParamValue("backgroundThresh", paramInput.backgroundThresh);
|
|
|
lpAlgorithm->SetOutParamValue("background", backgroundImage);
|
|
|
qDebug() << "finish cali valve";
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool algEg::Init(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm)
|
|
|
{
|
|
|
LP_ALGORITHM_PARAM param1("center", LP_POINTF, QVariant(), QObject::tr("轮毂中心坐标,绑定圆心定位"));
|
|
|
lpAlgorithm->AddParam(¶m1, 1);
|
|
|
LP_ALGORITHM_PARAM param2("ROI", LP_ROI, QVariant(), QObject::tr("气门芯模板"));
|
|
|
lpAlgorithm->AddParam(¶m2, 1);
|
|
|
LP_ALGORITHM_PARAM param3("barROI", LP_ROI, QVariant(), QObject::tr("辐条模板"));
|
|
|
lpAlgorithm->AddParam(¶m3, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param4("flagCircle", LP_INT, 0, QObject::tr("无气门芯识别"));
|
|
|
lpAlgorithm->AddParam(¶m4, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param5("backgroundThresh", LP_INT, 15, QObject::tr("背景剪除阈值"));
|
|
|
lpAlgorithm->AddParam(¶m5, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param6("ifClasify", LP_INT, 0, QObject::tr("型号判定,0关闭,1打开"));
|
|
|
lpAlgorithm->AddParam(¶m6, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param61("ibackground", LP_INT, 0, QObject::tr("背景图启用,0关闭,1打开"));
|
|
|
lpAlgorithm->AddParam(¶m61, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param7("barNum", LP_INT, 0, QObject::tr("辐条数量"));
|
|
|
lpAlgorithm->AddParam(¶m7, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param8("center", LP_POINTF);
|
|
|
lpAlgorithm->AddOutParam(¶m8, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param9("image", LP_IMAGE);
|
|
|
lpAlgorithm->AddOutParam(¶m9, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param10("valveDis", LP_DOUBLE);
|
|
|
lpAlgorithm->AddOutParam(¶m10, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param11("valveWidth", LP_DOUBLE);
|
|
|
lpAlgorithm->AddOutParam(¶m11, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param12("valveOffset", LP_INT);
|
|
|
lpAlgorithm->AddOutParam(¶m12, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param13("valveTemplate", LP_MAT);
|
|
|
lpAlgorithm->AddOutParam(¶m13, 1);
|
|
|
|
|
|
|
|
|
LP_ALGORITHM_PARAM param14("barTemplate", LP_MAT);
|
|
|
lpAlgorithm->AddOutParam(¶m14, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param15("withinOffset", LP_INT);
|
|
|
lpAlgorithm->AddOutParam(¶m15, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param16("barNum", LP_INT);
|
|
|
lpAlgorithm->AddOutParam(¶m16, 1);
|
|
|
|
|
|
LP_ALGORITHM_PARAM param17("flagCircle", LP_INT);
|
|
|
lpAlgorithm->AddOutParam(¶m17, 1);
|
|
|
|
|
|
|
|
|
LP_ALGORITHM_PARAM param18("baseImage", LP_MAT);
|
|
|
lpAlgorithm->AddOutParam(¶m18, 1);
|
|
|
|
|
|
|
|
|
LP_ALGORITHM_PARAM param19("weightMat", LP_MAT);
|
|
|
lpAlgorithm->AddOutParam(¶m19, 1);
|
|
|
|
|
|
|
|
|
LP_ALGORITHM_PARAM param20("backgroundThresh", LP_INT);
|
|
|
lpAlgorithm->AddOutParam(¶m20, 1);
|
|
|
|
|
|
|
|
|
LP_ALGORITHM_PARAM param21("background", LP_MAT);
|
|
|
lpAlgorithm->AddOutParam(¶m21, 1);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
void LpAlgoNewInstance(IAlgo** lppAlgo)
|
|
|
{
|
|
|
*lppAlgo = (IAlgo*)new algEg();
|
|
|
}
|
|
|
|
|
|
bool LpAlgoDeleteInstance()
|
|
|
{
|
|
|
return true;
|
|
|
}
|