I try to do OCR and output as PDF using Tess4J and the following code on Linux (Ubuntu 16 Xenial).
public void testOcr() throws Exception {
File imageFile = new File("/projects/de.conradt.core/tessdata/urkunde.jpg");
ITesseract instance = new Tesseract1(); // tried both Tesseract() and Tesseract1()
// File tessDataFolder = LoadLibs.extractTessResources("tessdata"); // Maven build bundles English data
// instance.setDatapath(tessDataFolder.getParent());
instance.setDatapath("/projects/de.conradt.core/tessdata");
instance.setLanguage("deu");
try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
List<ITesseract.RenderedFormat> list = new ArrayList<ITesseract.RenderedFormat>();
list.add(ITesseract.RenderedFormat.PDF);
File pdfFile = new File("/projects/de.conradt.core/tessdata/urkunde.pdf");
instance.createDocuments(pdfFile.getAbsolutePath(), "/projects/de.conradt.core/tessdata/urkunde", list);
}
The last line
instance.createDocuments(pdfFile.getAbsolutePath(), "/projects/de.conradt.core/tessdata/urkunde", list);
throws an Exception:
11:03:12.651 [http-nio-8080-exec-1] ERROR net.sourceforge.tess4j.Tesseract - Invalid calling convention 63
java.lang.IllegalArgumentException: Invalid calling convention 63
at com.sun.jna.Native.createNativeCallback(Native Method)
at com.sun.jna.CallbackReference.<init>(CallbackReference.java:239)
at com.sun.jna.CallbackReference.getFunctionPointer(CallbackReference.java:413)
at com.sun.jna.CallbackReference.getFunctionPointer(CallbackReference.java:395)
at com.sun.jna.Function.convertArgument(Function.java:541)
at com.sun.jna.Function.invoke(Function.java:305)
at com.sun.jna.Library$Handler.invoke(Library.java:236)
at com.sun.proxy.$Proxy89.gsapi_set_stdio(Unknown Source)
at org.ghost4j.Ghostscript.initialize(Ghostscript.java:323)
at net.sourceforge.tess4j.util.PdfUtilities.convertPdf2Png(PdfUtilities.java:103)
at net.sourceforge.tess4j.util.PdfUtilities.convertPdf2Tiff(PdfUtilities.java:48)
at net.sourceforge.tess4j.Tesseract.createDocuments(Tesseract.java:535)
at net.sourceforge.tess4j.Tesseract.createDocuments(Tesseract.java:507)
at de.conradt.core.Example.testOcr(Example.java:62)
at de.conradt.core.Example.ocr(Example.java:35)
I found this to be a known (but supposedly closed) issue with Tess4J:
https://github.com/nguyenq/tess4j/issues/35
https://sourceforge.net/p/tess4j/discussion/1202294/thread/2a25344c/
https://github.com/zippy1978/ghost4j/issues/44
but I checked my versions as well as the TESSDATA_PREFIX env variable. It's all set correctly as far as I can see.
Tesseract and Leptonica version:
$ /usr/bin/tesseract --version
tesseract 3.04.01
leptonica-1.73
libgif 5.1.2 : libjpeg 8d (libjpeg-turbo 1.4.2) : libpng 1.2.54 : libtiff 4.0.6 : zlib 1.2.8 : libwebp 0.4.4 : libopenjp2 2.1.0
Ghostscript version: (this is the latest version I get via apt-get)
$ ghostscript -v
GPL Ghostscript 9.18 (2015-10-05)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
Tess4j version:
3.2.1
and the TESSDATA_PREFIX (the config files etc. are under /projects/de.conradt.core/tessdata):
$ echo $TESSDATA_PREFIX
/projects/de.conradt.core
Looking at the Release log of Tess4j: http://tess4j.sourceforge.net/changelog.html, I should be using the correct version stack.
Especially version 3.2 in the change log says:
Version 3.2 - 15 May 2016: Revert JNA to 4.1.0 due to "Invalid calling
convention 63" errors invoking GhostScript via Ghost4J on Linux
so I thought I should be safe with 3.2.1.
Do I need to manually set anything about JNA? From my understanding, this had been fixed in 3.2.0 for Linux explicitly.
Ok, I didn't explicitly reference JNA anywhere in my project pom, I thought this is all done in Tess4J 3.2.1 and its pom.xml. I added JNA 4.1.0 as a dependency in my own pom.xml now as well and this seems to solve the problem.
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.1.0</version>
</dependency>
Related
I have written a programm in C and GTK3. I am using Arch Linux and everything works fine. However, I have to use my program also on a rather old Ubuntu machine.
gtk+-3.0 3.10.8
GCC 4.8.4
With this setup the program does not compile
In the Header file of a custom GTK-Widget I have:
#ifndef __LAYER_ELEMENT_H__
#define __LAYER_ELEMENT_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE(LayerElement, layer_element, LAYER, ELEMENT, GtkListBoxRow)
/* Rest of file comes here */
When compiling it throws the error message:
expected ')' before GtkListBoxRow in the line with the G_DECLARE_FINAL_TYPE macro.
How can I fix this issue?
G_DECLARE_FINAL_TYPE was added to GLib in version 2.44 (see the documentation). If you want to compile on an old version of Ubuntu, you will either have to get hold of a backport of GLib 2.44 (or later) for that version of Ubuntu, and compile against that; or you will have to modify your code to not use any GLib APIs added after version 2.40.
Converting VB code from XNA 3.1 to MonoGame.
Any attempt to access class GraphicsAdapter throws the exception below. For example, trying to enumerate GraphicsAdapters. On this line:
For Each adapter As GraphicsAdapter In GraphicsAdapter.Adapters
Result is an exception:
System.TypeInitializationException occurred
HResult=-2146233036
Message=The type initializer for 'Microsoft.Xna.Framework.Graphics.GraphicsAdapter' threw an exception.
Source=MonoGame.Framework
TypeName=Microsoft.Xna.Framework.Graphics.GraphicsAdapter
StackTrace:
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.get_Adapters()
at ...my code...
InnerException:
HResult=-2146233054
Message=Could not load type 'SharpDX.Rectangle' from assembly 'SharpDX, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1'.
Source=MonoGame.Framework
TypeName=SharpDX.Rectangle
StackTrace:
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.CreateAdapter(Adapter1 device, Output monitor)
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.PlatformInitializeAdapters(ReadOnlyCollection`1& adapters)
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter..cctor()
Note the inner exception:
Could not load type 'SharpDX.Rectangle' from assembly 'SharpDX, ...Version=4.0.1.0, ...
The project references these assemblies (among others):
MonoGame.Framework version=3.6.0.1625
from NuGet "MonoGame.Framework.WindowsDX", file
packages\MonoGame.Framework.WindowsDX.3.6.0.1625\lib\net40\MonoGame.Framework.dll
SharpDX version=4.0.1.0
SharpDX.Direct2D1 version=4.0.1.0
SharpDX.Direct3D9 version=4.0.1.0
SharpDX.DXGI version=4.0.1.0
SharpDX.Mathematics version=4.0.1.0
So I don't see why it would fail this way.
What could be wrong? Not compatible with this SharpDX version?
NOTE: These are all up-to-date packages from NuGet, in Visual Studio 2015. Targeting .Net 4.5.2.
UPDATE
To prove it isn't a problem with SharpDX, I put this line before that GraphicsAdapter line:
Dim testRect As SharpDX.Rectangle = New Rectangle()
This successfully created testRect. No Exception until attempt to access GraphicsAdapter. Also tried all the other Shared (static) properties of GraphicsAdapter, such as GraphicsAdapter.DefaultDevice. Any one fails with same exception.
I posted the same question to MonoGame forums:
http://community.monogame.net/t/solved-typeinitializationexception-accessing-graphicsadapter-adapters-could-not-load-type-sharpdx-rectangle/9803
Cause of problem:
Current release of MonoGame.Framework for WindowsDX (Windows OS + DirectX drivers), 3.6.0.1625 is built against SharpDX 2.6.3, and is not compatible with more recent SharpDX versions.
(Interim) Solution:
The developer branch of MonoGame does target the current SharpDX. Builds can be obtained from MonoGame's teamcity (free registration required).
Tested MonoGame.Framework build 3.7.0.994; it worked with SharpDX 4.0.1:
http://teamcity.monogame.net/viewLog.html?buildId=56483&tab=artifacts&buildTypeId=MonoGame_PackagingWindows
That build installs most SharpDX dlls to
C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows
However, SharpDX.Mathematics.dll is currently missing,
so I still install SharpDX from NuGet, rather than using those.
Standard location for MonoGame releases:
(look for at least 3.7, which is not there yet, as I write this):
http://www.monogame.net/downloads/
(If instead of NuGet packages for MonoGame and SharpDX, I had downloaded MonoGame 3.6 installer and used its version of SharpDX dlls at C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows, then I would not have had this incompatibility. However, that was not recent enough SharpDX for my purposes. This should be resolved by release of MonoGame 3.7)
I trying to use the j2pkcs11.dll (packaged with jdk1.8.0 - 64bit) to access certificates stored on a smartcard but not unable to make it work.
--- sample code to add the SunPKCS11 provider dynamically ---
String pkcs11ConfigSettings = "name = " + "TestSmartCard" + "\n" + "library = " + "C:/jdk1.8.0_11/jre/bin/j2pkcs11.dll";
byte[] pkcs11ConfigBytes = pkcs11ConfigSettings.getBytes();
ByteArrayInputStream confStream = new ByteArrayInputStream(pkcs11ConfigBytes);
Provider p = new sun.security.pkcs11.SunPKCS11(confStream);
---- the exception I get ---
java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
at scpoc.SmartCard.main(SmartCard.java:28)
Caused by: java.io.IOException: The specified procedure could not be found.
at sun.security.pkcs11.wrapper.PKCS11.connect(Native Method)
at sun.security.pkcs11.wrapper.PKCS11.<init>(PKCS11.java:138)
at sun.security.pkcs11.wrapper.PKCS11.getInstance(PKCS11.java:151)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:313)
JEP 131 claims to have PKCS11 support in Java 8 (http://openjdk.java.net/jeps/131) but I have not been able to get it to work on windows 7 using the java8 64-bit. Note: I also tried the java 8 32-bit on windows 7 - but no luck either.
Has anyone had any success using the SunPKCS11 provider with java 8 (Windows 7)?
SunPKCS11 provider is present only in 32-bit Windows version of JRE up until JRE7. Since JRE8 it is present also in 64-bit Windows version of JRE. This is the information you see in JEP131.
If you need to use PKCS#11 API in 64-bit Windows version of JRE older than JRE8 then you will have to use one of alternative 3rd party implementations - such as IAIK-JCE.
I have also noticed in your code sample that you are trying to directly use "j2pkcs11.dll" as a PKCS#11 library which is wrong because it is just a JNI wrapper sitting between JRE and the library implementing PKCS#11 interface. Instead of loading "j2pkcs11.dll" you need to load PKCS#11 library provided by your smartcard or HSM vendor.
I cannot get Eclipse, Statet, and R to work together. I receive an error when I launch R:
Launching the R Console was cancelled, because it seems starting the R engine failed.
Please make sure that R package 'rj' (2.0 or compatible) is installed and that the R library paths are set correctly for the R environment configuration 'R test'.
I have installed Eclipse Luna (64 bit), Statet, Java 1.8.0_25 (64bit) and R 3.1.2 (64bit). I am running on windows 7 (64bit). As required I installed the packages "rj" and "rj.gd" using:
install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-2.0")
It installed fine:
packageDescription("rj")
Encoding: UTF-8
Package: rj
Version: 2.0.2-1
Title: RJ - R Package for high-level Java-R library RJ
Author: Stephan Wahlbrink, Tobias Verbeke, low-level R binding based on the JRI library by Simon Urbanek
Maintainer: Stephan Wahlbrink <stephan.wahlbrink#walware.de>
Depends: R (>= 2.11.0)
Suggests: rj.gd
SystemRequirements: java
Description: Server implementation and R functions for the high-level Java-R library RJ. The package also includes callback functions for StatET. It is shipped with an adapted version of the JRI library. The package can be used only when R was loaded via RJ.
License: LGPL (>= 2.1)
URL: http://www.walware.de/goto/opensource
Packaged: 2014-07-11 15:43:15 UTC; build
Built: R 3.1.1; x86_64-w64-mingw32; 2014-07-11 15:47:59 UTC; windows
-- File: c:/~/R/win-library/3.1/rj/Meta/package.rds
I made sure that the library path is correct. I am a bit at a loss, how to proceed.
thanks for the help.
Christoph
Whilst digging around in the R-environment configuration (Run -> Run configurations... -> R config -> Configure), I tried something which worked:
Instead of specifying the user library link under "R_LIBS_USER", add an entry under "R_LIBS_SITE".
It works fine after that.
(I would have included visual pointers, but no rep)
I set R_LIBS_USER to the /library/ folder in the R environment and it worked fine.
I am using Modelsim ALTERA STARTER EDITION 10.1d and am importing a waveform file but am getting the following error.
The WLF file version is 132.Modelsim 10.1d can read up to and including WLF file version 121.
I have tried importing the same file into Modelsim 13.1 and am still receiving similar problems. If anybody knows what version of Modelsim I need to open this file version your help would be most appreciated. Thanks!
It looks like the version number is the fourth byte in the WLF header (121 = 0x79). I manually edited a version 121 file to bump up this field and got the same version warning you are seeing. Your version 132 file should have 0x84 in its fourth byte. You could manually edit the file to reduce its version and hope the format is otherwise compatible with the older version of Modelsim but there are no guarantees.