locked
Using Microsoft OCR Library with JS/jQuery in VS 2013 RRS feed

  • Question

  • I am currently working on a windows 8.1 application and I am using web languages and mostly jQuery (Cordova type project) as it might be used on other platforms. I need to use the Microsoft OCR Library (not Tesseract or any other ones, I know them but I really need to use this one for now) in order to analyze image and use the extracted text in my application.

    I downloaded the JavaScript sample app from MSDN and I launched it : it is fully working (after installing the OCR plugin in VS 2013 of course).

    I am now trying to integrate the OCR engine in my application (I installed the OCR plugin in my project too) but it is not working at all. In fact, when I try to launch my app on my machine, the execution fails and returns me this error message :

    Unmanagable exception on line 11, column 5 in ms-appx://io.cordova.blankcordovaapp2/www/scripts/myscript.js

    0x800a1391 - JavaScript execution error : « WindowsPreview » is undefined"

    Here is the "buggy" portion of code (it is at the very beginning of my script) :

    $(document).ready(function () {
    
    "use strict";
    
    // Keep objects in-scope across the lifetime of the scenario.
    var FileToken = "";
    
    // Define namespace and API aliases.
    var FutureAccess = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList;
    
    // Should be initialising the OCR engine
    var OCR = WindowsPreview.Media.Ocr;
    var ocrEngine = new OCR.OcrEngine(OCR.OcrLanguage.french);
    document.addEventListener("deviceready", onDeviceReady, false);

    I tried to initialize the OCR engine the same way as it is done in the microsoft OCR sample. VS seems not to find WindowsPreview.Media.Ocr which should be, according to the official documentation :

    The Microsoft OCR Library for Windows Runtime contains the WindowsPreview.Media.Ocr namespace. The library is distributed as a NuGet package - it is not included in the Windows Software Development Kit (SDK).

    I did install the plugin in the project using the NuGet command line so I don't know why it isn't identified and can't be initialized.

    Thanks in advance for your help and don't hesitate to ask for further detail if I wasn't clear enough.





    Thursday, April 16, 2015 9:34 AM

All replies

  • Is there any chance you can share your project with us?  Upload to OneDrive and share it here.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, April 16, 2015 7:41 PM
    Moderator
  • Hello Matt

    Thank you for taking time to help me. Yes, of course, here is the link to the project on OneDrive (I zipped it so it's easier to manage) :

    https://onedrive.live.com/redir?resid=56fe3259eb25a8ad!107&authkey=!AMWCA7X8QKY5DQs&ithint=file%2czip

    I didn't comment the OCR engine initialization in the code, so you should be having the error I described above. Just comment these 2 lines if you want the project to work.

    I have installed the NuGet for NodeJS and as I said before, the Microsoft OCR one (plus the JQuery one but I don't think it makes much of a difference for the app).

    I hope to ear from you soon

    Friday, April 17, 2015 11:21 AM
  • I don't know anything about Cordova - how does this project work? It doesn't open in VS2013.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, April 20, 2015 4:58 PM
    Moderator
  • Oh, sorry about that, you need to download and install the VS tool for Apache Cordova.

    You can find it here : https://www.microsoft.com/en-us/download/details.aspx?id=42675

    After installing this package, you should be able to open the project in VS 2013

    Tuesday, April 21, 2015 7:03 AM