tess4j version 4.0.0-SNAPSHOT. Invalid memory access, when I set oem to 2 or 3. - tesseract

The TESSDATA_PREFIX is set to the parent folder of the tessdata folder of the commandline tesseract 4.0.0 (C:\Program Files (x86)\Tesseract-OCR). The commandline tesseract produces reasonable output in all four OCR Engine Modes.
Here is my code:
package tessTest;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.tess4j.*;
import net.sourceforge.tess4j.ITesseract.RenderedFormat;
public class MainClass {
public static void main(String[] argv) {
ITesseract instance = new Tesseract1();
List<RenderedFormat> formats = new ArrayList<RenderedFormat>();
formats.add(RenderedFormat.PDF);
try {
instance.setPageSegMode(1);
instance.setOcrEngineMode(2);
instance.setTessVariable("textonly_pdf", "1");
instance.createDocuments("D:\\Documents\\Malverne.jpeg",
"D:\\Documents\\testOCR", formats);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
}
With setOcrEngineMode(1) or setOcrEngineMode(0) it produces the pdf as expected. With setOcrEngineMode(2) and setOcrEngineMode(3) it results in the following error:
Exception in thread "main" java.lang.Error: Invalid memory access
at net.sourceforge.tess4j.TessAPI1.TessBaseAPIProcessPages(Native Method)
at net.sourceforge.tess4j.Tesseract1.createDocuments(Tesseract1.java:542)
at net.sourceforge.tess4j.Tesseract1.createDocuments(Tesseract1.java:517)
at net.sourceforge.tess4j.Tesseract1.createDocuments(Tesseract1.java:484)
at tessTest.MainClass.main(MainClass.java:21)
Detected 358 diacritics
contains_unichar_id(unichar_id):Error:Assert failed:in file
c:\projects\github\tesseract-ocr\ccutil\unicharset.h, line 513
It seems to be an issue with this particular image since on other images OEM 2 works fine from tess4j 4.0.0. I am aware that preprocessing the image will probably help, but I am working on a project where regularily many thousands of pictures, only some of which are similar to this one, will have to be OCRed by users so tailored preprocessing on a case-by-case-basis is infeasible.
The image in question is this one:
http://malvernetheatre.org/wp-content/uploads/2012/07/Malverne-Community-Theatre-Newspaper-Reviews-14-page-0.jpg
Any help would be greatly appreciated. Many thanks in advance.

Related

How to compile documents and run Jshop2 in Eclipse?

I am a student who begin to study SHOP2 from China.
My teacher told me to run JSHOP2 in Eclipse.Now I can run original zenotravel problem and generate GUI and plans.Likewise, I want to put other domain and problems to SHOP2 and produce plans.
But the problem is that I don't know how to compile them and My teacher only asked me to run the the main function in Internaldomain but it can't succeed.Follow is the original code:
public static void main(String[] args) throws Exception
{
//compile();
// compile(args);
//-- run the planning algorithm
run(args);
}
This code can run zenotravel.Then I put domain and problems named pfile1 and
tdepots respectively into SHOP2 folder.Change the codes to:
{
compile(domaintdepots);
// compile(args);
//-- run the planning algorithm
run(args);
}
It warns "domainpdfiles cannot be resolved to a variable".
Or
//--compile();
compile(args);
//-- run the planning algorithm
//run(args);
It turns out:
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at JSHOP2.InternalDomain.compile(InternalDomain.java:748)
at JSHOP2.InternalDomain.main(InternalDomain.java:720)"
720 is main funcition above.And 748 is compile function:
public static void compile(String[] args) throws Exception
{
//-- The number of solution plans to be returned.
int planNo = -1;
//-- Handle the number of solution plans the user wants to be returned.
if (args.length == 2 || args[0].substring(0, 2).equals("-r")) {
if (args[0].equals("-r"))
planNo = 1;
else if (args[0].equals("-ra"))
planNo = Integer.MAX_VALUE;
else try {
planNo = Integer.parseInt(args[0].substring(2));
} catch (NumberFormatException e) {
}
}
Finally,according to the advice of the friend,I put the two pddls into src folder and use “java Jshop2.InternalDomain domaintdepots”in CMD commad but an error appeared:"the main class Interdomain can't be found or loaded".But I have set the class path accurately and the Zenotravel planning can run.So how
and where can I use the command ?
And what is written in the bracket"compile()" in Eclipse?
I am also not familiar with JAVA so it's better if there is concrete instruction.Thanks a lot.
Please describe what are you trying to build, what is it supposed to do, what is the expected end result.
If you do have a valid PDDL domain and problem file, you could try to load them into the online http://editor.planning.domains/ editor using the File > Load menu. Then press the Solve button and confirm which of the file is the domain and which is problem. If the PDDL model is valid (and the underlying solver can handle the requirements), you will get a plan back.
If you are trying to build a software solution that needs a PDDL-based planning engine as one of its component, perhaps you could use one of the available implementations: https://nergmada.github.io/pddl-reference/guide/whatisplanner.html#list-of-planners
If you are trying to build your own planning engine in Java using the Eclipse IDE, you probably need a Java-based PDDL parser. Here is a tutorial, how to use pddl4j for that purpose:
https://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner
If you need to use Jshop2 in particular, it looks from their documentation (http://www.cs.umd.edu/projects/shop/description.html) that you need to indeed compile the domain and problem PDDL into Java code using following commands:
java JSHOP2.InternalDomain domainFileName
java JSHOP2.InternalDomain -r problemFileName
Edited on June 19th
Java package names (e.g. JSHOP2) and class names (InternalDomain) are case sensitive, so make sure you type them as per the documentation. That is probably why you are getting the "main class not found error".
It is difficult to say what the lines numbers 748 and 720 exactly correspond to, because in the GitHub repo https://github.com/mas-group/jshop2/blob/master/src/JSHOP2/InternalDomain.java the code is different from yours. Can you indicate in your questions which lines those are exactly?
The make file shows how to execute an out-of-the-box example in the distribution:
cd examples\blocks
java JSHOP2.InternalDomain blocks
java JSHOP2.InternalDomain -r problem300
Does that work for you?

Error: Could not find or load main class

When I run my program this says:
Error: Could not find or load main class Hello world
Every setting I did several times but I get the same result.
Win 8.1 64 bit
Path settings ok
eclipse jre setting ok
public class newproject1
{
public static void main(String[] args) {
System.out.println("Hello World! ");
}
}
Error: Could not find or load main class newproject1
I would guess that your Hello world class does not have a main method defined. The format is:
public static void main(String[] args)
{
//in here you put what you want the program to do
System.out.println("Hello World");
}
Today I just got "Error: Could not find or load main class" in Eclipse indigo. I don't know if your problem is the same or not. In my case my project code was a backup of the original and I named the backup folder as "x86 31 mayıs yedek". "mayıs" is turkish word and there are generally problems associated with turkish characters and their language settings in software. "ı" in the this word is special character in turkish language.
Simply, I removed the project from the eclipse, I changed the backup folder's name by removing any extra character which is not in english. Then I imported the project again, rebuild it and It worked. Hope this helps.
I had the same problem and after trying some different ways, finally solve my problem by setting again the workspace!
File-> Switch workspace-> other
and set it again!

'xxx' cannot be resolved (String, Scanner etc.) after importing files

I took a backup of my workspace. Meanwhile I created another workspace in my pc after formatting for temprory purposes. So now I've imported everything from my hard disk to my pc from File -> Import. However nothing seems to be 'resolved'. Heres an example of the code:
package com.sarthak.main;
import java.util.Scanner;
public class Myfirstgame {
public static void main(String[] args) {
System.out.println("Welcome to Momo Land, a place full of horror and utter momoness ");
System.out.println("Enter Your Name: ");
Scanner input = new Scanner(System.in);
String name=input.nextLine();
MyGame game=new MyGame(name);
game.run();
}
}
Things like System.out.println , input game.run etc. can't be resolved for some reason.
Check if your Java libraries are referenced in the properties of your project. In most cases, it is the referencing problem when importing projects.
Create a new project and then just copy the code inside the files..This may solve your problem.

call MATLAB in Java via MatlabControl.java

Recently I am trying to write a java application that can execute matlab code but faced some problems.
First of all, I refer to the link: http://www.cs.virginia.edu/~whitehouse/matlab/JavaMatlab.html
It has some tips to execute matlab code under java application. I included the MatlabControl.java as well as jmi.jar, following the steps it gives.
but when I try to test just a piece of simple code as follows
package jmat;
public class MainProgram {
public static void main(String[] args) {
MatlabControl mc = new MatlabControl();
mc.eval(new String("x=5;"));
}
}
the console outputed the error as follows
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.mathworks.jmi.NativeMatlab.PostMatlabRunnable(JZ)V
at com.mathworks.jmi.NativeMatlab.PostMatlabRunnable(Native Method)
at com.mathworks.jmi.NativeMatlab.postMatlabRunnable(NativeMatlab.java:399)
at com.mathworks.jmi.MatlabLooper.postMatlabRunnable(MatlabLooper.java:178)
at com.mathworks.jmi.Matlab.whenMatlabReady(Matlab.java:1404)
at jmat.MatlabControl.eval(MatlabControl.java:88)
at jmat.MainProgram.main(MainProgram.java:8)
I have no idea why it failed in my program, does any one can help me?
MATLAB version: R2009b
OS: Win7 32bits
Actually, you will need more than just MatlabControl.java in order to use Matlabcontrol. I'm assuming you picked up the source file from Option #3 in the link; that's just how options #1 and #2 work inside.
Go to that link that you posted and look at Option #1. Go to the link posted there, http://matlabcontrol.googlecode.com and click on Downloads. The first jar, matlabcontrol-4.1.0.jar is the one you want.
Download that and include it in the build path of your project. Then follow the walkthrough guides that are posted online. Let me know if you have any additional questions.

ZXing-1.7 Sample implementation issue

I recently started a small project in which I wanted to use zxing. I downloaded the sources from here. I was able to successfully build the core and the javase jars.
When I tried to code along the sample provided here I ran into a problem I do not quite understand. So far the code looks like this:
public static void main(String[] args)
{
Reader reader = new MultiFormatReader();
ImageIcon imageIcon = new ImageIcon(SOMEPATH);
Image image = imageIcon.getImage();
BufferedImage buffImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImage.createGraphics();
g.drawImage(image, null, null);
LuminanceSource source = new BufferedImageLuminanceSource(buffImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
}
As you can see this is pretty much the same code as presented in the DevelopersNotes. But the code will not compile. The error message is:
Type mismatch: cannot convert from BufferedImageLuminanceSource to LuminanceSource
Does somebody know what I am missing?
Edit:
My imports are currently looking like this:
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Reader;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
I added the core.jar as well as the javase.jar to my project. Both I compiled using ant leaving the buildfiles as downloaded.
That's all correct. You must have some funny business in your imports. Those types are certainly compatible.