gali8 / Tesseract-OCR-iOS

Tesseract OCR iOS is a Framework for iOS7+, compiled also for armv7s and arm64.
http://www.nexor.it
MIT License
4.22k stars 949 forks source link

Swift recognition is faster than Objective-C? #372

Closed anonym24 closed 6 years ago

anonym24 commented 6 years ago

Swift recognition is faster than Objective-C? How is that possible?

Here what I tested (called the next functions for the same image many times)

Swift

let startTime = NSDate().timeIntervalSince1970 * 1000
tesseract.image = imageDigit
tesseract.recognize()
let endTime = NSDate().timeIntervalSince1970 * 1000 - startTime
print("Swift \(endTime) ms")

Objective-C

double startTime = [[NSDate date] timeIntervalSince1970] * 1000.0;
tesseract.image = [imageDigit g8_blackAndWhite];
[tesseract recognize];
double endTime = [[NSDate date] timeIntervalSince1970] * 1000.0 - startTime;
printf("Obj-C %f ms\n", endTime);

Output

Swift 6.02294921875 ms
Obj-C 25.954102 ms
Swift 5.19189453125 ms
Obj-C 41.064697 ms
Swift 5.010986328125 ms
Obj-C 30.672119 ms
Swift 5.11376953125 ms
Obj-C 28.249268 ms
Swift 4.9501953125 ms
Obj-C 36.845215 ms
Swift 4.71728515625 ms
anonym24 commented 6 years ago

SOLVED

for Objective-C I needed to replace

tesseract.image = [imageDigit g8_blackAndWhite];

with

tesseract.image = imageDigit;

please mention about it here https://github.com/gali8/Tesseract-OCR-iOS/wiki/Using-Tesseract-OCR-iOS

now output is ok

Obj-C 7.447998 ms
Swift 9.025146484375 ms
Obj-C 7.285889 ms
Swift 13.0029296875 ms
Obj-C 7.096680 ms
Swift 9.7451171875 ms
Obj-C 7.075928 ms
Swift 8.2158203125 ms
Obj-C 6.884766 ms
Swift 9.750732421875 ms
Obj-C 6.822021 ms
Swift 8.088134765625 ms
Obj-C 7.063965 ms
Swift 7.68115234375 ms
Obj-C 8.116943 ms
Swift 9.4638671875 ms