zouyu
2025-11-27 eed98e551c817ead7965e08820d4b7adbc4a47f0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.xindao.ocr.smartjavaai.entity;
 
import ai.djl.ndarray.NDArray;
 
/**
 * 旋转检测框 - 支持左上角 X 坐标升序排序
 */
public class RotatedBoxCompX implements Comparable<RotatedBoxCompX> {
    private NDArray box;
    private String text;
 
    public RotatedBoxCompX(NDArray box, String text) {
        this.box = box;
        this.text = text;
    }
 
    /**
     * 将左上角 X 坐标升序排序
     *
     * @param o
     * @return
     */
    @Override
    public int compareTo(RotatedBoxCompX o) {
        NDArray leftBox = this.getBox();
        NDArray rightBox = o.getBox();
        float leftX = leftBox.toFloatArray()[0];
        float rightX = rightBox.toFloatArray()[0];
        return (leftX < rightX) ? -1 : 1;
    }
 
    public NDArray getBox() {
        return box;
    }
 
    public void setBox(NDArray box) {
        this.box = box;
    }
 
    public String getText() {
        return text;
    }
 
    public void setText(String text) {
        this.text = text;
    }
}