Unable to load library 'libtesseract302':Module cannot be found (Windows10) - java

We are trying to make software for a car parking system using image processing. We used OCR. We intend to use a webcam to obtain images of the license plate when the vehicle leaves and enters. We will then use the number to calculate the time spent inside the park and price tickets based on that.
This is my code:
import java.io.File;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract1;
import net.sourceforge.tess4j.TesseractException;
public class TestOCR {
public static void main(String[] args) {
File imageFile = new File("C:"+File.separator+"projects"+File.separator+"plate.tif");
//ITesseract instance = new Tesseract(); // JNA Interface Mapping
ITesseract instance = new Tesseract1(); // JNA Direct Mapping
try {
//String result = instance.doOCR(imageFile);
//stem.out.println(result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
When I run this, I get this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302': The specified module could not be found.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:145)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:188)
at com.sun.jna.Library$Handler.<init>(Library.java:123)
at com.sun.jna.Native.loadLibrary(Native.java:255)
at com.sun.jna.Native.loadLibrary(Native.java:241)
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at com.nadeem.app.ocr.TesseractExample.main(TesseractExample.java:16)
Initially we had a NoSuchFieldError and after using Maven to fix that we encountered this problem.

Basically this error would come either of below reasons
dll path are not specified properly. You can add in vm argument as below. -Djna.library.path=<folder_contains_dll>, This folder should have three dll files gsdll64.dll,liblept168.dll and libtesseract302.dll
You should have Visual C++ Redistributable for VS2012 installed. Windows 10 doesn't have this installed by default.
You may do below steps to start with
Install Visual C++ Redistributable for VS2012 if its not installed
Clone the project from https://github.com/mnadeem/ocr-tess4j-example
Import the maven project in eclipse
Run the Java class TesseractExample.java

Related

How to export Java JOGL GlueGen project in BlueJ?

I want to export my Java project to a standalone Jar or exe file. I use blueJ as an IDE and I use following libraries: GLOOP, JOGL and GlueGen (aswell as pi4j). Running the program in the IDE itself works flawlessly, however when I export the program as a .jar file and wrap it into an exe with Launch4j I get following error:
Catched IllegalArgumentException: No Jar name in <jar:file:/C:/Users/neche/Desktop/UfoSpiel.exe!/com/jogamp/common/os/Platform.class>, got <UfoSpiel.exe>, while TempJarCache.bootstrapNativeLib() of null (null + null)
Exception in thread "main" java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:454)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:59)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:90)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:328)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:390)
at com.jogamp.common.os.Platform$2.run(Platform.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:231)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:99)
at GLOOP.GLRenderer.<init>(GLRenderer.java:90)
at GLOOP.GLKamera.<init>(GLKamera.java:49)
at UfoSzene.main(UfoSzene.java:14)
I use the Operating system Windows 64bit and BLuej version 414
I have googled a lot but never found someone who had the same problem or used the same OS or IDE.
It would be amazing if anyone of you could help.
Here is the main thread code:
import GLOOP.*;
public class UfoSzene
{
public static void main(String[] args)
{
GLKamera kamera;
GLLicht licht;
GLBoden weltall;
UfoSpiel ufoSpiel = new UfoSpiel();
Punkte punkteStand = new Punkte();
weltall = new GLBoden("Weltall.jpg");
kamera = new GLKamera(800,800);
kamera.setzePosition(2000,3001,20);
kamera.setzeBlickpunkt(2000,0,0);
licht = new GLLicht();
ufoSpiel.start();
punkteStand.start();
}
}
Thanks in advance!

Error in reading Ubuntu 14.04 mouse event file (/dev/input/event3) with java programmig

