feat(video): 精简画面线条。

This commit is contained in:
GuanYuankai 2026-01-08 14:10:23 +08:00
parent d2cbab34c7
commit 9280f52aef
1 changed files with 33 additions and 10 deletions

View File

@ -381,32 +381,55 @@ void VideoPipeline::updateTracker(const FrameData& frameData) {
void VideoPipeline::drawOverlay(cv::Mat& frame, const std::vector<TrackedVehicle>& trackedObjects) {
std::lock_guard<std::mutex> 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);
}