我正在使用Eclipse开发java应用程序,使用Asprise Library从图像中识别文本。在我的maven项目POM.xml文件中,我已经包含了这个依赖项
<dependency>
<groupId>com.asprise.ocr</groupId>
<artifactId>java-ocr-api</artifactId>
<version>15.3.0.3</version>
</dependency>
重要的jar文件已经下载到我的项目中,因为它可以在给定的图片中看到。如果我尝试制作一个Ocr对象,我会收到此错误。
Ocr cannot be resolved.
我是Eclipse中的maven新手。我不知道这有什么问题。我的完整代码显示在这里
package com.asprise;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import com.asprise.ocr.Ocr;
public class AspriseOCR {
static long startTime;
static long EndTime;
static double tPeriod;
static double ElapsedTime;
private static double totalTime = 0;
private static double correctImgs = 0;
static double averageTime = 0;
static double strMatch;
static double accuracy = 0;
public static void main(String[] args) {
try {
Ocr.setUp();
Ocr ocr = new Ocr();
ocr.startEngine("eng", Ocr.SPEED_FASTEST);
String groundTruthLine = "";
BufferedReader br = new BufferedReader(new FileReader("F:\\ground_truth.txt"));
int numOfImges = 100;
for (int i=1; i <=numOfImges; i++ )
{
System.out.println("\t\t\timg( " + i + ") \t\t\t" );
groundTruthLine = br.readLine();
String path2 = "F:\\img (" + i + ").png";
startTime = System.currentTimeMillis();
String recognizedText = ocr.recognize(new File[] {new File(path2)},
Ocr.RECOGNIZE_TYPE_TEXT, Ocr.OUTPUT_FORMAT_PLAINTEXT);
EndTime = System.currentTimeMillis();
tPeriod = EndTime - startTime;
ElapsedTime = tPeriod/1000.0;
matchString(groundTruthLine, recognizedText, ElapsedTime);
System.out.println();
System.out.println();
System.out.println("***************************************************************************");
}
br.close();
System.out.println("Average Time " + ElapsedTime/numOfImges);
System.out.println("Average Accuracy " + (accuracy/numOfImges));
ocr.stopEngine();
}catch(Exception e)
{
}
}
private static void matchString(String groundTruth, String result, double elapsedTime) {
String replacedText = result.replaceAll("\n", "");
int gTruthLenth = groundTruth.length();
int detectedText = replacedText.length();
if (detectedText > (gTruthLenth * 2)) {
replacedText = replacedText.substring(0, gTruthLenth * 2);
}
strMatch = StringMatchingViaEditDist(replacedText, groundTruth, replacedText.length(), groundTruth.length());
double imgAccuracy = ((groundTruth.length() - strMatch)/ groundTruth.length());
System.out.println("Ground Truth :: " + groundTruth);
System.out.println("Returned Text :: " + replacedText );
System.out.println("Match Found :: " + imgAccuracy);
totalTime += elapsedTime;
accuracy = accuracy + imgAccuracy;
}
private static int min(int x,int y,int z)
{
if (x<y && x<z) return x;
if (y<x && y<z) return y;
else return z;
}
static int StringMatchingViaEditDist(String str1 , String str2 , int m ,int n)
{
// If first string is empty, the only option is to
// insert all characters of second string into first
if (m == 0) return n;
// If second string is empty, the only option is to
// remove all characters of first string
if (n == 0) return m;
// If last characters of two strings are same, nothing
// much to do. Ignore last characters and get count for
// remaining strings.
if (str1.charAt(m-1) == str2.charAt(n-1))
return StringMatchingViaEditDist(str1, str2, m-1, n-1);
// If last characters are not same, consider all three
// operations on last character of first string, recursively
// compute minimum cost for all three operations and take
// minimum of three values.
return 1 + min ( StringMatchingViaEditDist(str1, str2, m, n-1), // Insert
StringMatchingViaEditDist(str1, str2, m-1, n), // Remove
StringMatchingViaEditDist(str1, str2, m-1, n-1) // Replace
);
}
}