This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
home.ts
84 lines (67 loc) · 2.22 KB
/
home.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { Component } from '@angular/core';
import { Camera, CameraOptions } from '@ionic-native/camera';
import { OpenALPR, OpenALPROptions, OpenALPRResult } from 'cordova-plugin-openalpr/native';
import { AlertController, ModalController, Platform } from 'ionic-angular';
import { ResultPage } from './../result/result';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
private cameraOptions: CameraOptions;
public scanOptions: OpenALPROptions;
constructor(private camera: Camera, private openALPR: OpenALPR, private alertCtrl: AlertController, private modalCtrl: ModalController, private platform: Platform) {
this.cameraOptions = {
quality: 80,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.scanOptions = {
country: this.openALPR.Country.EU,
amount: 3
}
}
/**
* Take picture and send it to OpenALPR
* @param input
*/
scan(input: string) {
this.cameraOptions.sourceType = input === 'camera' ? this.camera.PictureSourceType.CAMERA : this.camera.PictureSourceType.PHOTOLIBRARY;
this.camera.getPicture(this.cameraOptions)
.then((imageData) => {
this.openALPR.scan(imageData, this.scanOptions)
.then((result: [OpenALPRResult]) => {
if (result.length < 1) {
this.showError('No license plates found');
return;
}
const bestResult = result[0];
this.showResult(bestResult);
}).catch((error: Error) => console.error(error));
}).catch((error: Error) => console.error(error));
if (this.platform.is('ios')) {
this.camera.cleanup();
}
}
/**
* Show error using a popup
* @param text {string}
*/
showError(text: string) {
const alert = this.alertCtrl.create({
title: 'Error',
subTitle: text,
buttons: ['OK']
});
alert.present();
}
/**
* Show result using a popup
* @param result {OpenALPRResult}
*/
showResult(result: OpenALPRResult) {
const modal = this.modalCtrl.create(ResultPage, { licensePlate: result.number });
modal.present();
}
}