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.
- C#
- VB.NET
public class Tesseract : Component
Public Class Tesseract
Inherits Component
See: https://github.com/naptha/tesseract.js#tesseractjs.
Constructors
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;
Tesseract(container)
Initializes a new instance of the Tesseract class with a specified container.
| Name | Type | Description |
|---|---|---|
| container | IContainer | An IContainer that represents the container of the component. |
Throws:
- ArgumentNullException container is null.
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
Camera
Control: Returns or sets the Wisej.NET Camera instance to attach to. (Default: null)
See Wisej.Web.Ext.Camera
Enabled
Boolean: Returns or sets whether text-detection is enabled for the associated Camera. Set to true by default. (Default: True)
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.
Keywords
String[]: Returns or sets a list of keywords to filter for. (Default: null)
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
MinimumConfidence
Int32: Returns or sets the minimum confidence interval to accept.
ShowWords
Boolean: Returns or sets whether to show bounding rectangles around detected words in the live camera preview. (Default: True)
Defaults to true.
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.
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
OnAddReferences(list)
Ensures the Camera widget exists in the ComponentManager.
| Parameter | Type | Description |
|---|---|---|
| list | IList |
OnWebEvent(e)
Fires events from the client.
| Parameter | Type | Description |
|---|---|---|
| e | WisejEventArgs | WisejEventArgs |
OnWebRender(config)
Provides the client widget's configuration.
| Parameter | Type | Description |
|---|---|---|
| config | Object | The configuration. |
ScanImageAsync(imageSource)
Scans a given image source (url) and return the discovered text.
| Parameter | Type | Description |
|---|---|---|
| imageSource | String | The 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));
ScanImageAsync(image)
Scans a given Image and return the discovered text.
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
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.
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.