增加侧边右向行车摄像头使用箱角进行切分

This commit is contained in:
Mr.V 2024-11-27 20:38:06 +08:00
parent a582dfb23b
commit bdaaf2eca4
11 changed files with 76 additions and 69 deletions

View File

@ -56,6 +56,7 @@ namespace ai_matrix
dataSourceConfig.iSkipInterval = it["skip_interval"].as<int>(); dataSourceConfig.iSkipInterval = it["skip_interval"].as<int>();
dataSourceConfig.vecIdentifyAreas = it["identify_areas"].as<std::vector<int>>(); dataSourceConfig.vecIdentifyAreas = it["identify_areas"].as<std::vector<int>>();
dataSourceConfig.strDivideModel = it["divide_mode"].as<std::string>(); dataSourceConfig.strDivideModel = it["divide_mode"].as<std::string>();
dataSourceConfig.strRunDirection = it["run_direction"].as<std::string>();
this->vecDataSourceConfig_.emplace_back(dataSourceConfig); this->vecDataSourceConfig_.emplace_back(dataSourceConfig);
} }

View File

@ -64,6 +64,8 @@ namespace ai_matrix
std::vector<int> vecIdentifyAreas; std::vector<int> vecIdentifyAreas;
// 切箱方式 // 切箱方式
std::string strDivideModel; std::string strDivideModel;
// 汽车行进方向
std::string strRunDirection;
}; };
// 识别参数 // 识别参数

View File

@ -137,8 +137,8 @@ using namespace nvcaffeparser1;
#define STEP1_CLASS_NUM 19 //step1 7分类 #define STEP1_CLASS_NUM 19 //step1 7分类
#define STEP1_CLEAR_NUM 21 //step1 21个清晰度 #define STEP1_CLEAR_NUM 21 //step1 21个清晰度
#define STEP1_INPUT_H 960 //step1 输入图像高 #define STEP1_INPUT_H 640 //step1 输入图像高
#define STEP1_INPUT_W 960 //step1 输入图像宽 #define STEP1_INPUT_W 640 //step1 输入图像宽
#define STEP1_BATCH_SIZE 1 #define STEP1_BATCH_SIZE 1
#define STEP1_OUTPUT_HISTOGRAM_N 5 //不能超过139167 #define STEP1_OUTPUT_HISTOGRAM_N 5 //不能超过139167

View File

@ -330,6 +330,8 @@ typedef struct
Step2ResultData step2ResultData; Step2ResultData step2ResultData;
// 箱角大框 // 箱角大框
std::vector<Step2ResultData> vecCornerResultData; std::vector<Step2ResultData> vecCornerResultData;
// 图片
cv::Mat cvImage;
// 是否最后一节 // 是否最后一节
bool bIsEnd = false; bool bIsEnd = false;
} VStep2OutputData; } VStep2OutputData;

View File

@ -32,6 +32,8 @@ data_source:
identify_areas: [120, 0, 1800, 1080] identify_areas: [120, 0, 1800, 1080]
# 切箱方式 # 切箱方式
divide_mode: "corner" #[corner, pixel] divide_mode: "corner" #[corner, pixel]
# 汽车行进方向
run_direction: "down" #[up, down, left, right]
- # 侧部摄像头 - # 侧部摄像头
url: "./videos/buertai2.mp4" url: "./videos/buertai2.mp4"
# 跳帧数 # 跳帧数
@ -40,6 +42,8 @@ data_source:
identify_areas: [ 120, 0, 1800, 1080 ] identify_areas: [ 120, 0, 1800, 1080 ]
# 切箱方式 # 切箱方式
divide_mode: "pixel" #[corner, pixel] divide_mode: "pixel" #[corner, pixel]
# 汽车行进方向
run_direction: "right" #[up, down, left, right]
- # 侧边摄像头 - # 侧边摄像头
url: "./videos/buertai2.mp4" url: "./videos/buertai2.mp4"
# 跳帧数 # 跳帧数
@ -48,6 +52,8 @@ data_source:
identify_areas: [ 120, 0, 1800, 1080 ] identify_areas: [ 120, 0, 1800, 1080 ]
# 切箱方式 # 切箱方式
divide_mode: "pixel" #[corner, pixel] divide_mode: "pixel" #[corner, pixel]
# 汽车行进方向
run_direction: "left" #[up, down, left, right]
# 识别参数 # 识别参数
identify: identify:

