37

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.

daserge
  • 1,512
  • 12
  • 18
ColonelMoumou
  • 371
  • 2
  • 5
  • did you get this figured out? I see your post on MSDN that doesn't look like it got very far either. – Eonasdan Apr 21 '15 at 19:36
  • 1
    btw, I manually added a reference to `WindowsPreview.Media.Ocr.winmd` (from the package) and got `The specified module could not be found.` at `OcrEngine` – Eonasdan Apr 21 '15 at 20:30
  • 2
    Hello Eonasdan! No, I still didn't figured that out, but I am still working on it so I hope I will find the solution. It might help other people too so that would be great. But yes, as you can see, my post on MSDN still didn't got very far. – ColonelMoumou Apr 22 '15 at 07:55
  • 1
    Yes, I did the same with the winmd file located at Projects\'Myappname'\packages\Microsoft.Windows.Ocr.1.0.0\lib\win81\x64\WindowsPreview.Media.Ocr.winmd (plus the x86 one just in case), but it still doesn't work with a slighty different error message than the one you got. Mine seems like it can't find the WindowsPreview (the same error as the one I described before, which is weird as I added the reference...). – ColonelMoumou Apr 22 '15 at 08:05
  • 1
    Just curious - what's your platform - x86, x64 or ARM? – potatopeelings May 02 '15 at 12:03
  • 1
    I'm using x64. The reference is not getting added via the nuget package. Even MS's sample application doesn't work (at least not for me) – Eonasdan May 04 '15 at 13:16
  • @ColonelMoumou, does it make sense to use Cordova TACO project type if you use Windows-specific library? Is there a reason why you can't use WinJS universal project? – daserge Jan 10 '16 at 14:32

1 Answers1

3

This look like a VS Tools for Apache Cordova (TACO) issue.
As a workaround you can open platforms\windows\CordovaApp.sln, switch architecture to x64, add Nuget package to the CordovaApp.Windows project references, save (build will fail because of an issue in the PreBuild event:

<PreBuildEvent>
    cd /d $(MSBuildThisFileDirectory)
    node -e "require('C:\\Users\\{username}\\AppData\\Roaming\\npm\\node_modules\\vs-tac\\lib\\hooks.js').updateAppxManifest('C:\\ocrTest\\ocrTest\\platforms\\windows','C:\\ocrTest\\ocrTest\\platforms\\windows\\..\\..\\')"
</PreBuildEvent>

you can also try to temporarily clear it out to enable builds of the underlying projects).

Then open the parent Cordova project - it should work now.

This will work only for one architecture though so for ARM and Windows Phone you may need another copy (set CordovaApp.Phone as startup project, add Nuget package to it and switch to ARM).

Note: I was testing this on VS 2015 & Cordova Tools upd.1.

daserge
  • 1,512
  • 12
  • 18