Я пытаюсь разработать приложение OCR с NativeScript JS и комплектом Firebase ML (на устройстве). Я выполнил шаги следующей страницы без проблем:
Плагин док:
https://market.nativescript.org/plugins/nativescript-plugin-firebase#start-up-wiring
но Когда я искал документацию по javascript для части распознавания текста, я нашел только версии машинописных текстов (я не знаю, как это сделать.
ML комплект документов:
https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/ML_KIT.md
У меня на home-page.xml следующий код:
<Page
navigatingTo="onNavigatingTo"
xmlns:FirebaseMLKitTextRecognition="nativescript-plugin-firebase/mlkit/textrecognition">
<FirebaseMLKitTextRecognition:MLKitTextRecognition
class="my-class"
width="260"
height="380"
processEveryNthFrame="3"
preferFrontCamera="false"
pause="{{ pause }}"
scanResult="onTextRecognitionResult" />
</Page>
Кажется, это работает. Я вижу, что камера на моем устройстве активирована в этом случае с этим кодом home-page.js:
const HomeViewModel = require("./home-view-model");
function onNavigatingTo(args) {
const page = args.object;
//TODO
page.bindingContext = new HomeViewModel();
}
exports.onNavigatingTo = onNavigatingTo;
Я нашел этот код в документе MLkit:
import { MLKitRecognizeTextResult } from "nativescript-plugin-firebase/mlkit/textrecognition";
const firebase = require("nativescript-plugin-firebase");
firebase.mlkit.textrecognition.recognizeTextOnDevice({
image: imageSource // a NativeScript Image or ImageSource, see the demo for examples
}).then((result: MLKitRecognizeTextResult) => { // just look at this type to see what else is returned
console.log(result.text ? result.text : "");
}).catch(errorMessage => console.log("ML Kit error: " + errorMessage));
но этот код напечатан и у меня есть ошибки:
Successfully synced application org.nativescript.gocr on device ECPBBCF741803200.
ActivityManager: Start proc 16965:org.nativescript.gocr/u0a149 for activity org.nativescript.gocr/com.tns.NativeScriptActivity
ActivityManager: ActivityManagerService,attachApplication,callingPid = 16965
ActivityManager: New app record ProcessRecord{f7395dd 16965:org.nativescript.gocr/u0a149} thread=android.os.BinderProxy@11ce5552 pid=16965
ActivityManager: getContentProviderImpl: from caller=android.app.ApplicationThreadProxy@22b46920 (pid=16965, userId=0) to get content provider settings cpr=ContentProviderRecord{35d191e9 u0 com.android.providers.settings/.SettingsProvider}
D/ActivityThread(16965): hoder:android.app.IActivityManager$ContentProviderHolder@23a23c91,provider,holder.Provider:android.content.ContentProviderProxy@3ae27f6
ActivityManager: getContentProviderImpl: from caller=android.app.ApplicationThreadProxy@dece411 (pid=16965, userId=0) to get content provider com.google.android.gms.phenotype cpr=ContentProviderRecord{16a60ce8 u0 com.google.android.gms/.phenotype.provider.ConfigurationProvider}
D/ActivityThread(16965): hoder:android.app.IActivityManager$ContentProviderHolder@2b62a1df,provider,holder.Provider:android.content.ContentProviderProxy@17cb0e2c
ActivityManager: publishContentProviders: from caller=android.app.ApplicationThreadProxy@11807976 (pid=16965)
JS: firebase.init done
System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.gocr/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
System.err: Calling js method onCreate failed
System.err: Error: Building UI from XML. @file:///app/app-root.xml:1:1
System.err: > Unexpected token {
System.err: File: "file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js, line: 244, column: 20
System.err: StackTrace:
System.err: Frame: function:'ScopeError', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/utils/debug.js', line: 63, column: 24
System.err: Frame: function:'SourceError', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/utils/debug.js', line: 74, column: 23
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 263, column: 17
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 244, column: 33
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/xml/xml.js', line: 148, column: 13
System.err: Frame: function:'EasySAXParser.parse', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/js-libs/easysax/easysax.js', line: 751, column: 23
System.err: Frame: function:'XmlParser.parse', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/xml/xml.js', line: 195, column: 22
System.err: Frame: function:'XmlStringParser.parse', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 250, column: 27
System.err: Frame: function:'parseInternal', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 212, column: 11
System.err: Frame: function:'loadInternal', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 117, column: 27
System.err: Frame: function:'loadPage', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 53, column: 27
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 72, column: 12
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 86, column: 20
System.err: Frame: function:'ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 899, column: 50
System.err: Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 751, column: 14
System.err: Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2641)
System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2721)
System.err: at android.app.ActivityThread.access$1200(ActivityThread.java:186)
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
System.err: at android.os.Handler.dispatchMessage(Handler.java:111)
System.err: at android.os.Looper.loop(Looper.java:194)
System.err: at android.app.ActivityThread.main(ActivityThread.java:5931)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at java.lang.reflect.Method.invoke(Method.java:372)
System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:987)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
System.err: Caused by: com.tns.NativeScriptException:
System.err: Calling js method onCreate failed
System.err: Error: Building UI from XML. @file:///app/app-root.xml:1:1
System.err: > Unexpected token {
System.err: File: "file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js, line: 244, column: 20
System.err: StackTrace:
System.err: Frame: function:'ScopeError', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/utils/debug.js', line: 63, column: 24
System.err: Frame: function:'SourceError', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/utils/debug.js', line: 74, column: 23
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 263, column: 17
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 244, column: 33
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/xml/xml.js', line: 148, column: 13
System.err: Frame: function:'EasySAXParser.parse', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/js-libs/easysax/easysax.js', line: 751, column: 23
System.err: Frame: function:'XmlParser.parse', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/xml/xml.js', line: 195, column: 22
System.err: Frame: function:'XmlStringParser.parse', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 250, column: 27
System.err: Frame: function:'parseInternal', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 212, column: 11
System.err: Frame: function:'loadInternal', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 117, column: 27
System.err: Frame: function:'loadPage', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 53, column: 27
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 72, column: 12
System.err: Frame: function:'', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 86, column: 20
System.err: Frame: function:'ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 899, column: 50
System.err: Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 751, column: 14
System.err: Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.gocr/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
System.err: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:983)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:967)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:959)
System.err: at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:18)
System.err: at android.app.Activity.performCreate(Activity.java:6151)
System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2588)
System.err: ... 10 more
ActivityManager: Process org.nativescript.gocr (pid 16965) has died
ActivityManager: SVC-handleAppDiedLocked: app = ProcessRecord{f7395dd 16965:org.nativescript.gocr/u0a149}, app.pid = 16965
ActivityManager: cleanUpApplicationRecord -- 16965
где я могу найти javascript версию этого? или как я могу преобразовать этот код в JavaScript? Возможно я что-то не так делаю?