I want to handle mouse event in Linux terminal via java programming. I wrote two program via c++ and java that they do same process.
when i use c++ programming to open and read file ("/dev/input/event3"-mouse event file), there is no problem while running executable file.
(Ubuntu 14.04 terminal and Ubuntu server 14.04 ---> no problem).
But when i used java programming to open and read the same file ,there is a problem while running executable result file "java -jar program.jar" in Ubuntu 14.04 "terminal". No error for opening file , but reading file make an error like this:
java.io.IOException: Invalid argument
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(Unknown Source)
at eventfileopen.m.main(m.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
But when i run the same jar file on Ubuntu server 14.04, there is no error and the program work perfectly.
How can I resolve the problem?(Problem = run the java program on Ubuntu 14.04 with no error.) I guess the problem is related to Ubuntu GUI and JDK,but no idea for resolving that.
My java program code:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
public class m {
public static void main(String[] args) {
File f = new File("/dev/input/event3");
FileInputStream is = null;
try {
is = new FileInputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte[] bytes = new byte[16];
while(true){
try
{
is.read(bytes);
} catch (IOException e)
{
e.printStackTrace(); //-------> error while run on Ubuntu 14.04 and no error on Ubuntu server
}
System.out.println(Arrays.toString(bytes));
}
}
}
Check that your buffer size is correct.
In recent Linux kernels size of input_event structure is dependent on many things, but mainly on cpu architecture. Here's its declaration:
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
On 32-bit systems it's very likely that your buffer size is accepted(16 bytes).
On 64-bit systems it's very likely that the buffer should be no less than 24 bytes. The reason is that timeval struct takes twice as much space(8 bytes more) than on 32-bit systems.
I haven't found a reliable way to get input_event struct size from Java and personally I use JNI for that.

UnsatsifiedLinkError on JSSC Serial Interface (Processing)

I'm using Proclipsing (processing in Eclipse) but am getting an error when I try and open a port (printing the serial list works fine). I have a feeling some sort of native library is not connected but I'm baffled as to how to do so in Eclipse (and where it link to).
Here's my code:
import processing.core.PApplet;
import processing.serial.Serial;
public class visualization extends PApplet {
public Serial usb = null;
public void setup() {
println(Serial.list());
println(Serial.list()[5]);
usb = new Serial(this, Serial.list()[5], 115200);
}
public void draw() {
}
}
and the error it throws is:
Exception in thread "Animation Thread" java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.openPort(Ljava/lang/String;Z)J
at jssc.SerialNativeInterface.openPort(Native Method)
at jssc.SerialPort.openPort(SerialPort.java:158)
at processing.serial.Serial.<init>(Unknown Source)
at processing.serial.Serial.<init>(Unknown Source)
at bioauthvisualization3.BioauthVisualization3.setup(BioauthVisualization3.java:15)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
at processing.core.PApplet.run(PApplet.java:2256)
at java.lang.Thread.run(Thread.java:745)
I ran into the same issue while setting up IntelliJ IDEA for development with Processing. But I imagine you can apply the same method in Proclipsing. The solution that worked for me was threefold.
I created a global library that contained the Processing and Serial libraries. In OS X the required jar files can be found in the directory /Applications/Processing.app/Contents/Java/ and /Applications/Processing.app/Contents/Java/modes/libraries/serial/library/. I added the following libraries: core.jar, serial.jarand jssc.jar.
Next I had to add the global library to my module dependencies.
The last step was to add the path to the native libraries to the VM options for the appletviewer: -Djava.library.path="/Applications/Processing.app/Contents/Java/modes/java/libraries/serial/library/macosx"
My guess is that Proclipsing does the first two steps for you but you have to add the native libraries to the vm options manually since these depend on the system you're working on. Hope that helps.
I derived the solution for step 3 from this forum entry.

Java NIO FIle path Issue 2 [duplicate]

I am using Java 7 File API. I wrote a class that is working fine on Ubuntu creating directories perfectly, but when I run same code on Windows then it is throwing error:
Exception in thread "main" java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute
at sun.nio.fs.WindowsSecurityDescriptor.fromAttribute(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.createDirectory(Unknown Source)
at java.nio.file.Files.createDirectory(Unknown Source)
at java.nio.file.Files.createAndCheckIsDirectory(Unknown Source)
at java.nio.file.Files.createDirectories(Unknown Source)
at com.cloudspoke.folder_permission.Folder.createFolder(Folder.java:27)
at com.cloudspoke.folder_permission.Main.main(Main.java:139)
My Folder class code is
package com.cloudspoke.folder_permission;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.UserPrincipal;
import java.util.Set;
public class Folder{
// attributes required for creating a Folder
private UserPrincipal owner;
private Path folder_name;
private FileAttribute<Set<PosixFilePermission>> attr;
public Folder(UserPrincipal owner,Path folder_name,FileAttribute<Set<PosixFilePermission>> attr){
this.owner=owner;
this.folder_name=folder_name;
this.attr=attr;
}
//invoking this method will create folders
public void createFolder(){
try {
//createDirectories function is used for overwriting existing folder instead of createDirectory() method
Files.createDirectories(folder_name, attr);
Files.setOwner(folder_name, owner);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("created Folder "+this.folder_name);
}
}
The error is coming from createFolder method of Folder.
How do I resolve this error?
You use PosixFilePermission which can be used only with operating systems which are compatibile with POSIX:
A file attribute view that provides a view of the file attributes commonly associated with files on file systems used by operating systems that implement the Portable Operating System Interface (POSIX) family of standards.
Operating systems that implement the POSIX family of standards commonly use file systems that have a file owner, group-owner, and related access permissions. This file attribute view provides read and write access to these attributes`
Windows unfortunatelly doesn't support POSIX file systems so this is why your code doesn't work. In order to create a directory in Windows you should use:
new File("/path/to/folder").mkdir();
The / will be automatically changed to \ in Windows. If you want to create the whole path at once you have to use mkdirs() method. More info: http://docs.oracle.com/javase/6/docs/api/java/io/File.html
In order to set file permissions in Windows you have to use setReadable(), setWritable() and setExecutable(). That are File class methods and set only file owner's permissions. Note that mentioned methods were added in Java 1.6. In older versions you would have to use (Windows version):
Runtime.getRuntime().exec("attrib -r myFile");

java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute on Windows

I am using Java 7 File API. I wrote a class that is working fine on Ubuntu creating directories perfectly, but when I run same code on Windows then it is throwing error:
Exception in thread "main" java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute
at sun.nio.fs.WindowsSecurityDescriptor.fromAttribute(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.createDirectory(Unknown Source)
at java.nio.file.Files.createDirectory(Unknown Source)
at java.nio.file.Files.createAndCheckIsDirectory(Unknown Source)
at java.nio.file.Files.createDirectories(Unknown Source)
at com.cloudspoke.folder_permission.Folder.createFolder(Folder.java:27)
at com.cloudspoke.folder_permission.Main.main(Main.java:139)
My Folder class code is
package com.cloudspoke.folder_permission;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.UserPrincipal;
import java.util.Set;
public class Folder{
// attributes required for creating a Folder
private UserPrincipal owner;
private Path folder_name;
private FileAttribute<Set<PosixFilePermission>> attr;
public Folder(UserPrincipal owner,Path folder_name,FileAttribute<Set<PosixFilePermission>> attr){
this.owner=owner;
this.folder_name=folder_name;
this.attr=attr;
}
//invoking this method will create folders
public void createFolder(){
try {
//createDirectories function is used for overwriting existing folder instead of createDirectory() method
Files.createDirectories(folder_name, attr);
Files.setOwner(folder_name, owner);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("created Folder "+this.folder_name);
}
}
The error is coming from createFolder method of Folder.
How do I resolve this error?
You use PosixFilePermission which can be used only with operating systems which are compatibile with POSIX:
A file attribute view that provides a view of the file attributes commonly associated with files on file systems used by operating systems that implement the Portable Operating System Interface (POSIX) family of standards.
Operating systems that implement the POSIX family of standards commonly use file systems that have a file owner, group-owner, and related access permissions. This file attribute view provides read and write access to these attributes`
Windows unfortunatelly doesn't support POSIX file systems so this is why your code doesn't work. In order to create a directory in Windows you should use:
new File("/path/to/folder").mkdir();
The / will be automatically changed to \ in Windows. If you want to create the whole path at once you have to use mkdirs() method. More info: http://docs.oracle.com/javase/6/docs/api/java/io/File.html
In order to set file permissions in Windows you have to use setReadable(), setWritable() and setExecutable(). That are File class methods and set only file owner's permissions. Note that mentioned methods were added in Java 1.6. In older versions you would have to use (Windows version):
Runtime.getRuntime().exec("attrib -r myFile");

Categories