swift - Why does tesseract OCR recognition quality degrade when run on iOS device versus Simulator -
simply put, near perfect text recognition tesseractocr when run code on iphone 6 simulator, recognition degrades substantially when run same code on actual iphone 6. on device, of degradation occurs near non-text artifacts (e.g., lines). in case, there consistent single character recognition error same alphanumeric string. of text bold, not. there several font sizes.
so question is: know why recognition quality better on simulator , can if improve recognition on iphone?
i have built simple ios test app translates image text using tesseractocrios. eventually, images come device camera, use test image of invoice formatted jpeg. process looks following:
jpeg->uiimage->nsdata->uiimage->tesseract i'm assuming process lossless. intermediate translation nsdata part of overall process because device camera yields image data , photo library stores image data—the use of jpeg test image @ point makes process little convoluted.
to install tesseractocrios followed instructions on wiki. installed tesseractocrios 4.0.0 using following pod file.
platform :ios, '9.0' use_frameworks! workspace 'documentcapturev2' xcodeproj 'documentcapturedemo/documentcapturedemo.xcodeproj/' target 'documentcapturedemo' pod 'tesseractocrios', '4.0.0' end target 'documentcapturedemotests' pod 'tesseractocrios', '4.0.0' end target 'documentcapturedemouitests' pod 'tesseractocrios', '4.0.0' end post_install |installer| installer.pods_project.targets.each |target| target.build_configurations.each |config| config.build_settings['enable_bitcode'] = 'no' end end end the post install bit added make work on iphone 6 device. absent bit of pod file stuff (it took searching find bit of magic), link fails when trying run on device (can't use weak library , enable bitcode).
the code use recognize text below (basically example code on github). did change recognition time 1 10 thinking iphone might need more time. didn't make difference.
func updatepagetext(page: page, image: uiimage?) { if image != nil { // create new `g8recognitionoperation` perform ocr asynchronously // assumed there .traineddata file language pack // want tesseract use in "tessdata" folder in root of // project , "tessdata" folder referenced folder , not // symbolic group in project let operation = g8recognitionoperation(language: "eng") // use original tesseract engine mode in performing recognition // (see g8constants.h) other engine mode options operation.tesseract.enginemode = g8ocrenginemode.tesseractonly; // let tesseract automatically segment page blocks of text // based on analysis (see g8constants.h) other page segmentation // mode options operation.tesseract.pagesegmentationmode = g8pagesegmentationmode.autoonly; // optionally limit time tesseract should spend performing // recognition //operation.tesseract.maximumrecognitiontime = 10.0; // set delegate recognition class // (see `progressimagerecognitionfortesseract` , // `shouldcancelimagerecognitionfortesseract` methods below) operation.delegate = self; // optionally limit tesseract's recognition following whitelist // , blacklist of characters //operation.tesseract.charwhitelist = @"01234"; //operation.tesseract.charblacklist = @"56789"; // set image on tesseract should perform recognition operation.tesseract.image = image; // optionally limit region in image on tesseract should // perform recognition rectangle //operation.tesseract.rect = cgrectmake(20, 20, 100, 100); // specify function block should executed when tesseract // finishes performing recognition on image operation.recognitioncompleteblock = {(tesseract: g8tesseract!)->void in page.text = tesseract.recognizedtext.stringbytrimmingcharactersinset(nscharacterset.whitespaceandnewlinecharacterset()) page.save() } // finally, add recognition operation queue operationqueue.addoperation(operation); } } i assuming uiimage pass updatepagetext complete (i.e., not still loading). have looked @ thresholdedimage on iphone 6 , there nothing odd can see. there's virtually no documentation on tesseract configuration haven't tried there.
Comments
Post a Comment