Skip to content

fix: properly convert DetectionType to TNSMLKitDetectionType for detectWithStillImage #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 29 additions & 69 deletions packages/mlkit-core/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ function getGravity(value) {
return null;
}

function detectionTypeToNative(detectionType: DetectionType) {
switch (detectionType) {
case DetectionType.All:
return TNSMLKitDetectionType.All;
case DetectionType.Barcode:
return TNSMLKitDetectionType.Barcode;
case DetectionType.DigitalInk:
return TNSMLKitDetectionType.DigitalInk;
case DetectionType.Face:
return TNSMLKitDetectionType.Face;
case DetectionType.Image:
return TNSMLKitDetectionType.Image;
case DetectionType.Object:
return TNSMLKitDetectionType.Object;
case DetectionType.CustomObject:
return TNSMLKitDetectionType.CustomObject;
case DetectionType.Pose:
return TNSMLKitDetectionType.Pose;
case DetectionType.Text:
return TNSMLKitDetectionType.Text;
case DetectionType.Selfie:
return TNSMLKitDetectionType.Selfie;
default:
return TNSMLKitDetectionType.None;
}
}

export class MLKitView extends MLKitViewBase {
_device: AVCaptureDevice;
_preview: AVCaptureVideoPreviewLayer;
Expand Down Expand Up @@ -202,42 +229,7 @@ export class MLKitView extends MLKitViewBase {
}

[detectionTypeProperty.setNative](value) {
let type = 10; /* None */
switch (value) {
case DetectionType.All:
type = 8;
break;
case DetectionType.Barcode:
type = 0;
break;
case DetectionType.DigitalInk:
type = 1;
break;
case DetectionType.Face:
type = 2;
break;
case DetectionType.Image:
type = 3;
break;
case DetectionType.Object:
type = 4;
break;
case DetectionType.CustomObject:
type = 5;
break;
case DetectionType.Pose:
type = 6;
break;
case DetectionType.Text:
type = 7;
break;
case DetectionType.Selfie:
type = 9;
break;
default:
type = 10;
break;
}
const type = detectionTypeToNative(value);
this._setupDetectors();
this._mlkitHelper.detectorType = type;
}
Expand Down Expand Up @@ -823,39 +815,7 @@ export function detectWithStillImage(image: any, options?: StillImageDetectionOp
reject('Please use a valid Image');
}

let type = 9; /* None */
switch (options?.detectorType) {
case DetectionType.All:
type = 7;
break;
case DetectionType.Barcode:
type = 0;
break;
case DetectionType.DigitalInk:
type = 1;
break;
case DetectionType.Face:
type = 2;
break;
case DetectionType.Image:
type = 3;
break;
case DetectionType.Object:
type = 4;
break;
case DetectionType.Pose:
type = 5;
break;
case DetectionType.Text:
type = 6;
break;
case DetectionType.Selfie:
type = 8;
break;
default:
type = 9;
break;
}
const type = detectionTypeToNative(options?.detectorType);

TNSML.processImage(
nativeImage,
Expand Down