This commit is contained in:
XinJiang1 2024-12-25 18:33:44 +08:00
commit 2894a4d91a

View File

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