generated from zhangwei/Matrixai
114 lines
4.4 KiB
C++
114 lines
4.4 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->frameData.pData != nullptr && pSaveImgData->frameData.iSize != 0)
|
|
{
|
|
cv::Mat image(pSaveImgData->frameData.iHeight, pSaveImgData->frameData.iWidth, CV_8UC3, static_cast<uint8_t *>(pSaveImgData->frameData.pData.get())); //RGB
|
|
|
|
// cv::cvtColor(image, image, cv::COLOR_RGB2BGR);
|
|
|
|
// if (this->baseConfig_.bTestModel)
|
|
// {
|
|
// std::stringstream ss;
|
|
// std::string strTitle;
|
|
// ss << pSaveImgData->strTrainStage << " "
|
|
// << pSaveImgData->strDirection << " "
|
|
// << pSaveImgData->strTrainStatus;
|
|
// ss >> strTitle;
|
|
//
|
|
// cv::putText(image,
|
|
// strTitle,
|
|
// cv::Point(15, 45),
|
|
// cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0, 255), 2);
|
|
// for (int i = 0; i < pSaveImgData->vecCoordinate.size(); ++i)
|
|
// {
|
|
// float centerX = pSaveImgData->vecCoordinate.at(i).fLTX + (pSaveImgData->vecCoordinate.at(i).fRBX - pSaveImgData->vecCoordinate.at(i).fLTX)/2;
|
|
// float centerY = pSaveImgData->vecCoordinate.at(i).fLTY + (pSaveImgData->vecCoordinate.at(i).fRBY - pSaveImgData->vecCoordinate.at(i).fLTY)/2;
|
|
//
|
|
// cv::rectangle(image,
|
|
// cv::Point(pSaveImgData->vecCoordinate.at(i).fLTX, pSaveImgData->vecCoordinate.at(i).fLTY),
|
|
// cv::Point(pSaveImgData->vecCoordinate.at(i).fRBX, pSaveImgData->vecCoordinate.at(i).fRBY),
|
|
// cv::Scalar(0, 255, 0, 200), 2);
|
|
// cv::line(image,
|
|
// cv::Point(centerX, centerY-10), cv::Point(centerX, centerY+10),
|
|
// cv::Scalar(0, 255, 0, 100), 3);
|
|
// cv::putText(image,
|
|
// pSaveImgData->vecCoordinate.at(i).strClassName,
|
|
// cv::Point(pSaveImgData->vecCoordinate.at(i).fLTX+10, pSaveImgData->vecCoordinate.at(i).fLTY+10),
|
|
// cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0, 180), 2);
|
|
// }
|
|
// }
|
|
|
|
if (cv::imwrite(strImgFilePath, image, 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;
|
|
}
|