28 lines
1.1 KiB
Java
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.box();
|
||
|
|
int bgr = d.colorBGR();
|
||
|
|
Scalar c = new Scalar(bgr & 0xFF, (bgr >> 8) & 0xFF, (bgr >> 16) & 0xFF, 0);
|
||
|
|
rectangle(frame, r, c, 2, LINE_8, 0);
|
||
|
|
String label = d.cls()+" "+String.format("%.2f", d.conf());
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|