ocr-我的图像在tesseract ocr中无法识别

时间:2017-05-09 02:47:59

标签: angularjs cordova ionic-framework ocr

你好我目前是Tesseract-ocr的新手,当我拍照时我想要识别我的图像..我使用离子框架来做到这一点..图像捕获很好但是当我点击按钮时ocr的功能它什么都不做..我只是按照https://github.com/gustavomazzoni/cordova-plugin-tesseract

中的文档

这是我的HTML

<ion-view view-title="OCR Testing">
    <ion-content padding="true">
        <button class="button button-block button-positive" ng-click="startOCR()">
            <i class="icon ion-ios-camera"></i> Scanbot OCR
        </button>
        <button class="button button-block button-positive" ng-click="scan()">
            <i class="icon ion-ios-camera"></i> Scan
        </button>
        <!--   <button class="button button-block button-positive" ng-if="currentDocumentImage.originalImageFileUri" ng-click="startCroppingUi()">
      <i class="icon ion-ios-crop-strong"></i> Scanbot Cropping UI
    </button>
 -->
        <!-- <img ng-if="currentDocumentImage.imageFileUri" src="{{currentDocumentImage.imageFileUri}}" class="img-big-thumbnail padding"> -->
        <img ng-if="image" src="{{image}}" class="img-big-thumbnail padding">
        <code>{{text}}</code>

    </ion-content>
    </ion-views>

这是我的控制器

.controller('ScanbotOCRCtrl', function($scope, $cordovaCamera, DemoImageStorage, PhotoLibrary) {

    $scope.startOCR = function() {

      $scope.imageData = '';

        var options = {
            quality: 90,
            destinationType: Camera.DestinationType.DATA_URL,
            sourceType: Camera.PictureSourceType.CAMERA,
            allowEdit: true,
            encodingType: Camera.EncodingType.JPEG,
            targetWidth: 500,
            targetHeight: 500,
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: false
                // correctOrientation: true
        };

        $cordovaCamera.getPicture(options).then(function(imageData) {
            $scope.image = "data:image/jpeg;base64," + imageData;
            $scope.text = null;

            $timeout(function() {
                // DOM has finished rendering
                // insert here the call to TesseractPlugin.recognizeText function to recognize the text
                $scope.imageData = $scope.image;

            });


        }, function(err) {
            // error
            console.log('ERROR with camera plugin. Error: ' + err);
        });

    };


    $scope.scan = function() {

        window.TesseractPlugin.recognizeText($scope.imageData, language, function(recognizedText) {
            $scope.text = recognizedText;
            alert(recognizedText);
        }, function(reason) {
            console.log('Error on recognizing text from image. ' + reason);
        });


    }

1 个答案:

答案 0 :(得分:0)

我有点晚了,但这是解决方案。

直接输入getPicture()函数返回的原始数据,即imagedata,而不添加&#34; data:image / jpeg; base64,&#34;在它之前。所以它变成了:

$cordovaCamera.getPicture(options).then(function(imageData) {
        $scope.image = "data:image/jpeg;base64," + imageData;
        $scope.text = null;
         //here, do it like this and feed it to tesseract
        $scope.imageData = imageData;
        });