Don't overwrite detection options if not specified in setOptions()

PiperOrigin-RevId: 520790479
This commit is contained in:
Sebastian Schmidt 2023-03-30 17:54:15 -07:00 committed by Copybara-Service
parent 508c72ddc9
commit 145fc1ed38
2 changed files with 31 additions and 6 deletions

View File

@ -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

View File

@ -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[]];