From 9280f52aefa9e16833e8af17867ea747bce5414b Mon Sep 17 00:00:00 2001 From: GuanYuankai Date: Thu, 8 Jan 2026 14:10:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(video):=20=E7=B2=BE=E7=AE=80=E7=94=BB?= =?UTF-8?q?=E9=9D=A2=E7=BA=BF=E6=9D=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/videoService/video_pipeline.cpp | 43 ++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/videoService/video_pipeline.cpp b/src/videoService/video_pipeline.cpp index fcc1825..a1818c9 100644 --- a/src/videoService/video_pipeline.cpp +++ b/src/videoService/video_pipeline.cpp @@ -381,32 +381,55 @@ void VideoPipeline::updateTracker(const FrameData& frameData) { void VideoPipeline::drawOverlay(cv::Mat& frame, const std::vector& trackedObjects) { std::lock_guard lock(config_mtx_); - // 1. 画绊线 (如果启用) + + // 1. 画绊线 (保持不变) if (tripwire_config_.enabled) { cv::line(frame, tripwire_p1_pixel_, tripwire_p2_pixel_, cv::Scalar(0, 255, 255), 2); cv::putText(frame, tripwire_config_.name, tripwire_p1_pixel_, cv::FONT_HERSHEY_SIMPLEX, 0.7, cv::Scalar(0, 255, 255), 2); } - // 2. 画车辆 + // 2. 画车辆 (已修改) for (const auto& trk : trackedObjects) { if (trk.missing_frames > 0) continue; + // 设置颜色:EV为绿色,燃油车为红色 cv::Scalar color = (trk.last_class_id == 1) ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 0, 255); + + // 绘制车辆边框 cv::rectangle(frame, trk.box, color, 2); - // 画中心点轨迹(可选,调试用) - // cv::circle(frame, trk.prev_bottom_center, 3, cv::Scalar(255, 0, 0), -1); + // === [修改开始] 文字居中显示 EV / FUEL === - std::string text = fmt::format("{} {:.2f}", trk.label, trk.ev_score); - int y_pos = trk.box.y - 5; - if (y_pos < 10) - y_pos = trk.box.y + 15; - cv::putText(frame, text, cv::Point(trk.box.x, y_pos), cv::FONT_HERSHEY_SIMPLEX, 0.6, color, - 2); + // 1. 确定显示的文本 + // std::string text = (trk.last_class_id == 1) ? "EV" : "FUEL"; + + // 2. 设置字体参数 + // int fontFace = cv::FONT_HERSHEY_SIMPLEX; + // double fontScale = 0.8; // 稍微调大一点以便在框内看清 + // int thickness = 2; + // int baseline = 0; + + // 3. 计算文字本身的宽高 + // cv::Size textSize = cv::getTextSize(text, fontFace, fontScale, thickness, &baseline); + + // 4. 计算检测框的中心点 + // cv::Point boxCenter(trk.box.x + trk.box.width / 2, trk.box.y + trk.box.height / 2); + + // 5. 计算文字绘制的起始点 (Origin) + // 使得文字的中心与框的中心对齐 + // X轴: 框中心X - 文字宽度的一半 + // Y轴: 框中心Y + 文字高度的一半 (注意OpenCV原点在左上角,文字基线在下方) + // cv::Point textOrg(boxCenter.x - textSize.width / 2, boxCenter.y + textSize.height / 2); + + // 6. 绘制文字 + // cv::putText(frame, text, textOrg, fontFace, fontScale, color, thickness); + + // === [修改结束] === } + // 调试信息 (保持不变) cv::putText(frame, "RK3588 YOLOv8 Smooth", cv::Point(20, 50), cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(0, 255, 255), 2); }