Skip to content

Commit 19ddd60

Browse files
authored
feat: custom object detectors + fix related to automatic zooming on ios (#71)
1 parent f038a0a commit 19ddd60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1135
-224
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ Thumbs.db
4343
*.tgz
4444
packages/**/angular/dist
4545

46-
.nx/cache
46+
.nx/cache
47+
.nx/workspace-data

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- [@nativescript/mlkit-barcode-scanning](packages/mlkit-barcode-scanning/README.md)
22
- [@nativescript/mlkit-core](packages/mlkit-core/README.md)
3+
- [@nativescript/mlkit-custom-object-detection](packages/mlkit-custom-object-detection/README.md)
34
- [@nativescript/mlkit-digital-ink-recognition](packages/mlkit-digital-ink-recognition/README.md)
45
- [@nativescript/mlkit-face-detection](packages/mlkit-face-detection/README.md)
56
- [@nativescript/mlkit-image-labeling](packages/mlkit-image-labeling/README.md)

apps/demo-angular/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"@nativescript/mlkit-object-detection": "file:../../dist/packages/mlkit-object-detection",
1111
"@nativescript/mlkit-digital-ink-recognition": "file:../../dist/packages/mlkit-digital-ink-recognition",
1212
"@nativescript/mlkit-pose-detection": "file:../../dist/packages/mlkit-pose-detection",
13-
"@nativescript/mlkit-selfie-segmentation": "file:../../dist/packages/mlkit-selfie-segmentation"
13+
"@nativescript/mlkit-selfie-segmentation": "file:../../dist/packages/mlkit-selfie-segmentation",
14+
"@nativescript/mlkit-custom-object-detection": "file:../../dist/packages/mlkit-custom-object-detection"
1415
},
1516
"devDependencies": {
1617
"@nativescript/android": "8.8.0-alpha.7",

apps/demo-angular/src/app-routing.module.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ import { NativeScriptRouterModule } from '@nativescript/angular';
55
import { HomeComponent } from './home.component';
66

77
const routes: Routes = [
8-
{ path: '', redirectTo: '/home', pathMatch: 'full' },
9-
{ path: 'home', component: HomeComponent },
10-
{ path: 'mlkit-barcode-scanning', loadChildren: () => import('./plugin-demos/mlkit-barcode-scanning.module').then(m => m.MlkitBarcodeScanningModule) },
11-
{ path: 'mlkit-core', loadChildren: () => import('./plugin-demos/mlkit-core.module').then(m => m.MlkitCoreModule) },
12-
{ path: 'mlkit-digital-ink-recognition', loadChildren: () => import('./plugin-demos/mlkit-digital-ink-recognition.module').then(m => m.MlkitDigitalInkRecognitionModule) },
13-
{ path: 'mlkit-face-detection', loadChildren: () => import('./plugin-demos/mlkit-face-detection.module').then(m => m.MlkitFaceDetectionModule) },
14-
{ path: 'mlkit-image-labeling', loadChildren: () => import('./plugin-demos/mlkit-image-labeling.module').then(m => m.MlkitImageLabelingModule) },
15-
{ path: 'mlkit-object-detection', loadChildren: () => import('./plugin-demos/mlkit-object-detection.module').then(m => m.MlkitObjectDetectionModule) },
16-
{ path: 'mlkit-pose-detection', loadChildren: () => import('./plugin-demos/mlkit-pose-detection.module').then(m => m.MlkitPoseDetectionModule) },
17-
{ path: 'mlkit-selfie-segmentation', loadChildren: () => import('./plugin-demos/mlkit-selfie-segmentation.module').then(m => m.MlkitSelfieSegmentationModule) },
18-
{ path: 'mlkit-text-recognition', loadChildren: () => import('./plugin-demos/mlkit-text-recognition.module').then(m => m.MlkitTextRecognitionModule) }
8+
{ path: '', redirectTo: '/home', pathMatch: 'full' },
9+
{ path: 'home', component: HomeComponent },
10+
{ path: 'mlkit-barcode-scanning', loadChildren: () => import('./plugin-demos/mlkit-barcode-scanning.module').then((m) => m.MlkitBarcodeScanningModule) },
11+
{ path: 'mlkit-core', loadChildren: () => import('./plugin-demos/mlkit-core.module').then((m) => m.MlkitCoreModule) },
12+
{ path: 'mlkit-custom-object-detection', loadChildren: () => import('./plugin-demos/mlkit-custom-object-detection.module').then((m) => m.MlkitCustomObjectDetectionModule) },
13+
{ path: 'mlkit-digital-ink-recognition', loadChildren: () => import('./plugin-demos/mlkit-digital-ink-recognition.module').then((m) => m.MlkitDigitalInkRecognitionModule) },
14+
{ path: 'mlkit-face-detection', loadChildren: () => import('./plugin-demos/mlkit-face-detection.module').then((m) => m.MlkitFaceDetectionModule) },
15+
{ path: 'mlkit-image-labeling', loadChildren: () => import('./plugin-demos/mlkit-image-labeling.module').then((m) => m.MlkitImageLabelingModule) },
16+
{ path: 'mlkit-object-detection', loadChildren: () => import('./plugin-demos/mlkit-object-detection.module').then((m) => m.MlkitObjectDetectionModule) },
17+
{ path: 'mlkit-pose-detection', loadChildren: () => import('./plugin-demos/mlkit-pose-detection.module').then((m) => m.MlkitPoseDetectionModule) },
18+
{ path: 'mlkit-selfie-segmentation', loadChildren: () => import('./plugin-demos/mlkit-selfie-segmentation.module').then((m) => m.MlkitSelfieSegmentationModule) },
19+
{ path: 'mlkit-text-recognition', loadChildren: () => import('./plugin-demos/mlkit-text-recognition.module').then((m) => m.MlkitTextRecognitionModule) },
1920
];
2021

2122
@NgModule({
22-
imports: [NativeScriptRouterModule.forRoot(routes)],
23-
exports: [NativeScriptRouterModule],
23+
imports: [NativeScriptRouterModule.forRoot(routes)],
24+
exports: [NativeScriptRouterModule],
2425
})
2526
export class AppRoutingModule {}

apps/demo-angular/src/home.component.ts

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,40 @@ import { Component } from '@angular/core';
22
import { RouterExtensions } from '@nativescript/angular';
33

44
@Component({
5-
selector: 'demo-home',
6-
templateUrl: 'home.component.html',
5+
selector: 'demo-home',
6+
templateUrl: 'home.component.html',
77
})
88
export class HomeComponent {
9-
demos = [
10-
{
11-
name: 'mlkit-barcode-scanning'
12-
},
13-
{
14-
name: 'mlkit-core'
15-
},
16-
{
17-
name: 'mlkit-digital-ink-recognition'
18-
},
19-
{
20-
name: 'mlkit-face-detection'
21-
},
22-
{
23-
name: 'mlkit-image-labeling'
24-
},
25-
{
26-
name: 'mlkit-object-detection'
27-
},
28-
{
29-
name: 'mlkit-pose-detection'
30-
},
31-
{
32-
name: 'mlkit-selfie-segmentation'
33-
},
34-
{
35-
name: 'mlkit-text-recognition'
36-
}
37-
];
38-
39-
constructor(private router: RouterExtensions) { }
40-
41-
onTap(event) {
42-
const item = this.demos[event.index];
43-
this.router.navigate(['/' + item.name]);
44-
}
45-
}
9+
demos = [
10+
{
11+
name: 'mlkit-barcode-scanning',
12+
},
13+
{
14+
name: 'mlkit-core',
15+
},
16+
{
17+
name: 'mlkit-custom-object-detection',
18+
},
19+
{
20+
name: 'mlkit-digital-ink-recognition',
21+
},
22+
{
23+
name: 'mlkit-face-detection',
24+
},
25+
{
26+
name: 'mlkit-image-labeling',
27+
},
28+
{
29+
name: 'mlkit-object-detection',
30+
},
31+
{
32+
name: 'mlkit-pose-detection',
33+
},
34+
{
35+
name: 'mlkit-selfie-segmentation',
36+
},
37+
{
38+
name: 'mlkit-text-recognition',
39+
},
40+
];
41+
}
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<ActionBar title="mlkit-core" class="action-bar"> </ActionBar>
22
<StackLayout class="p-20">
3-
<GridLayout rows="*,auto,auto,auto,auto,auto,auto,auto,auto,auto" height="100%">
4-
<MLKitView [torchOn]="torchOn" [pause]="isPaused" height="100%" rowSpan="3" (loaded)="onLoaded($event)" cameraPosition="back"
5-
[detectionType]="detectorType" (detection)="onDetection($event)"></MLKitView>
6-
<Button row="1" height="40" text="Toggle Camera" (tap)="toggleCamera($event)"></Button>
7-
<Button row="2" height="40" text="Request Camera Permission" (tap)="requestPermission($event)"></Button>
8-
<Label row="3" [text]="'Detecting ' + detectorType"></Label>
9-
<Button row="4" height="40" text="Change Detector Type" (tap)="changeType($event)"></Button>
10-
<Label row="5" [text]="'isPaused : ' + isPaused"></Label>
11-
<Button row="6" height="40" text="Toggle Pause" (tap)="togglePause($event)"></Button>
12-
<Label row="7" [text]="'Torch On : ' + torchOn"></Label>
13-
<Button row="8" height="40" text="Toggle Torch" (tap)="toggleTorch($event)"></Button>
14-
<Button row="9" height="40" text="Process Still Image" (tap)="processStill($event)"></Button>
15-
</GridLayout>
16-
</StackLayout>
3+
<GridLayout rows="*,auto,auto,auto,auto,auto,auto,auto,auto,auto" height="100%">
4+
<MLKitView [torchOn]="torchOn" [pause]="isPaused" height="100%" rowSpan="3" (loaded)="onLoaded($event)" cameraPosition="back" [detectionType]="detectorType" (detection)="onDetection($event)"></MLKitView>
5+
<Button row="1" height="40" text="Toggle Camera" (tap)="toggleCamera($event)"></Button>
6+
<Button row="2" height="40" text="Request Camera Permission" (tap)="requestPermission($event)"></Button>
7+
<Label row="3" [text]="'Detecting ' + detectorType"></Label>
8+
<Button row="4" height="40" text="Change Detector Type" (tap)="changeType($event)"></Button>
9+
<Label row="5" [text]="'isPaused : ' + isPaused"></Label>
10+
<Button row="6" height="40" text="Toggle Pause" (tap)="togglePause($event)"></Button>
11+
<Label row="7" [text]="'Torch On : ' + torchOn"></Label>
12+
<Button row="8" height="40" text="Toggle Torch" (tap)="toggleTorch($event)"></Button>
13+
<Button row="9" height="40" text="Process Still Image" (tap)="processStill($event)"></Button>
14+
</GridLayout>
15+
</StackLayout>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ActionBar title="mlkit-custom-object-detection" class="action-bar"> </ActionBar>
2+
<StackLayout class="p-20">
3+
<ScrollView class="h-full">
4+
<StackLayout>
5+
<Button text="Test mlkit-custom-object-detection" (tap)="demoShared.testIt()" class="btn btn-primary"></Button>
6+
</StackLayout>
7+
</ScrollView>
8+
</StackLayout>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Component, NgZone } from '@angular/core';
2+
import { DemoSharedMlkitCustomObjectDetection } from '@demo/shared';
3+
import {} from '@nativescript/mlkit-custom-object-detection';
4+
5+
@Component({
6+
selector: 'demo-mlkit-custom-object-detection',
7+
templateUrl: 'mlkit-custom-object-detection.component.html',
8+
})
9+
export class MlkitCustomObjectDetectionComponent {
10+
demoShared: DemoSharedMlkitCustomObjectDetection;
11+
12+
constructor(private _ngZone: NgZone) {}
13+
14+
ngOnInit() {
15+
this.demoShared = new DemoSharedMlkitCustomObjectDetection();
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
3+
import { MlkitCustomObjectDetectionComponent } from './mlkit-custom-object-detection.component';
4+
5+
@NgModule({
6+
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: MlkitCustomObjectDetectionComponent }])],
7+
declarations: [MlkitCustomObjectDetectionComponent],
8+
schemas: [NO_ERRORS_SCHEMA],
9+
})
10+
export class MlkitCustomObjectDetectionModule {}

apps/demo-angular/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@nativescript/mlkit-text-recognition": ["packages/mlkit-text-recognition/index.ts"],
88
"@nativescript/mlkit-core": ["packages/mlkit-core/index.d.ts"],
99
"@nativescript/mlkit-core/angular": ["packages/mlkit-core/angular/index.ts"],
10+
"@nativescript/mlkit-custom-object-detection": ["../../packages/mlkit-custom-object-detection/index.d.ts"],
1011
"@nativescript/mlkit-barcode-scanning": ["packages/mlkit-barcode-scanning/index.ts"],
1112
"@nativescript/mlkit-face-detection": ["packages/mlkit-face-detection/index.ts"],
1213
"@nativescript/mlkit-image-labeling": ["packages/mlkit-image-labeling/index.ts"],

0 commit comments

Comments
 (0)