注释优化和尝试添加禁止版本

This commit is contained in:
karllzy 2024-12-25 16:38:23 +08:00
parent a8552c6223
commit 9bfe3ad683

View File

@ -46,7 +46,7 @@ ONNXRunner runner;
std::map<std::string, int> params; std::map<std::string, int> params;
int dual_cam_offset_y = 0; // 双相机之间的上下偏移值 int dual_cam_offset_y = 0; // 双相机之间的上下偏移值
int widthBlocks = 20; // 输出的喷阀通道数 int widthBlocks = 20; // 输出的喷阀通道数
int heightBlocks = 512; // 输出的Mask高度 int heightBlocks = 512; // 输出的Mask高度
int sizeThreshold = 20; // 转化为喷阀的每块要求像素个数 int sizeThreshold = 20; // 转化为喷阀的每块要求像素个数
@ -148,11 +148,14 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
Timer call_back_timer0; Timer call_back_timer0;
call_back_timer0.restart(); call_back_timer0.restart();
#endif #endif
int camera_id = 0; int camera_id = 0;
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
Timer timer_detection_time; Timer timer_detection_time;
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
MdigGetHookInfo(HookId, M_MODIFIED_BUFFER + M_BUFFER_ID, &ModifiedBufferId0); MdigGetHookInfo(HookId, M_MODIFIED_BUFFER + M_BUFFER_ID, &ModifiedBufferId0);
{ {
QMutexLocker locker(&gDispPicMutex0); QMutexLocker locker(&gDispPicMutex0);
@ -172,8 +175,9 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
// 将图像数据推入存储队列 // 将图像数据推入存储队列
ImageData data; ImageData data;
data.camera_id = 0; data.camera_id = 0;
data.image = img.clone(); // 确保图像数据被复制 data.image = img.clone(); // 确保图像数据被复制
g_storageQueue.enqueue(data); g_storageQueue.enqueue(data);
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
qDebug() << "CallBack1: push image to storage queue"; qDebug() << "CallBack1: push image to storage queue";
#endif #endif
@ -189,6 +193,7 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
timer_detection_time.printElapsedTime("CallBack1: High sat detection resize"); timer_detection_time.printElapsedTime("CallBack1: High sat detection resize");
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
// 图片镜像翻转 // 图片镜像翻转
MIL_UNIQUE_BUF_ID MimFlipDedtination = MbufClone(MilImage_Color0, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_UNIQUE_ID); MIL_UNIQUE_BUF_ID MimFlipDedtination = MbufClone(MilImage_Color0, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_UNIQUE_ID);
MbufClear(MimFlipDedtination, M_COLOR_BLACK); MbufClear(MimFlipDedtination, M_COLOR_BLACK);
@ -203,13 +208,13 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
recognitionData.image = img; recognitionData.image = img;
g_img_Queue[camera_id]->enqueue(recognitionData); g_img_Queue[camera_id]->enqueue(recognitionData);
} }
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack1: High sat detection mirror and push to DL"); timer_detection_time.printElapsedTime("CallBack1: High sat detection mirror and push to DL");
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
// 艳丽检测mask // 艳丽检测mask
// 修改 high_sat_detect 调用,使用 std::future 限制执行时间
std::vector<std::vector<uint8_t>> matrox_mask; std::vector<std::vector<uint8_t>> matrox_mask;
if(g_traditional_enable[camera_id]) if(g_traditional_enable[camera_id])
@ -225,21 +230,23 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack1: High sat detection finish"); timer_detection_time.printElapsedTime("CallBack1: High sat detection finish");
timer_detection_time.restart(); timer_detection_time.restart();
#endif \ #endif
// 20ms内完使 detection_result1 \ // 使 detection_result1 \
// 将 Matrox 的检测结果转换为 二维vector // 将 Matrox 的检测结果转换为 二维vector
matrox_mask = generateMaskFromMatImage(ImageUtils::mil2Mat(detection_result0), widthBlocks, heightBlocks, sizeThreshold); matrox_mask = generateMaskFromMatImage(ImageUtils::mil2Mat(detection_result0), widthBlocks, heightBlocks, sizeThreshold);
} }
else else
{ {
// 任务超时,处理超时情况 // 任务超时,处理超时情况
qWarning() << "high_sat_detect 超时未在20ms内完成。"; qWarning() << "high_sat_detect 超时, 未在指定时间内完成。";
// 创建一个大小为 widthBlocks x heightBlocks 的 matrox_mask // 创建一个大小为 widthBlocks x heightBlocks 的 matrox_mask
matrox_mask = std::vector<std::vector<uint8_t>>(heightBlocks, std::vector<uint8_t>(widthBlocks, 0)); matrox_mask = std::vector<std::vector<uint8_t>>(heightBlocks, std::vector<uint8_t>(widthBlocks, 0));
} }
} }
else
{
matrox_mask = std::vector<std::vector<uint8_t>>(heightBlocks, std::vector<uint8_t>(widthBlocks, 0));
}
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack1: High sat detection to mask"); timer_detection_time.printElapsedTime("CallBack1: High sat detection to mask");
@ -289,7 +296,6 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
merged_mask = matrox_mask; merged_mask = matrox_mask;
} }
// Update the current Img MIl id // Update the current Img MIl id
// 更新持久化存储 // 更新持久化存储
// { // {
@ -369,13 +375,13 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
recognitionData.image = img; recognitionData.image = img;
g_img_Queue[1]->enqueue(recognitionData); g_img_Queue[1]->enqueue(recognitionData);
} }
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack2: Without mirror and push to DL"); timer_detection_time.printElapsedTime("CallBack2: Without mirror and push to DL");
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
// 艳丽检测mask // 艳丽检测mask
// 修改 high_sat_detect 调用,使用 std::future 限制执行时间
std::vector<std::vector<uint8_t>> matrox_mask; std::vector<std::vector<uint8_t>> matrox_mask;
if(g_traditional_enable[camera_id]) if(g_traditional_enable[camera_id])
@ -395,6 +401,10 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
// 20ms内完成使 detection_result1 \ // 20ms内完成使 detection_result1 \
// 将 Matrox 的检测结果转换为 二维vector // 将 Matrox 的检测结果转换为 二维vector
matrox_mask = generateMaskFromMatImage(ImageUtils::mil2Mat(detection_result1), widthBlocks, heightBlocks, sizeThreshold); matrox_mask = generateMaskFromMatImage(ImageUtils::mil2Mat(detection_result1), widthBlocks, heightBlocks, sizeThreshold);
#if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack2: High sat detection to mask");
timer_detection_time.restart();
#endif
} }
else else
{ {
@ -403,20 +413,15 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
// 任务超时,处理超时情况 // 任务超时,处理超时情况
qWarning() << "high_sat_detect 超时未在20ms内完成。"; qWarning() << "high_sat_detect 超时,未在20ms内完成。";
// 创建一个大小为 widthBlocks x heightBlocks 的 matrox_mask // 创建一个大小为 widthBlocks x heightBlocks 的 matrox_mask
matrox_mask = std::vector<std::vector<uint8_t>>(heightBlocks, std::vector<uint8_t>(widthBlocks, 0)); matrox_mask = std::vector<std::vector<uint8_t>>(heightBlocks, std::vector<uint8_t>(widthBlocks, 0));
} }
} }
else
{
matrox_mask = std::vector<std::vector<uint8_t>>(heightBlocks, std::vector<uint8_t>(widthBlocks, 0));
}
#if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack2: High sat detection to mask");
timer_detection_time.restart();
#endif
// 获取深度学习的检测结果并进行合并 // 获取深度学习的检测结果并进行合并
std::vector<std::vector<uint8_t>> merged_mask; std::vector<std::vector<uint8_t>> merged_mask;
@ -484,19 +489,20 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
merged_mask = ImageUtils::mergeMasks(mask_0, mask_1, dual_cam_offset_y); merged_mask = ImageUtils::mergeMasks(mask_0, mask_1, dual_cam_offset_y);
std::tie(merged_mask, mask_tail) = ImageUtils::extractROI(merged_mask, 0, 0, widthBlocks, heightBlocks); std::tie(merged_mask, mask_tail) = ImageUtils::extractROI(merged_mask, 0, 0, widthBlocks, heightBlocks);
// 发送前的处理 // 结果后处理Post Process
// 将每个结果左右扩展扩展半径默认为1 // 将每个结果左右扩展扩展半径默认为1
auto mask_expaned = expandMaskHorizontally(merged_mask, expansionRaidus); auto mask_expaned = expandMaskHorizontally(merged_mask, expansionRaidus);
// 将结果的左右补充上0让物体大小符合要求 // 将结果的左右补充上0让物体大小符合要求
PadColumns(mask_expaned,padLeft,padRight,0); PadColumns(mask_expaned, padLeft, padRight, 0);
//将mask扩展到合适发送的大小 //将mask扩展到合适发送的大小
std::vector<std::vector<uint8_t>> mask_Total = expandArray(mask_expaned,64); std::vector<std::vector<uint8_t>> mask_Total = expandArray(mask_expaned,64);
// save masks // save masks
#if(GlobalDebug && DebugDetection) #if(GlobalDebug && DebugDetection)
VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask" + std::to_string(FuncCount1) + ".bmp"); VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask" + std::to_string(FuncCount1) + ".bmp");
VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask_ignored" + std::to_string(FuncCount1) + ".bmp"); VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask_ignored" + std::to_string(FuncCount1) + ".bmp");
VectorToImg(mask_Total,"C:/Users/Pc/Desktop/img/mask_expended" + std::to_string(FuncCount1) + ".bmp"); VectorToImg(mask_Total,"C:/Users/Pc/Desktop/img/mask_expended" + std::to_string(FuncCount1) + ".bmp");
#endif \ #endif
// 发送到下位机 // 发送到下位机
bool result_Low = get_valve_data(mask_Total); bool result_Low = get_valve_data(mask_Total);
if(!result_Low) if(!result_Low)
@ -505,6 +511,7 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
} }
MbufFree(detection_result1); MbufFree(detection_result1);
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
call_back_timer1.printElapsedTime("CallBack2: Total time spent: "); call_back_timer1.printElapsedTime("CallBack2: Total time spent: ");
#endif #endif
@ -1355,6 +1362,3 @@ std::vector<std::vector<uint8_t>> expandMaskHorizontally(
return expanded_mask; return expanded_mask;
} }
//onnx_Mask