View File

@ -245,12 +245,12 @@ APP_ERROR ControlEngine::Process()
outputQueMap_[strPort3_]->push(std::static_pointer_cast<void>(pVDetectInfo), true); outputQueMap_[strPort3_]->push(std::static_pointer_cast<void>(pVDetectInfo), true);
// 存图 // 存图
std::shared_ptr<SaveImgData> pSaveImgData = std::make_shared<SaveImgData>(); // std::shared_ptr<SaveImgData> pSaveImgData = std::make_shared<SaveImgData>();
pSaveImgData->strFilePath = strFilePath; // pSaveImgData->strFilePath = strFilePath;
pSaveImgData->strFileName = std::to_string(this->mapDetectNO_[pProcessData->iDataSource]) + "_" + std::to_string(pProcessData->iDataSource) + ".jpg"; // pSaveImgData->strFileName = std::to_string(this->mapDetectNO_[pProcessData->iDataSource]) + "_" + std::to_string(pProcessData->iDataSource) + ".jpg";
pSaveImgData->cvImage = image; // pSaveImgData->cvImage = image;
pSaveImgData->bIsEnd = pProcessData->bIsEnd; // pSaveImgData->bIsEnd = pProcessData->bIsEnd;
outputQueMap_[strPort4_]->push(std::static_pointer_cast<void>(pSaveImgData), true); // outputQueMap_[strPort4_]->push(std::static_pointer_cast<void>(pSaveImgData), true);
this->mapDetectNO_[pProcessData->iDataSource]++; this->mapDetectNO_[pProcessData->iDataSource]++;
} }

File diff suppressed because one or more lines are too long

View File

@ -25,7 +25,7 @@ private:
void divideInfo(std::shared_ptr<VStep2OutputData> pVStep2OutputData); void divideInfo(std::shared_ptr<VStep2OutputData> pVStep2OutputData);
void divideByPixelInfo(std::shared_ptr<VStep2OutputData> pVStep2OutputData); void divideByPixelInfo(std::shared_ptr<VStep2OutputData> pVStep2OutputData);
void divideByCornerInfo(std::shared_ptr<VStep2OutputData> pVStep2OutputData); void divideByCornerInfo(std::shared_ptr<VStep2OutputData> pVStep2OutputData);
void setectBestByCorner(); bool setectBestByCorner();
void sendBestData(const VSelectBestData& selectBestData); void sendBestData(const VSelectBestData& selectBestData);
void makeResult(const std::shared_ptr<VStep2OutputData>& pVStep2OutputData, void makeResult(const std::shared_ptr<VStep2OutputData>& pVStep2OutputData,
VSelectBestData & selectBestData) const; VSelectBestData & selectBestData) const;

View File

