-3

I have written this code:

import java.awt.Image;
import java.awt.image.RenderedImage;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType; 

// class and method declaration omitted

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//store screenshot at a specidfied location
File targetFile=new File("C:\\Users\\Srujan\\eclipse-workspace\\Batch98Appium\\images\\kiran.png");
FileUtils.copyFile(scrFile,targetFile );
System.out.println(targetFile.toString());

// URL url1 = new URL(targetFile.toString());  
Image image = ImageIO.read(targetFile);         

// we are asking it to recognize the characers present in the image and we are asking to it to read the contnet and to store the content in a variable
String s = new OCR().recognizeCharacters((RenderedImage) image);  

//below cmd is simply printing the information
System.out.println("Text From Image : \n"+ s);  

if (s.contains("Monitored switch is on")) {
    System.out.println("toastr verified successfully");
} else {
    System.out.println("toastr not verified successfully");
}

I added jars as Maven dependencies:

Java OCR API 15.3.0.1

java-client 6.1.0

The following compile error appears:

String s = new OCR().recognizeCharacters((RenderedImage) image);

OCR().Recog...OCR cannot be resolved to a type.

Vladimir Vagaytsev
  • 2,871
  • 9
  • 33
  • 36
  • What are the `import` statements of your class ? – Arnaud Oct 05 '18 at 12:41
  • import java.awt.Image; import java.awt.image.RenderedImage; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import javax.imageio.ImageIO; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.remote.MobileCapabilityType; – mahendra seervi Oct 05 '18 at 12:49
  • Maybe brackets needed around new ORC() eg. String s = (new OCR()).recog – dank8 Oct 05 '18 at 13:02
  • 1
    None of your import statements imports an `OCR` class. – Arnaud Oct 05 '18 at 13:19
  • Added imports form the OP's comment. Formatted code – Vladimir Vagaytsev Oct 05 '18 at 18:10
  • What is with the subject of your post? Please have a read through [ask]. – SiKing Oct 05 '18 at 23:22

1 Answers1

0

You did not include the import for Ocr class (note the lower case letter by the way). Add this near the top of your file:

 import com.asprise.ocr.Ocr;

And correct the name of the class in to Ocr.

  • thank you, Roman, but I am used that is import statement but methods undefined error displaying... String s = new Ocr().recognize(RenderedImage image, String recognizeType,String outputFormat,object propSpec); – mahendra seervi Oct 09 '18 at 05:03