face-api/src/classes/ObjectDetection.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-08-18 13:54:53 +02:00
import { Box } from './Box';
import { Dimensions, IDimensions } from './Dimensions';
import { IRect, Rect } from './Rect';
export class ObjectDetection {
private _score: number
2020-12-23 17:26:55 +01:00
2020-08-18 13:54:53 +02:00
private _classScore: number
2020-12-23 17:26:55 +01:00
2020-08-18 13:54:53 +02:00
private _className: string
2020-12-23 17:26:55 +01:00
2020-08-18 13:54:53 +02:00
private _box: Rect
2020-12-23 17:26:55 +01:00
2020-08-18 13:54:53 +02:00
private _imageDims: Dimensions
constructor(
score: number,
classScore: number,
className: string,
relativeBox: IRect,
2020-12-23 17:26:55 +01:00
imageDims: IDimensions,
2020-08-18 13:54:53 +02:00
) {
2020-12-23 17:26:55 +01:00
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);
2020-08-18 13:54:53 +02:00
}
2020-12-23 17:26:55 +01:00
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()); }
2020-08-18 13:54:53 +02:00
public forSize(width: number, height: number): ObjectDetection {
return new ObjectDetection(
this.score,
this.classScore,
this.className,
this.relativeBox,
2020-12-23 17:26:55 +01:00
{ width, height },
);
2020-08-18 13:54:53 +02:00
}
2020-12-23 17:26:55 +01:00
}