my tess4j in java with a error "Failed loading language 'osd'" - tesseract

public static void main(String[] args) throws TesseractException {
ITesseract instance = new Tesseract();
instance.setLanguage("osd");
instance.setDatapath("/usr/local/Cellar/tesseract/3.04.01_1/share/");
String tent = instance.doOCR(new File("/Users/qwf/Desktop/111.jpg"));
System.out.println(tent);
}
when i run the code ,there is 2 error:
Failed loading language 'osd'
Tesseract couldn't load any languages!
i don't konw how tess4j find there is any languages can be use
and when i run the "tesseract --list-langs" in iterm
the result is "eng osd"
i think the tesseract works well but why tess4j don't work
i have set the TESSDATA_PREFIX environment variable
echo $TESSDATA_PREFIX
output : /Users/qwf/tessdata/3.04.01_1/
i install tessdata by homebrew

Wrong order: set the datapath before the language.
instance.setDatapath("/usr/local/Cellar/tesseract/3.04.01_1/share/");
instance.setLanguage("osd");

Related

Problem when I am running java code in the terminal in vs code

public class Main {
public static void main(String[] args) {
// System.out.println("Hello");
int a = 5,b=6;
int c = a+b;
System.out.println(c);
}
}
When I am running this code in vscode I am getting my desired result i.e. 11 but with that I am getting a huge address of a file in my local computer . Can somebody explain the reason behind that?
The output I am getting :-
k:; cd 'k:\JavaBasics'; & 'C:\Program Files\Java\jdk-11.0.10\New Folder\bin\java.exe' '-cp' 'C:\Users\khushal\AppData\Roaming\Code\User\workspaceStorage\a6084cec5acdec0bc4f5c4be0d94ed8a\redhat.java\jdt_ws\JavaBasics_22fbb3a7\bin' 'Main'
11
I am only expecting 11 but why the address of that file
That's the actual command that sending to the terminal. If you do not want to see them, you can update the setting java.debug.settings.console to internalConsole.
Note: If your program needs to consume user input, you still needs to use the integrated terminal. Internal console will not work for that case.

Tesseract couldn't load any languages! java.lang.Error: Invalid memory access

I have upgraded the tess4j libraries from 3.4.8 to 4.3.0. Since then I am getting the below error :
"Error opening data file .src/img/tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
java.lang.Error: Invalid memory access
I have already set the environment variable and provided the path to the tessdata directory.
String processImage(String imageFileName){
File imageFile = new File(getImagePath()+imageFileName)
Tesseract process = new Tesseract()
process.setDatapath(".src/img/tessdata");
//process and extract
try {
String outputText = process.doOCR(imageFile)
//System.out.println("\n"+outputText)
return outputText
} catch (TesseractException e) {
return imageFile.toString()+" Unable to process image file"
}
}
How can this error be resolved. I have followed many solutions already in Stackoverflow, none seem to work. Any help on this would be highly appreciated

Could not load file or assembly(dll file path+name) or one of its dependencies. An attempt was made to load a program with an incorrect format

When trying to perform-
Import-Module 'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'
through program, I am receiving below error:
Could not load file or assembly 'file:///C:\Program Files\Nimble
Storage\bin\Nimble.Powershell.dll' or one of its dependencies. An
attempt was made to load a program with an incorrect format.
The same works when ran directly from Powershell but in the above case, facing issue.
C# program used and have used statement:
Collection< PSObject > resultCollection = runspaceInvoke.Invoke("Import-Module 'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'", null, out errors);
EBGreen is right. Need to see your code bro. In absence of that, something like the following should work:
using System.Management.Automation;
using System.Management.Automation.Runspaces;
class foo {
static void Main(string[] args) {
InitialSessionState initial = InitialSessionState.CreateDefault();
initial.ImportPSModule(new string[] {"'C:\\Program Files\\Nimble Storage\\bin\\Nimble.Powershell.dll'"} );
...
}
}
Check out Creating an InitialSessionState for more information.

NoClassDefFoundError when running HelloWorld.class

Im getting this error when I try to run HelloWorld.class
From this it looks like it's trying to run HelloWorld/class. The program should simply print out HelloWorld!.
package threads;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Any ideas?
Check your classpath: Select Start > Control Panel > System > Advanced > Environment Variables > System Variables > CLASSPATH.
You can make a new variable there OR in the command prompt type: SET CLASSPATH=.;C:\Program Files\Java\jdk-10.0.2(or whatever version you are using)\bin.
Type: cd C:\Users\David\Desktop\eclipse\JNP\bin\threads
this is your DIRECTORY NOT your CLASSPATH
Type: javac HelloWorld.java
a class file named HelloWorld.CLASS should appear in the threads folder.
Type: java HelloWorld
Also make sure you have named the file HelloWorld.java
I hope this helped!

The driver executable does not exist: C:\geckodriver.exe issue in Eclipse IDE

Please help me with this issue that is recurring every time I run my code.
I have extracted Geckodriver files in C Drive but when I run my code, the error that comes up is 'Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\geckodriver.exe'.
My code is given below:
package Basics;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Browserinvocation {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();//FirefoxDriver class is used to implement methods present in Webdriver-Invocation of browser
driver.get("https://www.amazon.in/");// Get method to hit the url in browser
}
}
Error in console :
Exception in thread "main" java.lang.IllegalStateException: The driver
executable does not exist: C:\geckodriver.exe at
com.google.common.base.Preconditions.checkState(Preconditions.java:534)
at
org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131)
at
org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at
org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:141)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at
org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:158)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at Basics.Browserinvocation.main(Browserinvocation.java:13)
Above exception occurs whenever Precondition does not find path of relevant driver mentioned in System.setProperty() method by any reason like below:
if path mentioned have different/wrong/single slashes.
Driver file itself is not present at mentioned location.
If path is mentioned in properties file or config file with double quotes.
Just check once before execution.
You should add the path to geckodriver.exe using / rather than \\. Change your line
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
to the following
System.setProperty("webdriver.gecko.driver","C:/geckodriver.exe");
Your code is running at my side, might be you are not extracting the gecko driver.
Change the path and try it once, it should worked
Please let me know selenium jars version and your firefox browser version
System.setProperty("webdriver.gecko.driver", "C:/Users/sankalp.gupta/Desktop/JAVASEL/geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.amazon.in");
System.out.println(driver.getCurrentUrl());
driver.close();
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
Here remove . in between gecko and driver
Just download geckodriver.exe and move it to drive C: