CARVIEW |
Select Language
HTTP/2 200
date: Tue, 29 Jul 2025 07:05:58 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"a4070706014a30536ff06efd3c0e7bfa"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=UyYKh6%2BmrIMzDoCvtWzM8nTBjN6wWYYVosd9N4KYFkk%2BQs1iZ3EfVolcJTmpmGJsn1a4MR5uTzE78YPiFuUUFG678frMsPJRcuXzB6ZSmAM%2FkAwU6kX5MifX6wS6w2f%2B2AbwiV3As0IUxSXwn3a2zGSzYxXnouFkWS5GdPofcHq5scMjNoTEwzJaG9J%2BeqdlAW08bx9wZ9zL2363GDHhb%2FZrp3qpQxOHmB3cjwbKpgOUALit84hmWI7TAn8cX01qRzB9wB70bKDUahHO8k9G%2Fw%3D%3D--S5yijnz5R%2F7eBlTz--jrUhKvaNwohPK8Ftp9QcHg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1450429739.1753772758; Path=/; Domain=github.com; Expires=Wed, 29 Jul 2026 07:05:58 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Wed, 29 Jul 2026 07:05:58 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: B4AE:397358:52BE79:6989F5:688872D6
Using Tesseract OCR iOS · gali8/Tesseract-OCR-iOS Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 951
Using Tesseract OCR iOS
Adrian edited this page Oct 16, 2017
·
8 revisions
MyViewController.h
#import <TesseractOCR/TesseractOCR.h>
@interface MyViewController : UIViewController <G8TesseractDelegate>
@end
MyViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Languages are used for recognition (e.g. eng, ita, etc.). Tesseract engine
// will search for the .traineddata language file in the tessdata directory.
// For example, specifying "eng+ita" will search for "eng.traineddata" and
// "ita.traineddata". Cube engine will search for "eng.cube.*" files.
// See https://github.com/tesseract-ocr/tessdata.
// Create your G8Tesseract object using the initWithLanguage method:
G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:@"eng+ita"];
// Optionaly: You could specify engine to recognize with.
// G8OCREngineModeTesseractOnly by default. It provides more features and faster
// than Cube engine. See G8Constants.h for more information.
//tesseract.engineMode = G8OCREngineModeTesseractOnly;
// Set up the delegate to receive Tesseract's callbacks.
// self should respond to TesseractDelegate and implement a
// "- (BOOL)shouldCancelImageRecognitionForTesseract:(G8Tesseract *)tesseract"
// method to receive a callback to decide whether or not to interrupt
// Tesseract before it finishes a recognition.
tesseract.delegate = self;
// Optional: Limit the character set Tesseract should try to recognize from
tesseract.charWhitelist = @"0123456789";
// This is wrapper for common Tesseract variable kG8ParamTesseditCharWhitelist:
// [tesseract setVariableValue:@"0123456789" forKey:kG8ParamTesseditCharBlacklist];
// See G8TesseractParameters.h for a complete list of Tesseract variables
// Optional: Limit the character set Tesseract should not try to recognize from
//tesseract.charBlacklist = @"OoZzBbSs";
// Specify the image Tesseract should recognize on
tesseract.image = [[UIImage imageNamed:@"image_sample.jpg"] g8_blackAndWhite];
// Optional: Limit the area of the image Tesseract should recognize on to a rectangle
tesseract.rect = CGRectMake(20, 20, 100, 100);
// Optional: Limit recognition time with a few seconds
tesseract.maximumRecognitionTime = 2.0;
// Start the recognition
[tesseract recognize];
// Retrieve the recognized text
NSLog(@"%@", [tesseract recognizedText]);
// You could retrieve more information about recognized text with that methods:
NSArray *characterBoxes = [tesseract recognizedBlocksByIteratorLevel:G8PageIteratorLevelSymbol];
NSArray *paragraphs = [tesseract recognizedBlocksByIteratorLevel:G8PageIteratorLevelParagraph];
NSArray *characterChoices = tesseract.characterChoices;
UIImage *imageWithBlocks = [tesseract imageWithBlocks:characterBoxes drawText:YES thresholded:NO];
}
- (void)progressImageRecognitionForTesseract:(G8Tesseract *)tesseract {
NSLog(@"progress: %lu", (unsigned long)tesseract.progress);
}
- (BOOL)shouldCancelImageRecognitionForTesseract:(G8Tesseract *)tesseract {
return NO; // return YES, if you need to interrupt tesseract before it finishes
}
MyViewController.h
#import <TesseractOCR/TesseractOCR.h>
@interface MyViewController : UIViewController
@end
MyViewController.m
- (void)viewDidLoad
{
// Create RecognitionOperation
G8RecognitionOperation *operation = [[G8RecognitionOperation alloc] initWithLanguage:@"eng+ita"];
// Configure inner G8Tesseract object as described before
operation.tesseract.charWhitelist = @"01234567890";
operation.tesseract.image = [[UIImage imageNamed:@"image_sample.jpg"] g8_blackAndWhite];
// Setup the recognitionCompleteBlock to receive the Tesseract object
// after text recognition. It will hold the recognized text.
operation.recognitionCompleteBlock = ^(G8Tesseract *recognizedTesseract) {
// Retrieve the recognized text upon completion
NSLog(@"%@", [recognizedTesseract recognizedText]);
};
// Add operation to queue
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
}
Make sure that you have used an Objective-C bridging header to include the library. Instructions on configuring a bridging header file can be found in the Apple Developer Library.
ViewController.swift
import UIKit
import TesseractOCR
class ViewController: UIViewController, G8TesseractDelegate {
override func viewDidLoad() {
super.viewDidLoad()
var tesseract:G8Tesseract = G8Tesseract(language:"eng+ita")
//tesseract.language = "eng+ita"
tesseract.delegate = self
tesseract.charWhitelist = "01234567890"
tesseract.image = UIImage(named: "image_sample.jpg")
tesseract.recognize()
print(tesseract.recognizedText)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func shouldCancelImageRecognitionForTesseract(tesseract: G8Tesseract!) -> Bool {
return false // return true if you need to interrupt tesseract before it finishes
}
}
Clone this wiki locally
You can’t perform that action at this time.