Skip to main content

Tesseract

Namespace: Wisej.Ext.Tesseract

Assembly: Wisej.Ext.Tesseract (4.1.0.0)

A component for extending the functionality of the Wisej Camera to include text detection.

public class Tesseract : Component

See: https://github.com/naptha/tesseract.js#tesseractjs.

Constructors​

Instance member Tesseract()​

Initializes a new instance of the Tesseract without a specified container.

Example:

// Create the component in code and attach it to an existing camera.
var tesseract = new Tesseract
{
Camera = this.camera1,
Language = "eng",
Interval = 1000,
MinimumConfidence = 70
};

tesseract.TextRecognized += (s, e) => label1.Text = e.Text;

Instance member Tesseract(container)​

Initializes a new instance of the Tesseract class with a specified container.

NameTypeDescription
containerIContainerAn IContainer that represents the container of the component.

Throws:

Example:

// Typically generated by the designer in InitializeComponent(),
// so the component is disposed together with its container.
this.components = new System.ComponentModel.Container();
this.tesseract1 = new Wisej.Ext.Tesseract.Tesseract(this.components);
this.tesseract1.Camera = this.camera1;

Properties​

Instance member Camera​

Control: Returns or sets the Wisej.NET Camera instance to attach to. (Default: null)

See Wisej.Web.Ext.Camera

Instance member Enabled​

Boolean: Returns or sets whether text-detection is enabled for the associated Camera. Set to true by default. (Default: True)

Instance member Interval​

Int32: Returns or sets the interval to use in between text detection requests in the live camera preview. (Default: 1500)

The interval is specified in milliseconds.

Instance member Keywords​

String[]: Returns or sets a list of keywords to filter for. (Default: null)

Instance member Language​

String: Returns or sets the detection language to use. (Default: "eng")

See: https://tesseract-ocr.github.io/tessdoc/Data-Files#data-files-for-version-400-november-29-2016

Instance member MinimumConfidence​

Int32: Returns or sets the minimum confidence interval to accept.

Instance member ShowWords​

Boolean: Returns or sets whether to show bounding rectangles around detected words in the live camera preview. (Default: True)

Defaults to true.

Instance member Whitelist​

String: Returns or sets the white listed characters to scan for. (Default: null)

Setting white list characters makes the result only contain these characters, useful if content in image is limited.

Instance member WorkerCount​

Int32: Returns or sets the number of workers used to detect text in the live camera preview. (Default: 1)

A Tesseract.js worker is an object that creates and manages an instance of Tesseract. Think of a worker as a thread that is responsible for doing OCR (Optical Character Recognition) jobs. A higher number of workers is better, but results in increased CPU and battery consumption.

Methods​

Protected member OnAddReferences(list)​

Ensures the Camera widget exists in the ComponentManager.

ParameterTypeDescription
listIList

Protected member OnWebEvent(e)​

Fires events from the client.

ParameterTypeDescription
eWisejEventArgsWisejEventArgs

Protected member OnWebRender(config)​

Provides the client widget's configuration.

ParameterTypeDescription
configObjectThe configuration.

Instance member ScanImageAsync(imageSource)​

Scans a given image source (url) and return the discovered text.

ParameterTypeDescription
imageSourceStringThe input image url.

Returns: Task<ScanResult>. ScanResult object containing the text, list of words, and confidence (accuracy) of the result.

The image source can be an absolute or relative URL, a Wisej.NET resource URL (e.g. the ImageSource of a PictureBox pointing to an embedded resource), or a base64 data URL. To scan an Image instance, use the ScanImageAsync overload instead.

Example:

// Scan an image from a website.
ScanResult result = await tesseract1.ScanImageAsync("https://www.example.com/images/sample.png");
AlertBox.Show(result.Text);

// Scan an embedded resource displayed in a PictureBox.
// Set the build action of the image to "Embedded Resource" and
// assign its resource path to the ImageSource property.
pictureBox1.ImageSource = "resource.wx/WisejWebPageApplication/Images/ITGlogo.png";
result = await tesseract1.ScanImageAsync(pictureBox1.ImageSource);

if (result.Confidence >= tesseract1.MinimumConfidence)
AlertBox.Show(string.Join(", ", result.Words));

Instance member ScanImageAsync(image)​

Scans a given Image and return the discovered text.

ParameterTypeDescription
imageImageThe image to be scanned Image.

Returns: Task<ScanResult>. ScanResult object containing the text, list of words, and confidence (accuracy) of the result.

The image is converted to a PNG base64 data URL and passed to ScanImageAsync. The image can come from any source, such as the Image of a PictureBox set in the designer, a file, or an embedded resource.

Example:

// Scan the image assigned to a PictureBox in the designer.
ScanResult result = await tesseract1.ScanImageAsync(pictureBox1.Image);
AlertBox.Show(result.Text);

// Load an embedded resource ending in "YourImage.png" and scan it.
System.Reflection.Assembly assembly = this.GetType().Assembly;
string resourceName = assembly.GetManifestResourceNames()
.FirstOrDefault(name => name.EndsWith("YourImage.png"));

if (!String.IsNullOrEmpty(resourceName))
{
using (System.IO.Stream resource = assembly.GetManifestResourceStream(resourceName))
using (Image image = Image.FromStream(resource))
{
result = await tesseract1.ScanImageAsync(image);
AlertBox.Show($"{result.Text} (confidence: {result.Confidence})");
}
}

Events​

Instance member TextRecognized​

EventHandler<TextRecognizedEventArgs> Fired when text is recognized by the camera.

TextRecognizedEventArgs contains information about the text discovered, the words in the text, and the confidence (accuracy) of the recognition.

Instance member WorkerError​

EventHandler<String> Fired when a worker throws an error.

A Tesseract.js worker is an object that creates and manages an instance of Tesseract. Think of a worker as a thread that is responsible for doing OCR (Optical Character Recognition) jobs.