From f4e1bf88fbd2e2e3d7259e99f8c923b2357f420f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=93=88=E5=B0=8F=E4=B8=BB?= Date: Wed, 3 Apr 2024 16:55:06 +0800 Subject: [PATCH 1/2] m --- Samples/YOLOV5USBCamera/scripts/sample_run.sh | 11 ++++-- Samples/YOLOV5USBCamera/src/main.cpp | 36 ++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Samples/YOLOV5USBCamera/scripts/sample_run.sh b/Samples/YOLOV5USBCamera/scripts/sample_run.sh index b56b8e8..208ef8a 100644 --- a/Samples/YOLOV5USBCamera/scripts/sample_run.sh +++ b/Samples/YOLOV5USBCamera/scripts/sample_run.sh @@ -3,14 +3,19 @@ ScriptPath="$( cd "$(dirname "$BASH_SOURCE")" ; pwd -P )" function main() { + if [ "$1" != "imshow" ] && [ "$1" != "stdout" ]; then + echo "[ERROR] please choose output display mode: [bash sample_run imshow] [bash sample_run stdout]" + return + fi + echo "[INFO] The sample starts to run" - running_command="./main" cd ${ScriptPath}/../out - ${running_command} + ./main $1 if [ $? -ne 0 ];then echo "[INFO] The program runs failed" else echo "[INFO] The program runs successfully" fi } -main +main $1 + diff --git a/Samples/YOLOV5USBCamera/src/main.cpp b/Samples/YOLOV5USBCamera/src/main.cpp index e36acd8..b17ce56 100644 --- a/Samples/YOLOV5USBCamera/src/main.cpp +++ b/Samples/YOLOV5USBCamera/src/main.cpp @@ -43,7 +43,7 @@ struct MsgOut { Queue msgDataQueue(32); Queue msgOutQueue(32); - +std::string displayMode = ""; typedef struct BoundBox { float x; float y; @@ -54,6 +54,21 @@ typedef struct BoundBox { size_t index; } BoundBox; +bool Initparam(int argc, char *argv[]) +{ + DIR *dir; + int outputDisplay = 1; + if ((dir = opendir("./out")) == NULL) + system("mkdir ./out"); + int paramNum = 2; + if(argc != paramNum) { + LOG_PRINT("[ERROR] please choose output display mode: [./main imshow] [./main stdout]"); + return false; + } + displayMode = argv[outputDisplay]; + return true; +} + bool sortScore(BoundBox box1, BoundBox box2) { return box1.score > box2.score; @@ -159,6 +174,7 @@ void GetResult(std::vector& inferOutputs, cv::Scalar(50, 205, 50), cv::Scalar(139, 85, 26)}; int half = 2; + string textPrint = "["; for (size_t i = 0; i < result.size(); ++i) { if (result[i].score < 0.7) { continue; @@ -171,11 +187,19 @@ void GetResult(std::vector& inferOutputs, cv::rectangle(srcImage, leftUpPoint, rightBottomPoint, colors[i % colors.size()], lineSolid); string className = label[result[i].classIndex]; string markString = to_string(result[i].score) + ":" + className; + textPrint += markString; cv::putText(srcImage, markString, cv::Point(leftUpPoint.x, leftUpPoint.y + labelOffset), cv::FONT_HERSHEY_COMPLEX, fountScale, fountColor); } - cv::imshow("usb-show-demo", srcImage); - cv::waitKey(1); + textPrint += "]"; + if (displayMode == "imshow") { + cv::imshow("usb-show-demo", srcImage); + cv::waitKey(1); + } else if (displayMode == "stdout") { + cout<<"Detect Result: "<< textPrint < Date: Wed, 3 Apr 2024 08:57:58 +0000 Subject: [PATCH 2/2] update Samples/YOLOV5USBCamera/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 哈小主 --- Samples/YOLOV5USBCamera/README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Samples/YOLOV5USBCamera/README.md b/Samples/YOLOV5USBCamera/README.md index f9301e6..4d5f179 100644 --- a/Samples/YOLOV5USBCamera/README.md +++ b/Samples/YOLOV5USBCamera/README.md @@ -98,11 +98,14 @@ 4. 运行样例。 - 执行以下脚本运行样例: - - ``` - bash sample_run.sh - ``` + - 在HDMI连接屏幕场景,执行以下脚本运行样例。此时会以画面的形式呈现推理效果。 + ``` + bash sample_run.sh imshow + ``` + - 在直连电脑场景,执行以下脚本运行样例。此时会以结果打屏的形式呈现推理效果。 + ``` + bash sample_run.sh stdout + ``` #### 相关操作 -- Gitee