Files
rtsp-video-analysis-system/ruoyi-video/src/main/java/com/ruoyi/video/utils/Overlay.java
2025-09-30 14:23:33 +08:00

28 lines
1.1 KiB
Java

package com.ruoyi.video.utils;
import com.ruoyi.video.domain.Detection;
import org.bytedeco.opencv.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_imgproc.*;
import java.util.List;
public final class Overlay {
private Overlay(){}
public static void draw(List<Detection> dets, Mat frame) {
for (Detection d : dets) {
Rect r = d.getRect();
int bgr = d.getColorBGR();
Scalar c = new Scalar(bgr & 0xFF, (bgr >> 8) & 0xFF, (bgr >> 16) & 0xFF, 0);
rectangle(frame, r, c, 2, LINE_8, 0);
String label = d.getLabel()+" "+String.format("%.2f", d.getConfidence());
int[] baseline = new int[1];
Size t = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, baseline);
int x = Math.max(0, r.x());
int y = Math.max(t.height(), r.y()-4);
rectangle(frame, new Rect(x, y-t.height()-4, t.width()+6, t.height()+6), c, FILLED, 0, 0);
putText(frame, label, new Point(x+3, y), FONT_HERSHEY_SIMPLEX, 0.5, new Scalar(0,0,0,0), 1, LINE_AA, false);
}
}
}