Image OCR Scripts
An Image OCR script is used to convert an image into plain text. This is often used when a website uses a CAPTCHA page to block automated access to the website. A CAPTCHA page contains an image with numbers and characters that a user must recognize and enter in plain text. Some websites also display emails and phone numbers as images, and an Image OCR script can be used to convert those images into plain text, making the data more useful.
Sequentum Enterprise does not include any OCR functionality, so you must use a 3rd party OCR service. The Image OCR script is used to integrate with a 3rd party service.
An Image OCR script can be added to a Download Image command by selecting the OCR configuration tab and setting the option Convert image to text.
The following two examples show how to integrate with two popular CAPTCHA recognition services:
public static string ConvertImageToText(ConvertImageToTextArguments args)
{
string captcha = DeathByCaptchaService.DecodeCaptcha(args.Image, "login", "password");
return captcha;
}
The script above integrates with the 3rd party service http://www.deathbycaptcha.com:
public static string ConvertImageToText(ConvertImageToTextArguments args)
{
string captcha = BypassCaptchaService.DecodeCaptcha(args.Image, "key");
return captcha;
}
The script above integrates with the 3rd party service http://bypasscaptcha.com/
The Image OCR script must have a static function with the following signature:
public static string ConvertImageToText(ConvertImageToTextArguments args)
The function must return the converted image as a string.
An instance of the ConvertImageToTextArguments class is provided by Sequentum Enterprise and has the following functions and properties:
Property or Function | Description |
---|---|
byte[] Image | The image needs to be converted to text. |
Agent Agent | The current agent. |
ScriptUtils ScriptUtilities | A script utility class with helper methods. See Script Utilities for more information. |
Command Command | The current agent command being executed. |
IContainer ParentContainer | The parent container command of the current command. |
IConnection DatabaseConnection | The current internal database connection used by the agent. This connection is already open and should not be closed by your script. |
IHtmlNode HtmlNode | The extracted HTML node. |
IInternalDataRow DataRow | The current internal data row containing the data that has been extracted so far in the current container command. |
bool IsDebug | True if the agent is running in debug mode. |
bool IsSchemaOnly | If true, only the data schema is required, so you can optimize processing by only returning the data schema with no data. |
IInputData InputDataCache | All input data available to the current command. |
void WriteDebug(string debugMessage, DebugMessageType messageType = DebugMessageType.Information) | Writes log information to the agent log. This method has no effect if agent logging is disabled, or if called during design time. |
void WriteDebug(string debugMessage, bool showMessageInDesignMode, DebugMessageType messageType = DebugMessageType.Information) | Writes log information to the agent log. This method has no effect if agent logging is disabled, or if called during design time. |
void Notify(bool alwaysNotify) | Triggers notification at the end of an agent run. If alwaysNotify is set to false, this method only triggers a notification if the agent has been configured to send notifications on critical errors. |
void Notify(string message, bool alwaysNotify) | Triggers notification at the end of an agent run, and adds the message to the notification email. If alwaysNotify is set to false, this method only triggers a notification if the agent has been configured to send notifications on critical errors. |
GlobalDataDictionary GlobalData | Global data dictionary that can be used to store data that needs to be available in all scripts and after agent restarts. Input Parameters are also stored in this dictionary. |
IConnection GetDatabaseConnection(string connectionName) | Returns the specified database connection. The database connection must have been previously defined for the agent or be a shared connection for all agents on the computer. Your script is responsible for opening and closing the connection by calling the OpenDatabase and CloseDatabase methods. |
IInputDataRow GetInputData() | If the current command is a data provider, the data for that command is returned. Otherwise this function searches the command's parents and returns the first found input data. |
IInputDataRow GetInputData(Command command) | If the specified command is a data provider, the data for that command is returned. Otherwise, this function searches the command's parents and returns the first found input data. |
IInputDataRow GetInputData(string commandName) | If the specified command is a data provider, the data for that command is returned. Otherwise, this function searches the command's parents and returns the first found input data. |
IInputDataRow GetInputData(Guid commandId) | If the specified command is a data provider, the data for that command is returned. Otherwise, the function throws an error. |