Invalid memory access Exception while extracting text using tes4j - java

I am extracting text from image pdf using Tes4j.
There are two steps involved here:
1)convert pdf to image:
PdfUtilities.convertPdf2Png(inputfilepath);
This works without any issues.
2)extract text from image:
try {
if(imgName.endsWith(".png")){
ITesseract instance = new Tesseract();
instance.setDatapath("tessdataPath");
extractedData= instance.doOCR(Image);
}
catch(Exception e2){
System.out.println("exception:"+e2.getMessage());
}
}
}
While doing this I get below exception for specific image file.
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokePointer(Native Method)
at com.sun.jna.Function.invokePointer(Function.java:470)
at com.sun.jna.Function.invoke(Function.java:404)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at com.sun.proxy.$Proxy1.TessBaseAPIGetUTF8Text(Unknown Source)
at net.sourceforge.tess4j.Tesseract.getOCRText(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.tcs.textExtraction.ImgToText.imagetoText(ImgToText.java:109)
at com.tcs.textExtraction.ImgToText.main(ImgToText.java:31)
split_pt >0 && split_pt < word->chopped_word->NumBlobs():Error:Assert failed:in file ..\..\ccmain\tfacepp.cpp, line 186
I have included following jars:
jna.jar,log4j-1.2.17.jar,pdfbox-1.8.13.jar,tess4j.jar,commons-logging-1.1.3.jar,fontbox-1.8.13.jar,ghost4j-0.5.1.jar,itext-2.1.7.jar,jai_imageio.jar
my tessdata has following files:
pdf.ttf,pdf.ttx,eng.traineddata,osd.traineddata

Related

get path file from webinf folder in ZUL ZK 3.6

how i can get real path of file.xml from web-inf in ZUL, i try this:
org.zkoss.zrss.RssFeed feed;
org.zkoss.zrss.RssBinder binder = new org.zkoss.zrss.RssBinder();
try {
feed = binder.lookUpFeed(new File("/WEB-INF/lesscoutsBeRss.xml").toURI().toURL().toString());
} catch (Exception e) {
e.getStackTrace();
}
but i have problem ,I think the problem because of the bad good recovery path
Failed to load /MainPage/rss_lesscouts.zul
Cause: Null Pointer in Method Invocation
java.lang.NullPointerException: Null Pointer in Method Invocation
at bsh.Name.invokeMethod(Unknown Source)
at bsh.BSHMethodInvocation.eval(Unknown Source)
at bsh.BSHPrimarySuffix.doSuffix(Unknown Source)
at bsh.BSHPrimaryExpression.eval(Unknown Source)
at bsh.BSHPrimaryExpression.eval(Unknown Source)
at bsh.BSHVariableDeclarator.eval(Unknown Source)
at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
...
You may try to use this, in order to retrieve the full path of WEB-INF folder in a ZK project:
Sessions.getCurrent().getWebApp().getRealPath("")+"/WEB-INF/"
Hope this helps you.

java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder

Summary:
When I try loading a DLL and the language in my computer is set to a non-latin based language (such as Korean), I get the error java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder
If you can help me figure out how to avoid this error, I'd appreciate any help.
I am trying to load a Native DLL Library using:
Native.loadLibrary
But I keep getting these errors:
java.lang.NoClassDefFoundError: java.nio.file.FileSystems$DefaultFileSystemHolder
at java.nio.file.FileSystems.<unknown>(Unknown Source)
at java.io.File.toPath(Unknown Source)
at sun.security.provider.SeedGenerator$1.run(Unknown Source)
at sun.security.provider.SeedGenerator$1.<unknown>(Unknown Source)
at java.security.AccessController.<unknown>(Unknown Source)
at sun.security.provider.SeedGenerator.getSystemEntropy(Unknown Source)
at sun.security.provider.SecureRandom$SeederHolder.<clinit>(Unknown Source)
at sun.security.provider.SecureRandom$SeederHolder.access$100(Unknown Source)
at sun.security.provider.SecureRandom.engineNextBytes(Unknown Source)
at java.security.SecureRandom.nextBytes(Unknown Source)
at java.security.SecureRandom.next(Unknown Source)
at java.util.Random.nextLong(Unknown Source)
at java.io.File$TempDirectory.generateFile(Unknown Source)
at java.io.File.createTempFile(Unknown Source)
at com.sun.jna.Native.extractFromResourcePath(Native.java:839)
at com.sun.jna.Native.loadNativeLibraryFromJar(Native.java:751)
at com.sun.jna.Native.loadNativeLibrary(Native.java:737)
at com.sun.jna.Native.<clinit>(Native.java:129)
at com.sun.jna.Native.loadLibrary(RefProp.java:246)
I only get this error when I set my language in my computer to Korean (or any other non-Latin language). When I have it as English, I don't have the error.
By the way, I have set the character encoding as UTF-8:
This code:
Charset charset = Charset.defaultCharset();
System.out.println("Character Set: " + charset.displayName());
Gives this result:
Character Set: UTF-8
So I know the encoding is not the problem.
I've read through:
http://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html
OSGi noClassDefFound for java.nio.files.FileSystems$DefaultFileSystemHolder
- Doesn't seem to apply because the error is slightly different.

How to set image using javafx

I got an error while using this code to set an image.
Also I put my image in src folder. I tried another ways but nothing worked for me.
Code:
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Clock extends Application{
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage ps) throws Exception {
ps.setTitle("Analog Clock");
ps.show();
StackPane pane = new StackPane();
pane.setAlignment(Pos.CENTER);
ImageView image = new ImageView(new Image(getClass().getResourceAsStream("analog.png")));
pane.getChildren().add(image);
//Image img = new Image("analog.png");
// ImageView iv1 = new ImageView();
// iv1.setImage(img);
Scene scene = new Scene(pane);
below are errors Every time I run the code.
Error:
Exception in Application start method
java.lang.reflect.InvocationTargetException
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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/14845382.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Input stream must not be null
at javafx.scene.image.Image.validateInputStream(Unknown Source)
at javafx.scene.image.Image.<init>(Unknown Source)
at Clock.start(Clock.java:26)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$53/2934105.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/18503843.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/19884472.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/2180324.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/3326003.run(Unknown Source)
... 1 more
Exception running application Clock
Help me to solve this issue.
thanks
Your InputStream is null. you should know that if your Image file is in your source folder then you should direct it to it. right click on your image and select copy qualified name and use that for example
i have a folder in my src folder-(package) called files and my image file is default_profile_icon.png, then i will use this code
new Image("/files/default_profile_icon.png",160,160,false,true)
the first parameter is what you look at, hope you get it now.
i do not know where your image is located,hence this answer
Caused by: java.lang.NullPointerException: Input stream must not be null
...
at Clock.start(Clock.java:26)
You've got a NPE at line 26, which is the following line of code:
ImageView image = new ImageView(new Image(getClass().getResourceAsStream("analog.png")));
The culprit is likely the reference to
analog.png. The system is failing to read the file from the location you're providing and getResourceAsStream() is returning a null value.
You can further determine this by breaking the line up as:
InputStream inStream = getClass().getResourceAsStream("analog.png");
Image imageObject = new Image(inStream);
ImageView image = new ImageView(imageObject);
and confirm which line number is referenced by the new stack trace when you run Clock.
Confirm your file analog.png is accessible or correct the path / location of your image file along the path. The rules for using getResourceAsStream() properly when it is returning null are summarized in this Stack Overflow Question.

Exception while trying to load openNLP POS models

I have been trying to use POS Models for POS tagging, but while loading the Models I get the following exception, and this happens for both maxent as well as perceptron models:
java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(Unknown Source)
at java.util.zip.InflaterInputStream.read(Unknown Source)
at java.util.zip.ZipInputStream.read(Unknown Source)
at java.io.DataInputStream.readFully(Unknown Source)
at java.io.DataInputStream.readLong(Unknown Source)
at java.io.DataInputStream.readDouble(Unknown Source)
at opennlp.model.BinaryFileDataReader.readDouble(BinaryFileDataReader.java:53)
at opennlp.model.AbstractModelReader.readDouble(AbstractModelReader.java:75)
at opennlp.model.AbstractModelReader.getParameters(AbstractModelReader.java:146)
at opennlp.perceptron.PerceptronModelReader.constructModel(PerceptronModelReader.java:69)
at opennlp.model.GenericModelReader.constructModel(GenericModelReader.java:59)
at opennlp.model.AbstractModelReader.getModel(AbstractModelReader.java:87)
at opennlp.tools.util.model.GenericModelSerializer.create(GenericModelSerializer.java:35)
at opennlp.tools.util.model.GenericModelSerializer.create(GenericModelSerializer.java:31)
at opennlp.tools.util.model.BaseModel.loadModel(BaseModel.java:231)
at opennlp.tools.util.model.BaseModel.(BaseModel.java:190)
at opennlp.tools.postag.POSModel.(POSModel.java:86)
at nlpcheck.NlpPOC.POSTag(NlpPOC.java:54)
at nlpcheck.NlpPOC.main(NlpPOC.java:86)
I have tried loading the tokenizaton model (en-token.bin) and Its loading and working fine.
Following is java snippet that I am using to load Model:
InputStream is = new FileInputStream(MODEL_PATH);
POSModel model = new POSModel(is);
I have downloaded the models (en-pos-perceptron.bin, en-pos-maxent.bin) from http://www.opennlp.org/models-1.5/.
It turns out the model file hosted on site mentioned above were corrupt, I was trying a different tool namely GATE(General architecture for Text Engineering) which was using the same model files so I copied them and put them on build path and it worked.

Double click on jar (netbeans built) and nothing happens. Write java -jar from prompt get null pointer exc

I'm quite new to java, so i'm sorry if i'm not noticing some mistake i made.
As the title said, when i build a project which is perfectly running on Netbeans 7.2.1 and then double click on the jar file, nothing happens.
Checking on the web i read it was suggested, in order to spot errors better, to go to the command prompt and write:
java -jar C:\Users\conserva\Documents\NetBeansProjects\EasyText\dist\EasyText.jar
It'gives me this:
C:\>java -jar C:\Users\conserva\Documents\NetBeansProjects\EasyText\dist\EasyText.jar
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at easytext.MainWindow.<init>(MainWindow.java:25)
at easytext.MainWindow$4.run(MainWindow.java:220)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
This is the part of code where line 25 is:
public MainWindow() {
initComponents();
selectfolder.removeAllItems();
String tempordir = ("src/easytext/textfiles/");
String[] arr = new java.io.File(tempordir).list();
/*line 25 */ int len = arr.length;
//System.out.println("arr.lenght รจ: "+arr.length);
for (int i = 0; i<len; ++i){
selectfolder.addItem(arr[i]);}
selecttext.removeAllItems();
tempordir = ("src/easytext/textfiles/"+selectfolder.getSelectedItem().toString());
arr = new java.io.File(tempordir).list();
for (int i = 0; i<len; ++i){
selecttext.addItem(arr[i]);}
GetText("src/easytext/textfiles/"+selectfolder.getSelectedItem().toString()+"/"+selecttext.getSelectedItem().toString());
}
So it looks like the nullpointerecxeption is thrown as i refer to the lenght of len array.
How can i solve this?
Thanks in advance, and sorry once again if i made some dumb mistake or didn't see something clear. I'm really spending some time on this without getting to a solution.
From the documentation of File.list():
An array of strings naming the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
So it sounds like the directory src/easytext/textfiles/ probably doesn't exist from where you're executing the code.

Categories

Resources