Skip to content

Commit 586464e

Browse files
authored
[Feataure] checkCount (#8)
1 parent 768a800 commit 586464e

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ export interface RecognizedObject {
2121
* @param width: the width of the device
2222
* @param recognitionCount: optional, minimum number of items you want before being considered as a top object
2323
* @param score: optional, minimum threshold of box score to keep track of
24+
* @param checkCount: optional, how many items to track for each tracked object
2425
*/
2526
interface Props {
2627
height: number;
2728
width: number;
2829
recognitionCount?: number;
2930
score?: number;
31+
checkCount?: number;
3032
}
3133

3234
/**
@@ -37,22 +39,30 @@ interface Props {
3739
export class FrameRecognition {
3840
private static readonly MAX_HISTORY_SIZE = 50;
3941
private static readonly MAX_MISSED_COUNT = 30;
40-
private static readonly TRACKING_THRESHOLD = 0.03;
42+
private static readonly TRACKING_THRESHOLD = 0.5;
4143

4244
private trackingObjects: Map<number, RecognizedObject>;
4345
private recognizedObjectsCount: number;
4446
private readonly height: number;
4547
private readonly width: number;
4648
private readonly recognitionCount: number;
4749
private readonly scoreThreshold: number;
48-
49-
constructor({ height, width, recognitionCount = 20, score = 0.25 }: Props) {
50+
private readonly checkCount: number;
51+
52+
constructor({
53+
height,
54+
width,
55+
recognitionCount = 20,
56+
score = 0.25,
57+
checkCount = 50,
58+
}: Props) {
5059
this.height = height;
5160
this.width = width;
5261
this.trackingObjects = new Map();
5362
this.recognizedObjectsCount = 0;
5463
this.recognitionCount = recognitionCount;
5564
this.scoreThreshold = score;
65+
this.checkCount = checkCount;
5666
}
5767

5868
// Memoize and optimize confident object retrieval
@@ -69,7 +79,7 @@ export class FrameRecognition {
6979
const currentTime = Date.now();
7080
if (
7181
this._cachedConfidentObject &&
72-
currentTime - this._lastConfidentObjectCheck < 100
82+
currentTime - this._lastConfidentObjectCheck < this.checkCount
7383
) {
7484
return this._cachedConfidentObject;
7585
}

0 commit comments

Comments
 (0)