Unable to Run Sample Code

  • 2.6K Views
  • Last Post 13 February 2013
naz posted this 10 February 2013

I am trying to evalute ABBYY but every time I get this exception

Exception in thread "main" java.lang.Exception: Error: Invalid task state
at com.abbyy.ocrsdk.Client.getResponse(Client.java:297)
at com.abbyy.ocrsdk.Client.processDocument(Client.java:62)
at TestApp.main(TestApp.java:43)

I have modified only a couple of lines in TestApp.java

restClient = new Client();
// replace with 'https://cloud.ocrsdk.com' to enable secure connection
restClient.serverUrl = "http://cloud.ocrsdk.com";
restClient.applicationId = ClientSettings.APPLICATION_ID;
restClient.password = ClientSettings.PASSWORD;

/* ******************************************Modifications **************************/
File filePath = new File("C:\\Users\\nali\\Desktop\\Tiff Image\\New Image.JPG");
restClient.submitImage(filePath.getAbsolutePath(), null);

ProcessingSettings settings = new ProcessingSettings();
settings.setOutputFormat(OutputFormat.txt);
Task task = restClient.processImage(filePath.getAbsolutePath(), settings);
Task task1 = null;
do{
 task1 = restClient.processDocument(task.Id, settings);
}
while(!task1.Status.equals("Completed"));

System.out.print("What should do with the task");

Vector<String> argList = new Vector<String>(Arrays.asList(args));"

Order By: Standard | Newest | Votes
Dmitry Me posted this 11 February 2013

There're several problems in your code.

First, this loop

do{
 task1 = restClient.processDocument(task.Id, settings);

} while(!task1.Status.equals("Completed"));

has no delay in the body. This loop will slam into our service several times per second. Our Developer Agreement contains a clause against abuse. No delay -> abuse clause -> you're banned.

Second, the code makes absolutely no sense. Yes, I mean exactly that. This loop

do{
 task1 = restClient.processDocument(task.Id, settings);
}

asks our service to reprocess the same task over and over again and your code never cares of the processing result. That makes no sense.

The Java sample we ship illustrates all the main concepts of using our service.

naz posted this 12 February 2013

Dear Dmitry.

thanks for the reply. The supplied Java code does not illustrates how to Process a sample or any Image. Even the API documentation present on ABBYY's website is not enough. There is not any running simple application. That can show a simple thing: This is the sample image and this is the output. This is your custom image and this is the output.

The reason I have used do while loop in the code, I was trying to figure out the problem. What I understand is :

1) Submit an image to the ABBY's server. File filePath = new File("C:\Users\nali\Desktop\Tiff Image\testImage.PNG"); restClient.submitImage(filePath.getAbsolutePath(), null);

2) The Abbyy's server will make a task for this image, process the image and return the result. ProcessingSettings settings = new ProcessingSettings(); settings.setOutputFormat(OutputFormat.txt); Task task = restClient.processImage(filePath.getAbsolutePath(), settings);

but I am not receiving any result. The task status is "Processing" for three times "responseCode == 200" and on third turn it returns "Respond Code 450", and the message is "Invalid task state".

Could you please provide a simple sample code or any proper documentation(I have already view API documentation) ?

Dmitry Me posted this 12 February 2013

This is the most concise thing for what you want I could have expected https://github.com/abbyysdk/ocrsdk.com/blob/55a662b0ee2ae1e13b3358b085d1fd4344ca8817/Java/Abbyy.Ocrsdk.client/src/TestApp.java#L150 The bottom line is you don't call processImage in a loop because it makes no sense.

naz posted this 12 February 2013

Dear Dmitry. One question please. Is ".tif" format supported by cloud ocr. I am getting "Unsupported Image file formate exception message"

Dmitry Me posted this 13 February 2013

Close