setDatapath should be set to the path to tessdata folder, which contains *.traineddata files. It's not the path to your image files.
On Saturday, February 15, 2020 at 8:14:09 AM UTC-6, Rajith Kariyawsam wrote: > > 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. > > On Saturday, February 15, 2020 at 7:22:36 PM UTC+5:30, Rajith Kariyawsam > wrote: >> >> 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 ? >> >> On Saturday, February 15, 2020 at 10:11:43 AM UTC+5:30, Quan Nguyen wrote: >>> >>> cptcha.setDatapath(pth); <---- incorrect pth value >>> >>> >>> On Wednesday, February 12, 2020 at 10:00:31 PM UTC-6, Rajith Kariyawsam >>> wrote: >>>> >>>> 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. >>>> >>>> >>>> >>>> On Thursday, February 13, 2020 at 12:16:27 AM UTC+5:30, Quan Nguyen >>>> wrote: >>>>> >>>>> It looks like the datapath is set incorrectly. It should be set to >>>>> tessdata folder. >>>>> >>>>> On Tuesday, February 11, 2020 at 2:30:45 AM UTC-6, Rajith Kariyawsam >>>>> wrote: >>>>>> >>>>>> 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); >>>>>> >>>>>> >>>>>> On Sunday, September 2, 2018 at 10:20:53 PM UTC+5:30, Subramaniyan >>>>>> Suresh wrote: >>>>>>> >>>>>>> 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(); >>>>>>> >>>>>>> } >>>>>>> >>>>>>> >>>>>>> } >>>>>>> >>>>>>> -- 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-ocr+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/0ddb242e-a56a-4804-a9bc-25731ce6273d%40googlegroups.com.