2025-02-14 03:43:41 +00:00
|
|
|
|
#include "ContainerDivideEngine.h"
#include <utility>
using namespace ai_matrix;
ContainerDivideEngine::ContainerDivideEngine() {}
ContainerDivideEngine::~ContainerDivideEngine() {}
APP_ERROR ContainerDivideEngine::Init()
{
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1";
this->vecDataSourceConfig_ = Config::getins()->getAllDataSourceConfig();
if (this->vecDataSourceConfig_.size() <= this->engineId_)
{
LogWarn << " -- " << engineName_ << "_" << engineId_ << " dataSource no set, Engine DeInit";
return APP_ERR_OK;
}
this->dataSourceConfig_ = this->vecDataSourceConfig_.at(engineId_);
this->baseConfig_ = Config::getins()->getBaseConfig();
this->identifyConfig_ = Config::getins()->getIdentifyConfig();
this->initParam();
LogInfo << "DetectDivideEngine Init ok";
return APP_ERR_OK;
}
APP_ERROR ContainerDivideEngine::DeInit()
{
LogInfo << "DetectDivideEngine DeInit ok";
return APP_ERR_OK;
}
/**
* 初始化参数信息
* inParam : N/A
* outParam: N/A
* return : N/A
*/
void ContainerDivideEngine::initParam()
{
this->iContainerIndex = 0;
this->pVStep2OutputDataPre_ = nullptr;
this->vecContainerFail_.clear();
}
void ContainerDivideEngine::sendBestData(const VSelectBestData& selectBestData)
{
// 直接发送第一个箱子的箱号
std::shared_ptr<VSelectBestData> pVSelectBestData = std::make_shared<VSelectBestData>();
*pVSelectBestData = selectBestData;
outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pVSelectBestData), true);
LogInfo << " 帧:" << selectBestData.iFrameId
<< " 数据源:" << selectBestData.iDataSource
<< " 节:" << selectBestData.iContainerIndex
<< " 发送识别结果 " << selectBestData.strNumResult;
this->stdContainerResult_ = selectBestData.strNumResult;
this->iContainerIndex++;
}
void ContainerDivideEngine::makeResult(const std::shared_ptr<VStep2OutputData>& pVStep2OutputData,
VSelectBestData & selectBestData) const
{
selectBestData.strDetectDate = pVStep2OutputData->strDetectDate;
selectBestData.strDetectTime = pVStep2OutputData->strDetectTime;
selectBestData.iDataSource = pVStep2OutputData->iDataSource;
selectBestData.iFrameId = pVStep2OutputData->iFrameId;
selectBestData.strNumResult = pVStep2OutputData->step2ResultData.transInfo.strTmpResult;
selectBestData.bIsChkFlag = pVStep2OutputData->step2ResultData.transInfo.bIsChkFlag;
selectBestData.fSumScore = pVStep2OutputData->step2ResultData.fSubScoreSum;
selectBestData.iContainerIndex = this->iContainerIndex;
selectBestData.bHaveTwoContainer = pVStep2OutputData->vecCornerResultData.size() > 2;
}
/**
* 依据像素进行集装箱切分
* @param pVStep2OutputData
*/
void ContainerDivideEngine::divideByPixelInfo(std::shared_ptr<VStep2OutputData> pVStep2OutputData)
{
auto vCompare = [](std::string a, std::string b) {
if (a.size() != b.size()) return 999;
int count = 0;
for (int i = 0; i < a.size(); ++i)
{
if (a[i] != b[i])
{
++count;
}
}
return count;
};
if (!this->pVStep2OutputDataPre_)
{
if (pVStep2OutputData->step2ResultData.fScore == 0.0f) return;
this->pVStep2OutputDataPre_ = pVStep2OutputData;
}
Step2ResultData step2ResultData = pVStep2OutputData->step2ResultData;
Step2ResultData step2ResultData_pre = this->pVStep2OutputDataPre_->step2ResultData;
float fCenterX = (step2ResultData.fRBX + step2ResultData.fLTX)/2;
float fCenterY = (step2ResultData.fRBY + step2ResultData.fLTY)/2;
float fCenterX_Pre = (step2ResultData_pre.fRBX + step2ResultData_pre.fLTX)/2;
float fCenterY_Pre = (step2ResultData_pre.fRBY + step2ResultData_pre.fLTY)/2;
LogDebug << " 帧:" << pVStep2OutputData->iFrameId
<< " 数据源:" << pVStep2OutputData->iDataSource
<< " Y<>
|