gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
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
48
49
50
51
52
53
54
55
import { Box } from './Box';
import { Dimensions, IDimensions } from './Dimensions';
import { IRect, Rect } from './Rect';
 
export class ObjectDetection {
  private _score: number;
 
  private _classScore: number;
 
  private _className: string;
 
  private _box: Rect;
 
  private _imageDims: Dimensions;
 
  constructor(
    score: number,
    classScore: number,
    className: string,
    relativeBox: IRect,
    imageDims: IDimensions,
  ) {
    this._imageDims = new Dimensions(imageDims.width, imageDims.height);
    this._score = score;
    this._classScore = classScore;
    this._className = className;
    this._box = new Box(relativeBox).rescale(this._imageDims);
  }
 
  public get score(): number { return this._score; }
 
  public get classScore(): number { return this._classScore; }
 
  public get className(): string { return this._className; }
 
  public get box(): Box { return this._box; }
 
  public get imageDims(): Dimensions { return this._imageDims; }
 
  public get imageWidth(): number { return this.imageDims.width; }
 
  public get imageHeight(): number { return this.imageDims.height; }
 
  public get relativeBox(): Box { return new Box(this._box).rescale(this.imageDims.reverse()); }
 
  public forSize(width: number, height: number): ObjectDetection {
    return new ObjectDetection(
      this.score,
      this.classScore,
      this.className,
      this.relativeBox,
      { width, height },
    );
  }
}