@ -42,16 +42,8 @@ APP_ERROR SaveDebugImageEngine::Process()
continue; continue;
} }
if (!this->baseConfig_.bTestModel)
{
usleep(1000);
continue;
}
std::shared_ptr<VStep2OutputData> pVStep2OutputData = std::static_pointer_cast<VStep2OutputData>(pvoidd); std::shared_ptr<VStep2OutputData> pVStep2OutputData = std::static_pointer_cast<VStep2OutputData>(pvoidd);
std::string strDataDir = this->baseConfig_.strDebugResultPath + "/" std::string strDataDir = this->baseConfig_.strDebugResultPath + "/"
+ pVStep2OutputData->strDetectDate + "/" + pVStep2OutputData->strDetectDate + "/"
+ StringUtil::getins()->replace_all_distinct(pVStep2OutputData->strDetectTime, ":", "-") + StringUtil::getins()->replace_all_distinct(pVStep2OutputData->strDetectTime, ":", "-")
@ -72,70 +64,74 @@ APP_ERROR SaveDebugImageEngine::Process()
continue; continue;
} }
cv::Mat image = cv::imread(strImagePath); // cv::Mat image = cv::imread(strImagePath);
if (image.empty()) if (pVStep2OutputData->cvImage.empty())
{ {
LogWarn << "图像未找到:" << strImagePath; LogWarn << " 帧:" << pVStep2OutputData->iFrameId << " 数据源:" << pVStep2OutputData->iDataSource << " debug图像未找到";
continue; continue;
} }
std::stringstream ss; if (this->baseConfig_.bTestModel)
std::vector<std::string> vecTitle;
vecTitle.emplace_back("FrameID:" + to_string(pVStep2OutputData->iFrameId));
vecTitle.emplace_back("TimeStamp:" + jvFrameInfo["timeStamp"].asString());
int base_line = 0;
cv::Point text_org(15, 45); // 文本起始点
for (const auto & i : vecTitle)
{ {
cv::Size text_size = cv::getTextSize(i, cv::FONT_HERSHEY_SIMPLEX, 1, 2, 0); // std::stringstream ss;
cv::Point baseline_loc(text_org); std::vector<std::string> vecTitle;
baseline_loc.y += base_line + text_size.height; vecTitle.emplace_back("FrameID:" + to_string(pVStep2OutputData->iFrameId));
cv::putText(image, i, baseline_loc, cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0, 255), 2); vecTitle.emplace_back("TimeStamp:" + jvFrameInfo["timeStamp"].asString());
// 手动调整x位置为下一个单词留出空间
text_org.x += text_size.width + 10;
text_org.x = text_org.x > IMAGE_WIDTH ? 15 : text_org.x;
base_line++;
}
cv::Scalar cvScalar = {0, 255, 0, 255}; int base_line = 0;
cv::Point text_org(15, 45); // 文本起始点
for (const auto & i : vecTitle)
{
cv::Size text_size = cv::getTextSize(i, cv::FONT_HERSHEY_SIMPLEX, 1, 2, 0);
cv::Point baseline_loc(text_org);
baseline_loc.y += base_line + text_size.height;
cv::putText(pVStep2OutputData->cvImage, i, baseline_loc, cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0, 255), 2);
// 手动调整x位置为下一个单词留出空间
text_org.x += text_size.width + 10;
text_org.x = text_org.x > IMAGE_WIDTH ? 15 : text_org.x;
base_line++;
}
float centerX = pVStep2OutputData->step2ResultData.fLTX + (pVStep2OutputData->step2ResultData.fRBX - pVStep2OutputData->step2ResultData.fLTX)/2; cv::Scalar cvScalar = {0, 255, 0, 255};
float centerY = pVStep2OutputData->step2ResultData.fLTY + (pVStep2OutputData->step2ResultData.fRBY - pVStep2OutputData->step2ResultData.fLTY)/2;
float centerX = pVStep2OutputData->step2ResultData.fLTX + (pVStep2OutputData->step2ResultData.fRBX - pVStep2OutputData->step2ResultData.fLTX)/2;
float centerY = pVStep2OutputData->step2ResultData.fLTY + (pVStep2OutputData->step2ResultData.fRBY - pVStep2OutputData->step2ResultData.fLTY)/2;
// auto start = std::chrono::system_clock::now(); //计时开始 // auto start = std::chrono::system_clock::now(); //计时开始
cv::rectangle(image, cv::rectangle(pVStep2OutputData->cvImage,
cv::Point(pVStep2OutputData->step2ResultData.fLTX, pVStep2OutputData->step2ResultData.fLTY), cv::Point(pVStep2OutputData->step2ResultData.fLTX, pVStep2OutputData->step2ResultData.fLTY),
cv::Point(pVStep2OutputData->step2ResultData.fRBX, pVStep2OutputData->step2ResultData.fRBY), cv::Point(pVStep2OutputData->step2ResultData.fRBX, pVStep2OutputData->step2ResultData.fRBY),
cvScalar, 2);
cv::line(image,
cv::Point(centerX, pVStep2OutputData->step2ResultData.fLTY-30), cv::Point(centerX, pVStep2OutputData->step2ResultData.fRBY+30),
cvScalar, 1);
cv::Size text_size = cv::getTextSize(pVStep2OutputData->step2ResultData.transInfo.strTmpResult, cv::FONT_HERSHEY_SIMPLEX, 1, 2, 0);
cv::Point linePoint(pVStep2OutputData->step2ResultData.fLTX, pVStep2OutputData->step2ResultData.fRBY + text_size.height + 5);
cv::putText(image,
pVStep2OutputData->step2ResultData.transInfo.strTmpResult,
linePoint,
cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0, 180), 2);
for (const auto &step2ResultData : pVStep2OutputData->vecCornerResultData)
{
cvScalar = {0, 255, 255, 255};
float centerX_corner = step2ResultData.fLTX + (step2ResultData.fRBX - step2ResultData.fLTX)/2;
cv::rectangle(image,
cv::Point(step2ResultData.fLTX, step2ResultData.fLTY),
cv::Point(step2ResultData.fRBX, step2ResultData.fRBY),
cvScalar, 2); cvScalar, 2);
cv::line(image, cv::line(pVStep2OutputData->cvImage,
cv::Point(centerX_corner, step2ResultData.fLTY-30), cv::Point(centerX_corner, step2ResultData.fRBY+30), cv::Point(centerX, pVStep2OutputData->step2ResultData.fLTY-30), cv::Point(centerX, pVStep2OutputData->step2ResultData.fRBY+30),
cvScalar, 1); cvScalar, 1);
cv::Size text_size = cv::getTextSize(pVStep2OutputData->step2ResultData.transInfo.strTmpResult, cv::FONT_HERSHEY_SIMPLEX, 1, 2, 0);
cv::Point linePoint(pVStep2OutputData->step2ResultData.fLTX, pVStep2OutputData->step2ResultData.fRBY + text_size.height + 5);
cv::putText(pVStep2OutputData->cvImage,
pVStep2OutputData->step2ResultData.transInfo.strTmpResult,
linePoint,
cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0, 180), 2);
for (const auto &step2ResultData : pVStep2OutputData->vecCornerResultData)
{
cvScalar = {0, 255, 255, 255};
float centerX_corner = step2ResultData.fLTX + (step2ResultData.fRBX - step2ResultData.fLTX)/2;
cv::rectangle(pVStep2OutputData->cvImage,
cv::Point(step2ResultData.fLTX, step2ResultData.fLTY),
cv::Point(step2ResultData.fRBX, step2ResultData.fRBY),
cvScalar, 2);
cv::line(pVStep2OutputData->cvImage,
cv::Point(centerX_corner, step2ResultData.fLTY-30), cv::Point(centerX_corner, step2ResultData.fRBY+30),
cvScalar, 1);
}
} }
// auto end = std::chrono::system_clock::now(); // auto end = std::chrono::system_clock::now();
// LogDebug << "图片存储用时: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms " << strImagePath; // LogDebug << "图片存储用时: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms " << strImagePath;
if (!cv::imwrite(strImagePath, image, this->vecCompressionParams_)) if (!cv::imwrite(strImagePath, pVStep2OutputData->cvImage, this->vecCompressionParams_))
{ {
LogError << "图片存储失败:" << strImagePath; LogError << "图片存储失败:" << strImagePath;
} }

View File

@ -24,7 +24,7 @@ private:
ai_matrix::BaseConfig baseConfig_; ai_matrix::BaseConfig baseConfig_;
std::string strPort0_; std::string strPort0_;
int iPicQuality_ = 80; int iPicQuality_ = 100;
std::vector<int> vecCompressionParams_; std::vector<int> vecCompressionParams_;
}; };

File diff suppressed because one or more lines are too long