VCarContainer/engine/SaveMoveImageEngine/SaveMoveImageEngine.cpp

77 lines
1.9 KiB
C++
Raw Normal View History

2024-11-24 00:58:06 +00:00
#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);
2025-07-12 09:40:22 +00:00
if (pSaveImgData->cvImage.empty())
{
LogWarn << "图片异常,跳过";
continue;
}
cv::Mat image = pSaveImgData->cvImage.clone();
2024-11-24 00:58:06 +00:00
//图片绝对路径
if (pSaveImgData->strFilePath.back() != '/')
{
pSaveImgData->strFilePath += "/";
}
std::string strImgFilePath = pSaveImgData->strFilePath + pSaveImgData->strFileName;
if (!FileUtil::getins()->createDirPath(pSaveImgData->strFilePath))
{
LogError << " 创建图片存储目录失败:" << strImgFilePath;
continue;
}
2025-07-12 09:40:22 +00:00
if (cv::imwrite(strImgFilePath, image, this->vecCompressionParams_))
{
}
else
2024-11-24 00:58:06 +00:00
{
2025-07-12 09:40:22 +00:00
LogError << "图片存储失败:" << strImgFilePath;
2024-11-24 00:58:06 +00:00
}
}
return APP_ERR_OK;
}