【问题标题】:I am asking it to recognise the characters present in the image and we are asking to it to read the content and to store the content in a variable我要求它识别图像中存在的字符,我们要求它读取内容并将内容存储在变量中
【发布时间】:2018-10-05 12:40:07
【问题描述】:

我已经写了这段代码:

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");
}

我添加了 jars 作为 Maven 依赖项:

Java OCR API 15.3.0.1

java-client 6.1.0

出现如下编译错误:

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

OCR().Recog...OCR 无法解析为类型。

【问题讨论】:

  • 你们班的import 声明是什么?
  • 导入 java.awt.Image;导入 java.awt.image.RenderedImage;导入java.io.File;导入 java.net.MalformedURLException;导入 java.net.URL;导入 javax.imageio.ImageIO;导入 org.apache.commons.io.FileUtils;导入 org.openqa.selenium.OutputType;导入 org.openqa.selenium.TakesScreenshot;导入 org.openqa.selenium.WebElement;导入 org.openqa.selenium.remote.DesiredCapabilities;导入 io.appium.java_client.android.AndroidDriver;导入 io.appium.java_client.remote.MobileCapabilityType;
  • 新 ORC() 周围可能需要括号,例如。字符串 s = (new OCR()).recog
  • 您的导入语句都没有导入OCR 类。
  • 从 OP 的评论中添加了导入。格式化代码

标签: java selenium selenium-webdriver appium-android


【解决方案1】:

您没有包含 Ocr 类的导入(顺便注意小写字母)。在文件顶部附近添加:

 import com.asprise.ocr.Ocr;

并将类名更正为Ocr

【讨论】:

  • 谢谢你,Roman,但我习惯使用 import 语句,但显示方法未定义错误... String s = new Ocr().recognize(RenderedImage image, String identifyType,String outputFormat,object propSpec );
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
  • 2014-05-17
  • 1970-01-01
  • 1970-01-01
  • 2022-06-13
  • 1970-01-01
相关资源
最近更新 更多