本文介绍了使用Selenium和Java读取图像内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用硒罐和asprise jars读取图像内容,并在我的项目中的jar文件下面添加了它:

I want to read content of image using selenium and asprise jars and added below jar files in my project :

  • aocr.jar
  • AspriseOCR
  • aocr.jar
  • AspriseOCR

下面是我的代码:

          BufferedImage image = ImageIO.read(new File("C:\\Users\\siddhesh.kalgaonkar\\Desktop\\love.jpg"));
          String imageText = new OCR().recognizeCharacters((RenderedImage)image);
          System.out.println("Text From Image : \n"+ imageText);
          System.out.println("Length of total text : \n"+ imageText.length());   

,但出现以下错误:

java.lang.UnsatisfiedLinkError: no AspriseOCR in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at com.asprise.util.ocr.OCR.loadLibrary(OCR.java:247)
    at com.asprise.util.ocr.OCR.<init>(OCR.java:56)
    at com.image.selenium.ImageVerification.start(ImageVerification.java:52)  

我还尝试使用链接,但没有用.请帮助任何人.

I also tried setting java.library.path using this link but of no use. Please help anyone.

推荐答案

我对自己的问题有一个答案.现在,我们可以在以下信息的帮助下做到这一点:

I got an answer to my own question. We can now do it with the help of below information:

  • 将最新的aocr.jar添加到您的项目.从下载链接.

  • Add latest aocr.jar to your project. Download it from this link.

  • 在项目中包含 pom.xml 文件以获取Maven依赖关系,并添加此依赖关系:

  • Include pom.xml file in your project for maven dependencies and add this dependency :

    <dependency>
    <groupId>com.asprise.ocr</groupId>
    <artifactId>java-ocr-api</artifactId>
    <version>[15,)</version>
    </dependency>  

在您的java文件中编写以下代码:

Write below code in your java file :

public class ImageVerification  

{  
 WebDriver driver;    

    @Test
    public void start() throws IOException {

        Ocr ocr = new Ocr(); // create a new OCR engine
        ocr.startEngine("eng", Ocr.SPEED_FASTEST); // English

        String s = ocr.recognize(new File[] { new File("C:\\Users\\siddhesh.kalgaonkar\\Desktop\\love.jpg") },
                Ocr.RECOGNIZE_TYPE_TEXT, Ocr.OUTPUT_FORMAT_PLAINTEXT);
        System.out.println(s);
        ocr.stopEngine();
    }  

  • 有关更多详细信息,请参考链接
    享受:)
    注意:仅适用于纯文本图像.doesn't适用于具有图形格式饼图趋势图

  • For more details refer this link
    Enjoy :)
    NOTE: It works only for images with plain text.It doesn't work for images with data in graph format or pie chart or trend chart

    这篇关于使用Selenium和Java读取图像内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 11-01 19:25