@@ -7,18 +7,18 @@ import { MLKitRecognizeTextResultBlock, MLKitRecognizeTextResultLine } from "./i
77export class MLKitTextRecognition extends MLKitTextRecognitionBase {
88 protected createDetector ( ) : any {
99 const firVision : FIRVision = FIRVision . vision ( ) ;
10- return firVision . textDetector ( ) ;
10+ return firVision . onDeviceTextRecognizer ( ) ;
1111 }
1212
1313 protected createSuccessListener ( ) : any {
14- return ( features : NSArray < FIRVisionText > , error : NSError ) => {
14+ return ( visionText : FIRVisionText , error : NSError ) => {
1515 if ( error !== null ) {
1616 console . log ( error . localizedDescription ) ;
17- } else if ( features !== null && features . count > 0 ) {
17+ } else if ( visionText !== null ) {
1818 this . notify ( {
1919 eventName : MLKitTextRecognition . scanResultEvent ,
2020 object : this ,
21- value : getOnDeviceResult ( features )
21+ value : getOnDeviceResult ( visionText )
2222 } ) ;
2323 }
2424 } ;
@@ -30,13 +30,14 @@ export class MLKitTextRecognition extends MLKitTextRecognitionBase {
3030
3131}
3232
33- function getOnDeviceResult ( features : NSArray < FIRVisionText > ) : MLKitRecognizeTextOnDeviceResult {
33+ function getOnDeviceResult ( visionText : FIRVisionText ) : MLKitRecognizeTextOnDeviceResult {
3434 const result = < MLKitRecognizeTextOnDeviceResult > {
35+ text : visionText . text ,
3536 blocks : [ ]
3637 } ;
3738
38- for ( let i = 0 , l = features . count ; i < l ; i ++ ) {
39- const feature = features . objectAtIndex ( i ) ;
39+ for ( let i = 0 , l = visionText . blocks . count ; i < l ; i ++ ) {
40+ const feature : FIRVisionTextBlock = visionText . blocks . objectAtIndex ( i ) ;
4041 const resultFeature = < MLKitRecognizeTextResultBlock > {
4142 text : feature . text ,
4243 bounds : feature . frame ,
@@ -59,13 +60,15 @@ function getOnDeviceResult(features: NSArray<FIRVisionText>): MLKitRecognizeText
5960 resultFeature . lines . push ( resultLine ) ;
6061 } ;
6162
63+ // TODO
6264 if ( feature instanceof FIRVisionTextBlock ) {
6365 const textBlock = < FIRVisionTextBlock > feature ;
6466 for ( let j = 0 , k = textBlock . lines . count ; j < k ; j ++ ) {
6567 addLineToResult ( textBlock . lines . objectAtIndex ( j ) ) ;
6668 }
6769 }
6870
71+ // TODO
6972 if ( feature instanceof FIRVisionTextLine ) {
7073 addLineToResult ( feature ) ;
7174 }
@@ -79,13 +82,13 @@ export function recognizeTextOnDevice(options: MLKitRecognizeTextOnDeviceOptions
7982 return new Promise ( ( resolve , reject ) => {
8083 try {
8184 const firVision : FIRVision = FIRVision . vision ( ) ;
82- const textDetector : FIRVisionTextDetector = firVision . textDetector ( ) ;
85+ const textDetector : FIRVisionTextRecognizer = firVision . onDeviceTextRecognizer ( ) ;
8386
84- textDetector . detectInImageCompletion ( getImage ( options ) , ( features : NSArray < FIRVisionText > , error : NSError ) => {
87+ textDetector . processImageCompletion ( getImage ( options ) , ( visionText : FIRVisionText , error : NSError ) => {
8588 if ( error !== null ) {
8689 reject ( error . localizedDescription ) ;
87- } else if ( features !== null ) {
88- resolve ( getOnDeviceResult ( features ) ) ;
90+ } else if ( visionText !== null ) {
91+ resolve ( getOnDeviceResult ( visionText ) ) ;
8992 }
9093 } ) ;
9194 } catch ( ex ) {
@@ -98,21 +101,21 @@ export function recognizeTextOnDevice(options: MLKitRecognizeTextOnDeviceOptions
98101export function recognizeTextCloud ( options : MLKitRecognizeTextCloudOptions ) : Promise < MLKitRecognizeTextCloudResult > {
99102 return new Promise ( ( resolve , reject ) => {
100103 try {
101- const fIRVisionCloudDetectorOptions = FIRVisionCloudDetectorOptions . new ( ) ;
102- fIRVisionCloudDetectorOptions . modelType = options . modelType === "latest" ? FIRVisionCloudModelType . Latest : FIRVisionCloudModelType . Stable ;
103- fIRVisionCloudDetectorOptions . maxResults = options . maxResults || 10 ;
104+ const fIRVisionCloudDetectorOptions = FIRVisionCloudTextRecognizerOptions . new ( ) ;
105+ fIRVisionCloudDetectorOptions . modelType = FIRVisionCloudTextModelType . Sparse ;
106+ // fIRVisionCloudDetectorOptions.modelType = options.modelType === "latest" ? FIRVisionCloudModelType.Latest : FIRVisionCloudModelType.Stable;
107+ // fIRVisionCloudDetectorOptions.maxResults = options.maxResults || 10;
104108
105109 const firVision : FIRVision = FIRVision . vision ( ) ;
106- const textDetector = firVision . cloudTextDetectorWithOptions ( fIRVisionCloudDetectorOptions ) ;
110+ const textDetector = firVision . cloudTextRecognizerWithOptions ( fIRVisionCloudDetectorOptions ) ;
107111
108- textDetector . detectInImageCompletion ( getImage ( options ) , ( cloudText : FIRVisionCloudText , error : NSError ) => {
109- console . log ( ">>> recognizeTextCloud error? " + error + ", cloudText ? " + cloudText ) ;
112+ textDetector . processImageCompletion ( getImage ( options ) , ( visionText : FIRVisionText , error : NSError ) => {
113+ console . log ( ">>> recognizeTextCloud error? " + error + ", visionText ? " + visionText ) ;
110114 if ( error !== null ) {
111115 reject ( error . localizedDescription ) ;
112- } else if ( cloudText !== null ) {
113- console . log ( ">>> recognizeTextCloud result: " + cloudText ) ;
116+ } else if ( visionText !== null ) {
114117 resolve ( {
115- text : cloudText . text
118+ text : visionText . text
116119 } ) ;
117120 } else {
118121 reject ( "Unknown error :'(" ) ;
0 commit comments