DecodedImage

Overview

To be used in conjunction with the ImageDecoder class.

This class represents decoded images. The objects can be queried for the text that was in the image, as well as any error that occurred while the image was being decoded. When the returned text is incorrect, there is a method that can be used to report it as bad. This can be used for sites like decaptcher.com, where refunds are given for incorrectly interpreted images.

getError

String getError ( )

Description

Gets any error message, or returns null if there was no error

Parameters

This method takes no parameters

Return Value

The error message returned

Error messages

  • OK Nothing went wrong
  • BALANCE_ERROR Insufficient funds with paid service
  • NETWORK_ERROR General network error (timeout, lost connection, server busy, etc...)
  • INVALID_LOGIN Credentials are invalid
  • GENERAL_ERROR General error, possibly image was bad or the site couldn't resolve it. See the error message for details
  • UNKNOWN Unknown error

Change Log

Version Description
5.5.29a Available in all editions.

Examples

Convert an image to text

 import com.screenscraper.util.images.*;

 // Assuming an ImageDecoder was created in a different location and saved in "IMAGE_DECODER"
 ImageDecoder decoder = session.getVariable("IMAGE_DECODER");
 DecodedImage result = decoder.decodeFile("someFile.jpg");

 if(result.wasError())
 {
   session.logWarn("Error converting image to text: " + result.getError());
 }
 else
 {
   session.log("Decoded Text: " + result.getResult());
 }

 // If the result was bad
 result.reportAsBad();

getResult

Object getResult ( )

Description

Gets the result from decoding the image. Most likely this will be a String, but each implementation could return a specific object type.

Parameters

This method takes no parameters

Return Value

The text extracted from the image, or null if there was an error

Change Log

Version Description
5.5.29a Available in all editions.

Examples

Convert and image to text

 import com.screenscraper.util.images.*;
 
 // Assuming an ImageDecoder was created in a different location and saved in "IMAGE_DECODER"
 ImageDecoder decoder = session.getVariable("IMAGE_DECODER");
 DecodedImage result = decoder.decodeFile("someFile.jpg");
 
 if(result.wasError())
 {
   session.logWarn("Error converting image to text: " + result.getError());
 }
 else
 {
   session.log("Decoded Text: " + result.getResult());
 }

 // If the result was bad
 result.reportAsBad();

reportAsBad

void reportAsBad ( )

Description

Handles an incorrectly resolved image. Some types of decoders won't have anything here

Parameters

This method takes no parameters

Return Value

This method returns void.

Change Log

Version Description
5.5.29a Available in all editions.

Examples

Convert and image to text

 import com.screenscraper.util.images.*;

 // Assuming an ImageDecoder was created in a different location and saved in "IMAGE_DECODER"
 ImageDecoder decoder = session.getVariable("IMAGE_DECODER");
 DecodedImage result = decoder.decodeFile("someFile.jpg");

 if(result.wasError())
 {
   session.logWarn("Error converting image to text: " + result.getError());
 }
 else
 {
   session.log("Decoded Text: " + result.getResult());
 }

 // If the result was bad
 result.reportAsBad();

wasError

String wasError ( )

Description

Returns true if there was an error, false otherwise. Also returns false if the image has not been resolved yet

Parameters

This method takes no parameters

Return Value

True if there was an error, false otherwise

Change Log

Version Description
5.5.29a Available in all editions.

Examples

Convert and image to text

 import com.screenscraper.util.images.*;

 // Assuming an ImageDecoder was created in a different location and saved in "IMAGE_DECODER"
 ImageDecoder decoder = session.getVariable("IMAGE_DECODER");
 DecodedImage result = decoder.decodeFile("someFile.jpg");

 if(result.wasError())
 {
   session.logWarn("Error converting image to text: " + result.getError());
 }
 else
 {
   session.log("Decoded Text: " + result.getResult());
 }

 // If the result was bad
 result.reportAsBad();