Tess4J: Invalid memory access

2,169 views
Skip to first unread message

Subramaniyan Suresh

unread,
Sep 2, 2018, 12:50:53 PM9/2/18
to tesseract-ocr

I am using Tess4J in my project to extract text from an image (Using Eclipse IDE). I am getting the following error when I try run the OCR. Any suggestion?  

Error: Exception in thread "main" java.lang.Error: Invalid memory access


Note: I have attached the image file which I've used 

My Code:


package tesseractTraining;


import java.io.File;

import net.sourceforge.tess4j.*;


public class TesseractMainRunner {

public static void main(String[] args) {

File imageFile = new File("E:\\Tesseract\\Test Images\\sample.png");

Tesseract instance = new Tesseract();

try {

instance.setDatapath("C:\\Program Files (x86)\\Tesseract-OCR\\tessdata");

instance.setLanguage("eng");

String result = instance.doOCR(imageFile);

System.out.println(result);

} catch (TesseractException e) {

System.err.println(e.getMessage());

}

imageFile.exists();

}


}


sample.png

Quan Nguyen

unread,
Sep 2, 2018, 2:52:14 PM9/2/18
to tesseract-ocr
I tested your sample image and confirmed the error. It looks like a bug in the routine that determines the image's bit depth. A new version will be released once a fix is worked out and committed.

Thank you for reporting.
Message has been deleted

Quan Nguyen

unread,
Sep 3, 2018, 11:20:35 AM9/3/18
to tesseract-ocr
The issue has been fixed in the latest releases published today.

Thanks.


On Sunday, September 2, 2018 at 11:50:53 AM UTC-5, Subramaniyan Suresh wrote:

Subramaniyan Suresh

unread,
Sep 3, 2018, 11:35:16 AM9/3/18
to tesser...@googlegroups.com
Thanks for your quick turnaround.

--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To post to this group, send email to tesser...@googlegroups.com.
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/a384bae2-9580-4066-a0f0-9d90eacc50fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rajith Kariyawsam

unread,
Feb 11, 2020, 3:30:45 AM2/11/20
to tesseract-ocr
Still, the same error occurred for me.

code: 

<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>4.3.1</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>

File imgFile = findElement(captchaimgIdPath).getScreenshotAs(OutputType.FILE);
String pth = "C:\\Users\\username\\Downloads\\capthca1\\testcap.png"; //src/main/resources
Thread.sleep(2000);
FileHandler.copy(imgFile, new File(pth));
Thread.sleep(2000);
Tesseract cptcha = new Tesseract();
cptcha.setDatapath(pth);
cptcha.setLanguage("eng");
String text = cptcha.doOCR(new File(pth));
System.out.println(text);

Quan Nguyen

unread,
Feb 12, 2020, 1:46:27 PM2/12/20
to tesseract-ocr
It looks like the datapath is set incorrectly. It should be set to tessdata folder.

Rajith Kariyawsam

unread,
Feb 12, 2020, 11:00:31 PM2/12/20
to tesseract-ocr
Hi Quan,
I didn't got wht do you mean by 'tessdata ' folder.
given pth is the copied image(png) location.  my image name is 'testcap.png'

as per the below line 

String pth = "C:\\Users\\username\\Downloads\\capthca1\\testcap.png";
FileHandler.copy(imgFile, new File(pth));


Appreciate it if you can further describe it, please.



Quan Nguyen

unread,
Feb 14, 2020, 11:41:43 PM2/14/20
to tesseract-ocr
cptcha.setDatapath(pth); <---- incorrect pth value

Rajith Kariyawsam

unread,
Feb 15, 2020, 8:52:36 AM2/15/20
to tesseract-ocr
Hi Quan,

'pth' is the image location in my PC. 
I verified it with debug mood too.
As I know image location should set to the 'Datapath.'

If the 'pth' is incorrect what should pass for that parameter. 

Realy helpful if you can further explain it to me, please ?

Rajith Kariyawsam

unread,
Feb 15, 2020, 9:14:09 AM2/15/20
to tesseract-ocr
Hi Quan,

I got the point. By the below video.
I miss download dependency.
https://www.youtube.com/watch?v=5DqW9KP-aQo&t=425s

And I will try that.
Thank you very much.

Quan Nguyen

unread,
Feb 15, 2020, 11:24:03 AM2/15/20
to tesseract-ocr
setDatapath should be set to the path to tessdata folder, which contains *.traineddata files. It's not the path to your image files.
Reply all
Reply to author
Forward
0 new messages