From 9bfe3ad6836320173b59dd5976849ae8c47bbdf8 Mon Sep 17 00:00:00 2001
From: karllzy
Date: Wed, 25 Dec 2024 16:38:23 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BC=98=E5=8C=96=E5=92=8C?=
=?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=B7=BB=E5=8A=A0=E7=A6=81=E6=AD=A2=E7=89=88?=
=?UTF-8?q?=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
camera.cpp | 62 +++++++++++++++++++++++++++++-------------------------
1 file changed, 33 insertions(+), 29 deletions(-)
diff --git a/camera.cpp b/camera.cpp
index b2c38d3..cb71bfb 100644
--- a/camera.cpp
+++ b/camera.cpp
@@ -46,7 +46,7 @@ ONNXRunner runner;
std::map 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> 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>(heightBlocks, std::vector(widthBlocks, 0));
}
}
-
-
+ else
+ {
+ matrox_mask = std::vector>(heightBlocks, std::vector(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> 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>(heightBlocks, std::vector(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>(heightBlocks, std::vector(widthBlocks, 0));
+ }
// 获取深度学习的检测结果并进行合并
std::vector> 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> 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> expandMaskHorizontally(
}
return expanded_mask;
-}
-
-
-//onnx_Mask
+}
\ No newline at end of file