VCarContainer/engine/SaveMoveImageEngine/SaveMoveImageEngine.cpp

78 lines
2.2 KiB
C++

#include "SaveMoveImageEngine.h"
using namespace ai_matrix;
SaveMoveImageEngine::SaveMoveImageEngine() {}
SaveMoveImageEngine::~SaveMoveImageEngine() {}
APP_ERROR SaveMoveImageEngine::Init()
{
strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0";
this->baseConfig_ = Config::getins()->getBaseConfig();
vecCompressionParams_.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg
vecCompressionParams_.push_back(this->iPicQuality_); //图片质量
LogInfo << "SaveMoveImageEngine Init ok";
return APP_ERR_OK;
}
APP_ERROR SaveMoveImageEngine::DeInit()
{
LogInfo << "SaveMoveImageEngine DeInit ok";
return APP_ERR_OK;
}
APP_ERROR SaveMoveImageEngine::Process()
{
int iRet = APP_ERR_OK;
while (!isStop_)
{
std::shared_ptr<void> pvoidd = nullptr;
inputQueMap_[strPort0_]->pop(pvoidd);
if (nullptr == pvoidd)
{
usleep(1000);
continue;
}
std::shared_ptr<SaveImgData> pSaveImgData = std::static_pointer_cast<SaveImgData>(pvoidd);
//图片绝对路径
if (pSaveImgData->strFilePath.back() != '/')
{
pSaveImgData->strFilePath += "/";
}
std::string strImgFilePath = pSaveImgData->strFilePath + pSaveImgData->strFileName;
if (!FileUtil::getins()->createDirPath(pSaveImgData->strFilePath))
{
LogError << " 创建图片存储目录失败:" << strImgFilePath;
continue;
}
if (!pSaveImgData->cvImage.empty())
{
if (cv::imwrite(strImgFilePath, pSaveImgData->cvImage, this->vecCompressionParams_))
{
// std::shared_ptr<VToStep1Data> pToStep1Data = std::make_shared<VToStep1Data>();
// pToStep1Data->bIsEnd = pSaveImgData->bIsEnd;
// pToStep1Data->strImagePath = pSaveImgData->strFilePath;
// pToStep1Data->strImageName = pSaveImgData->strFileName;
//
// outputQueMap_[strPort0_]->push(std::static_pointer_cast<void>(pToStep1Data), true);
}
else
{
LogError << "图片存储失败:" << strImgFilePath;
}
}
}
return APP_ERR_OK;
}