From 6962892648ff8d893b36600ae1a189c407341334 Mon Sep 17 00:00:00 2001 From: Robofish <1683502971@qq.com> Date: Mon, 15 Dec 2025 20:00:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhik=E7=9B=B8=E6=9C=BA?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 0 configs/camera.yaml | 16 +++++++-------- configs/sentry.yaml | 6 +++--- io/hikrobot/hikrobot.cpp | 43 +++++++++++++++++++++++++++++++--------- 4 files changed, 45 insertions(+), 20 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e69de29 diff --git a/configs/camera.yaml b/configs/camera.yaml index e1c9cdd..cddfc59 100644 --- a/configs/camera.yaml +++ b/configs/camera.yaml @@ -1,9 +1,9 @@ -camera_name: "mindvision" -exposure_ms: 2 -gamma: 0.5 -vid_pid: "f622:d13a" +# camera_name: "mindvision" +# exposure_ms: 2 +# gamma: 0.5 +# vid_pid: "f622:d13a" -# camera_name: "hikrobot" -# exposure_ms: 3 -# gain: 10.0 -# vid_pid: "2bdf:0001" \ No newline at end of file +camera_name: "hikrobot" +exposure_ms: 3 +gain: 10.0 +vid_pid: "2bdf:0001" \ No newline at end of file diff --git a/configs/sentry.yaml b/configs/sentry.yaml index b6b2cd4..6282e7a 100644 --- a/configs/sentry.yaml +++ b/configs/sentry.yaml @@ -1,5 +1,5 @@ -# enemy_color: "red" -enemy_color: "blue" +enemy_color: "red" +# enemy_color: "blue" #####-----神经网络参数-----##### @@ -10,7 +10,7 @@ yolov8_model_path: assets/yolov8.xml yolov5_model_path: assets/yolov5.xml device: GPU min_confidence: 0.8 -use_traditional: true +use_traditional: false #####-----ROI-----##### roi: diff --git a/io/hikrobot/hikrobot.cpp b/io/hikrobot/hikrobot.cpp index 92d7927..5c53b68 100644 --- a/io/hikrobot/hikrobot.cpp +++ b/io/hikrobot/hikrobot.cpp @@ -116,7 +116,21 @@ void HikRobot::capture_start() } auto timestamp = std::chrono::steady_clock::now(); - cv::Mat img(cv::Size(raw.stFrameInfo.nWidth, raw.stFrameInfo.nHeight), CV_8U, raw.pBufAddr); + + const auto & frame_info = raw.stFrameInfo; + auto pixel_type = frame_info.enPixelType; + + // Determine image type based on pixel format + int cv_type = CV_8U; + bool is_color = false; + + // Check if it's a color format (RGB or BGR already converted) + if (pixel_type == PixelType_Gvsp_RGB8_Packed || pixel_type == PixelType_Gvsp_BGR8_Packed) { + cv_type = CV_8UC3; + is_color = true; + } + + cv::Mat img(cv::Size(raw.stFrameInfo.nWidth, raw.stFrameInfo.nHeight), cv_type, raw.pBufAddr); cvt_param.nWidth = raw.stFrameInfo.nWidth; cvt_param.nHeight = raw.stFrameInfo.nHeight; @@ -130,16 +144,27 @@ void HikRobot::capture_start() cvt_param.enDstPixelType = PixelType_Gvsp_BGR8_Packed; // ret = MV_CC_ConvertPixelType(handle_, &cvt_param); - const auto & frame_info = raw.stFrameInfo; - auto pixel_type = frame_info.enPixelType; cv::Mat dst_image; const static std::unordered_map type_map = { - {PixelType_Gvsp_BayerGR8, cv::COLOR_BayerGR2RGB}, - {PixelType_Gvsp_BayerRG8, cv::COLOR_BayerRG2RGB}, - {PixelType_Gvsp_BayerGB8, cv::COLOR_BayerGB2RGB}, - {PixelType_Gvsp_BayerBG8, cv::COLOR_BayerBG2RGB}}; - cv::cvtColor(img, dst_image, type_map.at(pixel_type)); - img = dst_image; + {PixelType_Gvsp_BayerGR8, cv::COLOR_BayerGR2BGR}, + {PixelType_Gvsp_BayerRG8, cv::COLOR_BayerRG2BGR}, + {PixelType_Gvsp_BayerGB8, cv::COLOR_BayerGB2BGR}, + {PixelType_Gvsp_BayerBG8, cv::COLOR_BayerBG2BGR}, + {PixelType_Gvsp_BayerRBGG8, cv::COLOR_BayerRG2BGR}}; + + auto it = type_map.find(pixel_type); + if (it != type_map.end()) { + cv::cvtColor(img, dst_image, it->second); + img = dst_image; + } else if (is_color && pixel_type == PixelType_Gvsp_RGB8_Packed) { + // Convert RGB to BGR + cv::cvtColor(img, dst_image, cv::COLOR_RGB2BGR); + img = dst_image; + } else if (!is_color) { + tools::logger()->warn("Unsupported pixel type: {:#x}. Camera may be outputting already converted format. Using raw image.", pixel_type); + // If pixel format is not in the map, the image might already be in the desired format + img = img; + } queue_.push({img, timestamp});