0

I am developing java application using Eclipse for text recognition from image using Asprise Library. In my maven project POM.xml file I have included this dependencies

<dependency>
    <groupId>com.asprise.ocr</groupId>
    <artifactId>java-ocr-api</artifactId>
    <version>15.3.0.3</version> 
</dependency>

The important jar files has already been downloaded to my project as it can be seen in the given picture. If i try to make an Ocr object i am getting this error.

Ocr cannot be resolved.

enter image description here

I am new to maven in Eclipse. I have no idea what is wrong in this. My complete code is shown here

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

}
  • Did you already just try `Project->Clean-> AspriseDemo` and/or maven-> update project / ALT+F5 with AspriseDemo selected? – pirho Oct 23 '17 at 18:51
  • Yes- i have already tried all this. non of them worked – Nasir Rahim Oct 23 '17 at 22:05
  • For me ocr dependency worked instantly. Tried to remove target manually? What is the import line error,, could not resolve? – pirho Oct 23 '17 at 22:07
  • Yeah i tried to remove the target directory manually also. I am still getting the same error. "The import com.asprise.ocr.Ocr cannot be resolved". I am using Eclipse Version Oxygen.1a Release (4.7.1a). I have no idea what is going wrong. The same code worked fine few days. now I am getting this error – Nasir Rahim Oct 24 '17 at 02:40

0 Answers0