【问题标题】:Nativescript core convert imageAsset into Imagesource ML kit and camera interfaceNativescript 核心将 imageAsset 转换为 Imagesource ML 套件和相机接口
【发布时间】:2018-11-29 09:18:49
【问题描述】:

我正在使用 Nativescript 核心和带有 nativescript-camera 插件的 firebase ML 套件进行文本识别的在线版本(我不知道是否有更好的插件)

目前我对这个活动有意见:

exports.onCapture = function () {
    if (camera.isAvailable()) {
        var options = { width: 300, height: 300, keepAspectRatio: false, saveToGallery: false};
        camera.takePicture(options)   
            .then(function (imageAsset) {
                getTextFromPhotoCloud("HOW TO CONVERT imageAsset TO IMAGESOURCE"); 
            }).catch(function (err) {
                console.log("Error -> " + err.message);
            });
    }
}

ml Kit 的代码:

function getTextFromPhotoCloud(imageSource) {
    var firebase = require("nativescript-plugin-firebase");

    firebase.mlkit.textrecognition.recognizeTextCloud({
        image: imageSource
    }).then(function (result) {
        console.log(result.text ? result.text : "");
    }).catch(function (errorMessage) {
        return console.log("ML Kit error: " + errorMessage);
    });
}

如何将相机响应转换为图像源格式(用于 ML 套件)而不将其保存在图库中?

有没有更好的插件或相机的东西?实际上,我必须启动相机应用程序、拍照并接受预览才能启动 ML 套件。可以在应用程序中更集成的东西(不需要为每张照片采取 3 个动作的东西)可以连接到 ML 套件的在线模式吗?像这样的代码,坚果使用云方法而不是实时:

<MLKitTextRecognition
    class="my-class"
    width="260"
    height="380"
    processEveryNthFrame="10"
    preferFrontCamera="false"
    [pause]="pause"
    [torchOn]="torchOn"
    (scanResult)="onTextRecognitionResult($event)">
</MLKitTextRecognition>

【问题讨论】:

    标签: javascript camera nativescript imagesource firebase-mlkit


    【解决方案1】:

    在图像源中使用fromAsset 方法。

    import { fromAsset } from "tns-core-modules/image-source"
    
    fromAsset(imageAsset).
       then((imageSource) => {
            .....
        });
    

    【讨论】:

    • 有了这个和 const source = new imageSourceModule.ImageSource(); source.fromAsset(imageAsset)... 完美。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 2022-07-19
    • 1970-01-01
    • 2014-12-03
    • 2017-03-26
    相关资源
    最近更新 更多