Don't overwrite detection options if not specified in setOptions()
PiperOrigin-RevId: 520790479
This commit is contained in:
parent
508c72ddc9
commit
145fc1ed38
|
@ -140,6 +140,11 @@ export class GestureRecognizer extends VisionTaskRunner {
|
||||||
new HandGestureRecognizerGraphOptions();
|
new HandGestureRecognizerGraphOptions();
|
||||||
this.options.setHandGestureRecognizerGraphOptions(
|
this.options.setHandGestureRecognizerGraphOptions(
|
||||||
this.handGestureRecognizerGraphOptions);
|
this.handGestureRecognizerGraphOptions);
|
||||||
|
this.handDetectorGraphOptions.setMinDetectionConfidence(DEFAULT_CONFIDENCE);
|
||||||
|
this.handLandmarkerGraphOptions.setMinTrackingConfidence(
|
||||||
|
DEFAULT_CONFIDENCE);
|
||||||
|
this.handLandmarksDetectorGraphOptions.setMinDetectionConfidence(
|
||||||
|
DEFAULT_CONFIDENCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override get baseOptions(): BaseOptionsProto {
|
protected override get baseOptions(): BaseOptionsProto {
|
||||||
|
@ -162,12 +167,20 @@ export class GestureRecognizer extends VisionTaskRunner {
|
||||||
override setOptions(options: GestureRecognizerOptions): Promise<void> {
|
override setOptions(options: GestureRecognizerOptions): Promise<void> {
|
||||||
this.handDetectorGraphOptions.setNumHands(
|
this.handDetectorGraphOptions.setNumHands(
|
||||||
options.numHands ?? DEFAULT_NUM_HANDS);
|
options.numHands ?? DEFAULT_NUM_HANDS);
|
||||||
|
if ('minHandDetectionConfidence' in options) {
|
||||||
this.handDetectorGraphOptions.setMinDetectionConfidence(
|
this.handDetectorGraphOptions.setMinDetectionConfidence(
|
||||||
options.minHandDetectionConfidence ?? DEFAULT_CONFIDENCE);
|
options.minHandDetectionConfidence ?? DEFAULT_CONFIDENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('minTrackingConfidence' in options) {
|
||||||
this.handLandmarkerGraphOptions.setMinTrackingConfidence(
|
this.handLandmarkerGraphOptions.setMinTrackingConfidence(
|
||||||
options.minTrackingConfidence ?? DEFAULT_CONFIDENCE);
|
options.minTrackingConfidence ?? DEFAULT_CONFIDENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('minHandPresenceConfidence' in options) {
|
||||||
this.handLandmarksDetectorGraphOptions.setMinDetectionConfidence(
|
this.handLandmarksDetectorGraphOptions.setMinDetectionConfidence(
|
||||||
options.minHandPresenceConfidence ?? DEFAULT_CONFIDENCE);
|
options.minHandPresenceConfidence ?? DEFAULT_CONFIDENCE);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.cannedGesturesClassifierOptions) {
|
if (options.cannedGesturesClassifierOptions) {
|
||||||
// Note that we have to support both JSPB and ProtobufJS and cannot
|
// Note that we have to support both JSPB and ProtobufJS and cannot
|
||||||
|
|
|
@ -147,6 +147,18 @@ describe('GestureRecognizer', () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not reset default values when not specified', async () => {
|
||||||
|
await gestureRecognizer.setOptions({minHandDetectionConfidence: 0.5});
|
||||||
|
await gestureRecognizer.setOptions({});
|
||||||
|
verifyGraph(gestureRecognizer, [
|
||||||
|
[
|
||||||
|
'handLandmarkerGraphOptions', 'handDetectorGraphOptions',
|
||||||
|
'minDetectionConfidence'
|
||||||
|
],
|
||||||
|
0.5
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
describe('setOptions()', () => {
|
describe('setOptions()', () => {
|
||||||
interface TestCase {
|
interface TestCase {
|
||||||
optionPath: [keyof GestureRecognizerOptions, ...string[]];
|
optionPath: [keyof GestureRecognizerOptions, ...string[]];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user